anmolnar commented on code in PR #1930:
URL: https://github.com/apache/zookeeper/pull/1930#discussion_r1765351934


##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Learner.java:
##########
@@ -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 {

Review Comment:
   I'm not sure if this branch is correct, because in the old logic if 
`writeToTxnLog == true`, then the packet is added to `packetsCommitted` no 
matter if zxid matches with the next proposal or not.
   
   In your new logic, if I understand it right, if `zxid` differs you'll quit 
fast and log the above warning message only.
   
   Is that correct?



##########
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Learner.java:
##########
@@ -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());

Review Comment:
   Here. This logic is not handled in the new code for some reason.



-- 
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: notifications-unsubscr...@zookeeper.apache.org

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

Reply via email to