morningman commented on a change in pull request #2847: Doris support in memory 
olap table
URL: https://github.com/apache/incubator-doris/pull/2847#discussion_r377108563
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java
 ##########
 @@ -1405,6 +1420,88 @@ private void sendClearAlterTask(Database db, OlapTable 
olapTable) {
         LOG.info("send clear alter task for table {}, number: {}", 
olapTable.getName(), batchTask.getTaskNum());
     }
 
+    public void sendUpdateTabletMetaInfoTask(Database db, OlapTable olapTable, 
boolean isInMemory) throws DdlException {
+        List<Partition> partitions = Lists.newArrayList();
+        db.readLock();
+        try {
+            partitions.addAll(olapTable.getPartitions());
+        } finally {
+            db.readUnlock();
+        }
+        for(Partition partition: partitions) {
+            sendUpdateTabletMetaTaskForPartition(db, olapTable, partition, 
isInMemory);
+        }
+    }
+
+    public void sendUpdateTabletMetaTaskForPartition(Database db,
+                                                     OlapTable olapTable,
+                                                     Partition partition,
+                                                     boolean isInMemory) 
throws DdlException {
+        // be id -> <tablet id,schemaHash>
+        Map<Long, Set<Pair<Long, Integer>>> beIdToTabletIdWithHash = 
Maps.newHashMap();
+        db.readLock();
+        try {
+            for (MaterializedIndex index : 
partition.getMaterializedIndices(IndexExtState.VISIBLE)) {
+                int schemaHash = 
olapTable.getSchemaHashByIndexId(index.getId());
+                for (Tablet tablet : index.getTablets()) {
+                    for (Replica replica : tablet.getReplicas()) {
+                        Set<Pair<Long, Integer>> tabletIdWithHash = 
beIdToTabletIdWithHash.computeIfAbsent(replica.getBackendId(), k -> 
Sets.newHashSet());
+                        tabletIdWithHash.add(new Pair<>(tablet.getId(), 
schemaHash));
+                    }
+                }
+            }
+        } finally {
+            db.readUnlock();
+        }
+
+        int totalTaskNum = beIdToTabletIdWithHash.keySet().size();
+        MarkedCountDownLatch<Long, Set<Pair<Long, Integer>>> countDownLatch = 
new MarkedCountDownLatch<>(totalTaskNum);
+        AgentBatchTask batchTask = new AgentBatchTask();
+        for(Map.Entry<Long, Set<Pair<Long, Integer>>> kv: 
beIdToTabletIdWithHash.entrySet()) {
+            countDownLatch.addMark(kv.getKey(), kv.getValue());
+            UpdateTabletMetaInfoTask task = new 
UpdateTabletMetaInfoTask(kv.getKey(), kv.getValue(),
+                                                isInMemory,countDownLatch);
+            batchTask.addTask(task);
+        }
+        if (!FeConstants.runningUnitTest) {
+            // send all tasks and wait them finished
+            AgentTaskQueue.addBatchTask(batchTask);
+            AgentTaskExecutor.submit(batchTask);
+            LOG.info("send update tablet meta task for table {}, partitions 
{}, number: {}",
+                    olapTable.getName(), partition.getName(), 
batchTask.getTaskNum());
+
+            // estimate timeout
+            long timeout = Config.tablet_create_timeout_second * 1000L * 
totalTaskNum;
+            timeout = Math.min(timeout, Config.max_create_table_timeout_second 
* 1000);
+            boolean ok = false;
+            try {
+                ok = countDownLatch.await(timeout, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                LOG.warn("InterruptedException: ", e);
+            }
+
+            String errMsg;
 
 Review comment:
   `String errMsg;` can be put in the following `if` clause

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


With regards,
Apache Git Services

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

Reply via email to