You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ti...@apache.org on 2025/05/16 07:48:39 UTC

(ignite) branch master updated: IGNITE-25376 PerfStat: fix reading empty unsupported system views (#12059)

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

timoninmaxim pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 36ec141e7a7 IGNITE-25376 PerfStat: fix reading empty unsupported system views (#12059)
36ec141e7a7 is described below

commit 36ec141e7a7f29d33e6e11e3e63e1f82cc2a4d99
Author: Aleksandr Chesnokov <ch...@gmail.com>
AuthorDate: Fri May 16 10:48:31 2025 +0300

    IGNITE-25376 PerfStat: fix reading empty unsupported system views (#12059)
---
 .../FilePerformanceStatisticsReader.java           | 76 ++++++++++++++++++++--
 .../PerformanceStatisticsSystemViewTest.java       | 70 ++++++++++++++++++++
 2 files changed, 140 insertions(+), 6 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsReader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsReader.java
index c97527f4eba..e7f84986fbe 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/performancestatistics/FilePerformanceStatisticsReader.java
@@ -307,10 +307,13 @@ public class FilePerformanceStatisticsReader {
             assert walkerName.str != null : "Views are written by single thread, no string cache misses are possible";
 
             try {
-                sysViewEntry = new SystemViewEntry(viewName.str, walkerName.str);
+                sysViewEntry = new SystemViewEntryImpl(viewName.str, walkerName.str);
+            }
+            catch (ClassNotFoundException e) {
+                sysViewEntry = new UnsupportedSystemViewEntry(viewName.str, walkerName.str);
             }
             catch (ReflectiveOperationException e) {
-                throw new IgniteException("Could not find walker: " + walkerName);
+                throw new IgniteException("Failed to instantiate " + walkerName.str + " walker for " + viewName.str + " system view.");
             }
 
             return true;
@@ -322,7 +325,7 @@ public class FilePerformanceStatisticsReader {
                 return false;
 
             for (PerformanceStatisticsHandler hnd : curHnd)
-                hnd.systemView(nodeId, sysViewEntry.viewName, sysViewEntry.schema, row);
+                hnd.systemView(nodeId, sysViewEntry.viewName(), sysViewEntry.schema(), row);
 
             return true;
         }
@@ -661,8 +664,26 @@ public class FilePerformanceStatisticsReader {
         }
     }
 
+    /** System view entry. */
+    private interface SystemViewEntry {
+        /**
+         * @return System view name.
+         */
+        String viewName();
+
+        /**
+         * @return System view schema.
+         */
+        List<String> schema();
+
+        /**
+         * @return System view row.
+         */
+        List<Object> nextRow();
+    }
+
     /** Reads views from buf. */
-    private class SystemViewEntry {
+    private class SystemViewEntryImpl implements SystemViewEntry {
         /** */
         private final String viewName;
 
@@ -679,7 +700,7 @@ public class FilePerformanceStatisticsReader {
          * @param viewName System view name.
          * @param walkerName Name of walker to visist system view attributes.
          */
-        public SystemViewEntry(String viewName, String walkerName) throws ReflectiveOperationException {
+        public SystemViewEntryImpl(String viewName, String walkerName) throws ReflectiveOperationException {
             walker = (SystemViewRowAttributeWalker<?>)Class.forName(walkerName).getConstructor().newInstance();
 
             this.viewName = viewName;
@@ -697,16 +718,59 @@ public class FilePerformanceStatisticsReader {
             rowVisitor = new RowReaderVisitor(schema.size());
         }
 
+        /** {@inheritDoc} */
+        @Override public String viewName() {
+            return viewName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public List<String> schema() {
+            return schema;
+        }
+
         /**
          * @return System view row.
          */
-        public List<Object> nextRow() {
+        @Override public List<Object> nextRow() {
             rowVisitor.clear();
             walker.visitAll(rowVisitor);
             return rowVisitor.row();
         }
     }
 
+    /** System view entry for unsupported system view walker. */
+    private static class UnsupportedSystemViewEntry implements SystemViewEntry {
+        /** View name. */
+        private final String viewName;
+
+        /** Walker name. */
+        private final String walkerName;
+
+        /**
+         * @param viewName System view name.
+         * @param walkerName Name of walker to visist system view attributes.
+         */
+        public UnsupportedSystemViewEntry(String viewName, String walkerName) {
+            this.viewName = viewName;
+            this.walkerName = walkerName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String viewName() {
+            return viewName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public List<String> schema() {
+            throw new IgniteException(viewName + " system view with" + walkerName + " walker is not supported.");
+        }
+
+        /** {@inheritDoc} */
+        @Override public List<Object> nextRow() {
+            throw new IgniteException(viewName + " system view with" + walkerName + " walker is not supported.");
+        }
+    }
+
     /** */
     private class RowReaderVisitor implements SystemViewRowAttributeWalker.AttributeVisitor {
         /** Number of system view attributes. */
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSystemViewTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSystemViewTest.java
index bbd27e232c7..8f1ffcd59d7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSystemViewTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/PerformanceStatisticsSystemViewTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.ignite.internal.processors.performancestatistics;
 
+import java.io.File;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -28,13 +31,19 @@ import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.managers.systemview.GridSystemViewManager;
 import org.apache.ignite.internal.managers.systemview.walker.MetastorageViewWalker;
+import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
+import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.systemview.view.MetastorageView;
 import org.apache.ignite.testframework.ListeningTestLogger;
 import org.apache.ignite.testframework.LogListener;
 import org.junit.Test;
 
+import static java.util.UUID.randomUUID;
 import static java.util.function.Function.identity;
+import static org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW;
+import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.PERF_STAT_DIR;
+import static org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsWriter.writeString;
 import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
 
 /**
@@ -56,6 +65,9 @@ public class PerformanceStatisticsSystemViewTest extends AbstractPerformanceStat
     /** */
     private static final int INVALID_VIEWS_CNT = 10;
 
+    /** Read buffer size. */
+    private static final int BUFFER_SIZE = 100;
+
     /** */
     private final ListeningTestLogger listeningLog = new ListeningTestLogger();
 
@@ -152,4 +164,62 @@ public class PerformanceStatisticsSystemViewTest extends AbstractPerformanceStat
             assertEquals(viewsExpected, viewsActual);
         }
     }
+
+    /** Tests empty system view with custom system view walker. */
+    @Test
+    public void testCustomEmptySystemView() throws Exception {
+        File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), PERF_STAT_DIR, false);
+
+        List<String> expRow = createStatistics(dir);
+
+        FilePerformanceStatisticsReader reader = new FilePerformanceStatisticsReader(BUFFER_SIZE, new TestHandler() {
+            @Override public void systemView(UUID id, String name, List<String> schema, List<Object> row) {
+                assertEquals(METASTORE_VIEW, name);
+                assertEquals(expRow, row);
+            }
+        });
+
+        reader.read(List.of(dir));
+    }
+
+    /** Creates test performance statistics file. */
+    private List<String> createStatistics(File dir) throws Exception {
+        File file = new File(dir, "node-" + randomUUID() + ".prf");
+
+        try (FileIO fileIo = new RandomAccessFileIOFactory().create(file)) {
+            ByteBuffer buf = ByteBuffer.allocate(1024).order(ByteOrder.nativeOrder());
+
+            buf.put(OperationType.VERSION.id());
+            buf.putShort(FilePerformanceStatisticsWriter.FILE_FORMAT_VERSION);
+
+            writeSystemView(buf, "customView", "customWalker", null);
+
+            List<String> row = List.of("key", "value");
+            writeSystemView(buf, METASTORE_VIEW, MetastorageViewWalker.class.getName(), row);
+
+            buf.flip();
+
+            fileIo.write(buf);
+
+            fileIo.force();
+
+            return row;
+        }
+    }
+
+    /** */
+    private void writeSystemView(ByteBuffer buf, String view, String walker, List<String> row) {
+        buf.put(OperationType.SYSTEM_VIEW_SCHEMA.id());
+
+        writeString(buf, view, false);
+        writeString(buf, walker, false);
+
+        if (row == null)
+            return;
+
+        buf.put(OperationType.SYSTEM_VIEW_ROW.id());
+
+        for (String val : row)
+            writeString(buf, val, false);
+    }
 }