Skip to content

MINOR: Cleanups in storage module#20087

Merged
chia7712 merged 4 commits intoapache:trunkfrom
mimaison:cleanups-server
Jul 30, 2025
Merged

MINOR: Cleanups in storage module#20087
chia7712 merged 4 commits intoapache:trunkfrom
mimaison:cleanups-server

Conversation

@mimaison
Copy link
Copy Markdown
Member

@mimaison mimaison commented Jul 2, 2025

Cleanups including:

  • Java 17 syntax, record and switch
  • assertEquals() order
  • javadoc

Reviewers: Andrew Schofield aschofield@confluent.io, Jhen-Yung Hsu
jhenyunghsu@gmail.com, Ken Huang s7133700@gmail.com, Chia-Ping Tsai
chia7712@gmail.com

@github-actions github-actions bot added core Kafka Broker storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature KIP-932 Queues for Kafka labels Jul 2, 2025
Copy link
Copy Markdown
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, left some comments

public record LoadedLogOffsets(long logStartOffset, long recoveryPoint, LogOffsetMetadata nextOffsetMetadata) {
public LoadedLogOffsets(final long logStartOffset,
final long recoveryPoint,
final LogOffsetMetadata nextOffsetMetadata) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remain equals(), hashCode(), toString() for this record?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed equals() and hashCode()

assertEquals(batch.timestampType(), TimestampType.CREATE_TIME);
assertEquals(TimestampType.CREATE_TIME, batch.timestampType());
maybeCheckBaseTimestamp(timestampSeq.get(0), batch);
assertEquals(batch.maxTimestamp(), batch.maxTimestamp());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion also can remove

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are the same issue at L365, L1811, We could update the actual value to TestUtils.toList(batch).stream().map(Record::timestamp).max(Long::compare).get(), the root cause is #16167

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also found this issue while reviewing this PR and have already filed a MINOR to fix it before the comments. #20093

public final short producerEpoch;

public LastRecord(OptionalLong lastDataOffset, short producerEpoch) {
public record LastRecord(OptionalLong lastDataOffset, short producerEpoch) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove equals and hashCode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@wernerdv
Copy link
Copy Markdown
Contributor

wernerdv commented Jul 2, 2025

@mimaison I think you meant the 'storage' module in the PR title.

import java.util.Iterator;

/**
* @param <R1> The type of records used to formulate the expectations.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting of the type parameters in this javadoc comment is a little odd.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I blame IntelliJ :) Fixed

@mimaison mimaison changed the title MINOR: Cleanups in server module MINOR: Cleanups in storage module Jul 3, 2025
Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mimaison thanks for this cleanup

}

@Override
public String toString() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the generated toString should be good enough I think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

return OptionalLong.of(content.brokerEpoch);
} catch (Exception e) {
logger.debug("Fail to read the clean shutdown file in " + cleanShutdownFile.toPath() + ":" + e);
logger.debug("Fail to read the clean shutdown file in {}:{}", cleanShutdownFile.toPath(), e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last parameter could be handled well if it is an exception object. Perhaps, we could use {} instead of {}:{}?

}

@Override
public String toString() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not here as this also prints firstSeq and firstOffset which are not fields.

public record CompletedTxn(long producerId, long firstOffset, long lastOffset, boolean isAborted) {

@Override
public String toString() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

IndexValue(T index) {
this.index = index;
}
private record IndexValue<T extends AbstractIndex>(T index) implements IndexWrapper {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an argument before for the "suitable" variables in a record class. I prefer to use record class only if all variables are immutable. That can ensure the hashCode and equals are consistent. What do you think? That is a kind of personal taste, so any feedback is welcomed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a bit of a gray area. I'm happy to keep it as a regular class. I undid that change

@chia7712
Copy link
Copy Markdown
Member

@mimaison could you please fix the conflicts?

@mimaison
Copy link
Copy Markdown
Member Author

Rebased on trunk. The test failure, HandlingSourceTopicDeletionIntegrationTest, seems unrelated, it's in streams. There's a Jira for it: https://issues.apache.org/jira/browse/KAFKA-19511

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mimaison thanks for this cleanup. overall LGTM

return file.delete();
} catch (final Exception e) {
LOGGER.error(format("Encountered error while deleting %s", file.getAbsolutePath()));
LOGGER.error("Encountered error while deleting {}", file.getAbsolutePath());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should add the e to the logger

LOGGER.error("Encountered error while deleting {}", file.getAbsolutePath(), e);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

public Integer getExpectedFromSecondTierCount() {
return expectedFromSecondTierCount;
}
public record ConsumableSpec(Long fetchOffset, Integer expectedTotalCount, Integer expectedFromSecondTierCount) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the usage of this class, and it appears using primitive types should be fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I switched to primitive types in a bunch of classes

public Integer getEventCount() {
return eventCount;
}
public record DeletableSpec(Integer sourceBrokerId, LocalTieredStorageEvent.EventType eventType, Integer eventCount) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

public RemoteFetchCount getFetchCount() {
return fetchCount;
}
public record FetchableSpec(Integer sourceBrokerId, RemoteFetchCount fetchCount) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

public List<ProducerRecord<String, String>> getRecords() {
return records;
}
public record OffloadableSpec(Integer sourceBrokerId, Integer baseOffset,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I will file a separate minor PR, so we can focus on merging this large one first.

.orElse(events);

RemoteFetchCount remoteFetchCount = remoteFetchSpec.getRemoteFetchCount();
RemoteFetchCount.FetchCountAndOp expectedCountAndOp;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FetchCountAndOp could be rewritten as a record class

this.t1 = t1;
this.t2 = t2;
}
private record Tuple2<T1, T2>(T1 t1, T2 t2) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be replaced by Map.Entry

@chia7712
Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/KAFKA-19513 will handle the flaky

@chia7712 chia7712 merged commit 6973dea into apache:trunk Jul 30, 2025
24 of 26 checks passed
@mimaison mimaison deleted the cleanups-server branch July 30, 2025 08:16
@mimaison
Copy link
Copy Markdown
Member Author

Thanks!

k-apol pushed a commit to k-apol/kafka that referenced this pull request Aug 8, 2025
Cleanups including:
- Java 17 syntax, record and switch
- assertEquals() order
- javadoc

Reviewers: Andrew Schofield <aschofield@confluent.io>, Jhen-Yung Hsu
 <jhenyunghsu@gmail.com>, Ken Huang <s7133700@gmail.com>, Chia-Ping Tsai
 <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker KIP-932 Queues for Kafka storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants