sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.56k stars 1.14k forks source link

RheaKV: bContainsKey throws RouteTableException if key does not exist in region #984

Closed dajogiXrm closed 1 year ago

dajogiXrm commented 1 year ago

Describe the bug

when using bContainsKey in any RheaKVStore with a region configured, a RouteTableException is thrown.

Expected behavior

should return false if key is not found

Actual behavior

throws com.alipay.sofa.jraft.rhea.errors.RouteTableException: key: 626C61, message: fail to find region by key

Steps to reproduce

Minimal yet complete reproducer code (or GitHub URL to code)

final RegionEngineOptions e = new RegionEngineOptions(); e.setStartKey("myStartKey"); e.setRegionId(myId);

store.bContainsKey("does_not_exist");

Environment

fengjiachun commented 1 year ago

Throwing a RouteTableException exception is not because the key does not exist(It has not yet initiated a real query and does not know if it really does not exist.), but because the region partition strategy is configured incorrectly.

A valid configuration: Assuming there are two regions in total, region0 [start0, end0], region1 [start1, end1]. The range of [start0, end1] must be includes all keys.