Skip to content

Instantly share code, notes, and snippets.

@arjunsk
Created May 12, 2022 16:38
Show Gist options
  • Save arjunsk/359e80d57f29af8544ae7236e8a09c72 to your computer and use it in GitHub Desktop.
Save arjunsk/359e80d57f29af8544ae7236e8a09c72 to your computer and use it in GitHub Desktop.
* <pre>
* 1. The first step is to filter out region1, region2, and region3 from the routing table.
*
* ┌─────────────────┐ ┌─────────────────┐
* │ scan startKey │ │ scan endKey │
* └────────┬────────┘ └────────┬────────┘
* │ │
* │ │
* │ │
* ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ ┌ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ┐ │ ┌ ─ ─ ─ ─ ─ ─ ┐
* startKey1=byte[0] │ │ startKey2 startKey3 │ startKey4
* └ ─ ─ ─ ┬ ─ ─ ─ ─ ─ │ └ ─ ─ ─│─ ─ ─ ┘ └ ─ ─ ─│─ ─ ─ ┘ │ └ ─ ─ ─│─ ─ ─ ┘
* │ │ │ │ │ │
* ▼───────────────▼─────────▼─────────────────────────▼─────────────▼───────────▼─────────────────────────┐
* │ │ │ │ │
* │ │ │ │ │
* │ region1 │ region2 │ region3 │ region4 │
* │ │ │ │ │
* └─────────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┘
*
* 2. The second step is to split the request(scan -> multi-region scan):
* region1->regionScan(startKey, regionEndKey1)
* region2->regionScan(regionStartKey2, regionEndKey2)
* region3->regionScan(regionStartKey3, endKey)
*
* ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─
* call region1 │ call region2 │ call region3 │
* └ ─ ─ ─ ─ ─ ─ ─ ─ ─ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ └ ─ ─ ─ ─ ─ ─ ─ ─ ─
* ║ ║ ║
*
* ║ ║ ║
* ▽ ▽ ▽
* ┌─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┐
* │ │ │ │ │
* │ │ │ │ │
* │ region1 │ region2 │ region3 │ region4 │
* │ │ │ │ │
* └─────────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┘
*
* 3. The third step, encountering the region split (the sign of the split is the change of the region epoch)
* To refresh the RegionRouteTable, you need to obtain the latest routing table from the PD.
*
* For example, region2 is split into region2 + region5:
* The request 'region2->regionScan(regionStartKey2, regionEndKey2)' split and retry
* 1. region2->regionScan(regionStartKey2, newRegionEndKey2)
* 2. region5->regionScan(regionStartKey5, regionEndKey5)
*
* ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─
* call region1 │ call region3 │
* └ ─ ─ ─ ─ ─ ─ ─ ─ ─ └ ─ ─ ─ ─ ─ ─ ─ ─ ─
* ║ ┌ ─ ─ ─ ─ ─ ─ ┐ ║
* retry region2
* ║ └ ─ ─ ─ ─ ─ ─ ┘┌ ─ ─ ─ ─ ─ ─ ┐ ║
* ║ retry region5
* ║ └ ─ ─ ─ ─ ─ ─ ┘ ║
* ║ ║
* ║ ║
* ▽ ▽ ▽ ▽
* ┌─────────────────────────┬────────────┬ ─ ─ ─ ─ ─ ─┌─────────────────────────┬─────────────────────────┐
* │ │ │ │ │ │
* │ │ │ │ │ │
* │ region1 │ region2 │ region5 │ region3 │ region4 │
* │ │ │ │ │ │
* └─────────────────────────┴────────────┘─ ─ ─ ─ ─ ─ ┴─────────────────────────┴─────────────────────────┘
*
* 4. Encountering 'Invalid-Peer'(NOT_LEADER, NO_REGION_FOUND, LEADER_NOT_AVAILABLE)
* This is very simple, re-acquire the latest leader of the raft-group to which the current key belongs,
* and then call again.
* </pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment