Skip to content

Commit

Permalink
Replace StateNetworkInfo metadata atomically
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Tinker <[email protected]>
  • Loading branch information
tinker-michaelj committed Feb 19, 2025
1 parent f523b13 commit f5538bc
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,7 +56,14 @@ public class StateNetworkInfo implements NetworkInfo {
*/
private final Roster activeRoster;

private final Map<Long, NodeInfo> nodeInfos;
/**
* Non-final because we need {@code handleTransaction} to be able to swap in an
* updated map atomically, without giving a pre-handle thread a temporary view of
* an empty map. (Note that {@code handleTransaction}'s updates will only change
* <i>metadata</i> of nodes, but not the set of nodes itself; so pre-handle threads
* can use any version of the map to test for address book membership.)
*/
private Map<Long, NodeInfo> nodeInfos;

/**
* Constructs a new network information provider from the given state, roster, selfID, and configuration provider.
Expand Down Expand Up @@ -113,8 +120,7 @@ public boolean containsNode(final long nodeId) {

@Override
public void updateFrom(@NonNull final State state) {
nodeInfos.clear();
nodeInfos.putAll(nodeInfosFrom(state));
nodeInfos = nodeInfosFrom(state);
}

/**
Expand Down

0 comments on commit f5538bc

Please sign in to comment.