xnnyygn / xraft

xnnyygn's raft implementation
MIT License
228 stars 107 forks source link

Xraft-kvstore does not satisfy linearizability #39

Closed meteam2022 closed 7 months ago

meteam2022 commented 8 months ago

The read operation in the kvstore (i.e. kvstore-get command) can be processed in Followers without quorum round trips, which violates linearizability (e.g. reading stale values).

https://github.com/xnnyygn/xraft/blob/dea670012bf470071a519c2e8ecc7a14642042f5/xraft-kvstore/src/main/java/in/xnnyygn/xraft/kvstore/server/Service.java#L95-L101

I further discovered that the develop branch has implemented the readindex protocol to guarantee linearizability for reads. But there is no explanation of the consistency levels in the doc, so few users can find the develop branch and users might assume the kvstore satisfy linearizability because it is based on Raft.

A possible fix

For a reference, Consul has three read modes: default (Leader processes reads without quorums), consistent (like the develop branch of Xraft-kvstore), stale (like the main branch).

In the Xraft's documentation/README, it would be better to explicitly clarify the consistency modes. Specifically, provide an explanation that the kvstore-get operation may read stale values, directing users seeking consistent reads to the develop branch. Additionally, considering the feasibility, Xraft can offer the default level, akin to Consul, for users seeking a balanced compromise between availability and consistency.

xnnyygn commented 7 months ago

Thanks. You are right. The default mode for kvstore is to read without quorum guarantee. The develop branch implements the readindex so consistent read is offered. I'll update the README.