Commit 08336cf
committed
readyset-adapter: Add Query Sampler
This commit adds a Query Sampler thread.
The sampler thread is responsible for probabilistically sampling
queries that were originally sent to Readyset. The intention is to
pro-actively validate the correctness of the Readyset Server.
The sampler thread will run queries against the upstream database and
compare the normalized results with the results returned by the
Readyset Server.
Queries are passed from adapter to sampler via a bounded channel,
which will drop queries if the channel is full.
The sampler thread has two main queues:
- A queue of queries that have been sent from the adapter. Those are
randomly sampled.
- A retry queue. In case of a mismatch, we add queries to a second
queue to be retried.
Re-try logic is implemented by a new struct that keeps track of some
metadata about the query, such as last upstream result hash, the
number or retry attempts, and the query itself.
The retry queue is a double ended queue, since we need to be able
to add elements in the end of the queue and pop elements in the front.
Elements are added in retry order. The retry is based on a timestamp
calculated from the current time + the retry delay.
The retry queue is bounded, and will drop entries if it is full.
We added the following metrics:
- `readyset_query_sampler_queue_len`: The number of queries in the
sampler queue.
- `readyset_query_sampler_queries_sampled`: The number of queries
sampled.
- `readyset_query_sampler_queries_mismatched`: The number of
queries that were sampled but returned different results.
- `readyset_query_sampler_retry_queue_len`: The number of entries in
the retry queue.
- `readyset_query_sampler_retry_queue_full`: The number of times the
retry queue is full.
- `readyset_query_sampler_max_qps_hit`: The number of times the
sampler rate limiter is hit.
- `readyset_query_sampler_reconnects`: The number of times the
sampler reconnects to the upstream database.
We also added new configuration options:
- `SAMPLER_SAMPLE_RATE`: The probability of sampling a query.
- `SAMPLER_RETRY_DELAY_MS`: The delay between retries.
- `SAMPLER_QUEUE_CAPACITY`: The maximum number of queries in the
sampler queue.
- `SAMPLER_MAX_RETRIES`: The maximum number of retries for a query.
- `SAMPLER_MAX_QUERIES_PER_SECOND`: The maximum number of queries to
sample per second to avoid overwhelming the upstream database.
Note: The current implementation is limited to Text Protocol queries.
A further CL will add support for Binary Protocol queries.
Fixes REA-5328.
Release-Note-Core: Added a query sampler thread to the Readyset
Adapter. This thread will sample queries and compare the results
with the results returned by the upstream database and report possible
mismatches.
Change-Id: I95f8f8b15be977e30998b59f0f266cb685a9e99b
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/10231
Reviewed-by: Jason Brown <jason.b@readyset.io>
Tested-by: Buildkite CI1 parent ffe36fe commit 08336cf
File tree
11 files changed
+841
-6
lines changed- database-utils/src
- readyset-adapter
- src
- readyset-client/src/metrics
- readyset-util/src
- readyset/src
11 files changed
+841
-6
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
305 | 314 | | |
306 | 315 | | |
307 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| 297 | + | |
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
| |||
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
| 320 | + | |
319 | 321 | | |
320 | 322 | | |
321 | 323 | | |
| |||
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
| 385 | + | |
383 | 386 | | |
384 | 387 | | |
385 | 388 | | |
| |||
474 | 477 | | |
475 | 478 | | |
476 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
477 | 489 | | |
478 | 490 | | |
479 | 491 | | |
| |||
588 | 600 | | |
589 | 601 | | |
590 | 602 | | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
591 | 606 | | |
592 | 607 | | |
593 | 608 | | |
| |||
3124 | 3139 | | |
3125 | 3140 | | |
3126 | 3141 | | |
3127 | | - | |
| 3142 | + | |
3128 | 3143 | | |
3129 | 3144 | | |
3130 | 3145 | | |
| |||
3135 | 3150 | | |
3136 | 3151 | | |
3137 | 3152 | | |
3138 | | - | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
3139 | 3163 | | |
3140 | 3164 | | |
3141 | 3165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
0 commit comments