Skip to content

Commit

Permalink
Move NamenodeStats to file system abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
weijiii authored and electrum committed May 7, 2023
1 parent 2bf4078 commit e3bdafb
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.trino.filesystem.TrinoInput;
import io.trino.filesystem.TrinoInputFile;
import io.trino.filesystem.TrinoInputStream;
import io.trino.hdfs.CallStats;
import io.trino.hdfs.HdfsContext;
import io.trino.hdfs.HdfsEnvironment;
import io.trino.hdfs.TrinoHdfsFileSystemStats;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
Expand All @@ -42,9 +42,9 @@ class HdfsInputFile
private final Path file;
private Long length;
private FileStatus status;
private TrinoHdfsFileSystemStats.CallStats openFileCallStat;
private CallStats openFileCallStat;

public HdfsInputFile(Location location, Long length, HdfsEnvironment environment, HdfsContext context, TrinoHdfsFileSystemStats.CallStats openFileCallStat)
public HdfsInputFile(Location location, Long length, HdfsEnvironment environment, HdfsContext context, CallStats openFileCallStat)
{
this.location = requireNonNull(location, "location is null");
this.environment = requireNonNull(environment, "environment is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import io.airlift.stats.TimeStat;
import io.trino.filesystem.Location;
import io.trino.filesystem.TrinoOutputFile;
import io.trino.hdfs.CallStats;
import io.trino.hdfs.HdfsContext;
import io.trino.hdfs.HdfsEnvironment;
import io.trino.hdfs.MemoryAwareFileSystem;
import io.trino.hdfs.TrinoHdfsFileSystemStats;
import io.trino.memory.context.AggregatedMemoryContext;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
Expand All @@ -37,9 +37,9 @@ class HdfsOutputFile
private final Location location;
private final HdfsEnvironment environment;
private final HdfsContext context;
private final TrinoHdfsFileSystemStats.CallStats createFileCallStat;
private final CallStats createFileCallStat;

public HdfsOutputFile(Location location, HdfsEnvironment environment, HdfsContext context, TrinoHdfsFileSystemStats.CallStats createFileCallStat)
public HdfsOutputFile(Location location, HdfsEnvironment environment, HdfsContext context, CallStats createFileCallStat)
{
this.location = requireNonNull(location, "location is null");
this.environment = requireNonNull(environment, "environment is null");
Expand Down
88 changes: 88 additions & 0 deletions lib/trino-hdfs/src/main/java/io/trino/hdfs/CallStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed 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 io.trino.hdfs;

import io.airlift.stats.CounterStat;
import io.airlift.stats.TimeStat;
import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public final class CallStats
{
private final TimeStat time = new TimeStat(TimeUnit.MILLISECONDS);
private final CounterStat totalCalls = new CounterStat();
private final CounterStat totalFailures = new CounterStat();
private final CounterStat ioExceptions = new CounterStat();
private final CounterStat fileNotFoundExceptions = new CounterStat();

public TimeStat.BlockTimer time()
{
return time.time();
}

public void recordException(Exception exception)
{
if (exception instanceof FileNotFoundException) {
fileNotFoundExceptions.update(1);
}
else if (exception instanceof IOException) {
ioExceptions.update(1);
}
totalFailures.update(1);
}

@Managed
@Nested
public CounterStat getTotalCalls()
{
return totalCalls;
}

@Managed
@Nested
public CounterStat getTotalFailures()
{
return totalFailures;
}

@Managed
@Nested
public CounterStat getIoExceptions()
{
return ioExceptions;
}

@Managed
@Nested
public CounterStat getFileNotFoundExceptions()
{
return fileNotFoundExceptions;
}

@Managed
@Nested
public TimeStat getTime()
{
return time;
}

public void newCall()
{
totalCalls.update(1);
}
}
37 changes: 37 additions & 0 deletions lib/trino-hdfs/src/main/java/io/trino/hdfs/HdfsNamenodeStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed 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 io.trino.hdfs;

import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

public final class HdfsNamenodeStats
{
private final CallStats listLocatedStatus = new CallStats();
private final CallStats remoteIteratorNext = new CallStats();

@Managed
@Nested
public CallStats getListLocatedStatus()
{
return listLocatedStatus;
}

@Managed
@Nested
public CallStats getRemoteIteratorNext()
{
return remoteIteratorNext;
}
}
83 changes: 0 additions & 83 deletions lib/trino-hdfs/src/main/java/io/trino/hdfs/NamenodeStats.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
*/
package io.trino.hdfs;

import io.airlift.stats.CounterStat;
import io.airlift.stats.TimeStat;
import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class TrinoHdfsFileSystemStats
public final class TrinoHdfsFileSystemStats
{
private final CallStats openFileCalls = new CallStats();
private final CallStats createFileCalls = new CallStats();
Expand Down Expand Up @@ -72,69 +66,4 @@ public CallStats getDeleteDirectoryCalls()
{
return deleteDirectoryCalls;
}

public static class CallStats
{
private final TimeStat time = new TimeStat(TimeUnit.MILLISECONDS);
private final CounterStat totalCalls = new CounterStat();
private final CounterStat totalFailures = new CounterStat();
private final CounterStat ioExceptions = new CounterStat();
private final CounterStat fileNotFoundExceptions = new CounterStat();

public TimeStat.BlockTimer time()
{
return time.time();
}

public void recordException(Exception exception)
{
if (exception instanceof IOException) {
ioExceptions.update(1);
}
else if (exception instanceof FileNotFoundException) {
fileNotFoundExceptions.update(1);
}
totalFailures.update(1);
}

@Managed
@Nested
public CounterStat getTotalCalls()
{
return totalCalls;
}

@Managed
@Nested
public CounterStat getTotalFailures()
{
return totalFailures;
}

@Managed
@Nested
public CounterStat getIoExceptions()
{
return ioExceptions;
}

@Managed
@Nested
public CounterStat getFileNotFoundExceptions()
{
return fileNotFoundExceptions;
}

@Managed
@Nested
public TimeStat getTime()
{
return time;
}

public void newCall()
{
totalCalls.update(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.trino.hdfs.HdfsConfiguration;
import io.trino.hdfs.HdfsConfigurationInitializer;
import io.trino.hdfs.HdfsEnvironment;
import io.trino.hdfs.NamenodeStats;
import io.trino.hdfs.HdfsNamenodeStats;
import io.trino.hdfs.authentication.NoHdfsAuthentication;
import io.trino.plugin.base.CatalogName;
import io.trino.plugin.hive.AbstractTestHiveFileSystem.TestingHiveMetastore;
Expand Down Expand Up @@ -170,7 +170,7 @@ public S3SelectTestHelper(String host,
transactionManager,
hivePartitionManager,
new HdfsFileSystemFactory(hdfsEnvironment, HDFS_FILE_SYSTEM_STATS),
new NamenodeStats(),
new HdfsNamenodeStats(),
hdfsEnvironment,
new BoundedExecutor(executorService, this.hiveConfig.getMaxSplitIteratorThreads()),
new CounterStat(),
Expand Down
Loading

0 comments on commit e3bdafb

Please sign in to comment.