use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.
the class RegionRouteTable method findRegionsByCASEntries.
/**
* Returns the list of regions to which the keys belongs.
*/
public Map<Region, List<CASEntry>> findRegionsByCASEntries(final List<CASEntry> casEntries) {
Requires.requireNonNull(casEntries, "casEntries");
final Map<Region, List<CASEntry>> regionMap = Maps.newHashMap();
final StampedLock stampedLock = this.stampedLock;
final long stamp = stampedLock.readLock();
try {
for (final CASEntry casEntry : casEntries) {
final Region region = findRegionByKeyWithoutLock(casEntry.getKey());
regionMap.computeIfAbsent(region, k -> Lists.newArrayList()).add(casEntry);
}
return regionMap;
} finally {
stampedLock.unlockRead(stamp);
}
}
use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.
the class AbstractRheaKVStoreTest method checkRegion.
private void checkRegion(RheaKVStore store, byte[] key, long expectedRegionId) {
Region region = store.getPlacementDriverClient().findRegionByKey(key, false);
assertEquals(expectedRegionId, region.getId());
}
use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.
the class RegionRouteTableTest method brokenTest.
@Test(expected = RouteTableException.class)
public void brokenTest() {
RegionRouteTable table = new RegionRouteTable();
// Region r1 = makeRegion(1, null, KeyValueTool.makeKey("c"));
Region r2 = makeRegion(2, KeyValueTool.makeKey("c"), KeyValueTool.makeKey("e"));
Region r3 = makeRegion(3, KeyValueTool.makeKey("e"), KeyValueTool.makeKey("g"));
Region r4 = makeRegion(4, KeyValueTool.makeKey("g"), KeyValueTool.makeKey("i"));
Region r5 = makeRegion(5, KeyValueTool.makeKey("i"), KeyValueTool.makeKey("k"));
Region r6 = makeRegion(6, KeyValueTool.makeKey("k"), KeyValueTool.makeKey("n"));
Region r7 = makeRegion(7, KeyValueTool.makeKey("n"), null);
table.addOrUpdateRegion(r2);
table.addOrUpdateRegion(r3);
table.addOrUpdateRegion(r4);
table.addOrUpdateRegion(r5);
table.addOrUpdateRegion(r6);
table.addOrUpdateRegion(r7);
table.findRegionByKey(KeyValueTool.makeKey("a"));
}
use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.
the class RegionRouteTableTest method makeRegion.
Region makeRegion(long id, byte[] startKey, byte[] endKey) {
Region region = new Region();
region.setId(id);
region.setStartKey(startKey);
region.setEndKey(endKey);
region.setRegionEpoch(new RegionEpoch(-1, -1));
return region;
}
use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.
the class RegionRouteTableTest method splitRegionTest.
@Test
public void splitRegionTest() {
RegionRouteTable table = new RegionRouteTable();
Region region = makeRegion(-1, null, null);
table.addOrUpdateRegion(region);
Region newRegion = makeRegion(1, BytesUtil.writeUtf8("t"), null);
table.splitRegion(-1, newRegion);
Region found = table.findRegionByKey(BytesUtil.writeUtf8("a"));
assertEquals(-1, found.getId());
found = table.findRegionByKey(BytesUtil.writeUtf8("w"));
assertEquals(1, found.getId());
}
Aggregations