velox
velox copied to clipboard
Fix recover ssd cache data by preserving file id map
In Meta interactive Prestissimo workload, we found there is not much read can hit in SSD cache after cluster upgrade or worker reboot if we rerun the same set of queries. Sometime this is because of the non-deterministic execution order of multiple filter conditions in table scan. If the filter rate is high, then the last few filter conditions might not be executed and the decision is local to a split which means that filter condition execution order varies across splits. This might cause the rerun query to read from remote storage instead of local SSD cache. But this only cause a small portion of reads go to remote storage.
The main problem is due to the recover cache entries from checkpoint. Even though we guarantee that the same source file name maps to the same file id but we can't guarantee that the newly assigned file id will be mapped to the same SSD file shard. This will cause the cache space polution. Even if we recovered all the SSD cache entries from checkpoint file, the cache lookup can't find them if the newly assigned file id is mapped to a different SSD file shard.
To fix this problem, we add a new constructor in StringIdMap which takes both id and string to recover the previous string id map. The caller guarantees there is no conflict for the passed id/string pairs, and StringIdMap will throw if breaks. Correspondingly, when SSD file recovers from the checkpoint file, it will use the persisted file id and name to rebuild the string id map.
Verified on Meta interactive cluster with SSD and a second run after cluster reboot read all the data from local SSD. The end-to-end query latency has been reduced by half compared with the first run.