imay 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_r305623714
 
 

 ##########
 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 think there is a lack of synchronization mechanism here. You change 
replica  in memory to bad and log it. And maybe another thread change it to 
good and log it too. But there is no protect for these operation. This can lead 
differences between master and follower.
   
   For example,
   OP 1: set memory bad 
   OP 2: set memory good
   OP 3: log good
   OP 4: log bad
   
   And then, in master memory this replica is good, and in followers or 
observers replica status is bad.

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