tikv / tikv

Distributed transactional key-value database, originally created to complement TiDB
https://tikv.org
Apache License 2.0
15.04k stars 2.13k forks source link

Support stale read in RawKV #11004

Open andylokandy opened 2 years ago

andylokandy commented 2 years ago

Feature Request

Background

Follower read (aka. replica read) allows the follower to respond to read requests. To achieve that without breaking strong consistency guarantee, the follower will proxy a special read request (called read index) to the leader, to which the leader will not respond the data, and after receiving the response from the leader, the follower will read data from the local replica and respond to the client.

Describe the feature you'd like:

Eventually consistency is acceptable in some scenarios when using RawKV, thus to achieve this, the follower will be allowed to read the local replica without informing the leader.

Technical proposal

Add a bool field raw_stale_read to kvrpcpb.Context and raft_cmdpb.RaftRequestHeader. Then check the raw_stale_read field in RequestInspector::inspect() which is in components/raftstore/src/store/peer.rs and return RequestPolicy::ReadLocal if raw_stale_read is set.

BusyJay commented 2 years ago

Is anyone requesting for the features?

andylokandy commented 2 years ago

@BusyJay Do you think the technical approach is appropriate?

BusyJay commented 2 years ago

There is a stale read already. I think this is just a implement details of stale read in RawKV. Without knowing the detail background, it's hard to say if it's the right solution, even though it can work in some way.

andylokandy commented 2 years ago

@BusyJay IMO, replica read and stale read are also somehow similar, but still we gave them different names. Besides, the name in kvproto is also implementation detail, and we can hide these complexity in the client.

andylokandy commented 2 years ago

One more point: user will not read back different values from the different servers when using replica_read or stale_read while dirty_read will.

BusyJay commented 2 years ago

replica read and stale read are also somehow similar, but still we gave them different names

Replica read should not break learnability. Stale read can read whenever ACID is hold for transaction, and can read arbitrary data for raw kv. dirty is meaningless in raw kv as there is no transactions at all.

user will not read back different values from the different servers when using replica_read or stale_read

Nothing can prevent replica_read or stale_read to return different values for raw KV from different servers at different time. Repeated read is a property of transaction kv.

andylokandy commented 2 years ago

I've posted an RFC: https://github.com/tikv/rfcs/pull/80