rpuch commented on code in PR #1978:
URL: https://github.com/apache/ignite-3/pull/1978#discussion_r1180531037


##########
modules/network/src/main/java/org/apache/ignite/internal/network/recovery/VaultStateIds.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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 static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import org.apache.ignite.internal.vault.VaultEntry;
+import org.apache.ignite.internal.vault.VaultManager;
+import org.apache.ignite.lang.ByteArray;
+
+/**
+ * {@link StaleIds} implementating using Vault as a persistent storage.
+ */
+public class VaultStateIds implements StaleIds {
+    private static final ByteArray STALE_IDS_KEY = new 
ByteArray("network.staleIds");
+
+    private static final int DEFAULT_MAX_IDS_TO_REMEMBER = 10_000;
+
+    private final VaultManager vaultManager;
+
+    private final int maxIdsToRemember;
+
+    private Set<String> staleIds;
+
+    public VaultStateIds(VaultManager vaultManager) {
+        this(vaultManager, DEFAULT_MAX_IDS_TO_REMEMBER);
+    }
+
+    public VaultStateIds(VaultManager vaultManager, int maxIdsToRemember) {
+        this.vaultManager = vaultManager;
+        this.maxIdsToRemember = maxIdsToRemember;
+    }
+
+    @Override
+    public synchronized boolean isIdStale(String nodeId) {
+        if (staleIds == null) {
+            staleIds = loadStaleIdsFromVault();
+        }
+
+        return staleIds.contains(nodeId);
+    }
+
+    private Set<String> loadStaleIdsFromVault() {
+        VaultEntry entry = vaultManager.get(STALE_IDS_KEY).join();
+
+        if (entry == null) {
+            return new LinkedHashSet<>();
+        }
+
+        String[] idsArray = new String(entry.value(), UTF_8).split("\n");
+
+        Set<String> result = new LinkedHashSet<>();
+
+        Collections.addAll(result, idsArray);
+
+        return result;
+    }
+
+    @Override
+    public synchronized void markAsStale(String nodeId) {
+        if (staleIds == null) {
+            staleIds = new LinkedHashSet<>();

Review Comment:
   Oops, a bug. Fixed it.
   
   I did not load on start to avoid bringing in the concept of starting this 
component, it's too tiny to complicate it that much.



-- 
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]

Reply via email to