You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "cmccabe (via GitHub)" <gi...@apache.org> on 2023/09/07 19:27:50 UTC

[GitHub] [kafka] cmccabe commented on a diff in pull request #14354: KAFKA-14273; Close file before atomic move

cmccabe commented on code in PR #14354:
URL: https://github.com/apache/kafka/pull/14354#discussion_r1319034514


##########
raft/src/main/java/org/apache/kafka/raft/FileBasedStateStore.java:
##########
@@ -144,21 +144,29 @@ private void writeElectionStateToFile(final File stateFile, QuorumStateData stat
 
         log.trace("Writing tmp quorum state {}", temp.getAbsolutePath());
 
-        try (final FileOutputStream fileOutputStream = new FileOutputStream(temp);
-             final BufferedWriter writer = new BufferedWriter(
-                 new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8))) {
-            short version = state.highestSupportedVersion();
-
-            ObjectNode jsonState = (ObjectNode) QuorumStateDataJsonConverter.write(state, version);
-            jsonState.set(DATA_VERSION, new ShortNode(version));
-            writer.write(jsonState.toString());
-            writer.flush();
-            fileOutputStream.getFD().sync();
+        try {
+            try (final FileOutputStream fileOutputStream = new FileOutputStream(temp);
+                 final BufferedWriter writer = new BufferedWriter(
+                     new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8)
+                 )
+            ) {
+                short version = state.highestSupportedVersion();

Review Comment:
   while we're fixing this let's get rid of `highestSupportedVersion` here. Be clear about the version we're setting.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org