MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterSendMessage

Function clusterSendMessage

src/cluster.cpp:2447–2466  ·  view source on GitHub ↗

Put stuff into the send buffer. * * It is guaranteed that this function will never have as a side effect * the link to be invalidated, so it is safe to call this function * from event handlers that will do stuff with the same link later. */

Source from the content-addressed store, hash-verified

2445 * the link to be invalidated, so it is safe to call this function
2446 * from event handlers that will do stuff with the same link later. */
2447void clusterSendMessage(clusterLink *link, unsigned char *msg, size_t msglen) {
2448 serverAssert(GlobalLocksAcquired());
2449 if (sdslen(link->sndbuf) == 0 && msglen != 0)
2450 {
2451 aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [link] {
2452 /* The connection could be timed out before this posted function executes (thanks to TCP keepalive).
2453 * So check that the connection is still there before setting the write handler, otherwise you segfault */
2454 if (link->conn != nullptr)
2455 connSetWriteHandlerWithBarrier(link->conn, clusterWriteHandler, 1);
2456 });
2457 }
2458
2459 link->sndbuf = sdscatlen(link->sndbuf, msg, msglen);
2460
2461 /* Populate sent messages stats. */
2462 clusterMsg *hdr = (clusterMsg*) msg;
2463 uint16_t type = ntohs(hdr->type);
2464 if (type < CLUSTERMSG_TYPE_COUNT)
2465 g_pserver->cluster->stats_bus_messages_sent[type]++;
2466}
2467
2468/* Send a message to all the nodes that are part of the cluster having
2469 * a connected link.

Callers 7

clusterBroadcastMessageFunction · 0.85
clusterSendPingFunction · 0.85
clusterSendPublishFunction · 0.85
clusterSendUpdateFunction · 0.85
clusterSendModuleFunction · 0.85
clusterSendFailoverAuthFunction · 0.85
clusterSendMFStartFunction · 0.85

Calls 5

GlobalLocksAcquiredFunction · 0.85
sdslenFunction · 0.85
aePostFunctionFunction · 0.85
sdscatlenFunction · 0.85

Tested by

no test coverage detected