Server: fix peer sync not quite working with >2 nodes

This commit is contained in:
2025-03-21 12:44:00 +01:00
parent 4bfa93fca4
commit 92bca1e4e1
2 changed files with 13 additions and 2 deletions

View File

@@ -30,12 +30,14 @@ public class PeerInfoService {
@Inject
RemoteTransaction remoteTx;
public static final JObjectKey TREE_KEY = JObjectKey.of("peers");
private JKleppmannTreeManager.JKleppmannTree getTreeW() {
return jKleppmannTreeManager.getTree(JObjectKey.of("peers"));
return jKleppmannTreeManager.getTree(TREE_KEY);
}
private JKleppmannTreeManager.JKleppmannTree getTreeR() {
return jKleppmannTreeManager.getTree(JObjectKey.of("peers"), LockingStrategy.OPTIMISTIC);
return jKleppmannTreeManager.getTree(TREE_KEY, LockingStrategy.OPTIMISTIC);
}
public Optional<PeerInfo> getPeerInfoImpl(JObjectKey key) {

View File

@@ -5,7 +5,9 @@ import com.usatiuk.dhfs.objects.JObjectKey;
import com.usatiuk.dhfs.objects.RemoteObjectDataWrapper;
import com.usatiuk.dhfs.objects.jkleppmanntree.structs.JKleppmannTreeNode;
import com.usatiuk.dhfs.objects.repository.PersistentPeerDataService;
import com.usatiuk.dhfs.objects.repository.invalidation.InvalidationQueueService;
import com.usatiuk.dhfs.objects.repository.peersync.PeerInfo;
import com.usatiuk.dhfs.objects.repository.peersync.PeerInfoService;
import com.usatiuk.dhfs.objects.repository.peersync.structs.JKleppmannTreeNodeMetaPeer;
import com.usatiuk.dhfs.objects.transaction.PreCommitTxHook;
import com.usatiuk.dhfs.objects.transaction.Transaction;
@@ -19,15 +21,21 @@ public class PeerInfoCertUpdateTxHook implements PreCommitTxHook {
Transaction curTx;
@Inject
PersistentPeerDataService persistentPeerDataService;
@Inject
InvalidationQueueService invalidationQueueService;
@Override
public void onChange(JObjectKey key, JData old, JData cur) {
// We also need to force pushing invalidation to all, in case our node acts as a "middleman"
// connecting two other nodes
// TODO: Can there be a prettier way to do this? (e.g. more general proxying of ops?)
if (cur instanceof JKleppmannTreeNode n) {
if (n.key().name().equals("peers_jt_root")) {
// TODO: This is kinda sucky
Log.infov("Changed peer tree root: {0} to {1}", key, cur);
curTx.onCommit(() -> persistentPeerDataService.updateCerts());
curTx.onCommit(() -> invalidationQueueService.pushInvalidationToAll(PeerInfoService.TREE_KEY));
if (!(old instanceof JKleppmannTreeNode oldNode))
throw new IllegalStateException("Old node is not a tree node");
@@ -50,6 +58,7 @@ public class PeerInfoCertUpdateTxHook implements PreCommitTxHook {
Log.infov("Changed peer info: {0} to {1}", key, cur);
curTx.onCommit(() -> invalidationQueueService.pushInvalidationToAll(key));
curTx.onCommit(() -> persistentPeerDataService.updateCerts());
}