Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit 776dc77

Browse files
author
Joshua T Corbin
committed
WIP
1 parent 5a8e085 commit 776dc77

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

service-proxy.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,8 @@ ServiceDispatchHandler.prototype.ensurePeerConnected =
700700
function ensurePeerConnected(serviceName, peer, reason, now) {
701701
var self = this;
702702

703-
if (self.partialAffinityEnabled) {
704-
addIndexEntry(self.connectedServicePeers, serviceName, peer.hostPort, now);
705-
addIndexEntry(self.connectedPeerServices, peer.hostPort, serviceName, now);
706-
}
703+
addIndexEntry(self.connectedServicePeers, serviceName, peer.hostPort, now);
704+
addIndexEntry(self.connectedPeerServices, peer.hostPort, serviceName, now);
707705
delete self.peersToPrune[peer.hostPort];
708706

709707
if (peer.isConnected('out') && !peer.draining) {
@@ -837,7 +835,7 @@ function addNewPartialPeer(serviceChannel, hostPort, now) {
837835
serviceChannel, serviceName, hostPort,
838836
'advertise', now);
839837

840-
if (result && result.noop) {
838+
if (!result || result.noop) {
841839
// if ensurePartialConnections did no work, we need to freshen the
842840
// secondary indices since neither ensurePeerConnected nor
843841
// ensurePeerDisconnected were called for the advertising peer
@@ -943,8 +941,10 @@ function ensurePartialConnections(serviceChannel, serviceName, hostPort, reason,
943941
reason: reason,
944942
causingWorker: hostPort,
945943
numToConnect: result.toConnect.length,
946-
numToDisconnect: result.toDisconnect.length
947-
}))
944+
numToDisconnect: result.toDisconnect.length,
945+
DEBUGToConnect: result.toConnect,
946+
DEBUGToDisconnect: result.toDisconnect
947+
})
948948
);
949949
result.implement();
950950
}
@@ -955,10 +955,8 @@ ServiceDispatchHandler.prototype.ensurePeerDisconnected =
955955
function ensurePeerDisconnected(serviceName, peer, reason, now) {
956956
var self = this;
957957

958-
if (self.partialAffinityEnabled) {
959-
deleteIndexEntry(self.connectedServicePeers, serviceName, peer.hostPort);
960-
deleteIndexEntry(self.connectedPeerServices, peer.hostPort, serviceName);
961-
}
958+
deleteIndexEntry(self.connectedServicePeers, serviceName, peer.hostPort);
959+
deleteIndexEntry(self.connectedPeerServices, peer.hostPort, serviceName);
962960

963961
var peerServices = self.connectedPeerServices[peer.hostPort];
964962
if (!peerServices || isObjectEmpty(peerServices)) {
@@ -984,26 +982,22 @@ function removeServicePeer(serviceName, hostPort) {
984982
if (!peer) {
985983
return;
986984
}
987-
serviceChannel.peers.delete(hostPort);
988985

989986
if (self.partialAffinityEnabled) {
990987
var partialRange = self.partialRanges[serviceName];
991988
if (partialRange) {
992989
partialRange.removeWorker(hostPort, now);
993990
}
994-
995-
var result = self.ensurePartialConnections(
991+
self.ensurePartialConnections(
996992
serviceChannel, serviceName, hostPort,
997993
'unadvertise', now);
998-
if (result && result.noop) {
999-
// if ensurePartialConnections did no work, we need to celar the
1000-
// secondary indices since neither ensurePeerDisconnected was called
1001-
// for the unadvertising peer
1002-
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
1003-
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
1004-
}
1005994
}
1006995

996+
serviceChannel.peers.delete(hostPort);
997+
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
998+
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
999+
deleteIndexEntry(self.knownPeers, hostPort, serviceName); // XXX missing before
1000+
10071001
var subChanKeys = Object.keys(self.channel.subChannels);
10081002
var remain = [];
10091003
for (var i = 0; i < subChanKeys; i++) {
@@ -1012,6 +1006,7 @@ function removeServicePeer(serviceName, hostPort) {
10121006
remain.push(subChanKeys[i]);
10131007
}
10141008
}
1009+
// TODO: remaiv vs connectedPeerServices
10151010

10161011
if (remain.length) {
10171012
self.logger.info(
@@ -1068,7 +1063,13 @@ function removeServicePeer(serviceName, hostPort) {
10681063
serviceName: serviceName
10691064
})
10701065
);
1066+
1067+
// TODO: why double delete
10711068
self.channel.peers.delete(hostPort);
1069+
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
1070+
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
1071+
deleteIndexEntry(self.knownPeers, hostPort, serviceName);
1072+
10721073
}
10731074
};
10741075

@@ -1419,10 +1420,8 @@ function reapSinglePeer(hostPort, serviceNames, now) {
14191420
serviceChannel.peers.delete(hostPort);
14201421
}
14211422

1422-
if (self.partialAffinityEnabled) {
1423-
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
1424-
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
1425-
}
1423+
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
1424+
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
14261425
deleteIndexEntry(self.knownPeers, hostPort, serviceName);
14271426

14281427
var partialRange = self.partialRanges[serviceName];
@@ -1459,7 +1458,13 @@ function reapSinglePeer(hostPort, serviceNames, now) {
14591458
)
14601459
);
14611460
}
1461+
1462+
// TODO: why double delete
14621463
self.channel.peers.delete(hostPort);
1464+
deleteIndexEntry(self.connectedServicePeers, serviceName, hostPort);
1465+
deleteIndexEntry(self.connectedPeerServices, hostPort, serviceName);
1466+
deleteIndexEntry(self.knownPeers, hostPort, serviceName);
1467+
14631468
}
14641469
};
14651470

0 commit comments

Comments
 (0)