50
50
import org .apache .hadoop .conf .Configuration ;
51
51
import org .apache .hadoop .fs .FileSystem ;
52
52
import org .apache .hadoop .fs .Path ;
53
+ import org .apache .hadoop .hbase .Cell ;
53
54
import org .apache .hadoop .hbase .CoordinatedStateException ;
54
55
import org .apache .hadoop .hbase .HBaseIOException ;
55
56
import org .apache .hadoop .hbase .HConstants ;
68
69
import org .apache .hadoop .hbase .classification .InterfaceAudience ;
69
70
import org .apache .hadoop .hbase .client .Admin ;
70
71
import org .apache .hadoop .hbase .client .Admin .MasterSwitchType ;
72
+ import org .apache .hadoop .hbase .client .Delete ;
71
73
import org .apache .hadoop .hbase .client .RegionReplicaUtil ;
72
74
import org .apache .hadoop .hbase .client .Result ;
73
75
import org .apache .hadoop .hbase .coordination .BaseCoordinatedStateManager ;
@@ -3293,7 +3295,8 @@ Set<ServerName> rebuildUserRegions() throws
3293
3295
HRegionInfo regionInfo = hrl .getRegionInfo ();
3294
3296
if (regionInfo == null ) continue ;
3295
3297
int replicaId = regionInfo .getReplicaId ();
3296
- State state = RegionStateStore .getRegionState (result , replicaId );
3298
+ State state = RegionStateStore .getRegionState (result , replicaId ,
3299
+ ConfigUtil .isZKAssignmentInUse (server .getConfiguration ()));
3297
3300
// keep a track of replicas to close. These were the replicas of the split parents
3298
3301
// from the previous life of the master. The master should have closed them before
3299
3302
// but it couldn't maybe because it crashed
@@ -3303,7 +3306,8 @@ Set<ServerName> rebuildUserRegions() throws
3303
3306
}
3304
3307
}
3305
3308
ServerName lastHost = hrl .getServerName ();
3306
- ServerName regionLocation = RegionStateStore .getRegionServer (result , replicaId );
3309
+ ServerName regionLocation = RegionStateStore .getRegionServer (result , replicaId ,
3310
+ ConfigUtil .isZKAssignmentInUse (server .getConfiguration ()));
3307
3311
if (tableStateManager .isTableState (regionInfo .getTable (),
3308
3312
ZooKeeperProtos .Table .State .DISABLED )) {
3309
3313
// force region to forget it hosts for disabled/disabling tables.
@@ -3343,6 +3347,61 @@ Set<ServerName> rebuildUserRegions() throws
3343
3347
return offlineServers ;
3344
3348
}
3345
3349
3350
+ void deleteNonZkBasedQualifiersForZkBasedAssignment () throws IOException {
3351
+ boolean isZKAssignmentInUse = ConfigUtil .isZKAssignmentInUse (server .getConfiguration ());
3352
+ if (isZKAssignmentInUse ) {
3353
+ List <Result > results = MetaTableAccessor .fullScanOfMeta (server .getConnection ());
3354
+ List <Delete > redundantCQDeletes = new ArrayList <>();
3355
+ for (Result result : results ) {
3356
+ RegionLocations rl = MetaTableAccessor .getRegionLocations (result );
3357
+ if (rl == null ) {
3358
+ LOG .error ("No location found for " + result );
3359
+ continue ;
3360
+ }
3361
+ HRegionLocation [] locations = rl .getRegionLocations ();
3362
+ if (locations == null ) {
3363
+ LOG .error ("No location found for " + rl );
3364
+ continue ;
3365
+ }
3366
+ for (HRegionLocation hrl : locations ) {
3367
+ if (hrl == null ) {
3368
+ continue ;
3369
+ }
3370
+ HRegionInfo regionInfo = hrl .getRegionInfo ();
3371
+ if (regionInfo == null ) {
3372
+ LOG .error ("No region info found " + hrl );
3373
+ continue ;
3374
+ }
3375
+ int replicaId = regionInfo .getReplicaId ();
3376
+ Cell cell = result .getColumnLatestCell (HConstants .CATALOG_FAMILY ,
3377
+ RegionStateStore .getServerNameColumn (replicaId ));
3378
+ if (cell != null && cell .getValueLength () > 0 ) {
3379
+ Delete delete =
3380
+ new Delete (cell .getRowArray (), cell .getRowOffset (), cell .getRowLength ());
3381
+ delete .addColumns (HConstants .CATALOG_FAMILY ,
3382
+ RegionStateStore .getServerNameColumn (replicaId ));
3383
+ redundantCQDeletes .add (delete );
3384
+ }
3385
+ cell = result .getColumnLatestCell (HConstants .CATALOG_FAMILY ,
3386
+ RegionStateStore .getStateColumn (replicaId ));
3387
+ if (cell != null && cell .getValueLength () > 0 ) {
3388
+ Delete delete =
3389
+ new Delete (cell .getRowArray (), cell .getRowOffset (), cell .getRowLength ());
3390
+ delete
3391
+ .addColumns (HConstants .CATALOG_FAMILY , RegionStateStore .getStateColumn (replicaId ));
3392
+ redundantCQDeletes .add (delete );
3393
+ }
3394
+ }
3395
+ }
3396
+ if (!redundantCQDeletes .isEmpty ()) {
3397
+ LOG .info ("Meta contains multiple info:sn and/or info:state values that are not required "
3398
+ + "for ZK based region assignment workflows. Preparing to delete these CQs. Number of"
3399
+ + " Deletes: " + redundantCQDeletes .size ());
3400
+ MetaTableAccessor .deleteFromMetaTable (server .getConnection (), redundantCQDeletes );
3401
+ }
3402
+ }
3403
+ }
3404
+
3346
3405
/**
3347
3406
* Recover the tables that were not fully moved to DISABLED state. These
3348
3407
* tables are in DISABLING state when the master restarted/switched.
0 commit comments