Browse Source

MINOR: Various Java cleanups in core (#14561)

Reviewers: Josep Prat <josep.prat@aiven.io>
pull/14212/merge
Mickael Maison 1 year ago committed by GitHub
parent
commit
8aee297669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      core/src/main/java/kafka/log/remote/RemoteLogManager.java
  2. 4
      core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java
  3. 2
      core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java
  4. 20
      core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java
  5. 8
      core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java

5
core/src/main/java/kafka/log/remote/RemoteLogManager.java

@ -155,13 +155,12 @@ public class RemoteLogManager implements Closeable { @@ -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<TopicPartition, Uuid> 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> 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 { @@ -230,7 +229,6 @@ public class RemoteLogManager implements Closeable {
}
}
@SuppressWarnings("removal")
RemoteStorageManager createRemoteStorageManager() {
return java.security.AccessController.doPrivileged(new PrivilegedAction<RemoteStorageManager>() {
private final String classPath = rlmConfig.remoteStorageManagerClassPath();
@ -253,7 +251,6 @@ public class RemoteLogManager implements Closeable { @@ -253,7 +251,6 @@ public class RemoteLogManager implements Closeable {
remoteLogStorageManager.configure(rsmProps);
}
@SuppressWarnings("removal")
RemoteLogMetadataManager createRemoteLogMetadataManager() {
return java.security.AccessController.doPrivileged(new PrivilegedAction<RemoteLogMetadataManager>() {
private final String classPath = rlmConfig.remoteLogMetadataManagerClassPath();

4
core/src/main/java/kafka/server/ReplicaFetcherTierStateMachine.java

@ -69,8 +69,8 @@ import static org.apache.kafka.storage.internals.log.LogStartOffsetIncrementReas @@ -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) {

2
core/src/main/java/kafka/server/logger/RuntimeLoggerManager.java

@ -142,7 +142,7 @@ public class RuntimeLoggerManager { @@ -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");
}
});

20
core/src/test/java/kafka/log/remote/RemoteLogManagerTest.java

@ -661,12 +661,12 @@ public class RemoteLogManagerTest { @@ -661,12 +661,12 @@ public class RemoteLogManagerTest {
}
private double yammerMetricValue(String name) {
Gauge<Double> guage = (Gauge) KafkaYammerMetrics.defaultRegistry().allMetrics().entrySet().stream()
Gauge<Double> 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 { @@ -885,7 +885,7 @@ public class RemoteLogManagerTest {
public RemoteStorageManager createRemoteStorageManager() {
return rsmManager;
}
};
}
) {
assertEquals(rsmManager, remoteLogManager.storageManager());
}
@ -1057,12 +1057,12 @@ public class RemoteLogManagerTest { @@ -1057,12 +1057,12 @@ public class RemoteLogManagerTest {
txnIdxFile.createNewFile();
when(remoteStorageManager.fetchIndex(any(RemoteLogSegmentMetadata.class), any(IndexType.class)))
.thenAnswer(ans -> {
RemoteLogSegmentMetadata metadata = ans.<RemoteLogSegmentMetadata>getArgument(0);
IndexType indexType = ans.<IndexType>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 { @@ -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<Integer, Long> segmentEpochs6 = new TreeMap<Integer, Long>();
TreeMap<Integer, Long> 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 { @@ -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 { @@ -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;

8
core/src/test/java/kafka/test/server/BootstrapControllersIntegrationTest.java

@ -111,7 +111,7 @@ public class BootstrapControllersIntegrationTest { @@ -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 { @@ -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 { @@ -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 { @@ -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()));

Loading…
Cancel
Save