cockroachdb / cockroachdb/cockroach
kvserver: potentially incorrect MVCC statistics as a result of unlatched GCRequests
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
When evaluating the impact of #162085, we have hypothesised the following problem with the `KeyCount` MVCC statistic in the presence of unlatched GCRequest using the `Keys` field to GC that key.
First, note that as of 49bcc0962a54c4780fa5ca9e1a2e0cea797e7793 we do not take out write latches on keys specified in the Keys field of a GCRequest. While this is correct from the standpoint of a concurrent reader, it may have a problem with respect to a concurrent writer and the MVCC statistics.
Consider, the following:
```
t1. put(key)
t2. del(key)
t3. ...
t4. GCThreshold advanced to t3.
t5. concurrently gc(key), and put(key) are evaluated, uncoordinated by latching.
```
In this case, it is possible that the GCRequest reduces the key count by 1 (because it views the pre-put state where the GC request will remove all revisions of the key) while the Put leaves it unchanged (because it views the pre-GC'd state where it's write does not present a new Key). Our KeyCount is now under-counting the actual number of MVCCKeys.
We have not written a test to prove this is possible yet.
Jira issue: CRDB-59410
Contributor guide
Assessment
This issue has not been assessed yet.