-
Notifications
You must be signed in to change notification settings - Fork 7.3k
ZOOKEEPER-4394: Learner.syncWithLeader got NullPointerException #1930
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -555,6 +555,7 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| boolean syncSnapshot = false; | ||
| readPacket(qp); | ||
| Deque<Long> packetsCommitted = new ArrayDeque<>(); | ||
| Deque<PacketInFlight> packetsNotLogged = new ArrayDeque<>(); | ||
| Deque<PacketInFlight> packetsNotCommitted = new ArrayDeque<>(); | ||
| synchronized (zk) { | ||
| if (qp.getType() == Leader.DIFF) { | ||
|
|
@@ -643,33 +644,37 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| self.setLastSeenQuorumVerifier(qv, true); | ||
| } | ||
|
|
||
| packetsNotLogged.add(pif); | ||
| packetsNotCommitted.add(pif); | ||
| break; | ||
| case Leader.COMMIT: | ||
| case Leader.COMMITANDACTIVATE: | ||
| pif = packetsNotCommitted.peekFirst(); | ||
| if (pif.hdr.getZxid() == qp.getZxid() && qp.getType() == Leader.COMMITANDACTIVATE) { | ||
| QuorumVerifier qv = self.configFromString(new String(((SetDataTxn) pif.rec).getData(), UTF_8)); | ||
| boolean majorChange = self.processReconfig( | ||
| qv, | ||
| ByteBuffer.wrap(qp.getData()).getLong(), qp.getZxid(), | ||
| true); | ||
| if (majorChange) { | ||
| if (pif.hdr.getZxid() != qp.getZxid()) { | ||
| LOG.warn( | ||
| "Committing 0x{}, but next proposal is 0x{}", | ||
| Long.toHexString(qp.getZxid()), | ||
| Long.toHexString(pif.hdr.getZxid())); | ||
| } else { | ||
| if (qp.getType() == Leader.COMMITANDACTIVATE) { | ||
| QuorumVerifier qv = self.configFromString(new String(((SetDataTxn) pif.rec).getData(), UTF_8)); | ||
| boolean majorChange = self.processReconfig( | ||
| qv, | ||
| ByteBuffer.wrap(qp.getData()).getLong(), qp.getZxid(), | ||
| true); | ||
| if (majorChange) { | ||
| throw new Exception("changes proposed in reconfig"); | ||
| } | ||
| } | ||
| } | ||
| if (!writeToTxnLog) { | ||
| if (pif.hdr.getZxid() != qp.getZxid()) { | ||
| LOG.warn( | ||
| "Committing 0x{}, but next proposal is 0x{}", | ||
| Long.toHexString(qp.getZxid()), | ||
| Long.toHexString(pif.hdr.getZxid())); | ||
| } else { | ||
| if (!writeToTxnLog) { | ||
| // Apply to db directly if we haven't taken the snapshot. | ||
| zk.processTxn(pif.hdr, pif.rec); | ||
| packetsNotLogged.remove(); | ||
| packetsNotCommitted.remove(); | ||
| } else { | ||
| packetsNotCommitted.remove(); | ||
| packetsCommitted.add(qp.getZxid()); | ||
| } | ||
| } else { | ||
| packetsCommitted.add(qp.getZxid()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here. This logic is not handled in the new code for some reason. |
||
| } | ||
| break; | ||
| case Leader.INFORM: | ||
|
|
@@ -708,7 +713,7 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| // Apply to db directly if we haven't taken the snapshot | ||
| zk.processTxn(packet.hdr, packet.rec); | ||
| } else { | ||
| packetsNotCommitted.add(packet); | ||
| packetsNotLogged.add(packet); | ||
| packetsCommitted.add(qp.getZxid()); | ||
| } | ||
|
|
||
|
|
@@ -756,10 +761,10 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| zk.startupWithoutServing(); | ||
| if (zk instanceof FollowerZooKeeperServer) { | ||
| FollowerZooKeeperServer fzk = (FollowerZooKeeperServer) zk; | ||
| for (PacketInFlight p : packetsNotCommitted) { | ||
| for (PacketInFlight p : packetsNotLogged) { | ||
| fzk.logRequest(p.hdr, p.rec, p.digest); | ||
| } | ||
| packetsNotCommitted.clear(); | ||
| packetsNotLogged.clear(); | ||
| } | ||
|
|
||
| writePacket(new QuorumPacket(Leader.ACK, newLeaderZxid, null, null), true); | ||
|
|
@@ -782,7 +787,7 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| // We need to log the stuff that came in between the snapshot and the uptodate | ||
| if (zk instanceof FollowerZooKeeperServer) { | ||
| FollowerZooKeeperServer fzk = (FollowerZooKeeperServer) zk; | ||
| for (PacketInFlight p : packetsNotCommitted) { | ||
| for (PacketInFlight p : packetsNotLogged) { | ||
| fzk.logRequest(p.hdr, p.rec, p.digest); | ||
| } | ||
| for (Long zxid : packetsCommitted) { | ||
|
|
@@ -792,7 +797,7 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception { | |
| // Similar to follower, we need to log requests between the snapshot | ||
| // and UPTODATE | ||
| ObserverZooKeeperServer ozk = (ObserverZooKeeperServer) zk; | ||
| for (PacketInFlight p : packetsNotCommitted) { | ||
| for (PacketInFlight p : packetsNotLogged) { | ||
| Long zxid = packetsCommitted.peekFirst(); | ||
| if (p.hdr.getZxid() != zxid) { | ||
| // log warning message if there is no matching commit | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this branch is correct, because in the old logic if
writeToTxnLog == true, then the packet is added topacketsCommittedno matter if zxid matches with the next proposal or not.In your new logic, if I understand it right, if
zxiddiffers you'll quit fast and log the above warning message only.Is that correct?