englefly commented on code in PR #22227:
URL: https://github.com/apache/doris/pull/22227#discussion_r1275779950


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/InternalSchemaInitializer.java:
##########
@@ -75,6 +77,52 @@ public void run() {
             }
         }
         LOG.info("Internal schema is initialized");
+        Optional<Database> op
+                = 
Env.getCurrentEnv().getInternalCatalog().getDb(StatisticConstants.DB_NAME);
+        if (!op.isPresent()) {
+            LOG.warn("Internal DB got deleted!");
+            return;
+        }
+        Database database = op.get();
+        modifyTblReplicaCount(database, StatisticConstants.ANALYSIS_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.STATISTIC_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.HISTOGRAM_TBL_NAME);
+    }
+
+    public void modifyTblReplicaCount(Database database, String tblName) {
+        if (!(Config.min_replication_num_per_tablet < 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM
+                && Config.max_replication_num_per_tablet >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM)) {
+            return;
+        }
+        while (true) {
+            if (Env.getCurrentSystemInfo().aliveBECount() >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM) {
+                try {
+                    Map<String, String> props = new HashMap<>();
+                    
props.put(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION, 
"tag.location.default: 3");

Review Comment:
   "tag.location.default: 3" =>"tag.location.default: 
“+StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/InternalSchemaInitializer.java:
##########
@@ -75,6 +77,52 @@ public void run() {
             }
         }
         LOG.info("Internal schema is initialized");
+        Optional<Database> op
+                = 
Env.getCurrentEnv().getInternalCatalog().getDb(StatisticConstants.DB_NAME);
+        if (!op.isPresent()) {
+            LOG.warn("Internal DB got deleted!");
+            return;
+        }
+        Database database = op.get();
+        modifyTblReplicaCount(database, StatisticConstants.ANALYSIS_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.STATISTIC_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.HISTOGRAM_TBL_NAME);
+    }
+
+    public void modifyTblReplicaCount(Database database, String tblName) {
+        if (!(Config.min_replication_num_per_tablet < 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM
+                && Config.max_replication_num_per_tablet >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM)) {
+            return;
+        }
+        while (true) {
+            if (Env.getCurrentSystemInfo().aliveBECount() >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM) {
+                try {
+                    Map<String, String> props = new HashMap<>();
+                    
props.put(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION, 
"tag.location.default: 3");

Review Comment:
   "tag.location.default: 3" =>"tag.location.default: 
“+StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/InternalSchemaInitializer.java:
##########
@@ -75,6 +77,52 @@ public void run() {
             }
         }
         LOG.info("Internal schema is initialized");
+        Optional<Database> op
+                = 
Env.getCurrentEnv().getInternalCatalog().getDb(StatisticConstants.DB_NAME);
+        if (!op.isPresent()) {
+            LOG.warn("Internal DB got deleted!");
+            return;
+        }
+        Database database = op.get();
+        modifyTblReplicaCount(database, StatisticConstants.ANALYSIS_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.STATISTIC_TBL_NAME);
+        modifyTblReplicaCount(database, StatisticConstants.HISTOGRAM_TBL_NAME);
+    }
+
+    public void modifyTblReplicaCount(Database database, String tblName) {
+        if (!(Config.min_replication_num_per_tablet < 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM
+                && Config.max_replication_num_per_tablet >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM)) {
+            return;
+        }
+        while (true) {
+            if (Env.getCurrentSystemInfo().aliveBECount() >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM) {
+                try {
+                    Map<String, String> props = new HashMap<>();
+                    
props.put(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION, 
"tag.location.default: 3");
+                    TableIf colStatsTbl = 
StatisticsUtil.findTable(InternalCatalog.INTERNAL_CATALOG_NAME,
+                            StatisticConstants.DB_NAME, tblName);
+                    OlapTable olapTable = (OlapTable) colStatsTbl;
+                    Partition partition = 
olapTable.getPartition(olapTable.getName());
+                    if (partition.getReplicaCount() >= 
StatisticConstants.STATISTIC_INTERNAL_TABLE_REPLICA_NUM) {
+                        return;
+                    }
+                    try {
+                        colStatsTbl.writeLock();
+                        
Env.getCurrentEnv().modifyTableReplicaAllocation(database, (OlapTable) 
colStatsTbl, props);
+                    } finally {
+                        colStatsTbl.writeUnlock();
+                    }
+                    break;
+                } catch (Throwable t) {
+                    LOG.warn("Failed to scale replica of stats tbl:{} to 3", 
tblName, t);
+                }
+                try {
+                    Thread.sleep(5000);

Review Comment:
   this sleep should be moved into else block



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

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to