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

fix: fix NPE when backing a record that has null key/values #7268

Merged
merged 2 commits into from
Mar 23, 2021

Conversation

spena
Copy link
Member

@spena spena commented Mar 22, 2021

Description

What behavior do you want to change, why, how does your patch achieve the changes?

Fixes #7184

Testing done

Describe the testing strategy. Unit and integration tests are expected for any behavior changes.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena requested review from stevenpyzhang and a team March 22, 2021 15:26

if (record.key() == null || record.value() == null) {
throw new IllegalArgumentException(String.format(
"Record contain a null key/value: key=%s, value=%s", record.key(), record.value()));
Copy link
Contributor

Choose a reason for hiding this comment

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

it might also help to output the partition/offset (even though partition is always 0 here) - ditto for other error messages

Copy link
Member Author

@spena spena Mar 23, 2021

Choose a reason for hiding this comment

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

Done. Btw, I removed this redundant null check from this file. I left only the null checks in the CommandTopicBackupImpl.

@@ -84,6 +84,15 @@ public void write(final ConsumerRecord<byte[], byte[]> record) throws IOExceptio
throw new IOException("Write permission denied.");
}

if (record == null) {
throw new IllegalArgumentException("Record is null");
Copy link
Contributor

Choose a reason for hiding this comment

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

when can this ever happen? can we throw a more useful error message?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because any records read from the cmd topic should not have null records, I feel this can only happen if the local file was manipulated somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this never happen. I added just in case, but seems unnecessary. I removed it.

@@ -84,6 +84,15 @@ public void write(final ConsumerRecord<byte[], byte[]> record) throws IOExceptio
throw new IOException("Write permission denied.");
}

if (record == null) {
throw new IllegalArgumentException("Record is null");
Copy link
Contributor

Choose a reason for hiding this comment

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

Because any records read from the cmd topic should not have null records, I feel this can only happen if the local file was manipulated somehow?

recordString = String.format("key=%s, value=%s", record.key(), record.value());
}

LOG.warn("Cannot write a null record or null key/value to the backup file. This could be "
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here: could this ever happen, if we already check for null record/key/value when writing to cmd topic?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the redundant null check from the BackupReplayFile, which is called by the CommandTopicBackupImpl. I just left the one from this file.

@spena spena merged commit 0cbd4e8 into confluentinc:master Mar 23, 2021
@spena spena deleted the fix_npe_metadata_backup branch March 23, 2021 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An NPE while backing the metadata causes KSQL fail to start
3 participants