Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-6499: Do not write offset checkpoint file with empty offset map #4492

Conversation

guozhangwang
Copy link
Contributor

  • In Checkpoint.write(), if the offset map passed in is empty, skip the writing of the file which would only contain version number and the empty size. From the reading pov, it is the same as no file existed.

  • Add related unit tests.

  • Minor fixes on log4j messages.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@guozhangwang
Copy link
Contributor Author

@rodesai @bbejeck

@guozhangwang
Copy link
Contributor Author

retest this please

@mjsax mjsax added the streams label Jan 31, 2018
Copy link
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Overall LGTM.

@Test
public void testNotWriteEmptyMap() throws IOException {
// we do not need to worry about file name unqiueness since this file should not be created
File f = new File(TestUtils.tempDirectory().getAbsolutePath(), "kafka.tmp");
Copy link
Member

Choose a reason for hiding this comment

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

nit: add final -- same next line


assertEquals(Collections.<TopicPartition, Long>emptyMap(), checkpoint.read());

checkpoint.delete();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a delete here if the file was never created?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 - this line and the next shouldn't be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this line intentionally to make sure delete() would not bark if the file does not exist, i.e. internally it calls deleteIfExists.

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough - we still don't need the assertion though as it is already true as of line 69

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the assertion.

Copy link
Contributor

@dguy dguy left a comment

Choose a reason for hiding this comment

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

Thanks @guozhangwang, left s couple of comments

@@ -66,6 +66,10 @@ public OffsetCheckpoint(final File file) {
* @throws IOException if any file operation fails with an IO exception
*/
public void write(final Map<TopicPartition, Long> offsets) throws IOException {
// if there is no offsets, skip writing the file to save disk IOs
if (offsets.isEmpty())
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use java style here? i.e., if(..) {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@@ -56,4 +57,20 @@ public void testReadWrite() throws IOException {
checkpoint.delete();
}
}

@Test
public void testNotWriteEmptyMap() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldNotWriteCheckpointWhenNoOffsets?


assertEquals(Collections.<TopicPartition, Long>emptyMap(), checkpoint.read());

checkpoint.delete();
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 - this line and the next shouldn't be needed

Copy link
Contributor

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Thanks @guozhangwang LGTM

@asfgit
Copy link

asfgit commented Feb 1, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-test-coverage/219/

@dguy
Copy link
Contributor

dguy commented Feb 1, 2018

retest this please

@asfgit
Copy link

asfgit commented Feb 1, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-test-coverage/244/

@guozhangwang guozhangwang merged commit 4a2aa4b into apache:trunk Feb 1, 2018
@asfgit
Copy link

asfgit commented Feb 1, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-test-coverage/252/

@asfgit
Copy link

asfgit commented Feb 1, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-test-coverage/253/

guozhangwang added a commit that referenced this pull request Feb 1, 2018
…#4492)

* In Checkpoint.write(), if the offset map passed in is empty, skip the writing of the file which would only contain version number and the empty size. From the reading pov, it is the same as no file existed.
* Add related unit tests.
* Minor fixes on log4j messages.

Reviewers: Bill Bejeck <bill@confluent.io>, Damian Guy <damian@confluent.io>, Matthias J. Sax <matthias@confluent.io>
@guozhangwang
Copy link
Contributor Author

Cherry-picked to 1.1. Thanks for the reviews.

@guozhangwang guozhangwang deleted the K6499-not-write-checkpoint-with-empty-offset branch February 14, 2018 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants