morningman commented on a change in pull request #1522: Support setting replica 
status as bad manually
URL: https://github.com/apache/incubator-doris/pull/1522#discussion_r392636403
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/catalog/Catalog.java
 ##########
 @@ -6139,5 +6140,47 @@ public void replayBackendTabletsInfo(BackendTabletsInfo 
backendTabletsInfo) {
             replica.setBad(backendTabletsInfo.isBad());
         }
     }
+
+    // Set specified replica's status. If replica does not exist, just ignore 
it.
+    public void setReplicaStatus(AdminSetReplicaStatusStmt stmt) {
+        List<Long> tabletIds = stmt.getTabletIds();
+        long backendId = stmt.getBackendId();
+        String status = stmt.getStatus();
+
+        BackendTabletsInfo tabletsInfo = new BackendTabletsInfo(backendId);
+        tabletsInfo.setBad(true);
+        for (Long tabletId : tabletIds) {
+            TabletMeta meta = tabletInvertedIndex.getTabletMeta(tabletId);
+            if (meta == null) {
+                LOG.info("tablet {} does not exist", tabletId);
+                continue;
+            }
+            long dbId = meta.getDbId();
+            Database db = getDb(dbId);
+            if (db == null) {
+                LOG.info("database {} of tablet {} does not exist", dbId, 
tabletId);
+                continue;
+            }
+            db.writeLock();
+            try {
+                Replica replica = tabletInvertedIndex.getReplica(tabletId, 
backendId);
+                if (replica == null) {
+                    LOG.info("replica of tablet {} does not exist", tabletId);
+                    continue;
+                }
+                if (status.equals(AdminSetReplicaStatusStmt.STATUS_BAD)) {
+                    if (replica.setBad(true)) {
+                        tabletsInfo.addTabletWithSchemaHash(tabletId, 
meta.getOldSchemaHash());
+                        LOG.info("set replica {} of tablet {} on backend {} as 
bad",
+                                replica.getId(), tabletId, backendId);
+                    }
+                }
+            } finally {
+                db.writeUnlock();
+            }
+        }
+
+        Catalog.getInstance().getEditLog().logBackendTabletsInfo(tabletsInfo);
 
 Review comment:
   I move the log operation inside the db writelock

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to