yiguolei commented on code in PR #23616:
URL: https://github.com/apache/doris/pull/23616#discussion_r1312435820


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/ColumnIdFlushDaemon.java:
##########
@@ -0,0 +1,134 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.alter.AlterLightSchChangeHelper;
+import org.apache.doris.common.util.MasterDaemon;
+
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * note(tsy): this class is temporary, make table before 1.2 to enable light 
schema change
+ */
+public class ColumnIdFlushDaemon extends MasterDaemon {
+
+    /**
+     * db name -> (tbl name -> status)
+     */
+    private final Map<String, Map<String, FlushStatus>> resultCollector;
+
+    private final ReadWriteLock rwLock;
+
+    public ColumnIdFlushDaemon() {
+        super("colum-id-flusher", TimeUnit.HOURS.toMillis(1));
+        resultCollector = Maps.newHashMap();
+        rwLock = new ReentrantReadWriteLock();
+    }
+
+    @Override
+    protected void runAfterCatalogReady() {
+        flush();
+    }
+
+    private void flush() {
+        List<Database> dbs = Env.getCurrentEnv().getInternalCatalog().getDbs();
+        rwLock.writeLock().lock();
+        try {
+            for (Database db : dbs) {
+                db.getTables()
+                        .stream()
+                        .filter(table -> table instanceof OlapTable)
+                        .map(table -> (OlapTable) table)
+                        .filter(olapTable -> 
!olapTable.getTableProperty().getUseSchemaLightChange())
+                        .forEach(table -> {
+                            try {
+                                table.writeLock();
+                                if 
(table.getTableProperty().getUseSchemaLightChange()) {
+                                    table.writeUnlock();
+                                    return;
+                                }
+                                new AlterLightSchChangeHelper(db, 
table).enableLightSchemaChange();

Review Comment:
   at line 66, you get the table write lock.
   but line 71, it is maybe a very very heavy function, it need call all BEs to 
get the tablet column info. Then other read query or write query is blocked.
   I think you should decompose the process to 2 stages:
   1. call all BEs to get column info and do some checking work, this stage 
does not need write lock.
   2. modify the table's property if all check passed, this stage need write 
lock.



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