You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/08/16 07:11:39 UTC

[GitHub] [hbase] Apache9 commented on a change in pull request #498: HBASE-22819 Automatically migrate the rs group config for table after…

Apache9 commented on a change in pull request #498: HBASE-22819 Automatically migrate the rs group config for table after…
URL: https://github.com/apache/hbase/pull/498#discussion_r314606422
 
 

 ##########
 File path: hbase-server/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
 ##########
 @@ -356,9 +358,112 @@ public synchronized void removeServers(Set<Address> servers) throws IOException
     return RSGroupInfoList;
   }
 
-  @Override
-  public void refresh() throws IOException {
-    refresh(false);
+  private void waitUntilSomeProcsDone(Set<Long> pendingProcIds) {
+    int size = pendingProcIds.size();
+    while (!masterServices.isStopped()) {
+      for (Iterator<Long> iter = pendingProcIds.iterator(); iter.hasNext();) {
+        long procId = iter.next();
+        if (masterServices.getMasterProcedureExecutor().isFinished(procId)) {
+          iter.remove();
+        }
+      }
+      if (pendingProcIds.size() < size) {
+        return;
+      }
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+      }
+    }
+  }
+
+  private void waitUntilMasterStarted() {
+    while (!masterServices.isInitialized() && !masterServices.isStopped()) {
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+      }
+    }
+  }
+
+  private void migrate(List<RSGroupInfo> groupList, int maxConcurrency) {
+    LOG.info("Start migrating table rs group config");
+    waitUntilMasterStarted();
+    Set<Long> pendingProcIds = new HashSet<>();
+    for (RSGroupInfo groupInfo : groupList) {
+      if (groupInfo.getName().equals(RSGroupInfo.DEFAULT_GROUP)) {
+        continue;
+      }
+      SortedSet<TableName> failedTables = new TreeSet<>();
+      for (TableName tableName : groupInfo.getTables()) {
+        LOG.info("Migrating {} in group {}", tableName, groupInfo.getName());
+        TableDescriptor oldTd;
+        try {
+          oldTd = masterServices.getTableDescriptors().get(tableName);
+        } catch (IOException e) {
+          LOG.warn("Failed to migrate {} in group {}", tableName, groupInfo.getName(), e);
+          failedTables.add(tableName);
+          continue;
+        }
+        if (oldTd == null) {
+          continue;
+        }
+        if (oldTd.getRegionServerGroup().isPresent()) {
+          // either we have already migrated it or that user has set the rs group with the new
+          // code, skip.
+          LOG.debug("Skip migrating {} since it is already in group {}", tableName,
+            oldTd.getRegionServerGroup().get());
+          continue;
+        }
+        TableDescriptor newTd = TableDescriptorBuilder.newBuilder(oldTd)
+          .setRegionServerGroup(groupInfo.getName()).build();
+        try {
+          pendingProcIds.add(
+            masterServices.modifyTable(tableName, newTd, HConstants.NO_NONCE, HConstants.NO_NONCE));
 
 Review comment:
   Yes, this is the safest way...

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services