Skip to content

[#18983] DocDB: Sort yb-admin list_all_tablet_servers by status then host#32476

Open
ag26jan wants to merge 1 commit into
yugabyte:masterfrom
ag26jan:db-8417-yb-admin-list-tservers-sort
Open

[#18983] DocDB: Sort yb-admin list_all_tablet_servers by status then host#32476
ag26jan wants to merge 1 commit into
yugabyte:masterfrom
ag26jan:db-8417-yb-admin-list-tservers-sort

Conversation

@ag26jan

@ag26jan ag26jan commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Sort yb-admin list_all_tablet_servers output for easier operator scanning at scale.

  • Primary sort: ALIVE tablet servers before DEAD ones
  • Secondary sort: RPC host (alphabetical string compare), with UUID as tie-breaker
  • Sorting is implemented in SortListTabletServerEntries() and covered by a unit test

Fixes #18983

Testing Done:

  • ./yb_build.sh release --cxx-test yb-admin_client-test --gtest_filter ListTabletServerSortTest.AliveBeforeDeadThenHost --sj --skip-pg-parquet --no-odyssey --no-ybc
  • Manually verified build/release-clang21-dynamic-arm64-ninja/bin/yb-admin list_all_tablet_servers shows alive hosts first, then dead hosts, each group sorted by hostname

After fix:

build/release-clang21-dynamic-arm64-ninja/bin/yb-admin -master_addresses 127.0.0.1:7100,127.0.0.1:7110,127.0.0.1:7120 list_all_tablet_servers
Tablet Server UUID               RPC Host/Port Heartbeat delay Status   Reads/s  Writes/s Uptime   SST total size  SST uncomp size SST #files      Memory   Broadcast Host/Port
a3b423b811f04c819fd0bccabccadd9f yb-bignode-node1:9100 0.79s           ALIVE    0.20     0.00     8552     257.43 KB       964.62 KB       3               93.81 MB yb-bignode-node1:9100
1e70b965485a402f8555c961e92b8ed5 yb-bignode-node2:9100 0.78s           ALIVE    0.00     0.00     8543     103.68 KB       551.67 KB       1               75.74 MB yb-bignode-node2:9100
137117e25f094bda9c91a75ccf121a6e yb-bignode-node3:9100 0.95s           ALIVE    0.00     0.00     8515     0 B             0 B             0               41.17 MB yb-bignode-node3:9100
9cc7f27663cd4bbe81869a990cc01100 yb-bignode-node4:9100 0.76s           ALIVE    0.00     0.00     8535     257.43 KB       964.62 KB       3               76.44 MB yb-bignode-node4:9100
693f5820f2f74dd1a55936b9b9ed2ff0 yb-bignode-node5:9100 0.53s           ALIVE    0.00     0.00     8534     0 B             0 B             0               43.22 MB yb-bignode-node5:9100
70f50b8d894547beaa2a698ba6f2ce4e yb-bignode-node6:9100 0.65s           ALIVE    0.00     0.00     8533     0 B             0 B             0               63.91 MB yb-bignode-node6:9100
d726e87208c449198dbd76f58942b7e5 yb-bignode-node7:9100 0.85s           ALIVE    0.00     0.00     8531     0 B             0 B             0               58.38 MB yb-bignode-node7:9100
79ea0d242cc445b79a7296818b240a99 yb-bignode-node8:9100 0.44s           ALIVE    0.00     0.00     8534     0 B             0 B             0               44.23 MB yb-bignode-node8:9100
f99c37be78234103ae89fa4356d4ae8e yb-bignode-node10:9100 8149.29s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node10:9100
e050458be63441a294d583b3eb703aff yb-bignode-node11:9100 8125.11s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node11:9100
807bcd5a3f314ff8af5f1b24cde2aef1 yb-bignode-node12:9100 8108.61s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node12:9100
ff8a67d84fa6447c90a19e325c6012e7 yb-bignode-node13:9100 8107.54s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node13:9100
9ac59894d8814e97a9e0bd3f05b85eeb yb-bignode-node14:9100 8106.29s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node14:9100
6e2661e85242440487e626d043729ee4 yb-bignode-node15:9100 8105.47s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node15:9100
54072ccf9a7b4b0586f2cfaf36b2ceb4 yb-bignode-node9:9100 8175.09s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node9:9100

Before Fix:

 yb-admin -master_addresses 127.0.0.1:7100,127.0.0.1:7110,127.0.0.1:7120 list_all_tablet_servers
Tablet Server UUID               RPC Host/Port Heartbeat delay Status   Reads/s  Writes/s Uptime   SST total size  SST uncomp size SST #files      Memory   Broadcast Host/Port
137117e25f094bda9c91a75ccf121a6e yb-bignode-node3:9100 0.34s           ALIVE    0.00     0.00     8660     0 B             0 B             0               40.30 MB yb-bignode-node3:9100
1e70b965485a402f8555c961e92b8ed5 yb-bignode-node2:9100 0.17s           ALIVE    0.00     0.40     8683     103.68 KB       551.67 KB       1               74.67 MB yb-bignode-node2:9100
54072ccf9a7b4b0586f2cfaf36b2ceb4 yb-bignode-node9:9100 8316.63s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node9:9100
693f5820f2f74dd1a55936b9b9ed2ff0 yb-bignode-node5:9100 0.91s           ALIVE    0.00     0.00     8674     0 B             0 B             0               43.79 MB yb-bignode-node5:9100
6e2661e85242440487e626d043729ee4 yb-bignode-node15:9100 8247.01s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node15:9100
70f50b8d894547beaa2a698ba6f2ce4e yb-bignode-node6:9100 0.04s           ALIVE    0.00     0.00     8678     0 B             0 B             0               63.03 MB yb-bignode-node6:9100
79ea0d242cc445b79a7296818b240a99 yb-bignode-node8:9100 0.83s           ALIVE    0.00     0.00     8674     0 B             0 B             0               44.25 MB yb-bignode-node8:9100
807bcd5a3f314ff8af5f1b24cde2aef1 yb-bignode-node12:9100 8250.15s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node12:9100
9ac59894d8814e97a9e0bd3f05b85eeb yb-bignode-node14:9100 8247.83s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node14:9100
9cc7f27663cd4bbe81869a990cc01100 yb-bignode-node4:9100 0.14s           ALIVE    0.00     0.00     8675     257.43 KB       964.62 KB       3               75.63 MB yb-bignode-node4:9100
a3b423b811f04c819fd0bccabccadd9f yb-bignode-node1:9100 0.18s           ALIVE    0.20     0.00     8692     257.43 KB       964.62 KB       3               94.02 MB yb-bignode-node1:9100
d726e87208c449198dbd76f58942b7e5 yb-bignode-node7:9100 0.24s           ALIVE    0.00     0.00     8677     0 B             0 B             0               58.54 MB yb-bignode-node7:9100
e050458be63441a294d583b3eb703aff yb-bignode-node11:9100 8266.65s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node11:9100
f99c37be78234103ae89fa4356d4ae8e yb-bignode-node10:9100 8290.83s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node10:9100
ff8a67d84fa6447c90a19e325c6012e7 yb-bignode-node13:9100 8249.08s        DEAD     0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node13:9100

For all alive nodes normal behavior:

yb-admin -master_addresses yb-bignode-node1:7100,yb-bignode-node2:7100,yb-bignode-node4:7100 list_all_tablet_servers
Tablet Server UUID               RPC Host/Port Heartbeat delay Status   Reads/s  Writes/s Uptime   SST total size  SST uncomp size SST #files      Memory   Broadcast Host/Port
137117e25f094bda9c91a75ccf121a6e yb-bignode-node3:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node3:9100
1e70b965485a402f8555c961e92b8ed5 yb-bignode-node2:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node2:9100
54072ccf9a7b4b0586f2cfaf36b2ceb4 yb-bignode-node9:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node9:9100
693f5820f2f74dd1a55936b9b9ed2ff0 yb-bignode-node5:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node5:9100
6e2661e85242440487e626d043729ee4 yb-bignode-node15:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node15:9100
70f50b8d894547beaa2a698ba6f2ce4e yb-bignode-node6:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node6:9100
79ea0d242cc445b79a7296818b240a99 yb-bignode-node8:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node8:9100
807bcd5a3f314ff8af5f1b24cde2aef1 yb-bignode-node12:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node12:9100
9ac59894d8814e97a9e0bd3f05b85eeb yb-bignode-node14:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node14:9100
9cc7f27663cd4bbe81869a990cc01100 yb-bignode-node4:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node4:9100
a3b423b811f04c819fd0bccabccadd9f yb-bignode-node1:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node1:9100
d726e87208c449198dbd76f58942b7e5 yb-bignode-node7:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node7:9100
e050458be63441a294d583b3eb703aff yb-bignode-node11:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node11:9100
f99c37be78234103ae89fa4356d4ae8e yb-bignode-node10:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node10:9100
ff8a67d84fa6447c90a19e325c6012e7 yb-bignode-node13:9100 0.01s           ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node13:9100

But after fix:

build/release-clang21-dynamic-arm64-ninja/bin/yb-admin -master_addresses yb-bignode-node1:7100,yb-bignode-node2:7100,yb-bignode-node4:7100 list_all_tablet_servers
Tablet Server UUID               RPC Host/Port Heartbeat delay Status   Reads/s  Writes/s Uptime   SST total size  SST uncomp size SST #files      Memory   Broadcast Host/Port
a3b423b811f04c819fd0bccabccadd9f yb-bignode-node1:9100 16.64s          ALIVE    0.00     1.57     712      257.43 KB       964.62 KB       3               97.71 MB yb-bignode-node1:9100
f99c37be78234103ae89fa4356d4ae8e yb-bignode-node10:9100 25.01s          ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node10:9100
e050458be63441a294d583b3eb703aff yb-bignode-node11:9100 16.71s          ALIVE    0.00     0.00     891      0 B             0 B             0               75.22 MB yb-bignode-node11:9100
807bcd5a3f314ff8af5f1b24cde2aef1 yb-bignode-node12:9100 0.00s           ALIVE    0.00     0.00     728      0 B             0 B             0               73.61 MB yb-bignode-node12:9100
ff8a67d84fa6447c90a19e325c6012e7 yb-bignode-node13:9100 25.01s          ALIVE    0.00     0.00     0        0 B             0 B             0               0 B      yb-bignode-node13:9100
9ac59894d8814e97a9e0bd3f05b85eeb yb-bignode-node14:9100 16.70s          ALIVE    0.00     0.00     712      0 B             0 B             0               70.15 MB yb-bignode-node14:9100
6e2661e85242440487e626d043729ee4 yb-bignode-node15:9100 0.04s           ALIVE    0.00     0.00     906      0 B             0 B             0               36.68 MB yb-bignode-node15:9100
1e70b965485a402f8555c961e92b8ed5 yb-bignode-node2:9100 0.00s           ALIVE    0.00     0.00     729      103.68 KB       551.67 KB       1               85.68 MB yb-bignode-node2:9100
137117e25f094bda9c91a75ccf121a6e yb-bignode-node3:9100 17.03s          ALIVE    0.00     0.00     9662     0 B             0 B             0               39.40 MB yb-bignode-node3:9100
9cc7f27663cd4bbe81869a990cc01100 yb-bignode-node4:9100 16.64s          ALIVE    0.00     0.00     712      257.43 KB       964.62 KB       3               88.60 MB yb-bignode-node4:9100
693f5820f2f74dd1a55936b9b9ed2ff0 yb-bignode-node5:9100 0.00s           ALIVE    0.00     0.00     9697     0 B             0 B             0               40.04 MB yb-bignode-node5:9100
70f50b8d894547beaa2a698ba6f2ce4e yb-bignode-node6:9100 16.66s          ALIVE    0.00     0.00     712      0 B             0 B             0               77.66 MB yb-bignode-node6:9100
d726e87208c449198dbd76f58942b7e5 yb-bignode-node7:9100 16.66s          ALIVE    0.00     0.00     712      0 B             0 B             0               74.03 MB yb-bignode-node7:9100
79ea0d242cc445b79a7296818b240a99 yb-bignode-node8:9100 17.03s          ALIVE    0.00     0.00     9680     0 B             0 B             0               42.83 MB yb-bignode-node8:9100
54072ccf9a7b4b0586f2cfaf36b2ceb4 yb-bignode-node9:9100 16.66s          ALIVE    0.00     0.00     712      0 B             0 B             0               72.46 MB yb-bignode-node9:9100

What you're seeing

All 15 rows are ALIVE, so the first key (alive before dead) does not change anything. Ordering is purely by hostname string compare (alphabetical/lexicographic).

Position Host Why
1 node1 Starts with ...node1
2–7 node10node15 After ...node1, the next char is 05, which sorts before ...node2
8–15 node2node9 ...node2 comes after ...node15 in string order

So this order:

node1 → node10 → node11 → … → node15 → node2 → node3 → … → node9

is exactly what string sort produces.

Why node10 is before node2

String compare is character-by-character:

yb-bignode-node1...
yb-bignode-node2...
              ↑
              '1' < '2'  →  node10... sorts before node2

That is the classic node2 vs node10 lexicographic ordering.

Bottom line: The sort matches the agreed behavior. The surprising order is from lexicographic hostnames, not a broken comparator.

In real world the sorting will look more simple and human readable because nodes generally follows name > AZ.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces sorting functionality for the tablet server list in yb-admin, ensuring alive servers are listed before dead ones, followed by host and UUID sorting. It also includes a new test suite to verify this behavior. The feedback suggests optimizing the sorting implementation in SortListTabletServerEntries to sort the RepeatedPtrField in-place directly, avoiding unnecessary auxiliary allocations and deep copies of protobuf messages.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/yb/tools/yb-admin_util.cc Outdated
@ag26jan

ag26jan commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces sorting for the tablet server list in yb-admin, ordering alive servers before dead ones, followed by host/port, and using the UUID as a tie-breaker. The feedback suggests optimizing the comparator to avoid dynamic memory allocations by directly comparing protobuf fields, removing an unused header as a result, and expanding the unit tests to cover the UUID tie-breaker logic when hostnames are identical.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/yb/tools/yb-admin_util.cc Outdated
Comment thread src/yb/tools/yb-admin_util.cc Outdated
Comment thread src/yb/tools/yb-admin_client-test.cc
@ag26jan

ag26jan commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements sorting for the tablet server list in yb-admin so that alive servers are displayed before dead ones, with secondary sorting by host, port, and UUID. A unit test was also added to verify this behavior. The review feedback recommends replacing the global kEmptyHost string with std::string_view in the comparison helper to prevent potential static initialization/destruction order issues and avoid copy overhead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/yb/tools/yb-admin_util.cc
Comment thread src/yb/tools/yb-admin_util.cc
…us then host

Sort tablet server list output alive-first, then by RPC host, port, and
UUID tie-break. Sort in place on RepeatedPtrField and compare protobuf
fields directly in the comparator. Add a unit test for sort ordering.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ag26jan ag26jan force-pushed the db-8417-yb-admin-list-tservers-sort branch from d1d95fc to 83ef229 Compare July 3, 2026 08:27
@ag26jan ag26jan self-assigned this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request : Listing of hostnames (nodenames, IPs) in alfabetical order.

1 participant