Skip to content

Commit

Permalink
wtf: Simplify SQL statement shard_allocation
Browse files Browse the repository at this point in the history
> This looks unreasonable complicated to just translate the primary boolean
> into a string.

Co-authored-by: Sebastian Utz <[email protected]>
  • Loading branch information
amotl and seut committed Jun 13, 2024
1 parent 21b746e commit d191cb9
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cratedb_toolkit/wtf/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,11 @@ class Shards:
name="shard_allocation",
sql="""
SELECT
IF(s.primary = TRUE, 'primary', 'replica') AS shard_type,
COALESCE(shards, 0) AS shards
FROM
UNNEST([true, false]) s(primary)
LEFT JOIN (
SELECT primary, COUNT(*) AS shards
IF(primary = TRUE, 'primary', 'replica') AS shard_type,
COUNT(*) AS shards
FROM sys.allocations
WHERE current_state != 'STARTED'
GROUP BY 1
) a ON s.primary = a.primary;
""",
label="Shard Allocation",
description="Support identifying issues with shard allocation.",
Expand Down

0 comments on commit d191cb9

Please sign in to comment.