saintstack commented on a change in pull request #2476:
URL: https://github.com/apache/hbase/pull/2476#discussion_r499337978



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStateStore.java
##########
@@ -545,6 +547,83 @@ public void overwriteRegions(List<RegionInfo> regionInfos, 
int regionReplication
     LOG.debug("Overwritten regions: {} ", regionInfos);
   }
 
+  /**
+   * Update region replicas if necessary by adding new replica locations or 
removing unused region
+   * replicas
+   */
+  public void updateRegionReplicas(TableName tableName, int oldReplicaCount, 
int newReplicaCount)
+    throws IOException {
+    if (newReplicaCount < oldReplicaCount) {
+      removeRegionReplicas(tableName, oldReplicaCount, newReplicaCount);
+    } else if (newReplicaCount > oldReplicaCount) {
+      addRegionReplicas(tableName, oldReplicaCount, newReplicaCount);
+    }
+  }

Review comment:
       If old and new  replica counts are equal, we just pass through -- that 
seems right.

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
##########
@@ -357,22 +358,29 @@ protected static void deleteFromFs(final 
MasterProcedureEnv env,
   /**
    * There may be items for this table still up in hbase:meta in the case 
where the info:regioninfo
    * column was empty because of some write error. Remove ALL rows from 
hbase:meta that have to do
-   * with this table. See HBASE-12980.
+   * with this table.
+   * <p/>
+   * See HBASE-12980.
    */
   private static void cleanRegionsInMeta(final MasterProcedureEnv env, final 
TableName tableName)
-      throws IOException {
-    Connection connection = env.getMasterServices().getConnection();
-    Scan tableScan = MetaTableAccessor.getScanForTableName(connection, 
tableName);
-    try (Table metaTable = connection.getTable(TableName.META_TABLE_NAME)) {
-      List<Delete> deletes = new ArrayList<>();
-      try (ResultScanner resScanner = metaTable.getScanner(tableScan)) {
-        for (Result result : resScanner) {
-          deletes.add(new Delete(result.getRow()));
+    throws IOException {
+    Scan tableScan = 
MetaTableAccessor.getScanForTableName(env.getMasterConfiguration(), tableName)
+      .setFilter(new KeyOnlyFilter());
+    long now = EnvironmentEdgeManager.currentTime();
+    List<Delete> deletes = new ArrayList<>();
+    try (

Review comment:
       You don't want to make this a try (Table metaTalbe = env.getMaster....) 
.. instead so it gets auto-closed? (nit)

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/DeleteTableProcedure.java
##########
@@ -357,22 +358,29 @@ protected static void deleteFromFs(final 
MasterProcedureEnv env,
   /**
    * There may be items for this table still up in hbase:meta in the case 
where the info:regioninfo
    * column was empty because of some write error. Remove ALL rows from 
hbase:meta that have to do
-   * with this table. See HBASE-12980.
+   * with this table.
+   * <p/>
+   * See HBASE-12980.
    */
   private static void cleanRegionsInMeta(final MasterProcedureEnv env, final 
TableName tableName)
-      throws IOException {
-    Connection connection = env.getMasterServices().getConnection();
-    Scan tableScan = MetaTableAccessor.getScanForTableName(connection, 
tableName);
-    try (Table metaTable = connection.getTable(TableName.META_TABLE_NAME)) {
-      List<Delete> deletes = new ArrayList<>();
-      try (ResultScanner resScanner = metaTable.getScanner(tableScan)) {
-        for (Result result : resScanner) {
-          deletes.add(new Delete(result.getRow()));
+    throws IOException {
+    Scan tableScan = 
MetaTableAccessor.getScanForTableName(env.getMasterConfiguration(), tableName)
+      .setFilter(new KeyOnlyFilter());
+    long now = EnvironmentEdgeManager.currentTime();
+    List<Delete> deletes = new ArrayList<>();
+    try (

Review comment:
       Ditto on the ResultScanner?

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStateStore.java
##########
@@ -545,6 +547,83 @@ public void overwriteRegions(List<RegionInfo> regionInfos, 
int regionReplication
     LOG.debug("Overwritten regions: {} ", regionInfos);
   }
 
+  /**
+   * Update region replicas if necessary by adding new replica locations or 
removing unused region
+   * replicas
+   */
+  public void updateRegionReplicas(TableName tableName, int oldReplicaCount, 
int newReplicaCount)
+    throws IOException {
+    if (newReplicaCount < oldReplicaCount) {
+      removeRegionReplicas(tableName, oldReplicaCount, newReplicaCount);
+    } else if (newReplicaCount > oldReplicaCount) {
+      addRegionReplicas(tableName, oldReplicaCount, newReplicaCount);
+    }
+  }
+
+  private Scan getScanForUpdateRegionReplicas(TableName tableName) {
+    return MetaTableAccessor.getScanForTableName(master.getConfiguration(), 
tableName)
+      .addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
+  }
+
+  private void removeRegionReplicas(TableName tableName, int oldReplicaCount, 
int newReplicaCount)
+    throws IOException {
+    Scan scan = getScanForUpdateRegionReplicas(tableName);
+    List<Delete> deletes = new ArrayList<>();
+    long now = EnvironmentEdgeManager.currentTime();
+    try (Table metaTable = getMetaTable(); ResultScanner scanner = 
metaTable.getScanner(scan)) {
+      for (;;) {
+        Result result = scanner.next();
+        if (result == null) {
+          break;
+        }
+        RegionInfo primaryRegionInfo = 
CatalogFamilyFormat.getRegionInfo(result);
+        if (primaryRegionInfo == null || primaryRegionInfo.isSplitParent()) {
+          continue;
+        }
+        Delete delete = new Delete(result.getRow());
+        for (int i = newReplicaCount; i < oldReplicaCount; i++) {
+          delete.addColumns(HConstants.CATALOG_FAMILY, 
CatalogFamilyFormat.getServerColumn(i), now);
+          delete.addColumns(HConstants.CATALOG_FAMILY, 
CatalogFamilyFormat.getSeqNumColumn(i), now);
+          delete.addColumns(HConstants.CATALOG_FAMILY, 
CatalogFamilyFormat.getStartCodeColumn(i),
+            now);
+          delete.addColumns(HConstants.CATALOG_FAMILY, 
CatalogFamilyFormat.getServerNameColumn(i),
+            now);
+          delete.addColumns(HConstants.CATALOG_FAMILY, 
CatalogFamilyFormat.getRegionStateColumn(i),

Review comment:
       Not your fault but this is ugly... Pity replica columns were not tied 
together w/ a prefix (or in their on column family). For later.




----------------------------------------------------------------
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]


Reply via email to