@@ -1383,51 +1383,82 @@ public void processOfflineRegions() {
1383
1383
}
1384
1384
}
1385
1385
1386
- private void loadMeta () throws IOException {
1387
- // TODO: use a thread pool
1388
- regionStateStore .visitMeta (new RegionStateStore .RegionStateVisitor () {
1389
- @ Override
1390
- public void visitRegionState (Result result , final RegionInfo regionInfo , final State state ,
1391
- final ServerName regionLocation , final ServerName lastHost , final long openSeqNum ) {
1392
- if (state == null && regionLocation == null && lastHost == null &&
1393
- openSeqNum == SequenceId .NO_SEQUENCE_ID ) {
1394
- // This is a row with nothing in it.
1395
- LOG .warn ("Skipping empty row={}" , result );
1396
- return ;
1397
- }
1398
- State localState = state ;
1399
- if (localState == null ) {
1400
- // No region state column data in hbase:meta table! Are I doing a rolling upgrade from
1401
- // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta?
1402
- // In any of these cases, state is empty. For now, presume OFFLINE but there are probably
1403
- // cases where we need to probe more to be sure this correct; TODO informed by experience.
1404
- LOG .info (regionInfo .getEncodedName () + " regionState=null; presuming " + State .OFFLINE );
1405
- localState = State .OFFLINE ;
1406
- }
1407
- RegionStateNode regionNode = regionStates .getOrCreateRegionStateNode (regionInfo );
1408
- // Do not need to lock on regionNode, as we can make sure that before we finish loading
1409
- // meta, all the related procedures can not be executed. The only exception is for meta
1410
- // region related operations, but here we do not load the informations for meta region.
1411
- regionNode .setState (localState );
1412
- regionNode .setLastHost (lastHost );
1413
- regionNode .setRegionLocation (regionLocation );
1414
- regionNode .setOpenSeqNum (openSeqNum );
1415
-
1416
- // Note: keep consistent with other methods, see region(Opening|Opened|Closing)
1417
- // RIT/ServerCrash handling should take care of the transiting regions.
1418
- if (localState .matches (State .OPEN , State .OPENING , State .CLOSING , State .SPLITTING ,
1419
- State .MERGING )) {
1420
- assert regionLocation != null : "found null region location for " + regionNode ;
1421
- regionStates .addRegionToServer (regionNode );
1422
- } else if (localState == State .OFFLINE || regionInfo .isOffline ()) {
1423
- regionStates .addToOfflineRegions (regionNode );
1424
- }
1425
- if (regionNode .getProcedure () != null ) {
1426
- regionNode .getProcedure ().stateLoaded (AssignmentManager .this , regionNode );
1427
- }
1386
+ /* AM internal RegionStateStore.RegionStateVisitor implementation. To be used when
1387
+ * scanning META table for region rows, using RegionStateStore utility methods. RegionStateStore
1388
+ * methods will convert Result into proper RegionInfo instances, but those would still need to be
1389
+ * added into AssignmentManager.regionStates in-memory cache.
1390
+ * RegionMetaLoadingVisitor.visitRegionState method provides the logic for adding RegionInfo
1391
+ * instances as loaded from latest META scan into AssignmentManager.regionStates.
1392
+ */
1393
+ private class RegionMetaLoadingVisitor implements RegionStateStore .RegionStateVisitor {
1394
+
1395
+ @ Override
1396
+ public void visitRegionState (Result result , final RegionInfo regionInfo , final State state ,
1397
+ final ServerName regionLocation , final ServerName lastHost , final long openSeqNum ) {
1398
+ if (state == null && regionLocation == null && lastHost == null &&
1399
+ openSeqNum == SequenceId .NO_SEQUENCE_ID ) {
1400
+ // This is a row with nothing in it.
1401
+ LOG .warn ("Skipping empty row={}" , result );
1402
+ return ;
1428
1403
}
1429
- });
1404
+ State localState = state ;
1405
+ if (localState == null ) {
1406
+ // No region state column data in hbase:meta table! Are I doing a rolling upgrade from
1407
+ // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta?
1408
+ // In any of these cases, state is empty. For now, presume OFFLINE but there are probably
1409
+ // cases where we need to probe more to be sure this correct; TODO informed by experience.
1410
+ LOG .info (regionInfo .getEncodedName () + " regionState=null; presuming " + State .OFFLINE );
1411
+ localState = State .OFFLINE ;
1412
+ }
1413
+ RegionStateNode regionNode = regionStates .getOrCreateRegionStateNode (regionInfo );
1414
+ // Do not need to lock on regionNode, as we can make sure that before we finish loading
1415
+ // meta, all the related procedures can not be executed. The only exception is for meta
1416
+ // region related operations, but here we do not load the informations for meta region.
1417
+ regionNode .setState (localState );
1418
+ regionNode .setLastHost (lastHost );
1419
+ regionNode .setRegionLocation (regionLocation );
1420
+ regionNode .setOpenSeqNum (openSeqNum );
1421
+
1422
+ // Note: keep consistent with other methods, see region(Opening|Opened|Closing)
1423
+ // RIT/ServerCrash handling should take care of the transiting regions.
1424
+ if (localState .matches (State .OPEN , State .OPENING , State .CLOSING , State .SPLITTING ,
1425
+ State .MERGING )) {
1426
+ assert regionLocation != null : "found null region location for " + regionNode ;
1427
+ regionStates .addRegionToServer (regionNode );
1428
+ } else if (localState == State .OFFLINE || regionInfo .isOffline ()) {
1429
+ regionStates .addToOfflineRegions (regionNode );
1430
+ }
1431
+ if (regionNode .getProcedure () != null ) {
1432
+ regionNode .getProcedure ().stateLoaded (AssignmentManager .this , regionNode );
1433
+ }
1434
+ }
1435
+ };
1436
+
1437
+ /**
1438
+ * Query META if the given <code>RegionInfo</code> exists, adding to
1439
+ * <code>AssignmentManager.regionStateStore</code> cache if the region is found in META.
1440
+ * @param regionEncodedName encoded name for the region to be loaded from META into
1441
+ * <code>AssignmentManager.regionStateStore</code> cache
1442
+ * @return <code>RegionInfo</code> instance for the given region if it is present in META
1443
+ * and got successfully loaded into <code>AssignmentManager.regionStateStore</code>
1444
+ * cache, <b>null</b> otherwise.
1445
+ * @throws UnknownRegionException if any errors occur while querying meta.
1446
+ */
1447
+ public RegionInfo loadRegionFromMeta (String regionEncodedName ) throws UnknownRegionException {
1448
+ try {
1449
+ RegionMetaLoadingVisitor visitor = new RegionMetaLoadingVisitor ();
1450
+ regionStateStore .visitMetaForRegion (regionEncodedName , visitor );
1451
+ return regionStates .getRegionState (regionEncodedName ) == null ? null :
1452
+ regionStates .getRegionState (regionEncodedName ).getRegion ();
1453
+ } catch (IOException e ) {
1454
+ LOG .error ("Error trying to load region {} from META" , regionEncodedName , e );
1455
+ throw new UnknownRegionException ("Error while trying load region from meta" );
1456
+ }
1457
+ }
1430
1458
1459
+ private void loadMeta () throws IOException {
1460
+ // TODO: use a thread pool
1461
+ regionStateStore .visitMeta (new RegionMetaLoadingVisitor ());
1431
1462
// every assignment is blocked until meta is loaded.
1432
1463
wakeMetaLoadedEvent ();
1433
1464
}
0 commit comments