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

Function trackingBroadcastInvalidationMessages

src/tracking.cpp:546–592  ·  view source on GitHub ↗

This function will run the prefixes of clients in BCAST mode and * keys that were modified about each prefix, and will send the * notifications to each client in each prefix. */

Source from the content-addressed store, hash-verified

544 * keys that were modified about each prefix, and will send the
545 * notifications to each client in each prefix. */
546void trackingBroadcastInvalidationMessages(void) {
547 raxIterator ri, ri2;
548
549 /* Return ASAP if there is nothing to do here. */
550 if (TrackingTable == NULL || !g_pserver->tracking_clients) return;
551
552 raxStart(&ri,PrefixTable);
553 raxSeek(&ri,"^",NULL,0);
554
555 /* For each prefix... */
556 while(raxNext(&ri)) {
557 bcastState *bs = (bcastState*)ri.data;
558
559 if (raxSize(bs->keys)) {
560 /* Generate the common protocol for all the clients that are
561 * not using the NOLOOP option. */
562 sds proto = trackingBuildBroadcastReply(NULL,bs->keys);
563
564 /* Send this array of keys to every client in the list. */
565 raxStart(&ri2,bs->clients);
566 raxSeek(&ri2,"^",NULL,0);
567 while(raxNext(&ri2)) {
568 client *c;
569 memcpy(&c,ri2.key,sizeof(c));
570 if (c->flags & CLIENT_TRACKING_NOLOOP) {
571 /* This client may have certain keys excluded. */
572 sds adhoc = trackingBuildBroadcastReply(c,bs->keys);
573 if (adhoc) {
574 sendTrackingMessage(c,adhoc,sdslen(adhoc),1);
575 sdsfree(adhoc);
576 }
577 } else {
578 sendTrackingMessage(c,proto,sdslen(proto),1);
579 }
580 }
581 raxStop(&ri2);
582
583 /* Clean up: we can remove everything from this state, because we
584 * want to only track the new keys that will be accumulated starting
585 * from now. */
586 sdsfree(proto);
587 }
588 raxFree(bs->keys);
589 bs->keys = raxNew();
590 }
591 raxStop(&ri);
592}
593
594/* This is just used in order to access the amount of used slots in the
595 * tracking table. */

Callers 1

beforeSleepFunction · 0.85

Calls 11

raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
raxSizeFunction · 0.85
sendTrackingMessageFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
raxStopFunction · 0.85
raxFreeFunction · 0.85
raxNewFunction · 0.85

Tested by

no test coverage detected