From b221091fd68f7d5657519ee41a0531a85cc2e838 Mon Sep 17 00:00:00 2001 From: horizonzy Date: Thu, 25 Jan 2024 18:34:23 +0800 Subject: [PATCH 1/4] Reduce the committed log memory usage. --- .../org/apache/zookeeper/server/Request.java | 18 ++----- .../server/TxnLogProposalIterator.java | 7 ++- .../apache/zookeeper/server/ZKDatabase.java | 13 ++--- .../zookeeper/server/quorum/Leader.java | 54 +++++++++++++++++-- .../server/quorum/LearnerHandler.java | 4 +- .../quorum/flexible/QuorumOracleMaj.java | 10 ++-- .../server/quorum/LeaderWithObserverTest.java | 5 +- .../server/quorum/LearnerHandlerTest.java | 14 ++--- .../test/GetProposalFromTxnTest.java | 2 +- .../test/LocalSessionRequestTest.java | 4 +- 10 files changed, 82 insertions(+), 49 deletions(-) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java index 10111c8a64f..52e441d56cb 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java @@ -169,24 +169,16 @@ public boolean isThrottlable() { && this.type != OpCode.createSession; } - private transient byte[] serializeData; - - @SuppressFBWarnings(value = "EI_EXPOSE_REP") public byte[] getSerializeData() { if (this.hdr == null) { return null; } - - if (this.serializeData == null) { - try { - this.serializeData = Util.marshallTxnEntry(this.hdr, this.txn, this.txnDigest); - } catch (IOException e) { - LOG.error("This really should be impossible.", e); - this.serializeData = new byte[32]; - } + try { + return Util.marshallTxnEntry(this.hdr, this.txn, this.txnDigest); + } catch (IOException e) { + LOG.error("This really should be impossible.", e); + return new byte[32]; } - - return this.serializeData; } /** diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java index 847e3b2fabe..2d6ecb631fe 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/TxnLogProposalIterator.java @@ -58,20 +58,19 @@ public boolean hasNext() { @Override public Proposal next() { - Proposal p = new Proposal(); + Proposal p; try { byte[] serializedData = Util.marshallTxnEntry(itr.getHeader(), itr.getTxn(), itr.getDigest()); QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, itr.getHeader().getZxid(), serializedData, null); - p.packet = pp; - p.request = null; - + p = new Proposal(pp); // This is the only place that can throw IO exception hasNext = itr.next(); } catch (IOException e) { LOG.error("Unable to read txnlog from disk", e); hasNext = false; + p = new Proposal(); } return p; diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java index eaad05cd295..13df9121168 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java @@ -54,9 +54,8 @@ import org.apache.zookeeper.server.persistence.FileTxnSnapLog.PlayBackListener; import org.apache.zookeeper.server.persistence.SnapStream; import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; -import org.apache.zookeeper.server.quorum.Leader; +import org.apache.zookeeper.server.quorum.Leader.PureRequestProposal; import org.apache.zookeeper.server.quorum.Leader.Proposal; -import org.apache.zookeeper.server.quorum.QuorumPacket; import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; import org.apache.zookeeper.server.util.SerializeUtils; import org.apache.zookeeper.txn.TxnDigest; @@ -323,19 +322,15 @@ public void addCommittedProposal(Request request) { wl.lock(); if (committedLog.size() > commitLogCount) { committedLog.remove(); - minCommittedLog = committedLog.peek().packet.getZxid(); + minCommittedLog = committedLog.peek().getZxid(); } if (committedLog.isEmpty()) { minCommittedLog = request.zxid; maxCommittedLog = request.zxid; } - byte[] data = request.getSerializeData(); - QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, data, null); - Proposal p = new Proposal(); - p.packet = pp; - p.request = request; + PureRequestProposal p = new PureRequestProposal(request); committedLog.add(p); - maxCommittedLog = p.packet.getZxid(); + maxCommittedLog = p.getZxid(); } finally { wl.unlock(); } diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java index 3b9c827c340..0b57bb1824a 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java @@ -88,14 +88,60 @@ public class Leader extends LearnerMaster { public static class Proposal extends SyncedLearnerTracker { - public QuorumPacket packet; - public Request request; + private QuorumPacket packet; + protected Request request; + + public Proposal() { + } + + public Proposal(QuorumPacket packet) { + this.packet = packet; + } + + public Proposal(Request request, QuorumPacket packet) { + this.request = request; + this.packet = packet; + } + + public QuorumPacket getQuorumPacket() { + return packet; + } + + public Request getRequest() { + return request; + } + + public long getZxid() { + return packet.getZxid(); + } @Override public String toString() { return packet.getType() + ", " + packet.getZxid() + ", " + request; } + } + public static class PureRequestProposal extends Proposal { + + public PureRequestProposal(Request request) { + this.request = request; + } + + @Override + public QuorumPacket getQuorumPacket() { + byte[] data = request.getSerializeData(); + return new QuorumPacket(Leader.PROPOSAL, request.zxid, data, null); + } + + @Override + public long getZxid() { + return request.zxid; + } + + @Override + public String toString() { + return request.toString(); + } } // log ack latency if zxid is a multiple of ackLoggingFrequency. If <=0, disable logging. @@ -1258,9 +1304,7 @@ public Proposal propose(Request request) throws XidRolloverException { proposalStats.setLastBufferSize(data.length); QuorumPacket pp = new QuorumPacket(Leader.PROPOSAL, request.zxid, data, null); - Proposal p = new Proposal(); - p.packet = pp; - p.request = request; + Proposal p = new Proposal(request, pp); synchronized (this) { p.addQuorumVerifier(self.getQuorumVerifier()); diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerHandler.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerHandler.java index e9d5cd4e5e8..049336a16ee 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerHandler.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerHandler.java @@ -957,7 +957,7 @@ protected long queueCommittedProposals(Iterator itr, long peerLastZxid while (itr.hasNext()) { Proposal propose = itr.next(); - long packetZxid = propose.packet.getZxid(); + long packetZxid = propose.getZxid(); // abort if we hit the limit if ((maxZxid != null) && (packetZxid > maxZxid)) { break; @@ -1020,7 +1020,7 @@ protected long queueCommittedProposals(Iterator itr, long peerLastZxid // Since this is already a committed proposal, we need to follow // it by a commit packet - queuePacket(propose.packet); + queuePacket(propose.getQuorumPacket()); queueOpPacket(Leader.COMMIT, packetZxid); queuedZxid = packetZxid; diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java index 01f3a8240be..08d3c6cab81 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java @@ -123,18 +123,18 @@ public boolean revalidateOutstandingProp(Leader self, ArrayList LOG.debug("Start Revalidation outstandingProposals"); try { while (outstandingProposal.size() >= 1) { - outstandingProposal.sort((o1, o2) -> (int) (o1.packet.getZxid() - o2.packet.getZxid())); + outstandingProposal.sort((o1, o2) -> (int) (o1.getZxid() - o2.getZxid())); Leader.Proposal p; int i = 0; while (i < outstandingProposal.size()) { p = outstandingProposal.get(i); - if (p.request.zxid > lastCommitted) { - LOG.debug("Re-validate outstanding proposal: 0x{} size:{} lastCommitted:{}", Long.toHexString(p.request.zxid), outstandingProposal.size(), Long.toHexString(lastCommitted)); - if (!self.tryToCommit(p, p.request.zxid, null)) { + if (p.getZxid()> lastCommitted) { + LOG.debug("Re-validate outstanding proposal: 0x{} size:{} lastCommitted:{}", Long.toHexString(p.getZxid()), outstandingProposal.size(), Long.toHexString(lastCommitted)); + if (!self.tryToCommit(p, p.getZxid(), null)) { break; } else { - lastCommitted = p.request.zxid; + lastCommitted = p.getZxid(); outstandingProposal.remove(p); } } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderWithObserverTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderWithObserverTest.java index 7ac563698b5..8e39f61e982 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderWithObserverTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderWithObserverTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; +import java.lang.reflect.Field; import java.net.InetSocketAddress; import java.util.Map; import java.util.Set; @@ -144,7 +145,9 @@ public void testWaitForNewLeaderAck() throws Exception { long zxid = leader.zk.getZxid(); // things needed for waitForNewLeaderAck to run (usually in leader.lead(), but we're not running leader here) - leader.newLeaderProposal.packet = new QuorumPacket(0, zxid, null, null); + Field field = Leader.Proposal.class.getDeclaredField("packet"); + field.setAccessible(true); + field.set(leader.newLeaderProposal, new QuorumPacket(0, zxid, null, null)); leader.newLeaderProposal.addQuorumVerifier(peer.getQuorumVerifier()); Set ackSet = leader.newLeaderProposal.qvAcksetPairs.get(0).getAckset(); diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java index bbf36367ef0..43202716d2b 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java @@ -86,14 +86,14 @@ public long getDataTreeLastProcessedZxid() { public long getmaxCommittedLog() { if (!committedLog.isEmpty()) { - return committedLog.getLast().packet.getZxid(); + return committedLog.getLast().getZxid(); } return 0; } public long getminCommittedLog() { if (!committedLog.isEmpty()) { - return committedLog.getFirst().packet.getZxid(); + return committedLog.getFirst().getZxid(); } return 0; } @@ -107,7 +107,7 @@ public ReentrantReadWriteLock getLogLock() { } public Iterator getProposalsFromTxnLog(long peerZxid, long limit) { - if (peerZxid >= txnLog.peekFirst().packet.getZxid()) { + if (peerZxid >= txnLog.peekFirst().getZxid()) { return txnLog.iterator(); } else { return Collections.emptyIterator(); @@ -150,10 +150,10 @@ public Long answer(InvocationOnMock invocation) { } Proposal createProposal(long zxid) { - Proposal p = new Proposal(); - p.packet = new QuorumPacket(); - p.packet.setZxid(zxid); - p.packet.setType(Leader.PROPOSAL); + QuorumPacket packet = new QuorumPacket(); + packet.setZxid(zxid); + packet.setType(Leader.PROPOSAL); + Proposal p = new Proposal(packet); return p; } diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/GetProposalFromTxnTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/GetProposalFromTxnTest.java index 010d69b3365..a85e76d01ec 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/GetProposalFromTxnTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/GetProposalFromTxnTest.java @@ -107,7 +107,7 @@ public void testGetProposalFromTxn() throws Exception { while (itr.hasNext()) { Proposal proposal = itr.next(); TxnLogEntry logEntry = SerializeUtils.deserializeTxn( - proposal.packet.getData()); + proposal.getQuorumPacket().getData()); TxnHeader hdr = logEntry.getHeader(); Record rec = logEntry.getTxn(); if (hdr.getType() == OpCode.create) { diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java index 1c1c72e1a82..16a470c31d8 100644 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java +++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/LocalSessionRequestTest.java @@ -82,8 +82,8 @@ private void validateRequestLog(long sessionId, int peerId) { QuorumPeer peer = qb.getPeerList().get(peerId); ZKDatabase db = peer.getActiveServer().getZKDatabase(); for (Proposal p : db.getCommittedLog()) { - assertFalse(p.request.sessionId == sessionId, - "Should not see " + Request.op2String(p.request.type) + assertFalse(p.getRequest().sessionId == sessionId, + "Should not see " + Request.op2String(p.getRequest().type) + " request from local session 0x" + session + " on the " + peerType); } } From cf19d19187a29ccb6af0a386585ba362633c77df Mon Sep 17 00:00:00 2001 From: horizonzy Date: Thu, 25 Jan 2024 18:50:40 +0800 Subject: [PATCH 2/4] Fix ci. --- .../src/main/java/org/apache/zookeeper/server/Request.java | 1 - .../src/main/java/org/apache/zookeeper/server/ZKDatabase.java | 2 +- .../zookeeper/server/quorum/flexible/QuorumOracleMaj.java | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java index 52e441d56cb..27fa4e2dff7 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java @@ -19,7 +19,6 @@ package org.apache.zookeeper.server; import static java.nio.charset.StandardCharsets.UTF_8; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java index 13df9121168..d98c97f2c07 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java @@ -54,8 +54,8 @@ import org.apache.zookeeper.server.persistence.FileTxnSnapLog.PlayBackListener; import org.apache.zookeeper.server.persistence.SnapStream; import org.apache.zookeeper.server.persistence.TxnLog.TxnIterator; -import org.apache.zookeeper.server.quorum.Leader.PureRequestProposal; import org.apache.zookeeper.server.quorum.Leader.Proposal; +import org.apache.zookeeper.server.quorum.Leader.PureRequestProposal; import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; import org.apache.zookeeper.server.util.SerializeUtils; import org.apache.zookeeper.txn.TxnDigest; diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java index 08d3c6cab81..b3e7fa24926 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/flexible/QuorumOracleMaj.java @@ -129,7 +129,7 @@ public boolean revalidateOutstandingProp(Leader self, ArrayList int i = 0; while (i < outstandingProposal.size()) { p = outstandingProposal.get(i); - if (p.getZxid()> lastCommitted) { + if (p.getZxid() > lastCommitted) { LOG.debug("Re-validate outstanding proposal: 0x{} size:{} lastCommitted:{}", Long.toHexString(p.getZxid()), outstandingProposal.size(), Long.toHexString(lastCommitted)); if (!self.tryToCommit(p, p.getZxid(), null)) { break; From 64f6b2c728bf20132c5b2dd768e4a2dbfdc78123 Mon Sep 17 00:00:00 2001 From: horizonzy Date: Wed, 7 Feb 2024 16:23:13 +0800 Subject: [PATCH 3/4] Support committed log size limitation policy. --- .../org/apache/zookeeper/server/Request.java | 10 +++- .../apache/zookeeper/server/ZKDatabase.java | 52 +++++++++++++++---- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java index 27fa4e2dff7..8a8bb833a68 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/Request.java @@ -168,18 +168,26 @@ public boolean isThrottlable() { && this.type != OpCode.createSession; } + private long approximateSize = 0; + public byte[] getSerializeData() { if (this.hdr == null) { return null; } try { - return Util.marshallTxnEntry(this.hdr, this.txn, this.txnDigest); + byte[] bytes = Util.marshallTxnEntry(this.hdr, this.txn, this.txnDigest); + approximateSize = bytes.length; + return bytes; } catch (IOException e) { LOG.error("This really should be impossible.", e); return new byte[32]; } } + public long getApproximateSize() { + return approximateSize; + } + /** * If this is a create or close request for a local-only session. */ diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java index d98c97f2c07..61eda43d120 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; @@ -92,9 +93,16 @@ public class ZKDatabase { public static final String COMMIT_LOG_COUNT = "zookeeper.commitLogCount"; public static final int DEFAULT_COMMIT_LOG_COUNT = 500; public int commitLogCount; + public static final String COMMIT_LOG_SIZE = "zookeeper.commitLogSize"; + public static final double DEFAULT_COMMIT_LOG_SIZE = Runtime.getRuntime().maxMemory() * 0.2; + public double commitLogSize; protected Queue committedLog = new ArrayDeque<>(); protected ReentrantReadWriteLock logLock = new ReentrantReadWriteLock(); private volatile boolean initialized = false; + /** + * committedLog bytes size. + */ + private AtomicLong totalCommittLogSize = new AtomicLong(0); /** * Number of txn since last snapshot; @@ -137,12 +145,11 @@ public ZKDatabase(FileTxnSnapLog snapLog) { commitLogCount = Integer.parseInt( System.getProperty(COMMIT_LOG_COUNT, Integer.toString(DEFAULT_COMMIT_LOG_COUNT))); - if (commitLogCount < DEFAULT_COMMIT_LOG_COUNT) { + if (commitLogCount <= 0) { commitLogCount = DEFAULT_COMMIT_LOG_COUNT; LOG.warn( - "The configured commitLogCount {} is less than the recommended {}, going to use the recommended one", - COMMIT_LOG_COUNT, - DEFAULT_COMMIT_LOG_COUNT); + "The configured commitLogCount {} is less than zero, going to use the recommended value {}", + COMMIT_LOG_COUNT, DEFAULT_COMMIT_LOG_COUNT); } } catch (NumberFormatException e) { LOG.error( @@ -151,7 +158,24 @@ public ZKDatabase(FileTxnSnapLog snapLog) { DEFAULT_COMMIT_LOG_COUNT); commitLogCount = DEFAULT_COMMIT_LOG_COUNT; } - LOG.info("{}={}", COMMIT_LOG_COUNT, commitLogCount); + try { + commitLogSize = Double.parseDouble( + System.getProperty(COMMIT_LOG_SIZE, + Double.toString(DEFAULT_COMMIT_LOG_SIZE))); + if (commitLogSize <= 0) { + commitLogSize = DEFAULT_COMMIT_LOG_SIZE; + LOG.warn( + "The configured commitLogSize {} is less than the zero, going to use the recommended value {}", + COMMIT_LOG_SIZE, DEFAULT_COMMIT_LOG_SIZE); + } + } catch (NumberFormatException e) { + LOG.error( + "Error parsing {} - use default value {}", + COMMIT_LOG_SIZE, + DEFAULT_COMMIT_LOG_SIZE); + commitLogSize = DEFAULT_COMMIT_LOG_SIZE; + } + LOG.info("{}={}, {}={}", COMMIT_LOG_COUNT, commitLogCount, COMMIT_LOG_SIZE, commitLogSize); } /** @@ -182,6 +206,7 @@ public void clear() { try { lock.lock(); committedLog.clear(); + totalCommittLogSize.set(0); } finally { lock.unlock(); } @@ -320,17 +345,24 @@ public void addCommittedProposal(Request request) { WriteLock wl = logLock.writeLock(); try { wl.lock(); - if (committedLog.size() > commitLogCount) { - committedLog.remove(); - minCommittedLog = committedLog.peek().getZxid(); - } if (committedLog.isEmpty()) { minCommittedLog = request.zxid; - maxCommittedLog = request.zxid; } PureRequestProposal p = new PureRequestProposal(request); committedLog.add(p); maxCommittedLog = p.getZxid(); + totalCommittLogSize.addAndGet(request.getApproximateSize()); + while (committedLog.size() > 0 && + (committedLog.size() > commitLogCount || totalCommittLogSize.get() > commitLogSize)) { + committedLog.remove(); + Proposal peek = committedLog.peek(); + if (peek == null) { + minCommittedLog = 0; + maxCommittedLog = 0; + } else { + minCommittedLog = p.getZxid(); + } + } } finally { wl.unlock(); } From 41a352291f2f93ffb55d8d5aabf8c3d168ef7ad9 Mon Sep 17 00:00:00 2001 From: horizonzy Date: Fri, 9 Feb 2024 18:36:35 +0800 Subject: [PATCH 4/4] fix ci. --- .../src/main/java/org/apache/zookeeper/server/ZKDatabase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java index 61eda43d120..1b61620e8bd 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java @@ -352,8 +352,8 @@ public void addCommittedProposal(Request request) { committedLog.add(p); maxCommittedLog = p.getZxid(); totalCommittLogSize.addAndGet(request.getApproximateSize()); - while (committedLog.size() > 0 && - (committedLog.size() > commitLogCount || totalCommittLogSize.get() > commitLogSize)) { + while (committedLog.size() > 0 + && (committedLog.size() > commitLogCount || totalCommittLogSize.get() > commitLogSize)) { committedLog.remove(); Proposal peek = committedLog.peek(); if (peek == null) {