Skip to content

Commit 6affe01

Browse files
committed
CNDB-15946: Revamp SAI metrics for fetched/returned keys/partitions/rows/tombstones
The metrics partitionsRead, rowsFiltered, rowsPreFiltered and shadowedPrimaryKeyCount, which dodn't always work as expected, are replaced by these metrics: * keysFetched: Number of partition/row keys that will be used to fetch rows from the base table. * partitionsFetched: Number of live partitions fetched from the base table, before post-filtering and sorting. Note that currently ANN fetches one partition per index key, without any grouping of same-partition clusterings. * partitionsReturned: Number of live partitions returned to the coordinator, after post-filtering and sorting. * partitionTombstonesFetched: Number of deleted partitions found when reading the base table. * rowsFetched: Number of live rows fetched from the base table, before post-filtering and sorting. * rowsReturned: Number of live rows returned to the coordinator, after post-filtering and sorting. * rowTombstonesFetched: Number deleted rows or row ranges found when reading the base table. StorageAttachedIndexSearcher is modified to use the command timestamp, rather than getting the current time everytime a query timestamp is needed, which was possibly buggy and inefficient.
1 parent 3950114 commit 6affe01

File tree

9 files changed

+1638
-168
lines changed

9 files changed

+1638
-168
lines changed

src/java/org/apache/cassandra/index/sai/QueryContext.java

Lines changed: 116 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,31 @@ public class QueryContext
4444

4545
private final LongAdder sstablesHit = new LongAdder();
4646
private final LongAdder segmentsHit = new LongAdder();
47-
private final LongAdder partitionsRead = new LongAdder();
48-
private final LongAdder rowsPreFiltered = new LongAdder();
49-
private final LongAdder rowsFiltered = new LongAdder();
47+
48+
/**
49+
* The partition/row keys that will be used to fetch rows from the base table.
50+
* They will be either partition keys in AA, or row keys in the later row-aware disk formats.
51+
*/
52+
private final LongAdder keysFetched = new LongAdder();
53+
54+
/** The number of live partitions fetched from the storage engine, before post-filtering. */
55+
private final LongAdder partitionsFetched = new LongAdder();
56+
57+
/** The number of live partitions returned to the coordinator, after post-filtering. */
58+
private final LongAdder partitionsReturned = new LongAdder();
59+
60+
/** The number of deleted partitions that are fetched. */
61+
private final LongAdder partitionTombstonesFetched = new LongAdder();
62+
63+
/** The number of live rows fetched from the storage engine, before post-filtering. */
64+
private final LongAdder rowsFetched = new LongAdder();
65+
66+
/** The number of live rows returned to the coordinator, after post-filtering. */
67+
private final LongAdder rowsReturned = new LongAdder();
68+
69+
/** The number of deleted individual rows or ranges of rows that are fetched. */
70+
private final LongAdder rowTombstonesFetched = new LongAdder();
71+
5072
private final LongAdder trieSegmentsHit = new LongAdder();
5173

5274
private final LongAdder bkdPostingListsHit = new LongAdder();
@@ -64,8 +86,6 @@ public class QueryContext
6486

6587
private float annRerankFloor = 0.0f; // only called from single-threaded setup code
6688

67-
private final LongAdder shadowedPrimaryKeyCount = new LongAdder();
68-
6989
// Determines the order of using indexes for filtering and sorting.
7090
// Null means the query execution order hasn't been decided yet.
7191
private FilterSortOrder filterSortOrder = null;
@@ -92,49 +112,81 @@ public void addSstablesHit(long val)
92112
{
93113
sstablesHit.add(val);
94114
}
115+
95116
public void addSegmentsHit(long val) {
96117
segmentsHit.add(val);
97118
}
98-
public void addPartitionsRead(long val)
119+
120+
public void addKeysFetched(long val)
121+
{
122+
keysFetched.add(val);
123+
}
124+
125+
public void addPartitionsFetched(long val)
126+
{
127+
partitionsFetched.add(val);
128+
}
129+
130+
public void addPartitionsReturned(long val)
99131
{
100-
partitionsRead.add(val);
132+
partitionsReturned.add(val);
101133
}
102-
public void addRowsFiltered(long val)
134+
135+
public void addPartitionTombstonesFetched(long val)
103136
{
104-
rowsFiltered.add(val);
137+
partitionTombstonesFetched.add(val);
105138
}
106-
public void addRowsPreFiltered(long val)
139+
140+
public void addRowsFetched(long val)
107141
{
108-
rowsPreFiltered.add(val);
142+
rowsFetched.add(val);
109143
}
144+
145+
public void addRowsReturned(long val)
146+
{
147+
rowsReturned.add(val);
148+
}
149+
150+
public void addRowTombstonesFetched(long val)
151+
{
152+
rowTombstonesFetched.add(val);
153+
}
154+
110155
public void addTrieSegmentsHit(long val)
111156
{
112157
trieSegmentsHit.add(val);
113158
}
159+
114160
public void addBkdPostingListsHit(long val)
115161
{
116162
bkdPostingListsHit.add(val);
117163
}
164+
118165
public void addBkdSegmentsHit(long val)
119166
{
120167
bkdSegmentsHit.add(val);
121168
}
169+
122170
public void addBkdPostingsSkips(long val)
123171
{
124172
bkdPostingsSkips.add(val);
125173
}
174+
126175
public void addBkdPostingsDecodes(long val)
127176
{
128177
bkdPostingsDecodes.add(val);
129178
}
179+
130180
public void addTriePostingsSkips(long val)
131181
{
132182
triePostingsSkips.add(val);
133183
}
184+
134185
public void addTriePostingsDecodes(long val)
135186
{
136187
triePostingsDecodes.add(val);
137188
}
189+
138190
public void addQueryTimeouts(long val)
139191
{
140192
queryTimeouts.add(val);
@@ -156,53 +208,86 @@ public long sstablesHit()
156208
{
157209
return sstablesHit.longValue();
158210
}
211+
159212
public long segmentsHit() {
160213
return segmentsHit.longValue();
161214
}
162-
public long partitionsRead()
215+
216+
public long keysFetched()
163217
{
164-
return partitionsRead.longValue();
218+
return keysFetched.longValue();
165219
}
166-
public long rowsFiltered()
220+
221+
public long partitionsFetched()
167222
{
168-
return rowsFiltered.longValue();
223+
return partitionsFetched.longValue();
169224
}
170-
public long rowsPreFiltered()
225+
226+
public long partitionsReturned()
227+
{
228+
return partitionsReturned.longValue();
229+
}
230+
231+
public long partitionTombstonesFetched()
232+
{
233+
return partitionTombstonesFetched.longValue();
234+
}
235+
236+
public long rowsFetched()
237+
{
238+
return rowsFetched.longValue();
239+
}
240+
241+
public long rowsReturned()
242+
{
243+
return rowsReturned.longValue();
244+
}
245+
246+
public long rowTombstonesFetched()
171247
{
172-
return rowsPreFiltered.longValue();
248+
return rowTombstonesFetched.longValue();
173249
}
250+
174251
public long trieSegmentsHit()
175252
{
176253
return trieSegmentsHit.longValue();
177254
}
255+
178256
public long bkdPostingListsHit()
179257
{
180258
return bkdPostingListsHit.longValue();
181259
}
260+
182261
public long bkdSegmentsHit()
183262
{
184263
return bkdSegmentsHit.longValue();
185264
}
265+
186266
public long bkdPostingsSkips()
187267
{
188268
return bkdPostingsSkips.longValue();
189269
}
270+
190271
public long bkdPostingsDecodes()
191272
{
192273
return bkdPostingsDecodes.longValue();
193274
}
275+
194276
public long triePostingsSkips()
195277
{
196278
return triePostingsSkips.longValue();
197279
}
280+
198281
public long triePostingsDecodes()
199282
{
200283
return triePostingsDecodes.longValue();
201284
}
285+
202286
public long queryTimeouts()
203287
{
204288
return queryTimeouts.longValue();
205289
}
290+
206291
public long annGraphSearchLatency()
207292
{
208293
return annGraphSearchLatency.longValue();
@@ -222,19 +307,6 @@ public void checkpoint()
222307
}
223308
}
224309

225-
public void addShadowed(long count)
226-
{
227-
shadowedPrimaryKeyCount.add(count);
228-
}
229-
230-
/**
231-
* @return shadowed primary keys, in ascending order
232-
*/
233-
public long getShadowedPrimaryKeyCount()
234-
{
235-
return shadowedPrimaryKeyCount.longValue();
236-
}
237-
238310
public float getAnnRerankFloor()
239311
{
240312
return annRerankFloor;
@@ -277,9 +349,13 @@ public static class Snapshot
277349
public final long totalQueryTimeNs;
278350
public final long sstablesHit;
279351
public final long segmentsHit;
280-
public final long partitionsRead;
281-
public final long rowsFiltered;
282-
public final long rowsPreFiltered;
352+
public final long keysFetched;
353+
public final long partitionsFetched;
354+
public final long partitionsReturned;
355+
public final long partitionTombstonesFetched;
356+
public final long rowsFetched;
357+
public final long rowsReturned;
358+
public final long rowTombstonesFetched;
283359
public final long trieSegmentsHit;
284360
public final long bkdPostingListsHit;
285361
public final long bkdSegmentsHit;
@@ -289,7 +365,6 @@ public static class Snapshot
289365
public final long triePostingsDecodes;
290366
public final long queryTimeouts;
291367
public final long annGraphSearchLatency;
292-
public final long shadowedPrimaryKeyCount;
293368
public final FilterSortOrder filterSortOrder;
294369

295370
/**
@@ -302,9 +377,13 @@ private Snapshot(QueryContext context)
302377
totalQueryTimeNs = context.totalQueryTimeNs();
303378
sstablesHit = context.sstablesHit();
304379
segmentsHit = context.segmentsHit();
305-
partitionsRead = context.partitionsRead();
306-
rowsFiltered = context.rowsFiltered();
307-
rowsPreFiltered = context.rowsPreFiltered();
380+
keysFetched = context.keysFetched();
381+
partitionsFetched = context.partitionsFetched();
382+
partitionsReturned = context.partitionsReturned();
383+
partitionTombstonesFetched = context.partitionTombstonesFetched();
384+
rowsFetched = context.rowsFetched();
385+
rowsReturned = context.rowsReturned();
386+
rowTombstonesFetched = context.rowTombstonesFetched();
308387
trieSegmentsHit = context.trieSegmentsHit();
309388
bkdPostingListsHit = context.bkdPostingListsHit();
310389
bkdSegmentsHit = context.bkdSegmentsHit();
@@ -314,7 +393,6 @@ private Snapshot(QueryContext context)
314393
triePostingsDecodes = context.triePostingsDecodes();
315394
queryTimeouts = context.queryTimeouts();
316395
annGraphSearchLatency = context.annGraphSearchLatency();
317-
shadowedPrimaryKeyCount = context.getShadowedPrimaryKeyCount();
318396
filterSortOrder = context.filterSortOrder();
319397
}
320398
}

0 commit comments

Comments
 (0)