junrao commented on code in PR #14603:
URL: https://github.com/apache/kafka/pull/14603#discussion_r1372017036


##########
storage/src/main/java/org/apache/kafka/storage/internals/checkpoint/CleanShutdownFileHandler.java:
##########
@@ -73,10 +77,8 @@ void write(long brokerEpoch, int version) throws Exception {
         FileOutputStream os = new FileOutputStream(cleanShutdownFile);
         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, 
StandardCharsets.UTF_8));
         try {
-            Map<String, String> payload = new HashMap<>();
-            payload.put(Fields.VERSION.toString(), Integer.toString(version));
-            payload.put(Fields.BROKER_EPOCH.toString(), 
Long.toString(brokerEpoch));
-            bw.write(new ObjectMapper().writeValueAsString(payload));
+            Content content = new Content(version, brokerEpoch);
+            bw.write(OBJECT_MAPPER.writeValueAsString(content));

Review Comment:
   Could we reuse `Json.encodeAsString`?



##########
storage/src/main/java/org/apache/kafka/storage/internals/checkpoint/CleanShutdownFileHandler.java:
##########
@@ -85,17 +87,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 = OBJECT_MAPPER.readValue(text, Content.class);

Review Comment:
   Could we reuse `Json.parseStringAs`?



##########
storage/src/main/java/org/apache/kafka/storage/internals/checkpoint/CleanShutdownFileHandler.java:
##########
@@ -45,17 +44,22 @@
 
 public class CleanShutdownFileHandler {
     public static final String CLEAN_SHUTDOWN_FILE_NAME = 
".kafka_cleanshutdown";
-    private final File cleanShutdownFile;
+    // Visible for testing
+    public final File cleanShutdownFile;

Review Comment:
   Should we limit that to package level access?



##########
core/src/main/scala/kafka/server/BrokerLifecycleManager.scala:
##########
@@ -190,7 +192,7 @@ class BrokerLifecycleManager(
   /**
    * The broker epoch from the previous run, or -1 if the epoch is not able to 
be found.
    */
-  @volatile private var previousBrokerEpoch: Long = -1L
+  @volatile private var previousBrokerEpoch: OptionalLong = 
OptionalLong.empty()

Review Comment:
   Could we change the above comment on -1 accordingly?



-- 
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]

Reply via email to