Skip to content

KAFKA-6054: Code cleanup to prepare the actual fix for an upgrade path#4630

Merged
mjsax merged 3 commits into
apache:trunkfrom
mjsax:kafka-6054-fix-upgrade
Mar 5, 2018
Merged

KAFKA-6054: Code cleanup to prepare the actual fix for an upgrade path#4630
mjsax merged 3 commits into
apache:trunkfrom
mjsax:kafka-6054-fix-upgrade

Conversation

@mjsax

@mjsax mjsax commented Mar 1, 2018

Copy link
Copy Markdown
Member

Small change in decoding version 1 metadata: don't upgrade to version 2 automatically

@mjsax mjsax added the streams label Mar 1, 2018
@mjsax
mjsax requested review from dguy and guozhangwang March 1, 2018 06:08
@mjsax

mjsax commented Mar 1, 2018

Copy link
Copy Markdown
Member Author

@bbejeck @vvcephei @guozhangwang @dguy

This is almost a pure code cleanup PR -- required to get clean code for introducing next metadata version.

One change: we should not auto-upgrade the received subscription info (from 1 to 2), otherwise the leader does not know what it received and what encoding to use for the assignment to send back (must send back version 1 encoding if at least one version 1 subscription was received).

@bbejeck

bbejeck commented Mar 1, 2018

Copy link
Copy Markdown
Member

one meta-comment might be worth commenting in AssingmentInfo why we need to call encodeVersionOne from encodeVersionTwo (and for decode... as well) like you did in the PR description above.

Otherwise LGTM.

@guozhangwang guozhangwang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left some comments.

encodeVersionOneData(out);
}

private void encodeVersionOneData(final DataOutputStream out) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd suggest we change to encodeAssignedTasksData and encodeHostPartitionsData correspondingly. In the future versions we may remove some of the old encoded data so the names could be misleading.

throw new IllegalStateException("Unknown metadata version: " + usedVersion
+ "; latest supported version: " + SubscriptionInfo.LATEST_SUPPORTED_VERSION);
}
if (info.version() < minUserMetadataVersion) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: use usedVersion, and the same in the next line.

switch (usedVersion) {
case 1:
processVersionOneAssignment(info, partitions, activeTasks);
partitionsByHost = new HashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Collections.emptyMap.

buf = encodeVersionOne();
break;
case 2:
byte[] endPointBytes = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Merge these two lines.

assertEquals(2, decoded.version); // automatically upgraded to v2 on decode;
assertEquals(oldVersion.activeTasks(), decoded.activeTasks());
assertEquals(oldVersion.standbyTasks(), decoded.standbyTasks());
assertNull(decoded.partitionsByHost()); // should be empty as wasn't in V1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: update the comment in this line.

*/
@Override
public Map<String, Assignment> assign(Cluster metadata, Map<String, Subscription> subscriptions) {
public Map<String, Assignment> assign(final Cluster metadata,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a unit test with two subscriptions, v1 and v2, and then check that the returned assignment map contains v1?

@guozhangwang

Copy link
Copy Markdown
Contributor

@mjsax Just clarifying that with this patch, KAFKA-6054 is still not resolved right?

@mjsax

mjsax commented Mar 2, 2018

Copy link
Copy Markdown
Member Author

Correct. This is not a fix for KAFKA-6054 -- I plan to piggyback a fix with the RocksDBs upgrade story -- we need to add a config to fix it and thus need a KIP.

@mjsax

mjsax commented Mar 2, 2018

Copy link
Copy Markdown
Member Author

Updated this. @bbejeck I followed Guozhang's suggestion to rename the encoding-methods -- this should address your comment, too?

partitionAssignor.configure(config);
}

public void shouldReturnLowestAssignmentVersionForDifferentSubscriptionVersions() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add @test annotation.

@guozhangwang

Copy link
Copy Markdown
Contributor

LGTM! Left a minor comment on the PR, please feel free to merge after addressing it

@mjsax

mjsax commented Mar 2, 2018

Copy link
Copy Markdown
Member Author

Updated. Will wait for build to pass.

@mjsax
mjsax merged commit 2a4ba75 into apache:trunk Mar 5, 2018
@mjsax
mjsax deleted the kafka-6054-fix-upgrade branch March 5, 2018 18:56
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.

4 participants