Skip to content

Add vector_index_compact_read_bytes metric to track compaction input size#30360

Open
keisku wants to merge 1 commit intoyugabyte:masterfrom
keisku:vector_index_compact_read_bytes
Open

Add vector_index_compact_read_bytes metric to track compaction input size#30360
keisku wants to merge 1 commit intoyugabyte:masterfrom
keisku:vector_index_compact_read_bytes

Conversation

@keisku
Copy link
Copy Markdown
Contributor

@keisku keisku commented Feb 18, 2026

Part of #28578 and follow up on 82e7741#diff-c2003959336de6b22d907014e32e29d09f1d194097b380dd542a91f4d6505680


Set up a testing env.

./bin/ysqlsh -c "CREATE EXTENSION IF NOT EXISTS vector;"
./bin/ysqlsh -c "CREATE TABLE IF NOT EXISTS items (id int PRIMARY KEY, embedding vector(3));"
./bin/ysqlsh -c "CREATE INDEX IF NOT EXISTS items_embedding_idx ON items USING ybhnsw (embedding vector_l2_ops);"

The metrics are per-tserver, so we need to query the correct node. Find which tserver leads the index tablet.

./build/latest/bin/yb-admin --master_addresses 127.0.0.1:7100,127.0.0.2:7100,127.0.0.3:7100 list_all_masters
Master UUID                             RPC Host/Port           State           Role    Broadcast Host/Port
1e72c027e9d74934bfebcba681588fa0        127.0.0.1:7100          ALIVE           FOLLOWER        N/A
eac81bb7e1fb4bf1bd277978cd1aec35        127.0.0.2:7100          ALIVE           FOLLOWER        N/A
89979012063047b895171a8301ffedcc        127.0.0.3:7100          ALIVE           LEADER  N/A

Verify metrics start at zero.

curl -s http://127.0.0.3:9000/metrics | jq . | grep -A2 vector_index_compact
        "name": "vector_index_compact_write_bytes",
        "value": 0
      },
--
        "name": "vector_index_compact_read_bytes",
        "value": 0
      },

Metrics remain at 0 after INSERT — 10k vectors is well below the 100k flush threshold (vector_index_initial_chunk_size), so no chunks reach disk and compaction never triggers.

./bin/ysqlsh -c "INSERT INTO items SELECT i, ARRAY[random(), random(), random()]::vector FROM generate_series(1, 10000) i;"

curl -s http://127.0.0.3:9000/varz\?raw 2>&1 | grep vector_index_initial_chunk_size
--vector_index_initial_chunk_size=100000

Force vector index compaction.

./build/latest/bin/yb-admin -master_addresses 127.0.0.3:7100 compact_table ysql.yugabyte items ADD_VECTOR_INDEXES
Compacted [yugabyte.items [ysql_schema=public] [000034e10000300080000000000040f9]] tables and associated vector indexes.

grep -hr 'Compaction input' /Users/keisukeumegaki/yugabyte-data/node-3/disk-1/yb-data/tserver/logs
I0218 10:34:03.594872 1884237824 vector_lsm.cc:2472] T 6d235c3f23a54e90889eb0a6475f4126 P 703f5f16dcd340be9142b5a3bf82d9c9 VI 000034e10000300080000000000040fe: Compaction input [chunks: 2, indexes: 1, vectors: 10000]

curl -s http://127.0.0.3:9000/metrics | jq . | grep -A2 vector_index_compact
        "name": "vector_index_compact_write_bytes",
        "value": 840357
      },
--
        "name": "vector_index_compact_read_bytes",
        "value": 841451
      },

Note

Low Risk
Adds a new counter and increments it during compaction without changing compaction behavior or persistence logic; main risk is metric miscounting due to relying on chunk file_size().

Overview
Adds a new per-tserver metric, vector_index_compact_read_bytes, to track total input bytes read during Vector LSM compactions.

VectorLSM::DoCompact now sums file_size() across the compaction scope and increments the new counter alongside existing compact_write_bytes, and unit tests are updated/extended to assert the read metric stays at 0 when no compaction occurs and increases appropriately for both background and manual compactions.

Written by Cursor Bugbot for commit 9a18f30. This will update automatically on new commits. Configure here.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 18, 2026

Deploy Preview for infallible-bardeen-164bc9 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2cfdbbc
🔍 Latest deploy log https://app.netlify.com/projects/infallible-bardeen-164bc9/deploys/69b0c13dc0fde30008e0c417
😎 Deploy Preview https://deploy-preview-30360--infallible-bardeen-164bc9.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@keisku keisku marked this pull request as ready for review February 18, 2026 08:04
@hari90 hari90 requested a review from spolitov February 18, 2026 19:16
@keisku keisku force-pushed the vector_index_compact_read_bytes branch from 37c1a29 to 9a18f30 Compare February 26, 2026 00:39
@keisku
Copy link
Copy Markdown
Contributor Author

keisku commented Feb 26, 2026

@spolitov Any chance you could take a look at this PR?

@keisku keisku force-pushed the vector_index_compact_read_bytes branch from 9a18f30 to 2cfdbbc Compare March 11, 2026 01:11
@keisku
Copy link
Copy Markdown
Contributor Author

keisku commented Mar 11, 2026

@hari90 Any chance you could take a look at this PR?

@hari90 hari90 requested a review from arybochkin March 11, 2026 17:12
@hari90
Copy link
Copy Markdown
Contributor

hari90 commented Mar 11, 2026

@keisku sorry for the delay

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.

3 participants