junrao commented on code in PR #14603:
URL: https://github.com/apache/kafka/pull/14603#discussion_r1370850704
##########
storage/src/main/java/org/apache/kafka/storage/internals/log/CleanShutdownFileHandler.java:
##########
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package kafka.log;
+package org.apache.kafka.storage.internals.log;
Review Comment:
CleanShutdownFileHandler is a kind of checkpoint file. Would it be better to
have this in the checkpoint package?
##########
core/src/main/scala/kafka/log/LogManager.scala:
##########
@@ -1421,15 +1422,15 @@ class LogManager(logDirs: Seq[File],
for (dir <- liveLogDirs) {
val cleanShutdownFileHandler = new CleanShutdownFileHandler(dir.getPath)
val currentBrokerEpoch = cleanShutdownFileHandler.read
- if (currentBrokerEpoch == -1L) {
+ if (!currentBrokerEpoch.isPresent) {
info(s"Unable to read the broker epoch in ${dir.toString}.")
return -1L
}
- if (brokerEpoch != -1 && currentBrokerEpoch != brokerEpoch) {
+ if (brokerEpoch != -1 && currentBrokerEpoch.getAsLong != brokerEpoch) {
info(s"Found different broker epochs in ${dir.toString}.
Other=$brokerEpoch vs current=$currentBrokerEpoch.")
return -1L
}
- brokerEpoch = currentBrokerEpoch
+ brokerEpoch = currentBrokerEpoch.getAsLong
Review Comment:
Should we propagate Option[Long] all the way until we convert it to a
request?
##########
storage/src/main/java/org/apache/kafka/storage/internals/log/CleanShutdownFileHandler.java:
##########
@@ -85,17 +83,16 @@ void write(long brokerEpoch, int version) throws Exception {
}
}
- public long read() {
- long brokerEpoch = -1L;
+ @SuppressWarnings("unchecked")
+ public OptionalLong read() {
try {
String text =
Utils.readFileAsString(cleanShutdownFile.toPath().toString());
- Map<String, String> content = new ObjectMapper().readValue(text,
HashMap.class);
-
- brokerEpoch =
Long.parseLong(content.getOrDefault(Fields.BROKER_EPOCH.toString(), "-1L"));
+ Content content = new ObjectMapper().readValue(text,
Content.class);
Review Comment:
Hmm, by doing this, it seems that we can't upgrade from the current clean
shutdown file nor could we downgrade if we add a new field in the future?
##########
storage/src/main/java/org/apache/kafka/storage/internals/log/CleanShutdownFileHandler.java:
##########
@@ -49,13 +47,15 @@ public class CleanShutdownFileHandler {
private static final int CURRENT_VERSION = 0;
private final Logger logger;
- private enum Fields {
- VERSION,
- BROKER_EPOCH;
+ private static class Content {
+ public int version;
+ public Long brokerEpoch;
- @Override
- public String toString() {
- return name().toLowerCase(Locale.ROOT);
+ public Content() {};
Review Comment:
Is this constructor used?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]