This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new e7bb2f6c5c9 IGNITE-26499 Fix registering table metrics on recovery 
(#6730)
e7bb2f6c5c9 is described below

commit e7bb2f6c5c9672749e06d740144eb1306bb91932
Author: Slava Koptilin <[email protected]>
AuthorDate: Fri Oct 10 19:41:58 2025 +0300

    IGNITE-26499 Fix registering table metrics on recovery (#6730)
---
 .../internal/table/distributed/TableManager.java   | 47 ++++++++++++++--------
 .../internal/table/metrics/TableMetricSource.java  |  5 ++-
 2 files changed, 35 insertions(+), 17 deletions(-)

diff --git 
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
 
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
index 1da94c5d46c..9d0ede0ce26 100644
--- 
a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
+++ 
b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java
@@ -1186,7 +1186,7 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
 
     private void onTableDrop(DropTableEventParameters parameters) {
         inBusyLock(busyLock, () -> {
-            unregisterMetricsSource(parameters.tableId());
+            unregisterMetricsSource(startedTables.get(parameters.tableId()));
 
             destructionEventsQueue.enqueue(new 
DestroyTableEvent(parameters.catalogVersion(), parameters.tableId()));
         });
@@ -3087,7 +3087,12 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
 
                     PartitionModificationCounterMetricSource metricSource = 
partModCounterMetricSources.remove(tablePartitionId);
                     if (metricSource != null) {
-                        metricManager.unregisterSource(metricSource);
+                        try {
+                            metricManager.unregisterSource(metricSource);
+                        } catch (Exception e) {
+                            String message = "Failed to register metrics 
source for table [name={}, partitionId={}].";
+                            LOG.warn(message, e, table.name(), 
tablePartitionId.partitionId());
+                        }
                     }
 
                     return mvGc.removeStorage(tablePartitionId);
@@ -3188,7 +3193,7 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
         PartitionModificationCounter modificationCounter = 
partitionModificationCounterFactory.create(
                 partSizeSupplier, table::stalenessConfiguration
         );
-        registerPartitionModificationCounterMetrics(table.tableId(), 
partitionId, modificationCounter);
+        registerPartitionModificationCounterMetrics(table, partitionId, 
modificationCounter);
 
         StorageUpdateHandler storageUpdateHandler = new StorageUpdateHandler(
                 partitionId,
@@ -3202,10 +3207,12 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
     }
 
     private void registerPartitionModificationCounterMetrics(
-            int tableId, int partitionId, PartitionModificationCounter 
counter) {
-
+            TableViewInternal table,
+            int partitionId,
+            PartitionModificationCounter counter
+    ) {
         PartitionModificationCounterMetricSource metricSource =
-                new PartitionModificationCounterMetricSource(tableId, 
partitionId);
+                new PartitionModificationCounterMetricSource(table.tableId(), 
partitionId);
 
         metricSource.addMetric(new LongGauge(
                 PartitionModificationCounterMetricSource.METRIC_COUNTER,
@@ -3228,10 +3235,14 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
                 () -> counter.lastMilestoneTimestamp().longValue()
         ));
 
-        metricManager.registerSource(metricSource);
-        metricManager.enable(metricSource);
+        try {
+            metricManager.registerSource(metricSource);
+            metricManager.enable(metricSource);
 
-        partModCounterMetricSources.put(new TablePartitionId(tableId, 
partitionId), metricSource);
+            partModCounterMetricSources.put(new 
TablePartitionId(table.tableId(), partitionId), metricSource);
+        } catch (Exception e) {
+            LOG.warn("Failed to register metrics source for table [name={}, 
partitionId={}].", e, table.name(), partitionId);
+        }
     }
 
     /**
@@ -3307,9 +3318,8 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
                 // Handle missed table drop event.
                 int tableId = tableDescriptor.id();
 
-                if (nextCatalog != null && nextCatalog.table(tableId) == null) 
{
-                    unregisterMetricsSource(tableId);
-
+                boolean destroyTableEventFired = nextCatalog != null && 
nextCatalog.table(tableId) == null;
+                if (destroyTableEventFired) {
                     destructionEventsQueue.enqueue(new 
DestroyTableEvent(nextCatalog.version(), tableId));
                 }
 
@@ -3329,6 +3339,12 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
                             tableDescriptor,
                             schemaDescriptor
                     );
+
+                    if (destroyTableEventFired) {
+                        // prepareTableResourcesOnRecovery registers a table 
metric source, so we need to unregister it here,
+                        // just because the table is being dropped and there 
is no need to keep the metric source.
+                        unregisterMetricsSource(tables.get(tableId));
+                    }
                 } else {
                     startTableFuture = createTableLocally(recoveryRevision, 
ver, tableDescriptor, true);
                 }
@@ -3668,8 +3684,7 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
         return source;
     }
 
-    private void unregisterMetricsSource(int tableId) {
-        TableViewInternal table = startedTables.get(tableId);
+    private void unregisterMetricsSource(TableViewInternal table) {
         if (table == null) {
             return;
         }
@@ -3679,7 +3694,7 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
         try {
             
metricManager.unregisterSource(TableMetricSource.sourceName(tableName));
         } catch (Exception e) {
-            LOG.warn("Failed to unregister metrics source for table [id={}, 
name={}].", e, tableId, tableName);
+            LOG.warn("Failed to unregister metrics source for table [id={}, 
name={}].", e, table.tableId(), tableName);
         }
 
         String storageProfile = 
table.internalTable().storage().getTableDescriptor().getStorageProfile();
@@ -3689,7 +3704,7 @@ public class TableManager implements 
IgniteTablesInternal, IgniteComponent {
             try {
                 
metricManager.unregisterSource(StorageEngineTablesMetricSource.sourceName(engine.name(),
 tableName));
             } catch (Exception e) {
-                LOG.warn("Failed to unregister storage engine metrics source 
for table [id={}, name={}].", e, tableId, tableName);
+                LOG.warn("Failed to unregister storage engine metrics source 
for table [id={}, name={}].", e, table.tableId(), tableName);
             }
         }
     }
diff --git 
a/modules/table/src/main/java/org/apache/ignite/internal/table/metrics/TableMetricSource.java
 
b/modules/table/src/main/java/org/apache/ignite/internal/table/metrics/TableMetricSource.java
index 732c6b55f24..a8800ee4c52 100644
--- 
a/modules/table/src/main/java/org/apache/ignite/internal/table/metrics/TableMetricSource.java
+++ 
b/modules/table/src/main/java/org/apache/ignite/internal/table/metrics/TableMetricSource.java
@@ -129,7 +129,10 @@ public class TableMetricSource extends 
AbstractMetricSource<Holder> {
     }
 
     /**
-     * Returns a metric source name for the given table.
+     * Returns a metric source name for the given table name.
+     *
+     * @param tableName Qualified table name.
+     * @return Metric source name.
      */
     public static String sourceName(QualifiedName tableName) {
         return SOURCE_NAME + '.' + tableName.toCanonicalForm();

Reply via email to