From 8aee2976699072c8f2af1dfccdc8f7a133b6113d Mon Sep 17 00:00:00 2001 From: Mickael Maison Date: Wed, 18 Oct 2023 11:49:25 +0200 Subject: [PATCH] MINOR: Various Java cleanups in core (#14561) Reviewers: Josep Prat --- .../kafka/log/remote/RemoteLogManager.java | 5 +---- .../ReplicaFetcherTierStateMachine.java | 4 ++-- .../server/logger/RuntimeLoggerManager.java | 2 +- .../log/remote/RemoteLogManagerTest.java | 20 +++++++++---------- .../BootstrapControllersIntegrationTest.java | 8 ++++---- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/kafka/log/remote/RemoteLogManager.java b/core/src/main/java/kafka/log/remote/RemoteLogManager.java index e3923afba1a..81406ee2070 100644 --- a/core/src/main/java/kafka/log/remote/RemoteLogManager.java +++ b/core/src/main/java/kafka/log/remote/RemoteLogManager.java @@ -155,13 +155,12 @@ public class RemoteLogManager implements Closeable { // topic ids that are received on leadership changes, this map is cleared on stop partitions private final ConcurrentMap topicIdByPartitionMap = new ConcurrentHashMap<>(); private final String clusterId; + private final KafkaMetricsGroup metricsGroup = new KafkaMetricsGroup(this.getClass()); // The endpoint for remote log metadata manager to connect to private Optional endpoint = Optional.empty(); private boolean closed = false; - private KafkaMetricsGroup metricsGroup = new KafkaMetricsGroup(this.getClass()); - /** * Creates RemoteLogManager instance with the given arguments. * @@ -230,7 +229,6 @@ public class RemoteLogManager implements Closeable { } } - @SuppressWarnings("removal") RemoteStorageManager createRemoteStorageManager() { return java.security.AccessController.doPrivileged(new PrivilegedAction() { private final String classPath = rlmConfig.remoteStorageManagerClassPath(); @@ -253,7 +251,6 @@ public class RemoteLogManager implements Closeable { remoteLogStorageManager.configure(rsmProps); } - @SuppressWarnings("removal") RemoteLogMetadataManager createRemoteLogMetadataManager() { return java.security.AccessController.doPrivileged(new PrivilegedAction() { private final String classPath = rlmConfig.remoteLogMetadataManagerClassPath(); diff --git a/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java b/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java index 74fc7caaea2..d203bfe7c5f 100644 --- a/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java +++ b/core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java @@ -69,8 +69,8 @@ import static org.apache.kafka.storage.internals.log.LogStartOffsetIncrementReas public class ReplicaFetcherTierStateMachine implements TierStateMachine { private static final Logger log = LoggerFactory.getLogger(ReplicaFetcherTierStateMachine.class); - private LeaderEndPoint leader; - private ReplicaManager replicaMgr; + private final LeaderEndPoint leader; + private final ReplicaManager replicaMgr; public ReplicaFetcherTierStateMachine(LeaderEndPoint leader, ReplicaManager replicaMgr) { diff --git a/core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java b/core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java index f66454e164c..1eff13b5f24 100644 --- a/core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java +++ b/core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java @@ -142,7 +142,7 @@ public class RuntimeLoggerManager { " operation is not allowed for the " + BROKER_LOGGER + " resource"); default: throw new InvalidRequestException("Unknown operation type " + - (int) op.configOperation() + " is not alowed for the " + + (int) op.configOperation() + " is not allowed for the " + BROKER_LOGGER + " resource"); } }); diff --git a/core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java b/core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java index 109ab874cd6..0ebe08de3ca 100644 --- a/core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java +++ b/core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java @@ -661,12 +661,12 @@ public class RemoteLogManagerTest { } private double yammerMetricValue(String name) { - Gauge guage = (Gauge) KafkaYammerMetrics.defaultRegistry().allMetrics().entrySet().stream() + Gauge gauge = (Gauge) KafkaYammerMetrics.defaultRegistry().allMetrics().entrySet().stream() .filter(e -> e.getKey().getMBeanName().contains(name)) .findFirst() .get() .getValue(); - return guage.value(); + return gauge.value(); } @Test @@ -885,7 +885,7 @@ public class RemoteLogManagerTest { public RemoteStorageManager createRemoteStorageManager() { return rsmManager; } - }; + } ) { assertEquals(rsmManager, remoteLogManager.storageManager()); } @@ -1057,12 +1057,12 @@ public class RemoteLogManagerTest { txnIdxFile.createNewFile(); when(remoteStorageManager.fetchIndex(any(RemoteLogSegmentMetadata.class), any(IndexType.class))) .thenAnswer(ans -> { - RemoteLogSegmentMetadata metadata = ans.getArgument(0); - IndexType indexType = ans.getArgument(1); + RemoteLogSegmentMetadata metadata = ans.getArgument(0); + IndexType indexType = ans.getArgument(1); int maxEntries = (int) (metadata.endOffset() - metadata.startOffset()); - OffsetIndex offsetIdx = new OffsetIndex(new File(tpDir, String.valueOf(metadata.startOffset()) + UnifiedLog.IndexFileSuffix()), + OffsetIndex offsetIdx = new OffsetIndex(new File(tpDir, metadata.startOffset() + UnifiedLog.IndexFileSuffix()), metadata.startOffset(), maxEntries * 8); - TimeIndex timeIdx = new TimeIndex(new File(tpDir, String.valueOf(metadata.startOffset()) + UnifiedLog.TimeIndexFileSuffix()), + TimeIndex timeIdx = new TimeIndex(new File(tpDir, metadata.startOffset() + UnifiedLog.TimeIndexFileSuffix()), metadata.startOffset(), maxEntries * 12); switch (indexType) { case OFFSET: @@ -1241,7 +1241,7 @@ public class RemoteLogManagerTest { segmentEpochs5), logEndOffset, leaderEpochToStartOffset)); // Test whether any of the epoch's is not with in the leader epoch chain. - TreeMap segmentEpochs6 = new TreeMap(); + TreeMap segmentEpochs6 = new TreeMap<>(); segmentEpochs6.put(5, 55L); segmentEpochs6.put(6, 60L); // epoch 6 exists here but it is missing in leaderEpochToStartOffset segmentEpochs6.put(7, 70L); @@ -1834,7 +1834,7 @@ public class RemoteLogManagerTest { } // This is the key scenario that we are testing here - RecordBatch findFirstBatch(RemoteLogInputStream remoteLogInputStream, long offset) throws IOException { + RecordBatch findFirstBatch(RemoteLogInputStream remoteLogInputStream, long offset) { return null; } }) { @@ -1900,7 +1900,7 @@ public class RemoteLogManagerTest { return 1; } - RecordBatch findFirstBatch(RemoteLogInputStream remoteLogInputStream, long offset) throws IOException { + RecordBatch findFirstBatch(RemoteLogInputStream remoteLogInputStream, long offset) { when(firstBatch.sizeInBytes()).thenReturn(recordBatchSizeInBytes); doNothing().when(firstBatch).writeTo(capture.capture()); return firstBatch; diff --git a/core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java b/core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java index 2eef6d30481..5182293f4b7 100644 --- a/core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java +++ b/core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java @@ -111,7 +111,7 @@ public class BootstrapControllersIntegrationTest { } @Test - public void testPutBrokersInBootstrapControllersConfig() throws Exception { + public void testPutBrokersInBootstrapControllersConfig() { Properties properties = cluster.clientProperties(); properties.put(BOOTSTRAP_CONTROLLERS_CONFIG, properties.getProperty(BOOTSTRAP_SERVERS_CONFIG)); properties.remove(BOOTSTRAP_SERVERS_CONFIG); @@ -127,7 +127,7 @@ public class BootstrapControllersIntegrationTest { @Disabled @Test - public void testPutControllersInBootstrapBrokersConfig() throws Exception { + public void testPutControllersInBootstrapBrokersConfig() { Properties properties = cluster.clientProperties(); properties.put(BOOTSTRAP_SERVERS_CONFIG, bootstrapControllerString); try (Admin admin = Admin.create(properties)) { @@ -169,7 +169,7 @@ public class BootstrapControllersIntegrationTest { @ParameterizedTest @ValueSource(booleans = {false, true}) - public void testUpdateFeatures(boolean usingBootstrapControllers) throws Exception { + public void testUpdateFeatures(boolean usingBootstrapControllers) { try (Admin admin = Admin.create(adminProperties(usingBootstrapControllers))) { UpdateFeaturesResult result = admin.updateFeatures(Collections.singletonMap("foo.bar.feature", new FeatureUpdate((short) 1, FeatureUpdate.UpgradeType.UPGRADE)), @@ -196,7 +196,7 @@ public class BootstrapControllersIntegrationTest { } @Test - public void testUsingBootstrapControllersOnUnsupportedAdminApi() throws Exception { + public void testUsingBootstrapControllersOnUnsupportedAdminApi() { try (Admin admin = Admin.create(adminProperties(true))) { ListOffsetsResult result = admin.listOffsets(Collections.singletonMap( new TopicPartition("foo", 0), OffsetSpec.earliest()));