-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster_debug.c
More file actions
3771 lines (3501 loc) · 183 KB
/
Copy pathcluster_debug.c
File metadata and controls
3771 lines (3501 loc) · 183 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-------------------------------------------------------------------------
*
* cluster_debug.c
* pgrac cluster diagnostic snapshot (Stage 0.29).
*
* Backs the pg_cluster_state view via the cluster_dump_state SRF.
* Aggregates read-only state from every cluster subsystem into a
* single (category, key, value) result set:
*
* shmem ClusterShmem ctl block (magic / version / node_id_at_
* init / created_at)
* guc cluster.* GUC current values
* ic active interconnect tier vtable name
* inject armed_count + per-injection-point fault_type / hits
* (uses cluster_injection_get_count + _get_state_at)
* pgstat per-counter name / value (uses cluster_pgstat_get_count
* + _get_at)
* conf pgrac.conf topology summary (node_count + self_in_topology)
* phase cluster_phase lifecycle string
*
* Output is ordered by category (fixed registration order) and by
* key inside each category (lexicographic, except injection-point
* children which follow registry order). See spec-0.29 §3.1 and
* docs/cluster-debug-design.md §2 for the contract.
*
* Adding a new category at Stage 1+: write a static dump_<name>
* helper following the existing pattern, append a call in
* cluster_dump_state, and update docs/cluster-debug-design.md §3.1
* + matching TAP / unit tests (CLAUDE.md rule 10 three-way sync).
*
*
* 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 <sqlrush@gmail.com>
*
* IDENTIFICATION
* src/backend/cluster/cluster_debug.c
*
* NOTES
* This is a pgrac-original file (no derivation from PostgreSQL).
* cluster_debug.c is the cross-module aggregator: it reads from
* cluster_shmem / cluster_guc / cluster_ic / cluster_inject /
* cluster_pgstat / cluster_conf / cluster_elog public APIs. The
* dependency direction is one-way (cluster_debug imports them, not
* the reverse). No cluster_*.c file should ever include
* cluster_debug.h.
*
* The SRF entry point is unconditionally compiled because pg_proc.dat
* references it in both build modes; the body is #ifdef USE_PGRAC_
* CLUSTER guarded. Internal helpers / dumpers are compiled out
* completely on --disable-cluster builds (spec-0.3 contract).
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "funcapi.h"
#include "utils/builtins.h"
#include "cluster/cluster_debug.h"
#include "cluster/cluster_inject.h" /* CLUSTER_INJECTION_POINT (always-linked SRF) */
/* SRF info-V1 declaration -- always linked because pg_proc.dat
* references this regardless of build mode. */
PG_FUNCTION_INFO_V1(cluster_dump_state);
#ifdef USE_PGRAC_CLUSTER
#include "cluster/cluster_cf_stats.h" /* CF counters (spec-5.6 Dc4) */
#include "cluster/cluster_conf.h"
#include "cluster/cluster_elog.h" /* cluster_phase */
#include "cluster/cluster_diag.h" /* cluster_diag_status (spec-1.13 D12) */
#include "cluster/cluster_hang.h" /* Hang Manager dump (spec-5.11 D4) */
#include "cluster/cluster_hang_resolve.h" /* Hang Manager disposition dump (spec-5.12 D8) */
#include "cluster/cluster_lck.h" /* cluster_lck_status (spec-1.12 D12) */
#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_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) */
#include "cluster/cluster_ts.h" /* TT tablespace-DDL lock counters (spec-5.7 D5) */
#include "cluster/cluster_ko.h" /* KO object-reuse flush counters (spec-5.7 D6) */
#include "cluster/cluster_sequence.h" /* cluster_sq_* counters (spec-5.4 D9) */
#include "cluster/cluster_advisory.h" /* cluster_advisory_* counters (spec-5.5 D8) */
#include "cluster/cluster_lmd.h" /* cluster_lmd_* observability accessors (spec-2.19 D10) */
#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_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_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) */
#include "cluster/cluster_hw_lease.h" /* space-lease counters (spec-6.12d) */
#include "cluster/cluster_resolver_cache.h" /* cluster_resolver_cache_* counters (spec-5.55 D8) */
#include "cluster/cluster_cr_coordinator_stat.h" /* cluster_cr_coordinator_* counters (spec-5.57 D3) */
#include "cluster/cluster_wal_state.h" /* wal_state registry dump (spec-4.2 D5) */
#include "cluster/cluster_wal_thread.h" /* wal_thread dump accessors (spec-4.1 D7) */
#include "cluster/cluster_tt_durable.h" /* cluster_tt_durable_* counters (spec-3.11 D8) */
#include "cluster/cluster_grd_outbound.h"
#include "cluster/cluster_grd_pending.h"
#include "cluster/cluster_grd_work_queue.h"
#include "cluster/cluster_cssd.h" /* cluster_cssd_status (spec-2.5 D12) */
#include "cluster/cluster_stats.h" /* cluster_stats_status (spec-1.14 D12) */
#include "cluster/cluster_undo_cleaner.h"
#include "cluster/cluster_undo_horizon.h" /* D5-5 brake observability (spec-5.22e) */ /* dump_undo_cleaner (spec-3.13 D1) */
#include "cluster/cluster_undo_gcs.h" /* undo GCS grant-plane counters (spec-5.22b D2-6) */
#include "cluster/cluster_lmon.h" /* cluster_lmon_status (spec-1.11 Sprint B D12) */
#include "cluster/cluster_guc.h"
#include "catalog/pg_control.h" /* DBState (spec-4.3 plan dump) */
#include "cluster/cluster_recovery_plan.h"
#include "cluster/cluster_recovery_worker.h"
#include "cluster/cluster_recovery_merge.h" /* is_materialized (spec-4.5a D11) */
#include "cluster/cluster_reconfig.h" /* spec-5.14 D6 touched counters */
#include "cluster/cluster_touched_peers.h" /* spec-5.14 D6 self_touched_hex */
#include "cluster/cluster_block_recovery.h" /* block-recovery counters (spec-4.10 D6) */
#include "cluster/cluster_thread_recovery.h" /* online thread-recovery counters (spec-4.11 D5) */
#include "cluster/cluster_write_fence.h" /* write-fence counters (spec-4.12 D7) */
#include "cluster/cluster_catalog_stats.h" /* catalog counters (spec-6.14 D10b) */
#include "cluster/cluster_oid_lease.h" /* catalog category (spec-6.14 D10) */
#include "cluster/cluster_relmap_authority.h" /* relmap authority state (spec-6.14 D5) */
#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_pcm_x_convert.h" /* PCM-X external FIFO observability */
#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_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"
#include "cluster/cluster_shmem.h"
#include "cluster/storage/cluster_shared_fs.h" /* dump_shared_fs (stage 1.1) */
#include "cluster/storage/cluster_smgr.h" /* cluster_smgr_active_relation_count (stage 1.2) */
#include "lib/stringinfo.h"
#include "utils/timestamp.h"
/* ============================================================
* Row-emission helper.
*
* Every dumper funnels through emit_row to write a single
* (category, key, value) triple to the SRF tuplestore. category
* and key are always non-NULL string literals; value may have been
* palloc'd by the caller and is consumed by CStringGetTextDatum.
* ============================================================ */
static void
emit_row(ReturnSetInfo *rsinfo, const char *category, const char *key, const char *value)
{
Datum values[3];
bool nulls[3] = { false, false, false };
values[0] = CStringGetTextDatum(category);
values[1] = CStringGetTextDatum(key);
values[2] = CStringGetTextDatum(value ? value : "(null)");
tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
}
/* ============================================================
* Value-formatting helpers.
*
* Each returns a palloc'd C string in CurrentMemoryContext (the
* tuplestore copies the bytes via CStringGetTextDatum, so the
* caller does not need to track lifetime). Callers must pass the
* result through emit_row immediately.
* ============================================================ */
static char *
fmt_int32(int32 v)
{
return psprintf("%d", v);
}
static char *
fmt_int64(int64 v)
{
return psprintf(INT64_FORMAT, v);
}
static char *
fmt_uint32_hex(uint32 v)
{
return psprintf("0x%08X", v);
}
/* Hardening v1.0.1 (round 8 P2): full 64-bit hex formatter for SCN
* and other 64-bit identifiers. scn_current_encoded was previously
* truncated to the high 32 bits, hiding the entire local_scn (low 56
* bits). All future cluster shmem 64-bit fields should use this. */
static char *
fmt_uint64_hex(uint64 v)
{
return psprintf("0x%016" INT64_MODIFIER "X", v);
}
static char *
fmt_bool(bool v)
{
return pstrdup(v ? "t" : "f");
}
static char *
fmt_timestamptz(TimestampTz v)
{
return DatumGetCString(DirectFunctionCall1(timestamptz_out, TimestampTzGetDatum(v)));
}
static const char *
str_or_default(const char *s, const char *fallback)
{
if (s == NULL)
return fallback;
if (s[0] == '\0')
return fallback;
return s;
}
static const char *
fault_type_to_text(ClusterInjectFaultType t)
{
switch (t) {
case CLUSTER_FAULT_NONE:
return "none";
case CLUSTER_FAULT_ERROR:
return "error";
case CLUSTER_FAULT_WARNING:
return "warning";
case CLUSTER_FAULT_SLEEP:
return "sleep";
case CLUSTER_FAULT_CRASH:
return "crash";
case CLUSTER_FAULT_SKIP:
return "skip";
case CLUSTER_FAULT_SKIP_N:
return "skipn"; /* spec-7.2a count-based skip (:skipn:N arm syntax) */
}
return "unknown";
}
static const char *
ic_tier_to_text(int t)
{
switch ((ClusterICTier)t) {
case CLUSTER_IC_TIER_STUB:
return "stub";
case CLUSTER_IC_TIER_MOCK:
return "mock";
case CLUSTER_IC_TIER_1:
return "tier1";
case CLUSTER_IC_TIER_2:
return "tier2";
case CLUSTER_IC_TIER_3:
return "tier3";
}
return "unknown";
}
static const char *
cf_delayed_cleanout_to_text(int mode)
{
switch ((ClusterCfDelayedCleanoutMode)mode) {
case CLUSTER_CF_DELAYED_CLEANOUT_OFF:
return "off";
case CLUSTER_CF_DELAYED_CLEANOUT_READER:
return "reader";
case CLUSTER_CF_DELAYED_CLEANOUT_EAGER:
return "eager";
}
return "unknown";
}
/* ============================================================
* Per-category dumpers.
*
* Order below matches the registration order in cluster_dump_state.
* Stage 1+ subsystems append a new dumper here; see file header for
* the procedure.
* ============================================================ */
static void
dump_shmem(ReturnSetInfo *rsinfo)
{
int idx;
ClusterShmemRegion region;
StringInfoData key_buf;
if (ClusterShmem == NULL) {
emit_row(rsinfo, "shmem", "magic", "(null)");
emit_row(rsinfo, "shmem", "version_packed", "(null)");
emit_row(rsinfo, "shmem", "node_id_at_init", "(null)");
emit_row(rsinfo, "shmem", "created_at", "(null)");
} else {
emit_row(rsinfo, "shmem", "magic", fmt_uint32_hex(ClusterShmem->magic));
emit_row(rsinfo, "shmem", "version_packed", fmt_uint32_hex(ClusterShmem->version_packed));
emit_row(rsinfo, "shmem", "node_id_at_init", fmt_int32(ClusterShmem->node_id_at_init));
emit_row(rsinfo, "shmem", "created_at", fmt_timestamptz(ClusterShmem->created_at));
}
/*
* Stage 1.3: per-region rollup from the cluster shmem registry.
* region_count + total_bytes are the summary; region.<name>.bytes
* + region.<name>.owner expand each registered region for direct
* lookup. Both surfaces complement pg_cluster_shmem (the SQL view)
* which is the structured per-row source of truth.
*/
emit_row(rsinfo, "shmem", "region_count", fmt_int32(cluster_shmem_get_region_count()));
emit_row(rsinfo, "shmem", "total_bytes", fmt_int64((int64)cluster_shmem_get_total_bytes()));
initStringInfo(&key_buf);
idx = 0;
while (cluster_shmem_iter_regions(&idx, ®ion)) {
resetStringInfo(&key_buf);
appendStringInfo(&key_buf, "region.%s.bytes", region.name);
emit_row(rsinfo, "shmem", key_buf.data, fmt_int64((int64)region.size_fn()));
resetStringInfo(&key_buf);
appendStringInfo(&key_buf, "region.%s.owner", region.name);
emit_row(rsinfo, "shmem", key_buf.data, region.owner_subsys);
}
pfree(key_buf.data);
}
static void
dump_guc(ReturnSetInfo *rsinfo)
{
const ClusterSharedFsOps *shared_fs_active;
emit_row(rsinfo, "guc", "cluster.config_file", str_or_default(cluster_config_file, "(empty)"));
emit_row(rsinfo, "guc", "cluster.injection_points",
str_or_default(cluster_injection_points, "(empty)"));
emit_row(rsinfo, "guc", "cluster.interconnect_tier",
ic_tier_to_text(cluster_interconnect_tier));
emit_row(rsinfo, "guc", "cluster.node_id", fmt_int32(cluster_node_id));
/*
* Stage 1.1: cluster.shared_storage_backend value as a human-readable
* backend name (looked up from the active vtable rather than mapping
* the int again here). Pre-init backends fall back to "(none)" so
* the row remains present for diagnostic stability.
*/
shared_fs_active = cluster_shared_fs_get_active_ops();
emit_row(rsinfo, "guc", "cluster.shared_storage_backend",
shared_fs_active != NULL ? shared_fs_active->name : "(none)");
/* Stage 1.2: cluster.smgr_user_relations boolean. */
emit_row(rsinfo, "guc", "cluster.smgr_user_relations", fmt_bool(cluster_smgr_user_relations));
/* Stage 1.3: cluster.shmem_max_regions int. */
emit_row(rsinfo, "guc", "cluster.shmem_max_regions", fmt_int32(cluster_shmem_max_regions));
emit_row(rsinfo, "guc", "cluster.cf_terminal_authority",
fmt_bool(cluster_cf_terminal_authority));
emit_row(rsinfo, "guc", "cluster.cf_delayed_cleanout",
cf_delayed_cleanout_to_text(cluster_cf_delayed_cleanout));
emit_row(rsinfo, "guc", "cluster.smart_fusion", fmt_bool(cluster_smart_fusion));
emit_row(rsinfo, "guc", "cluster.smart_fusion_tier_min",
ic_tier_to_text(cluster_smart_fusion_tier_min));
emit_row(rsinfo, "guc", "cluster.smart_fusion_commit_brake_timeout_ms",
fmt_int32(cluster_smart_fusion_commit_brake_timeout_ms));
emit_row(rsinfo, "guc", "cluster.smart_fusion_origin_durable_gossip_ms",
fmt_int32(cluster_smart_fusion_origin_durable_gossip_ms));
}
static void
dump_ic(ReturnSetInfo *rsinfo)
{
const char *tier_name = "(null)";
if (ClusterICOps_Active != NULL && ClusterICOps_Active->tier_name != NULL)
tier_name = ClusterICOps_Active->tier_name;
emit_row(rsinfo, "ic", "active_tier_name", tier_name);
/*
* Hardening v1.0.1 F3: expose listener metadata so observers can
* detect "LMON has respawned, listener was rebound". Useful for
* t/077 TAP and runtime diagnostics; the fd itself is process-
* local and never exposed.
*/
if (ClusterICOps_Active == &ClusterICOps_Tier1) {
emit_row(rsinfo, "ic", "tier1_listener_pid",
fmt_int32((int32)cluster_ic_tier1_get_listener_pid()));
emit_row(rsinfo, "ic", "tier1_listener_incarnation",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_listener_incarnation()));
emit_row(rsinfo, "ic", "tier1_listener_port",
fmt_int32((int32)cluster_ic_tier1_get_listener_port()));
/* PGRAC: GCS-race round-4c tier1-partial-IO F2 — backpressured-tail
* drain wakeups per plane (the DATA plane parked such tails forever
* before the fix; a loaded S3 run must show the DATA row moving). */
emit_row(
rsinfo, "ic", "tier1_writable_drain_control",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_writable_drain(CLUSTER_IC_PLANE_CONTROL)));
emit_row(
rsinfo, "ic", "tier1_writable_drain_data",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_writable_drain(CLUSTER_IC_PLANE_DATA)));
/* PGRAC: GCS serve-stall round-5 — per-peer outbound FIFO accounting
* per plane. admitted - promoted = frames currently queued (the S3
* gate proves the queue bounds and returns to zero); not_admitted
* counts explicit refusals (peer mid-HELLO or FIFO at capacity). */
emit_row(
rsinfo, "ic", "tier1_fifo_admitted_control",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_fifo_admitted(CLUSTER_IC_PLANE_CONTROL)));
emit_row(
rsinfo, "ic", "tier1_fifo_admitted_data",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_fifo_admitted(CLUSTER_IC_PLANE_DATA)));
emit_row(
rsinfo, "ic", "tier1_fifo_promoted_control",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_fifo_promoted(CLUSTER_IC_PLANE_CONTROL)));
emit_row(
rsinfo, "ic", "tier1_fifo_promoted_data",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_fifo_promoted(CLUSTER_IC_PLANE_DATA)));
emit_row(rsinfo, "ic", "tier1_send_not_admitted_control",
psprintf(UINT64_FORMAT,
cluster_ic_tier1_get_send_not_admitted(CLUSTER_IC_PLANE_CONTROL)));
emit_row(
rsinfo, "ic", "tier1_send_not_admitted_data",
psprintf(UINT64_FORMAT, cluster_ic_tier1_get_send_not_admitted(CLUSTER_IC_PLANE_DATA)));
emit_row(rsinfo, "ic", "tier1_fifo_dropped_close_control",
psprintf(UINT64_FORMAT,
cluster_ic_tier1_get_fifo_dropped_close(CLUSTER_IC_PLANE_CONTROL)));
emit_row(rsinfo, "ic", "tier1_fifo_dropped_close_data",
psprintf(UINT64_FORMAT,
cluster_ic_tier1_get_fifo_dropped_close(CLUSTER_IC_PLANE_DATA)));
}
/*
* spec-2.2 additive amendment (spec-5.22e D5 prereq): per-peer learned
* HELLO capability records (generation-bound) + the PEER_CAPS_REPLY
* validation-drop counter. The directed capability matrix TAP legs and
* rolling-upgrade compat legs read these.
*/
emit_row(rsinfo, "ic", "peer_capabilities", cluster_sf_peer_capabilities_summary());
emit_row(rsinfo, "ic", "caps_reply_reject_count",
psprintf(UINT64_FORMAT, cluster_sf_caps_reply_reject_count()));
}
static void
dump_inject(ReturnSetInfo *rsinfo)
{
int n;
emit_row(rsinfo, "inject", "armed_count", fmt_int32(cluster_injection_armed_count));
n = cluster_injection_get_count();
for (int i = 0; i < n; i++) {
const char *name = NULL;
ClusterInjectFaultType type = CLUSTER_FAULT_NONE;
uint64 hits = 0;
char *key_type;
char *key_hits;
if (!cluster_injection_get_state_at(i, &name, &type, &hits))
continue;
if (name == NULL)
continue;
key_type = psprintf("%s.fault_type", name);
key_hits = psprintf("%s.hits", name);
emit_row(rsinfo, "inject", key_type, fault_type_to_text(type));
emit_row(rsinfo, "inject", key_hits, fmt_int64((int64)hits));
}
}
static void
dump_pgstat(ReturnSetInfo *rsinfo)
{
int n = cluster_pgstat_get_count();
for (int i = 0; i < n; i++) {
const char *name = NULL;
uint64 value = 0;
if (!cluster_pgstat_get_at(i, &name, &value))
continue;
if (name == NULL)
continue;
emit_row(rsinfo, "pgstat", name, fmt_int64((int64)value));
}
}
static void
dump_conf(ReturnSetInfo *rsinfo)
{
int node_count = cluster_conf_node_count();
bool self_in_topology = false;
if (cluster_node_id >= 0)
self_in_topology = (cluster_conf_lookup_node(cluster_node_id) != NULL);
emit_row(rsinfo, "conf", "node_count", fmt_int32(node_count));
emit_row(rsinfo, "conf", "self_in_topology", fmt_bool(self_in_topology));
}
static void
dump_phase(ReturnSetInfo *rsinfo)
{
ClusterStartupPhase current = cluster_current_phase();
TimestampTz started = cluster_phase_started_at(current);
char history_buf[1024];
/*
* Spec-1.10.2 F7 (2026-05-04 codex review fix): the SQL-visible
* "cluster_phase" key MUST derive from shmem-backed
* cluster_current_phase() instead of the legacy const char *
* cluster_phase global. The legacy mirror is fork-coherent (child
* inherits postmaster's last write) but EXEC_BACKEND children
* re-exec and re-run the static initializer -> the mirror reverts
* to "pre_init" while shmem still holds the live phase. Reading
* via cluster_startup_phase_to_string(current) closes that gap.
*/
emit_row(rsinfo, "phase", "cluster_phase", cluster_startup_phase_to_string(current));
/*
* Spec-1.10 (2026-05-03) phase 4 new keys (HC5 fixed-size ring on
* phase_history; user 修订 5).
*/
emit_row(rsinfo, "phase", "phase_enum_value", fmt_int32((int32)current));
if (started == 0) {
emit_row(rsinfo, "phase", "phase_started_at", "(unset)");
emit_row(rsinfo, "phase", "phase_elapsed_seconds", fmt_int64(0));
} else {
emit_row(rsinfo, "phase", "phase_started_at", pstrdup(timestamptz_to_str(started)));
emit_row(rsinfo, "phase", "phase_elapsed_seconds",
fmt_int64(cluster_phase_elapsed_seconds()));
}
cluster_phase_history_format(history_buf, sizeof(history_buf));
emit_row(rsinfo, "phase", "phase_history",
pstrdup(history_buf[0] != '\0' ? history_buf : "(empty)"));
}
/*
* dump_lmon -- Stage 1.11 Sprint B LMON state diagnostics
* (spec-1.11 D12). Six SQL keys exposed to pg_cluster_state.lmon
* for operators to monitor LMON liveness without log-grepping. All
* reads go through cluster_lmon_status() / cluster_lmon_state shmem
* (HC2 SSOT, HC3 limited scope).
*/
static void
dump_lmon(ReturnSetInfo *rsinfo)
{
ClusterLmonStatus s = cluster_lmon_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
int64 iters;
emit_row(rsinfo, "lmon", "lmon_status", cluster_lmon_status_to_string(s));
emit_row(rsinfo, "lmon", "lmon_status_enum_value", fmt_int32((int32)s));
/*
* Spec-1.11.1 F11 (codex round 4 P2 fix): emit the 5 keys Sprint B
* D12 left out so cluster.lmon_main_loop_interval GUC + LMON
* liveness are SQL-verifiable. pid==0 / timestamps==0 surface as
* "(unset)" to match other lifecycle keys; main_loop_iters is
* always int8.
*/
pid = cluster_lmon_pid();
emit_row(rsinfo, "lmon", "lmon_pid", pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_lmon_spawned_at();
emit_row(rsinfo, "lmon", "lmon_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_lmon_ready_at();
emit_row(rsinfo, "lmon", "lmon_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_lmon_last_liveness_tick_at();
emit_row(rsinfo, "lmon", "lmon_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_lmon_main_loop_iters();
emit_row(rsinfo, "lmon", "lmon_main_loop_iters", fmt_int64(iters));
emit_row(rsinfo, "lmon", "lmon_last_iter_us", fmt_int64((int64)cluster_lmon_last_iter_us()));
emit_row(rsinfo, "lmon", "lmon_max_iter_us", fmt_int64((int64)cluster_lmon_max_iter_us()));
emit_row(rsinfo, "lmon", "lmon_slow_iter_count",
fmt_int64((int64)cluster_lmon_slow_iter_count()));
}
/*
* dump_lck -- Stage 1.12 LCK state diagnostics (mirrors dump_lmon
* spec-1.11.1 F11 6 keys complete model). Sprint A starts with full
* 6 keys, not the Sprint B starter trap that bit spec-1.11 D12.
*/
static void
dump_lck(ReturnSetInfo *rsinfo)
{
ClusterLckStatus s = cluster_lck_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
int64 iters;
emit_row(rsinfo, "lck", "lck_status", cluster_lck_status_to_string(s));
emit_row(rsinfo, "lck", "lck_status_enum_value", fmt_int32((int32)s));
pid = cluster_lck_pid();
emit_row(rsinfo, "lck", "lck_pid", pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_lck_spawned_at();
emit_row(rsinfo, "lck", "lck_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_lck_ready_at();
emit_row(rsinfo, "lck", "lck_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_lck_last_liveness_tick_at();
emit_row(rsinfo, "lck", "lck_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_lck_main_loop_iters();
emit_row(rsinfo, "lck", "lck_main_loop_iters", fmt_int64(iters));
}
/*
* dump_diag -- Stage 1.13 DIAG state diagnostics (mirrors dump_lck /
* dump_lmon F11 7-key complete model: 2 status + 5 lifecycle).
*/
static void
dump_diag(ReturnSetInfo *rsinfo)
{
ClusterDiagStatus s = cluster_diag_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
int64 iters;
emit_row(rsinfo, "diag", "diag_status", cluster_diag_status_to_string(s));
emit_row(rsinfo, "diag", "diag_status_enum_value", fmt_int32((int32)s));
pid = cluster_diag_pid();
emit_row(rsinfo, "diag", "diag_pid", pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_diag_spawned_at();
emit_row(rsinfo, "diag", "diag_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_diag_ready_at();
emit_row(rsinfo, "diag", "diag_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_diag_last_liveness_tick_at();
emit_row(rsinfo, "diag", "diag_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_diag_main_loop_iters();
emit_row(rsinfo, "diag", "diag_main_loop_iters", fmt_int64(iters));
}
/*
* dump_hang -- spec-5.11 Hang Manager diagnostics.
*
* Emits the aggregate sampling state + cumulative counters, the spec-5.8
* aggregate deadlock context (D6 reader: cluster-wide, the only per-proc
* confirmed-deadlock signal shipped 5.8 exposes), and one group of per-row
* keys per long-wait sample. All of it comes from a single consistent
* snapshot copied under the DIAG LWLock (cluster_hang_get_dump_data), so
* the rows have real shmem backing — never a hollow dump (spec §2.1b / R4).
*/
static void
dump_hang(ReturnSetInfo *rsinfo)
{
ClusterHangDumpData data;
int i;
cluster_hang_get_dump_data(&data);
emit_row(rsinfo, "hang", "hang_manager_enabled", fmt_bool(cluster_hang_manager_enabled));
emit_row(rsinfo, "hang", "hang_dump_enabled", fmt_bool(cluster_hang_dump_enabled));
emit_row(rsinfo, "hang", "hang_threshold_ms", fmt_int32(cluster_hang_threshold_ms));
emit_row(rsinfo, "hang", "hang_sample_interval_ms", fmt_int32(cluster_hang_sample_interval_ms));
emit_row(rsinfo, "hang", "hang_max_sampled", fmt_int32(cluster_hang_max_sampled));
if (!data.available) {
/* DIAG region not attached (e.g. cluster disabled): zeroed view. */
emit_row(rsinfo, "hang", "hang_available", fmt_bool(false));
return;
}
emit_row(rsinfo, "hang", "hang_available", fmt_bool(true));
emit_row(rsinfo, "hang", "hang_sample_epoch", fmt_int64((int64)data.store.sample_epoch));
emit_row(rsinfo, "hang", "hang_last_sample_at",
data.last_sample_at == 0 ? "(unset)"
: pstrdup(timestamptz_to_str(data.last_sample_at)));
emit_row(rsinfo, "hang", "hang_last_dump_emitted_at",
data.last_dump_emitted_at == 0
? "(unset)"
: pstrdup(timestamptz_to_str(data.last_dump_emitted_at)));
emit_row(rsinfo, "hang", "hang_long_wait_count", fmt_int64(data.long_wait_count));
emit_row(rsinfo, "hang", "hang_longest_wait_us", fmt_int64(data.longest_wait_us));
emit_row(rsinfo, "hang", "hang_truncated", fmt_bool(data.store.truncated));
emit_row(rsinfo, "hang", "hang_n_samples", fmt_int32(data.store.n_samples));
/* Cumulative counters (D8). */
emit_row(rsinfo, "hang", "hang_samples_taken", fmt_int64((int64)data.counters.samples_taken));
emit_row(rsinfo, "hang", "hang_long_waits_seen",
fmt_int64((int64)data.counters.long_waits_seen));
emit_row(rsinfo, "hang", "hang_dumps_emitted", fmt_int64((int64)data.counters.dumps_emitted));
emit_row(rsinfo, "hang", "hang_incomplete_sample_count",
fmt_int64((int64)data.counters.incomplete_samples));
emit_row(rsinfo, "hang", "hang_excluded_deadlock_count",
fmt_int64((int64)data.counters.excluded_deadlock));
emit_row(rsinfo, "hang", "hang_excluded_idle_count",
fmt_int64((int64)data.counters.excluded_idle));
emit_row(rsinfo, "hang", "hang_excluded_bgworker_count",
fmt_int64((int64)data.counters.excluded_bgworker));
emit_row(rsinfo, "hang", "hang_proc_signal_dump_count",
fmt_int64((int64)data.counters.proc_signal_dumps));
emit_row(rsinfo, "hang", "hang_error_count", fmt_int64((int64)data.counters.error_count));
/*
* spec-5.11 D6 — spec-5.8 reader: aggregate cluster-wide deadlock context.
* The shipped 5.8 surface exposes deadlock confirmation only as these
* aggregate counters (not a per-proc confirmed-cycle flag), so per-sample
* in_confirmed_deadlock stays false; the live per-proc exclusion is
* forward to a 5.9 per-proc victim/confirmed signal (D0 re-ground).
*/
emit_row(rsinfo, "hang", "hang_deadlock_confirmed_count",
fmt_int64((int64)cluster_lmd_deadlock_confirmed_count_get()));
emit_row(rsinfo, "hang", "hang_cycle_detected_count",
fmt_int64((int64)cluster_lmd_cycle_detected_count_get()));
/*
* spec-5.12 D8 — Hang Manager disposition state + cumulative counters.
* Appended to the same `hang` category (no new category); the mode comes
* from the GUC, the rest from a consistent copy of the DIAG region.
*/
{
ClusterHangResolveCounters rc;
cluster_hang_resolve_get_counters(&rc);
emit_row(rsinfo, "hang", "hang_resolution_mode",
cluster_hang_resolve_mode_str(cluster_hang_resolution_mode));
emit_row(rsinfo, "hang", "hang_resolve_evaluations",
fmt_int64((int64)rc.resolve_evaluations));
emit_row(rsinfo, "hang", "hang_victims_selected", fmt_int64((int64)rc.victims_selected));
emit_row(rsinfo, "hang", "hang_soft_cancels_issued",
fmt_int64((int64)rc.soft_cancels_issued));
emit_row(rsinfo, "hang", "hang_terminates_issued", fmt_int64((int64)rc.terminates_issued));
emit_row(rsinfo, "hang", "hang_resolved_confirmed",
fmt_int64((int64)rc.resolved_confirmed));
emit_row(rsinfo, "hang", "hang_resolution_failed", fmt_int64((int64)rc.resolution_failed));
emit_row(rsinfo, "hang", "hang_hard_skipped", fmt_int64((int64)rc.hard_skipped));
emit_row(rsinfo, "hang", "hang_non_actionable_skipped",
fmt_int64((int64)rc.non_actionable_skipped));
emit_row(rsinfo, "hang", "hang_over_excluded", fmt_int64((int64)rc.over_excluded));
emit_row(rsinfo, "hang", "hang_unprovable_root_skipped",
fmt_int64((int64)rc.unprovable_root_skipped));
emit_row(rsinfo, "hang", "hang_aba_revalidate_failed",
fmt_int64((int64)rc.aba_revalidate_failed));
emit_row(rsinfo, "hang", "hang_not_confirmed_yet", fmt_int64((int64)rc.not_confirmed_yet));
emit_row(rsinfo, "hang", "hang_no_safe_victim", fmt_int64((int64)rc.no_safe_victim));
emit_row(rsinfo, "hang", "hang_degraded_to_timeout",
fmt_int64((int64)rc.degraded_to_timeout));
emit_row(rsinfo, "hang", "hang_advisory_recommendations",
fmt_int64((int64)rc.advisory_recommendations));
emit_row(rsinfo, "hang", "hang_resolve_last_victim_pid", fmt_int32(rc.last_victim_pid));
emit_row(rsinfo, "hang", "hang_resolve_last_action",
cluster_hang_action_tier_str(rc.last_action));
}
/* Per-row long-wait samples (real shmem backing). */
for (i = 0; i < data.store.n_samples; i++) {
const ClusterHangSampleSlot *s = &data.store.slots[i];
emit_row(rsinfo, "hang", psprintf("hang_sample%d_pid", i), fmt_int32(s->pid));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_wait_event", i),
s->wait_event[0] ? pstrdup(s->wait_event) : "(none)");
emit_row(rsinfo, "hang", psprintf("hang_sample%d_wait_ms", i),
fmt_int64(s->duration_us / 1000));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_duration_kind", i),
s->duration_kind == HANG_DUR_TRUE ? "true" : "approx");
emit_row(rsinfo, "hang", psprintf("hang_sample%d_source", i),
cluster_hang_wait_source_str(s->source));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_quality", i),
cluster_hang_quality_str(s->quality));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_blocker_pid", i),
fmt_int32(s->blocker_pid));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_blocker_remote_node", i),
fmt_int32(s->blocker_remote_node));
emit_row(rsinfo, "hang", psprintf("hang_sample%d_in_confirmed_deadlock", i),
fmt_bool(s->in_confirmed_deadlock));
}
}
/*
* dump_cluster_stats -- Stage 1.14 Cluster Stats state diagnostics
* (mirrors dump_diag F11 7-key complete model: 2 status + 5 lifecycle).
*/
static void
dump_cluster_stats(ReturnSetInfo *rsinfo)
{
ClusterStatsStatus s = cluster_stats_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
int64 iters;
emit_row(rsinfo, "cluster_stats", "cluster_stats_status", cluster_stats_status_to_string(s));
emit_row(rsinfo, "cluster_stats", "cluster_stats_status_enum_value", fmt_int32((int32)s));
pid = cluster_stats_pid();
emit_row(rsinfo, "cluster_stats", "cluster_stats_pid",
pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_stats_spawned_at();
emit_row(rsinfo, "cluster_stats", "cluster_stats_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_stats_ready_at();
emit_row(rsinfo, "cluster_stats", "cluster_stats_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_stats_last_liveness_tick_at();
emit_row(rsinfo, "cluster_stats", "cluster_stats_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_stats_main_loop_iters();
emit_row(rsinfo, "cluster_stats", "cluster_stats_main_loop_iters", fmt_int64(iters));
}
/*
* dump_cluster_cssd -- Stage 2.5 CSSD aux process state diagnostics
* (mirrors dump_cluster_stats F11 7-key complete model: 2 status + 5
* lifecycle).
*/
static void
dump_cluster_cssd(ReturnSetInfo *rsinfo)
{
ClusterCssdStatus s = cluster_cssd_get_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
uint64 iters;
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_status", cluster_cssd_status_to_string(s));
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_status_enum_value", fmt_int32((int32)s));
pid = cluster_cssd_get_pid();
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_pid",
pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_cssd_get_spawned_at();
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_cssd_get_ready_at();
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_cssd_get_last_liveness_tick_at();
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_cssd_get_main_loop_iters();
emit_row(rsinfo, "cluster_cssd", "cluster_cssd_main_loop_iters", fmt_int64((int64)iters));
/*
* spec-2.5 Hardening v1.0.3: declared-alive aggregate observability
* substrate. Pure observability — these keys MUST NOT be consumed
* for any decision path (quorum_state / reconfig / fence broadcast).
* Provided as SQL surface for future fence/reconfig/SCN consumers
* to verify substrate health from operator perspective.
*/
{
int alive_count = cluster_cssd_get_declared_alive_count();
uint8 alive_bitmap[CLUSTER_CSSD_PEER_ALIVE_BITMAP_BYTES];
char hex_buf[2 + CLUSTER_CSSD_PEER_ALIVE_BITMAP_BYTES * 2 + 1];
int i;
emit_row(rsinfo, "cluster_cssd", "cssd.declared_alive_count",
fmt_int32((int32)alive_count));
cluster_cssd_get_declared_alive_bitmap(alive_bitmap);
hex_buf[0] = '0';
hex_buf[1] = 'x';
for (i = 0; i < CLUSTER_CSSD_PEER_ALIVE_BITMAP_BYTES; i++)
snprintf(hex_buf + 2 + (i * 2), 3, "%02x", alive_bitmap[i]);
hex_buf[2 + CLUSTER_CSSD_PEER_ALIVE_BITMAP_BYTES * 2] = '\0';
emit_row(rsinfo, "cluster_cssd", "cssd.declared_alive_bitmap", pstrdup(hex_buf));
}
}
/*
* dump_undo_cleaner -- Stage 3.13 Undo Cleaner aux process state
* diagnostics (mirrors dump_cluster_stats F11 7-key model: 2 status +
* 5 lifecycle).
*/
static void
dump_undo_cleaner(ReturnSetInfo *rsinfo)
{
UndoCleanerStatus s = cluster_undo_cleaner_status();
pid_t pid;
TimestampTz spawned_at, ready_at, last_tick;
int64 iters;
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_status",
cluster_undo_cleaner_status_to_string(s));
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_status_enum_value", fmt_int32((int32)s));
pid = cluster_undo_cleaner_pid();
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_pid",
pid == 0 ? "(unset)" : fmt_int64((int64)pid));
spawned_at = cluster_undo_cleaner_spawned_at();
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_spawned_at",
spawned_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(spawned_at)));
ready_at = cluster_undo_cleaner_ready_at();
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_ready_at",
ready_at == 0 ? "(unset)" : pstrdup(timestamptz_to_str(ready_at)));
last_tick = cluster_undo_cleaner_last_liveness_tick_at();
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_last_liveness_tick_at",
last_tick == 0 ? "(unset)" : pstrdup(timestamptz_to_str(last_tick)));
iters = cluster_undo_cleaner_main_loop_iters();
emit_row(rsinfo, "undo_cleaner", "undo_cleaner_main_loop_iters", fmt_int64(iters));
}
/*
* dump_xid_stripe -- spec-6.15 D6 xid stripe face diagnostics.
*
* 14 keys over the activation face (disk/slot state, floor, epoch),
* the D3 herding plane (own floor/hwm promise, cluster min/max active
* hwm), the D5d replay face (replay-learned floor + active slot
* bitmap) and the spec-7.1 D3-a mxid stripe face (activated mxid
* floor -- 0 = extension absent -- plus the half-space-refusal and
* underivable-read guardrail counters). Values come from one shmem
* snapshot plus the multixact counter atomics.
*/
static void
dump_xid_stripe(ReturnSetInfo *rsinfo)
{
static const char *disk_states[] = { "unknown", "absent", "published", "corrupt" };
static const char *slot_states[] = { "unknown", "absent", "mine", "retired", "corrupt" };
ClusterXidStripeObs obs;
cluster_xid_stripe_observe(&obs);
emit_row(rsinfo, "xid_stripe", "xid_stripe_disk_state",
obs.disk_state < lengthof(disk_states) ? pstrdup(disk_states[obs.disk_state])
: fmt_int32((int32)obs.disk_state));
emit_row(rsinfo, "xid_stripe", "xid_stripe_slot_state",
obs.slot_state < lengthof(slot_states) ? pstrdup(slot_states[obs.slot_state])
: fmt_int32((int32)obs.slot_state));
emit_row(rsinfo, "xid_stripe", "xid_stripe_activated_floor",
fmt_int64((int64)obs.activated_floor_full));
emit_row(rsinfo, "xid_stripe", "xid_stripe_mode_epoch",
fmt_int64((int64)obs.stride_mode_epoch));
emit_row(rsinfo, "xid_stripe", "xid_stripe_my_slot_floor",
fmt_int64((int64)obs.my_slot_floor_full));
emit_row(rsinfo, "xid_stripe", "xid_stripe_my_hwm_promise",
fmt_int64((int64)obs.my_hwm_on_disk));
emit_row(rsinfo, "xid_stripe", "xid_stripe_herding_floor",
fmt_int64((int64)obs.herding_floor_full));
emit_row(rsinfo, "xid_stripe", "xid_stripe_cluster_min_hwm",
fmt_int64((int64)obs.cluster_min_active_hwm));
emit_row(rsinfo, "xid_stripe", "xid_stripe_cluster_max_hwm",
fmt_int64((int64)obs.cluster_max_active_hwm));
emit_row(rsinfo, "xid_stripe", "xid_stripe_replay_floor",
fmt_int64((int64)obs.replay_floor_full));
emit_row(rsinfo, "xid_stripe", "xid_stripe_replay_active_bitmap",
fmt_uint64_hex((uint64)obs.replay_active_bitmap));
emit_row(rsinfo, "xid_stripe", "mxid_stripe_activated_floor",
fmt_int64((int64)obs.activated_mxid_floor));
emit_row(rsinfo, "xid_stripe", "mxid_stripe_disk_state", fmt_int64((int64)obs.mxid_disk_state));
emit_row(rsinfo, "xid_stripe", "mxid_stripe_halfspace_refusals",