AMashenkov commented on code in PR #6649:
URL: https://github.com/apache/ignite-3/pull/6649#discussion_r2413285605


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/statistic/SqlStatisticManagerImpl.java:
##########
@@ -151,6 +126,57 @@ public void start() {
                 tableSizeMap.putIfAbsent(table.id(), DEFAULT_VALUE);
             }
         }
+
+        scheduler.scheduleAtFixedRate(this::update, INITIAL_DELAY, 
REFRESH_PERIOD, TimeUnit.MILLISECONDS);
+    }
+
+    private void update() {
+        if (!latestUpdateFut.get().isDone()) {
+            return;
+        }
+
+        for (Map.Entry<Integer, ActualSize> ent : tableSizeMap.entrySet()) {
+            Integer tableId = ent.getKey();
+
+            if (droppedTables.contains(tableId)) {
+                continue;
+            }
+
+            TableViewInternal tableView = tableManager.cachedTable(tableId);
+
+            if (tableView == null) {
+                LOG.debug("No table found to update statistics [id={}].", 
ent.getKey());
+                continue;
+            }
+
+            CompletableFuture<Void> updateResult = 
statSupplier.estimatedSizeWithLastUpdate(tableView.internalTable())
+                    .handle((res, err) -> {
+                            if (err != null) {
+                                LOG.debug("Can't calculate size for table 
[id={}].", err, tableId);
+
+                                return null;
+                            } else {
+                                // the table can be concurrently dropped and 
we shouldn't put new value in this case.
+                                tableSizeMap.compute(tableId, (k, v) -> {
+                                    if (v == null) {
+                                        return new 
ActualSize(Math.max(res.keyLong(), DEFAULT_TABLE_SIZE), res.value());
+                                    }
+
+                                    // check for stale update
+                                    if (v.timestamp.compareTo(res.value()) > 
0) {
+                                        return v;
+                                    }
+
+                                    return new 
ActualSize(Math.max(res.keyLong(), DEFAULT_TABLE_SIZE), res.value());
+                                });
+
+                                return null;
+                            }
+                        }
+                    );
+
+            latestUpdateFut.updateAndGet(prev -> prev == null ? updateResult : 
prev.thenCompose(none -> updateResult));

Review Comment:
   Here we can set `null` if `estimatedSizeWithLastUpdate` call was 
unsuccessful.
   Why can't we just keep previous value?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to