sashapolo commented on code in PR #5092:
URL: https://github.com/apache/ignite-3/pull/5092#discussion_r1961639990


##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/DataNodesHistory.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.distributionzones;
+
+import static java.util.Collections.emptySet;
+import static org.apache.ignite.internal.lang.Pair.pair;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.Objects;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lang.Pair;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.apache.ignite.internal.versioned.VersionedSerializer;
+
+/**
+ * Data nodes history. Is actually a map of timestamps to sets of nodes with 
their attributes.
+ */
+public class DataNodesHistory {
+    private final NavigableMap<HybridTimestamp, Set<NodeWithAttributes>> 
history;
+
+    public DataNodesHistory() {
+        this(new TreeMap<>());
+    }
+
+    public DataNodesHistory(NavigableMap<HybridTimestamp, 
Set<NodeWithAttributes>> history) {
+        this.history = history;
+    }
+
+    /**
+     * Copies existing history and adds a new history entry.
+     *
+     * @param timestamp Timestamp.
+     * @param nodes Nodes.
+     * @return New data nodes history.
+     */
+    public DataNodesHistory addHistoryEntry(HybridTimestamp timestamp, 
Set<NodeWithAttributes> nodes) {
+        DataNodesHistory dataNodesHistory = new DataNodesHistory(new 
TreeMap<>(this.history));
+        dataNodesHistory.history.put(timestamp, nodes);
+        return dataNodesHistory;
+    }
+
+    /**
+     * Checks that the exact timestamp is present in history.
+     *
+     * @param timestamp Timestamp.
+     * @return {@code true} if the exact timestamp is present in history.
+     */
+    public boolean entryIsPresentAtExactTimestamp(HybridTimestamp timestamp) {
+        return history.containsKey(timestamp);
+    }
+
+    /**
+     * Checks that the history is empty.
+     *
+     * @return {@code true} if history is empty.
+     */
+    public boolean isEmpty() {
+        return history.isEmpty();
+    }
+
+    /**
+     * Returns data nodes for timestamp, or empty set.
+     *
+     * @param timestamp Timestamp.
+     * @return Data nodes for timestamp, or empty set.
+     */
+    public Pair<HybridTimestamp, Set<NodeWithAttributes>> 
dataNodesForTimestamp(HybridTimestamp timestamp) {

Review Comment:
   ok, makes sense, but can we use a specific class instead of the Pair then?



-- 
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...@ignite.apache.org

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

Reply via email to