JingsongLi commented on code in PR #5550: URL: https://github.com/apache/paimon/pull/5550#discussion_r2083549112
########## paimon-common/src/main/java/org/apache/paimon/fs/MetricsFileIO.java: ########## @@ -0,0 +1,113 @@ +/* + * 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.paimon.fs; + +import org.apache.paimon.annotation.VisibleForTesting; +import org.apache.paimon.catalog.CatalogContext; +import org.apache.paimon.fs.metrics.InputMetrics; +import org.apache.paimon.fs.metrics.OutputMetrics; + +import java.io.IOException; + +/** + * FileIOWrapper is a wrapper class for the {@link FileIO}. + * + * <p>It allows users to monitor and track file I/O operations (e.g., read, write, delete, rename). + */ +public class MetricsFileIO implements FileIO { + + protected final FileIO fileIO; + protected InputMetrics inputMetrics = null; + protected OutputMetrics outputMetrics = null; + + public MetricsFileIO(FileIO fileIO) { + this.fileIO = fileIO; + } + + public MetricsFileIO withMetrics(InputMetrics inputMetrics, OutputMetrics outputMetrics) { + this.inputMetrics = inputMetrics; + this.outputMetrics = outputMetrics; + return this; + } + + public FileIO getFileIOInternal() { + FileIO currentFileIO = fileIO; + while (currentFileIO instanceof MetricsFileIO) { + currentFileIO = ((MetricsFileIO) currentFileIO).fileIO; + } + return currentFileIO; + } + + @VisibleForTesting + public Boolean isMetricsEnabled() { + return inputMetrics != null && outputMetrics != null; + } + + @Override + public boolean isObjectStore() { + return fileIO.isObjectStore(); + } + + @Override + public void configure(CatalogContext context) { + fileIO.configure(context); + } + + @Override + public SeekableInputStream newInputStream(Path path) throws IOException { + SeekableInputStream inputStream = fileIO.newInputStream(path); + return new SeekableInputStreamIOWrapper(inputStream, this.inputMetrics); Review Comment: Please consider `SeekableInputStream` can be `VectoredReadable`. -- 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]
