SammyVimes commented on code in PR #804: URL: https://github.com/apache/ignite-3/pull/804#discussion_r871115838
########## modules/network/src/main/java/org/apache/ignite/internal/network/recovery/RecoveryDescriptor.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.network.recovery; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.tostring.S; +import org.apache.ignite.network.OutNetworkObject; + +/** + * Recovery protocol descriptor. + */ +public class RecoveryDescriptor { + /** Unacknowledged messages. */ + private final ArrayDeque<OutNetworkObject> unacknowledgedMessages; + + /** Count of sent messages. */ + private long sentCount; + + /** Count of acknowledged sent messages. */ + private long acknowledgedCount; + + /** Count of received messages. */ + private long receivedCount; + + /** + * Constructor. + * + * @param queueLimit Maximum size of unacknowledged messages queue. + */ + public RecoveryDescriptor(int queueLimit) { + this.unacknowledgedMessages = new ArrayDeque<>(queueLimit); + } + + /** + * Returns count of received messages. + * + * @return Count of received messages. + */ + public long receivedCount() { + return receivedCount; + } + + /** + * Acknowledges that sent messages were received by the remote node. + * + * @param messagesReceivedByRemote Number of all messages received by the remote node. + */ + public void acknowledge(long messagesReceivedByRemote) { + while (acknowledgedCount < messagesReceivedByRemote) { + OutNetworkObject req = unacknowledgedMessages.pollFirst(); + + assert req != null; + + acknowledgedCount++; + } + } + + /** + * Returns the number of the messages unacknowledged by the remote node. + * + * @return The number of the messages unacknowledged by the remote node. + */ + public long unacknowledgedCount() { + long res = sentCount - acknowledgedCount; + + assert res >= 0; + assert res == unacknowledgedMessages.size(); + + return res; + } + + /** + * Returns unacknowledged messages. + * + * @return Unacknowledged messages. + */ + public List<OutNetworkObject> unacknowledgedMessages() { + return new ArrayList<>(unacknowledgedMessages); + } + + /** + * Adds a sent message. + * + * @param msg Message. + */ + public void add(OutNetworkObject msg) { + msg.shouldBeSavedForRecovery(false); + sentCount++; + unacknowledgedMessages.addLast(msg); Review Comment: Will be addressed here: https://issues.apache.org/jira/browse/IGNITE-16954. Basically we will close the connection in the event of queue "overflow" -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
