HBASE-18796 Admin#isTableAvailable returns incorrect result before daughter regions are opened

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
Abhishek Singh Chouhan 2017-09-18 15:02:11 +05:30 committed by Andrew Purtell
parent a29ea36194
commit 29a3ff3037
2 changed files with 52 additions and 2 deletions

View File

@ -1724,8 +1724,8 @@ public class MetaTableAccessor {
Put putA = makePutFromRegionInfo(splitA); Put putA = makePutFromRegionInfo(splitA);
Put putB = makePutFromRegionInfo(splitB); Put putB = makePutFromRegionInfo(splitB);
addLocation(putA, sn, 1, -1, splitA.getReplicaId()); //new regions, openSeqNum = 1 is fine. addSequenceNum(putA, 1, -1, splitA.getReplicaId()); //new regions, openSeqNum = 1 is fine.
addLocation(putB, sn, 1, -1, splitB.getReplicaId()); addSequenceNum(putB, 1, -1, splitB.getReplicaId());
// Add empty locations for region replicas of daughters so that number of replicas can be // 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 // cached whenever the primary region is looked up from meta
@ -2100,6 +2100,15 @@ public class MetaTableAccessor {
return p.getClass().getSimpleName() + p.toJSON(); return p.getClass().getSimpleName() + p.toJSON();
} }
public static Put addSequenceNum(final Put p, long openSeqNum, long time, int replicaId) {
if (time <= 0) {
time = EnvironmentEdgeManager.currentTime();
}
p.addImmutable(HConstants.CATALOG_FAMILY, getSeqNumColumn(replicaId), time,
Bytes.toBytes(openSeqNum));
return p;
}
/** /**
* Get replication position for a peer in a region. * Get replication position for a peer in a region.
* @param connection connection we're using * @param connection connection we're using

View File

@ -699,5 +699,46 @@ public class TestMetaTableAccessor {
assertTrue(prevCalls < scheduler.numPriorityCalls); assertTrue(prevCalls < scheduler.numPriorityCalls);
} }
} }
@Test
public void testEmptyMetaDaughterLocationDuringSplit() throws IOException {
long regionId = System.currentTimeMillis();
ServerName serverName0 = ServerName.valueOf("foo", 60010, random.nextLong());
HRegionInfo parent = new HRegionInfo(TableName.valueOf("table_foo"), HConstants.EMPTY_START_ROW,
HConstants.EMPTY_END_ROW, false, regionId, 0);
HRegionInfo splitA = new HRegionInfo(TableName.valueOf("table_foo"), HConstants.EMPTY_START_ROW,
Bytes.toBytes("a"), false, regionId + 1, 0);
HRegionInfo splitB = new HRegionInfo(TableName.valueOf("table_foo"), Bytes.toBytes("a"),
HConstants.EMPTY_END_ROW, false, regionId + 1, 0);
Table meta = MetaTableAccessor.getMetaHTable(connection);
try {
List<HRegionInfo> regionInfos = Lists.newArrayList(parent);
MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3);
MetaTableAccessor.splitRegion(connection, parent, splitA, splitB, serverName0, 3, false);
Get get1 = new Get(splitA.getRegionName());
Result resultA = meta.get(get1);
Cell serverCellA = resultA.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getServerColumn(splitA.getReplicaId()));
Cell startCodeCellA = resultA.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getStartCodeColumn(splitA.getReplicaId()));
assertNull(serverCellA);
assertNull(startCodeCellA);
Get get2 = new Get(splitA.getRegionName());
Result resultB = meta.get(get2);
Cell serverCellB = resultB.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getServerColumn(splitB.getReplicaId()));
Cell startCodeCellB = resultB.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getStartCodeColumn(splitB.getReplicaId()));
assertNull(serverCellB);
assertNull(startCodeCellB);
} finally {
if (meta != null) {
meta.close();
}
}
}
} }