ibessonov commented on code in PR #7387:
URL: https://github.com/apache/ignite-3/pull/7387#discussion_r2811241155


##########
modules/file-io/src/main/java/org/apache/ignite/internal/fileio/MeteredFileIo.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.ignite.internal.fileio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+
+/**
+ * FileIo decorator that records metrics for read and write operations.
+ */
+public class MeteredFileIo implements FileIo {

Review Comment:
   I propose two "alternatives":
   - You can extend this class from 
`org.apache.ignite.internal.fileio.FileIoDecorator` to reduce the volume of 
unnecessary code.
   - Or you can introduce all such changes into 
`org.apache.ignite.internal.fileio.AbstractFileIo`, given that we will always 
use metrics for IO.
   
   I think I would prefer option 1, it's a bit more flexible. Both options 
would help us to track individual file access in methods like `readFully` or 
`writeFully`, instead of measuring an entire batch.



##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/store/FilePageStoreIoTest.java:
##########
@@ -113,6 +124,40 @@ void testCheckHeader() throws Exception {
         }
     }
 
+    @Test
+    void testIoMetricsRecordedDuringActualFileOperations() throws Exception {
+        Path testFilePath = workDir.resolve("test");
+
+        CollectionMetricSource ioMetricSource = new 
CollectionMetricSource("testPageStoreIo", "storage", "Page memory I/O metrics");
+        PageMemoryIoMetrics ioMetrics = new 
PageMemoryIoMetrics(ioMetricSource);
+        MetricSet metricSet = ioMetricSource.enable();
+
+        long pageId = pageId(0, FLAG_DATA, 0);
+
+        try (FilePageStoreIo filePageStoreIo = 
createFilePageStoreIo(testFilePath, ioMetrics)) {
+            // Verify metrics start at zero
+            assertMetricValue(metricSet, PageMemoryIoMetrics.TOTAL_BYTES_READ, 
 0L);
+            assertMetricValue(metricSet, 
PageMemoryIoMetrics.TOTAL_BYTES_WRITTEN,  0L);
+
+            // Perform write operation
+            ByteBuffer writeBuffer = createPageByteBuffer(pageId, PAGE_SIZE);
+            filePageStoreIo.write(pageId, writeBuffer);

Review Comment:
   Please either assert the result of `write` operation or use `writeFully`



##########
modules/file-io/src/main/java/org/apache/ignite/internal/fileio/FileIoMetrics.java:
##########
@@ -15,16 +15,25 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.cli.core.style;
+package org.apache.ignite.internal.fileio;
 
 /**
- * Provider for the current color scheme.
+ * Metrics for file I/O operations.
  */
-public interface ColorSchemeProvider {
+public interface FileIoMetrics {
     /**
-     * Returns the current color scheme.
+     * Records a read operation.
      *
-     * @return Current color scheme, never null.
+     * @param bytesRead Number of bytes read (positive on success, 0 for EOF, 
-1 on error).
+     * @param durationNanos Operation duration in nanoseconds.
      */
-    ColorScheme colorScheme();
+    void recordRead(int bytesRead, long durationNanos);
+
+    /**
+     * Records a write operation.
+     *
+     * @param bytesWritten Number of bytes written (positive on success, 0 or 
-1 on error).

Review Comment:
   What does `0` mean? Is it success or error?



##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/store/FilePageStoreIoTest.java:
##########
@@ -113,6 +124,40 @@ void testCheckHeader() throws Exception {
         }
     }
 
+    @Test
+    void testIoMetricsRecordedDuringActualFileOperations() throws Exception {
+        Path testFilePath = workDir.resolve("test");
+
+        CollectionMetricSource ioMetricSource = new 
CollectionMetricSource("testPageStoreIo", "storage", "Page memory I/O metrics");
+        PageMemoryIoMetrics ioMetrics = new 
PageMemoryIoMetrics(ioMetricSource);
+        MetricSet metricSet = ioMetricSource.enable();
+
+        long pageId = pageId(0, FLAG_DATA, 0);
+
+        try (FilePageStoreIo filePageStoreIo = 
createFilePageStoreIo(testFilePath, ioMetrics)) {
+            // Verify metrics start at zero
+            assertMetricValue(metricSet, PageMemoryIoMetrics.TOTAL_BYTES_READ, 
 0L);
+            assertMetricValue(metricSet, 
PageMemoryIoMetrics.TOTAL_BYTES_WRITTEN,  0L);
+
+            // Perform write operation
+            ByteBuffer writeBuffer = createPageByteBuffer(pageId, PAGE_SIZE);
+            filePageStoreIo.write(pageId, writeBuffer);
+
+            // Verify write metrics were recorded - 1 write of header + 1 
write of page
+            assertMetricValue(metricSet, 
PageMemoryIoMetrics.TOTAL_BYTES_WRITTEN,  PAGE_SIZE * 2);
+            assertDistributionMetricRecordsCount(metricSet, 
PageMemoryIoMetrics.WRITES_TIME, 2L);
+
+            // Perform read operation
+            long pageOff = filePageStoreIo.pageOffset(pageId);
+            ByteBuffer readBuffer = 
ByteBuffer.allocateDirect(PAGE_SIZE).order(java.nio.ByteOrder.nativeOrder());
+            filePageStoreIo.read(pageId, pageOff, readBuffer, false);

Review Comment:
   Same comment is applied to `read`



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