This function will attempt to share the instance link we already have * for the same Sentinel in the context of a different master, with the * instance we are passing as argument. * * This way multiple Sentinel objects that refer all to the same physical * Sentinel instance but in the context of different masters will use * a single connection, will send a single PING per second for failure
| 1136 | * different master and sharing was performed. Otherwise C_ERR |
| 1137 | * is returned. */ |
| 1138 | int sentinelTryConnectionSharing(sentinelRedisInstance *ri) { |
| 1139 | serverAssert(ri->flags & SRI_SENTINEL); |
| 1140 | dictIterator *di; |
| 1141 | dictEntry *de; |
| 1142 | |
| 1143 | if (ri->runid == NULL) return C_ERR; /* No way to identify it. */ |
| 1144 | if (ri->link->refcount > 1) return C_ERR; /* Already shared. */ |
| 1145 | |
| 1146 | di = dictGetIterator(sentinel.masters); |
| 1147 | while((de = dictNext(di)) != NULL) { |
| 1148 | sentinelRedisInstance *master = (sentinelRedisInstance*)dictGetVal(de), *match; |
| 1149 | /* We want to share with the same physical Sentinel referenced |
| 1150 | * in other masters, so skip our master. */ |
| 1151 | if (master == ri->master) continue; |
| 1152 | match = getSentinelRedisInstanceByAddrAndRunID(master->sentinels, |
| 1153 | NULL,0,ri->runid); |
| 1154 | if (match == NULL) continue; /* No match. */ |
| 1155 | if (match == ri) continue; /* Should never happen but... safer. */ |
| 1156 | |
| 1157 | /* We identified a matching Sentinel, great! Let's free our link |
| 1158 | * and use the one of the matching Sentinel. */ |
| 1159 | releaseInstanceLink(ri->link,NULL); |
| 1160 | ri->link = match->link; |
| 1161 | match->link->refcount++; |
| 1162 | dictReleaseIterator(di); |
| 1163 | return C_OK; |
| 1164 | } |
| 1165 | dictReleaseIterator(di); |
| 1166 | return C_ERR; |
| 1167 | } |
| 1168 | |
| 1169 | /* Drop all connections to other sentinels. Returns the number of connections |
| 1170 | * dropped.*/ |
no test coverage detected