Skip to content

Commit 6594244

Browse files
adelapenamichaelsembwever
authored andcommitted
CNDB-15946: Revamp SAI metrics for fetched/returned keys/partitions/rows/tombstones (#2132)
The metrics partitionsRead, rowsFiltered, rowsPreFiltered and shadowedPrimaryKeyCount, which don'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 every time a query timestamp is needed, which was possibly buggy and inefficient.
1 parent 78550b7 commit 6594244

File tree

11 files changed

+1648
-171
lines changed

11 files changed

+1648
-171
lines changed

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

Lines changed: 116 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,31 @@ public class QueryContext
4545

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

5375
private final LongAdder bkdPostingListsHit = new LongAdder();
@@ -65,7 +87,6 @@ public class QueryContext
6587

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

68-
private final LongAdder shadowedPrimaryKeyCount = new LongAdder();
6990
private final LongAdder postFilteringReadLatency = new LongAdder();
7091

7192
// Determines the order of using indexes for filtering and sorting.
@@ -94,49 +115,81 @@ public void addSstablesHit(long val)
94115
{
95116
sstablesHit.add(val);
96117
}
118+
97119
public void addSegmentsHit(long val) {
98120
segmentsHit.add(val);
99121
}
100-
public void addPartitionsRead(long val)
122+
123+
public void addKeysFetched(long val)
124+
{
125+
keysFetched.add(val);
126+
}
127+
128+
public void addPartitionsFetched(long val)
129+
{
130+
partitionsFetched.add(val);
131+
}
132+
133+
public void addPartitionsReturned(long val)
101134
{
102-
partitionsRead.add(val);
135+
partitionsReturned.add(val);
103136
}
104-
public void addRowsFiltered(long val)
137+
138+
public void addPartitionTombstonesFetched(long val)
139+
{
140+
partitionTombstonesFetched.add(val);
141+
}
142+
143+
public void addRowsFetched(long val)
105144
{
106-
rowsFiltered.add(val);
145+
rowsFetched.add(val);
107146
}
108-
public void addRowsPreFiltered(long val)
147+
148+
public void addRowsReturned(long val)
149+
{
150+
rowsReturned.add(val);
151+
}
152+
153+
public void addRowTombstonesFetched(long val)
109154
{
110-
rowsPreFiltered.add(val);
155+
rowTombstonesFetched.add(val);
111156
}
157+
112158
public void addTrieSegmentsHit(long val)
113159
{
114160
trieSegmentsHit.add(val);
115161
}
162+
116163
public void addBkdPostingListsHit(long val)
117164
{
118165
bkdPostingListsHit.add(val);
119166
}
167+
120168
public void addBkdSegmentsHit(long val)
121169
{
122170
bkdSegmentsHit.add(val);
123171
}
172+
124173
public void addBkdPostingsSkips(long val)
125174
{
126175
bkdPostingsSkips.add(val);
127176
}
177+
128178
public void addBkdPostingsDecodes(long val)
129179
{
130180
bkdPostingsDecodes.add(val);
131181
}
182+
132183
public void addTriePostingsSkips(long val)
133184
{
134185
triePostingsSkips.add(val);
135186
}
187+
136188
public void addTriePostingsDecodes(long val)
137189
{
138190
triePostingsDecodes.add(val);
139191
}
192+
140193
public void addQueryTimeouts(long val)
141194
{
142195
queryTimeouts.add(val);
@@ -163,53 +216,86 @@ public long sstablesHit()
163216
{
164217
return sstablesHit.longValue();
165218
}
219+
166220
public long segmentsHit() {
167221
return segmentsHit.longValue();
168222
}
169-
public long partitionsRead()
223+
224+
public long keysFetched()
170225
{
171-
return partitionsRead.longValue();
226+
return keysFetched.longValue();
172227
}
173-
public long rowsFiltered()
228+
229+
public long partitionsFetched()
174230
{
175-
return rowsFiltered.longValue();
231+
return partitionsFetched.longValue();
176232
}
177-
public long rowsPreFiltered()
233+
234+
public long partitionsReturned()
178235
{
179-
return rowsPreFiltered.longValue();
236+
return partitionsReturned.longValue();
180237
}
238+
239+
public long partitionTombstonesFetched()
240+
{
241+
return partitionTombstonesFetched.longValue();
242+
}
243+
244+
public long rowsFetched()
245+
{
246+
return rowsFetched.longValue();
247+
}
248+
249+
public long rowsReturned()
250+
{
251+
return rowsReturned.longValue();
252+
}
253+
254+
public long rowTombstonesFetched()
255+
{
256+
return rowTombstonesFetched.longValue();
257+
}
258+
181259
public long trieSegmentsHit()
182260
{
183261
return trieSegmentsHit.longValue();
184262
}
263+
185264
public long bkdPostingListsHit()
186265
{
187266
return bkdPostingListsHit.longValue();
188267
}
268+
189269
public long bkdSegmentsHit()
190270
{
191271
return bkdSegmentsHit.longValue();
192272
}
273+
193274
public long bkdPostingsSkips()
194275
{
195276
return bkdPostingsSkips.longValue();
196277
}
278+
197279
public long bkdPostingsDecodes()
198280
{
199281
return bkdPostingsDecodes.longValue();
200282
}
283+
201284
public long triePostingsSkips()
202285
{
203286
return triePostingsSkips.longValue();
204287
}
288+
205289
public long triePostingsDecodes()
206290
{
207291
return triePostingsDecodes.longValue();
208292
}
293+
209294
public long queryTimeouts()
210295
{
211296
return queryTimeouts.longValue();
212297
}
298+
213299
public long annGraphSearchLatency()
214300
{
215301
return annGraphSearchLatency.longValue();
@@ -229,19 +315,6 @@ public void checkpoint()
229315
}
230316
}
231317

232-
public void addShadowed(long count)
233-
{
234-
shadowedPrimaryKeyCount.add(count);
235-
}
236-
237-
/**
238-
* @return shadowed primary keys, in ascending order
239-
*/
240-
public long getShadowedPrimaryKeyCount()
241-
{
242-
return shadowedPrimaryKeyCount.longValue();
243-
}
244-
245318
public float getAnnRerankFloor()
246319
{
247320
return annRerankFloor;
@@ -289,9 +362,13 @@ public static class Snapshot
289362
public final long totalQueryTimeNs;
290363
public final long sstablesHit;
291364
public final long segmentsHit;
292-
public final long partitionsRead;
293-
public final long rowsFiltered;
294-
public final long rowsPreFiltered;
365+
public final long keysFetched;
366+
public final long partitionsFetched;
367+
public final long partitionsReturned;
368+
public final long partitionTombstonesFetched;
369+
public final long rowsFetched;
370+
public final long rowsReturned;
371+
public final long rowTombstonesFetched;
295372
public final long trieSegmentsHit;
296373
public final long bkdPostingListsHit;
297374
public final long bkdSegmentsHit;
@@ -301,7 +378,6 @@ public static class Snapshot
301378
public final long triePostingsDecodes;
302379
public final long queryTimeouts;
303380
public final long annGraphSearchLatency;
304-
public final long shadowedPrimaryKeyCount;
305381
public final long postFilteringReadLatency;
306382
public final FilterSortOrder filterSortOrder;
307383

@@ -315,9 +391,13 @@ private Snapshot(QueryContext context)
315391
totalQueryTimeNs = context.totalQueryTimeNs();
316392
sstablesHit = context.sstablesHit();
317393
segmentsHit = context.segmentsHit();
318-
partitionsRead = context.partitionsRead();
319-
rowsFiltered = context.rowsFiltered();
320-
rowsPreFiltered = context.rowsPreFiltered();
394+
keysFetched = context.keysFetched();
395+
partitionsFetched = context.partitionsFetched();
396+
partitionsReturned = context.partitionsReturned();
397+
partitionTombstonesFetched = context.partitionTombstonesFetched();
398+
rowsFetched = context.rowsFetched();
399+
rowsReturned = context.rowsReturned();
400+
rowTombstonesFetched = context.rowTombstonesFetched();
321401
trieSegmentsHit = context.trieSegmentsHit();
322402
bkdPostingListsHit = context.bkdPostingListsHit();
323403
bkdSegmentsHit = context.bkdSegmentsHit();
@@ -327,7 +407,6 @@ private Snapshot(QueryContext context)
327407
triePostingsDecodes = context.triePostingsDecodes();
328408
queryTimeouts = context.queryTimeouts();
329409
annGraphSearchLatency = context.annGraphSearchLatency();
330-
shadowedPrimaryKeyCount = context.getShadowedPrimaryKeyCount();
331410
postFilteringReadLatency = context.getPostFilteringReadLatency();
332411
filterSortOrder = context.filterSortOrder();
333412
}

0 commit comments

Comments
 (0)