Apache9 commented on a change in pull request #2010:
URL: https://github.com/apache/hbase/pull/2010#discussion_r484078461
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStateStore.java
##########
@@ -250,15 +255,62 @@ private long getOpenSeqNumForParentRegion(RegionInfo
region) throws IOException
//
============================================================================================
// Update Region Splitting State helpers
//
============================================================================================
- public void splitRegion(RegionInfo parent, RegionInfo hriA, RegionInfo hriB,
- ServerName serverName) throws IOException {
- TableDescriptor htd = getDescriptor(parent.getTable());
+ /**
+ * Splits the region into two in an atomic operation. Offlines the parent
region with the
+ * information that it is split into two, and also adds the daughter
regions. Does not add the
+ * location information to the daughter regions since they are not open yet.
+ */
+ public void splitRegion(RegionInfo parent, RegionInfo splitA, RegionInfo
splitB,
+ ServerName serverName, TableDescriptor htd) throws IOException {
long parentOpenSeqNum = HConstants.NO_SEQNUM;
if (htd.hasGlobalReplicationScope()) {
parentOpenSeqNum = getOpenSeqNumForParentRegion(parent);
}
- MetaTableAccessor.splitRegion(master.getConnection(), parent,
parentOpenSeqNum, hriA, hriB,
- serverName, getRegionReplication(htd));
+ long time = EnvironmentEdgeManager.currentTime();
+ // Put for parent
+ Put putParent = MetaTableAccessor.makePutFromRegionInfo(
+
RegionInfoBuilder.newBuilder(parent).setOffline(true).setSplit(true).build(),
time);
+ MetaTableAccessor.addDaughtersToPut(putParent, splitA, splitB);
+
+ // Puts for daughters
+ Put putA = MetaTableAccessor.makePutFromRegionInfo(splitA, time);
+ Put putB = MetaTableAccessor.makePutFromRegionInfo(splitB, time);
+ if (parentOpenSeqNum > 0) {
+ MetaTableAccessor.addReplicationBarrier(putParent, parentOpenSeqNum);
+ MetaTableAccessor.addReplicationParent(putA,
Collections.singletonList(parent));
+ MetaTableAccessor.addReplicationParent(putB,
Collections.singletonList(parent));
+ }
+ // Set initial state to CLOSED
+ // NOTE: If initial state is not set to CLOSED then daughter regions get
added with the
+ // default OFFLINE state. If Master gets restarted after this step, start
up sequence of
+ // master tries to assign these offline regions. This is followed by
re-assignments of the
+ // daughter regions from resumed {@link SplitTableRegionProcedure}
+ MetaTableAccessor.addRegionStateToPut(putA, RegionState.State.CLOSED);
+ MetaTableAccessor.addRegionStateToPut(putB, RegionState.State.CLOSED);
+
+ // new regions, openSeqNum = 1 is fine.
+ MetaTableAccessor.addSequenceNum(putA, 1, splitA.getReplicaId());
+ MetaTableAccessor.addSequenceNum(putB, 1, splitB.getReplicaId());
+
+ // Add empty locations for region replicas of daughters so that number of
replicas can be
+ // cached whenever the primary region is looked up from meta
+ int regionReplication = getRegionReplication(htd);
+ for (int i = 1; i < regionReplication; i++) {
+ MetaTableAccessor.addEmptyLocation(putA, i);
+ MetaTableAccessor.addEmptyLocation(putB, i);
+ }
+
+ List<Mutation> mutations = Arrays.asList(putParent, putA, putB);
+ if (htd.isMetaTable()) {
+ masterRegion.update(region -> {
+ List<byte[]> rowsToLock =
+
mutations.stream().map(Mutation::getRow).collect(Collectors.toList());
+ region.mutateRowsWithLocks(mutations, rowsToLock, HConstants.NO_NONCE,
HConstants.NO_NONCE);
Review comment:
Like what?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]