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. */
| 544 | * keys that were modified about each prefix, and will send the |
| 545 | * notifications to each client in each prefix. */ |
| 546 | void 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. */ |
no test coverage detected