Skip to content

Commit 3198f84

Browse files
spotbugs and ceckstyle
1 parent e1d1570 commit 3198f84

File tree

9 files changed

+89
-63
lines changed

9 files changed

+89
-63
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ public class AbfsConfiguration{
545545
private int writeMediumCpuThreshold;
546546

547547
@IntegerConfigurationValidatorAnnotation(ConfigurationKey = FS_AZURE_WRITE_LOW_CPU_THRESHOLD_PERCENT,
548-
MinValue = MIN_WRITE_LOW_CPU_THRESHOLD_PERCENT,
549548
MaxValue = MAX_WRITE_LOW_CPU_THRESHOLD_PERCENT,
550549
DefaultValue = DEFAULT_WRITE_LOW_CPU_THRESHOLD_PERCENT)
551550
private int writeLowCpuThreshold;

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/WriteThreadPoolSizeManager.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HIGH_CPU_LOW_MEMORY_REDUCTION_FACTOR;
4949
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HIGH_CPU_REDUCTION_FACTOR;
5050
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HIGH_MEDIUM_HEAP_FACTOR;
51+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED;
5152
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED_D;
5253
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.LOW_CPU_HEAP_FACTOR;
5354
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.LOW_CPU_HIGH_MEMORY_DECREASE_FACTOR;
5455
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.LOW_CPU_POOL_SIZE_INCREASE_FACTOR;
5556
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.MEDIUM_CPU_LOW_MEMORY_REDUCTION_FACTOR;
5657
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.MEDIUM_CPU_REDUCTION_FACTOR;
5758
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.THIRTY_SECONDS;
59+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO;
60+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO_D;
5861

5962
/**
6063
* Manages a thread pool for writing operations, adjusting the pool size based on CPU utilization.
@@ -280,9 +283,9 @@ private double getCpuUtilization() {
280283
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(
281284
OperatingSystemMXBean.class);
282285
double cpuLoad = osBean.getSystemCpuLoad();
283-
if (cpuLoad < 0) {
286+
if (cpuLoad < ZERO) {
284287
LOG.warn("System CPU load value unavailable (returned -1.0). Defaulting to 0.0.");
285-
return 0.0;
288+
return ZERO_D;
286289
}
287290
return cpuLoad;
288291
}
@@ -295,7 +298,7 @@ public static double getJvmCpuUtilization() {
295298
(OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
296299
long cpuTime = osBean.getProcessCpuTime();
297300
long now = System.nanoTime();
298-
if (lastTime == 0) {
301+
if (lastTime == ZERO) {
299302
lastCpuTime = cpuTime;
300303
lastTime = now;
301304
return 0.0; // first call has no previous data
@@ -304,9 +307,11 @@ public static double getJvmCpuUtilization() {
304307
long elapsedTime = now - lastTime;
305308
lastCpuTime = cpuTime;
306309
lastTime = now;
307-
if (elapsedTime <= 0) return 0.0;
308-
double load = (elapsedCpu * 100.0) / (elapsedTime * osBean.getAvailableProcessors());
309-
return Math.max(0.0, Math.min(load, 100.0));
310+
if (elapsedTime <= ZERO) {
311+
return ZERO_D;
312+
}
313+
double load = (elapsedCpu * HUNDRED_D) / (elapsedTime * osBean.getAvailableProcessors());
314+
return Math.max(ZERO_D, Math.min(load, HUNDRED_D));
310315
}
311316

312317

@@ -495,28 +500,40 @@ public WriteThreadPoolStats(int currentPoolSize, int maxPoolSize,
495500
}
496501

497502
/** @return the current number of threads in the pool. */
498-
public int getCurrentPoolSize() { return currentPoolSize; }
503+
public int getCurrentPoolSize() {
504+
return currentPoolSize;
505+
}
499506

500507
/** @return the maximum allowed size of the thread pool. */
501-
public int getMaxPoolSize() { return maxPoolSize; }
508+
public int getMaxPoolSize() {
509+
return maxPoolSize;
510+
}
502511

503512
/** @return the number of threads currently executing tasks. */
504-
public int getActiveThreads() { return activeThreads; }
513+
public int getActiveThreads() {
514+
return activeThreads;
515+
}
505516

506517
/** @return the JVM process CPU utilization percentage. */
507-
public double getJvmCpuUtilization() { return jvmCpuUtilization; }
518+
public double getJvmCpuUtilization() {
519+
return jvmCpuUtilization;
520+
}
508521

509522
/** @return the overall system CPU utilization percentage. */
510-
public double getCpuUtilization() { return cpuUtilization; }
523+
public double getCpuUtilization() {
524+
return cpuUtilization;
525+
}
511526

512527
/** @return the available heap memory in gigabytes. */
513-
public long getMemoryUtilization() { return availableHeapGB; }
528+
public long getMemoryUtilization() {
529+
return availableHeapGB;
530+
}
514531

515532
@Override
516533
public String toString() {
517534
return String.format(
518535
"currentPoolSize=%d, maxPoolSize=%d, activeThreads=%d, jvmCpuUtilization=%.2f%%, cpuUtilization=%.2f%%, availableHeap=%dGB",
519-
currentPoolSize, maxPoolSize, activeThreads, jvmCpuUtilization, cpuUtilization * 100, availableHeapGB);
536+
currentPoolSize, maxPoolSize, activeThreads, jvmCpuUtilization, cpuUtilization * HUNDRED, availableHeapGB);
520537
}
521538
}
522539

@@ -530,7 +547,7 @@ public String toString() {
530547
*/
531548
synchronized WriteThreadPoolStats getCurrentStats() {
532549
if (boundedThreadPool == null) {
533-
return new WriteThreadPoolStats(0, 0, 0, 0.0, 0.0, 0);
550+
return new WriteThreadPoolStats(ZERO, ZERO, ZERO, ZERO_D, ZERO_D, ZERO);
534551
}
535552

536553
ThreadPoolExecutor exec = (ThreadPoolExecutor) this.boundedThreadPool;

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsReadThreadPoolMetrics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public synchronized void update(ReadBufferManagerV2.ReadThreadPoolStats stats) {
128128
* Returns a flag indicating whether the metrics have been updated at least once.
129129
* Used to verify if metric updates have occurred since initialization.
130130
*/
131-
public AtomicBoolean getUpdatedAtLeastOnce() {
132-
return updatedAtLeastOnce;
131+
public boolean getUpdatedAtLeastOnce() {
132+
return updatedAtLeastOnce.get();
133133
}
134134

135135
/**

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsWriteThreadPoolMetrics.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,6 @@ public synchronized void update(WriteThreadPoolSizeManager.WriteThreadPoolStats
128128
updateVersion.incrementAndGet();
129129
}
130130

131-
/**
132-
* Returns a flag indicating whether the metrics have been updated at least once.
133-
* Used to verify if metric updates have occurred since initialization.
134-
*/
135-
public AtomicBoolean getUpdatedAtLeastOnce() {
136-
return updatedAtLeastOnce;
137-
}
138-
139131
/**
140132
* Returns metrics as a string only once per update version.
141133
*/

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
import org.apache.hadoop.classification.VisibleForTesting;
4848

4949
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.BYTES_PER_GIGABYTE;
50+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED;
5051
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED_D;
52+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO;
53+
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO_D;
5154

5255
/**
5356
* The Improved Read Buffer Manager for Rest AbfsClient.
@@ -1075,7 +1078,7 @@ public static double getJvmCpuUtilization() {
10751078
(OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
10761079
long cpuTime = osBean.getProcessCpuTime();
10771080
long now = System.nanoTime();
1078-
if (lastTime == 0) {
1081+
if (lastTime == ZERO) {
10791082
lastCpuTime = cpuTime;
10801083
lastTime = now;
10811084
return 0.0; // first call has no previous data
@@ -1084,9 +1087,11 @@ public static double getJvmCpuUtilization() {
10841087
long elapsedTime = now - lastTime;
10851088
lastCpuTime = cpuTime;
10861089
lastTime = now;
1087-
if (elapsedTime <= 0) return 0.0;
1088-
double load = (elapsedCpu * 100.0) / (elapsedTime * osBean.getAvailableProcessors());
1089-
return Math.max(0.0, Math.min(load, 100.0));
1090+
if (elapsedTime <= ZERO) {
1091+
return ZERO_D;
1092+
}
1093+
double load = (elapsedCpu * HUNDRED_D) / (elapsedTime * osBean.getAvailableProcessors());
1094+
return Math.max(ZERO_D, Math.min(load, HUNDRED_D));
10901095
}
10911096

10921097
@VisibleForTesting
@@ -1198,28 +1203,40 @@ public ReadThreadPoolStats(int currentPoolSize, int maxPoolSize,
11981203
}
11991204

12001205
/** @return the current number of threads in the pool. */
1201-
public int getCurrentPoolSize() { return currentPoolSize; }
1206+
public int getCurrentPoolSize() {
1207+
return currentPoolSize;
1208+
}
12021209

12031210
/** @return the maximum allowed size of the thread pool. */
1204-
public int getMaxPoolSize() { return maxPoolSize; }
1211+
public int getMaxPoolSize() {
1212+
return maxPoolSize;
1213+
}
12051214

12061215
/** @return the number of threads currently executing tasks. */
1207-
public int getActiveThreads() { return activeThreads; }
1216+
public int getActiveThreads() {
1217+
return activeThreads;
1218+
}
12081219

12091220
/** @return the JVM process CPU utilization percentage. */
1210-
public double getJvmCpuUtilization() { return jvmCpuUtilization; }
1221+
public double getJvmCpuUtilization() {
1222+
return jvmCpuUtilization;
1223+
}
12111224

12121225
/** @return the overall system CPU utilization percentage. */
1213-
public double getCpuUtilization() { return cpuUtilization; }
1226+
public double getCpuUtilization() {
1227+
return cpuUtilization;
1228+
}
12141229

12151230
/** @return the available heap memory in gigabytes. */
1216-
public long getMemoryUtilization() { return availableHeapGB; }
1231+
public long getMemoryUtilization() {
1232+
return availableHeapGB;
1233+
}
12171234

12181235
@Override
12191236
public String toString() {
12201237
return String.format(
12211238
"currentPoolSize=%d, maxPoolSize=%d, activeThreads=%d, jvmCpuUtilization=%.2f%%, cpuUtilization=%.2f%%, availableHeap=%dGB",
1222-
currentPoolSize, maxPoolSize, activeThreads, jvmCpuUtilization, cpuUtilization * 100, availableHeapGB);
1239+
currentPoolSize, maxPoolSize, activeThreads, jvmCpuUtilization, cpuUtilization * HUNDRED, availableHeapGB);
12231240
}
12241241
}
12251242

@@ -1233,7 +1250,7 @@ public String toString() {
12331250
*/
12341251
synchronized ReadThreadPoolStats getCurrentStats() {
12351252
if (workerPool == null) {
1236-
return new ReadThreadPoolStats(0, 0, 0, 0.0, 0.0, 0);
1253+
return new ReadThreadPoolStats(ZERO, ZERO, ZERO, ZERO_D, ZERO_D, ZERO);
12371254
}
12381255

12391256
ThreadPoolExecutor exec = this.workerPool;

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/TestWriteThreadPoolSizeManager.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,13 @@
4141
import org.apache.hadoop.fs.FileSystem;
4242
import org.apache.hadoop.fs.Path;
4343
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
44-
import org.apache.hadoop.fs.azurebfs.services.AbfsCounters;
4544
import org.apache.hadoop.fs.azurebfs.services.AbfsWriteThreadPoolMetrics;
4645

4746
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_WRITE_MAX_CONCURRENT_REQUESTS;
48-
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ABFS_ENABLE_CHECKSUM_VALIDATION;
4947
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_WRITE_DYNAMIC_THREADPOOL_ENABLEMENT;
50-
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_WRITE_HIGH_CPU_THRESHOLD_PERCENT;
5148
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_WRITE_LOW_CPU_THRESHOLD_PERCENT;
5249
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ZERO;
53-
import static org.mockito.Mockito.doReturn;
5450
import static org.mockito.Mockito.mock;
55-
import static org.mockito.Mockito.spy;
5651
import static org.mockito.Mockito.when;
5752

5853
class TestWriteThreadPoolSizeManager extends AbstractAbfsIntegrationTest {
@@ -800,7 +795,7 @@ void testThreadPoolScalesDownOnHighCpuLoadAndMetricsUpdate()
800795
Configuration conf = getRawConfiguration();
801796
conf.setBoolean(FS_AZURE_WRITE_DYNAMIC_THREADPOOL_ENABLEMENT, true);
802797
conf.setInt(AZURE_WRITE_MAX_CONCURRENT_REQUESTS, 2);
803-
conf.setInt(FS_AZURE_WRITE_LOW_CPU_THRESHOLD_PERCENT, 10);
798+
conf.setInt(FS_AZURE_WRITE_LOW_CPU_THRESHOLD_PERCENT, 1);
804799
FileSystem fileSystem = FileSystem.newInstance(conf);
805800
try (AzureBlobFileSystem abfs = (AzureBlobFileSystem) fileSystem) {
806801
WriteThreadPoolSizeManager instance =
@@ -817,6 +812,7 @@ void testThreadPoolScalesDownOnHighCpuLoadAndMetricsUpdate()
817812
(ThreadPoolExecutor) instance.getExecutorService();
818813
// Start monitoring CPU load
819814
instance.startCPUMonitoring();
815+
String metricsOutput = metrics.toString();
820816

821817
// Create a CPU-bound task (simulate heavy computation)
822818
Runnable cpuBurn = () -> {
@@ -872,14 +868,6 @@ void testThreadPoolScalesDownOnHighCpuLoadAndMetricsUpdate()
872868
.as("Thread pool stats should update after CPU load")
873869
.isNotEqualTo(statsBefore);
874870

875-
boolean updatedMetrics = metrics.getUpdatedAtLeastOnce().get();
876-
877-
Assertions.assertThat(updatedMetrics)
878-
.as("Metrics should be updated at least once after CPU load")
879-
.isTrue();
880-
881-
String metricsOutput = metrics.toString();
882-
883871
// Assertions for metrics correctness
884872
Assertions.assertThat(metricsOutput)
885873
.as("Metrics output should not be empty")

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/TestAbfsInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ public void testPrefetchReadAddsPriorityHeaderWithDifferentConfigs()
920920

921921
Configuration configuration2 = new Configuration(getRawConfiguration());
922922
//use the default value for the config: false
923-
configuration2.unset(FS_AZURE_ENABLE_PREFETCH_REQUEST_PRIORITY);
923+
configuration2.set(FS_AZURE_ENABLE_PREFETCH_REQUEST_PRIORITY, "false");
924924

925925
TracingContext tracingContext1 = mock(TracingContext.class);
926926
when(tracingContext1.getReadType()).thenReturn(PREFETCH_READ);

0 commit comments

Comments
 (0)