Helper function for handleClientsBlockedOnKeys(). This function is called * when there may be clients blocked on a sorted set key, and there may be new * data to fetch (the key is ready). */
| 348 | * when there may be clients blocked on a sorted set key, and there may be new |
| 349 | * data to fetch (the key is ready). */ |
| 350 | void serveClientsBlockedOnSortedSetKey(robj *o, readyList *rl) { |
| 351 | /* We serve clients in the same order they blocked for |
| 352 | * this key, from the first blocked to the last. */ |
| 353 | dictEntry *de = dictFind(rl->db->blocking_keys,rl->key); |
| 354 | if (de) { |
| 355 | list *clients = (list*)dictGetVal(de); |
| 356 | int numclients = listLength(clients); |
| 357 | unsigned long zcard = zsetLength(o); |
| 358 | |
| 359 | while(numclients-- && zcard) { |
| 360 | listNode *clientnode = listFirst(clients); |
| 361 | client *receiver = (client*)clientnode->value; |
| 362 | std::unique_lock<decltype(receiver->lock)> lock(receiver->lock); |
| 363 | |
| 364 | if (receiver->btype != BLOCKED_ZSET) { |
| 365 | /* Put at the tail, so that at the next call |
| 366 | * we'll not run into it again. */ |
| 367 | listRotateHeadToTail(clients); |
| 368 | continue; |
| 369 | } |
| 370 | |
| 371 | int where = (receiver->lastcmd && |
| 372 | receiver->lastcmd->proc == bzpopminCommand) |
| 373 | ? ZSET_MIN : ZSET_MAX; |
| 374 | monotime replyTimer; |
| 375 | elapsedStart(&replyTimer); |
| 376 | genericZpopCommand(receiver,&rl->key,1,where,1,NULL); |
| 377 | updateStatsOnUnblock(receiver, 0, elapsedUs(replyTimer)); |
| 378 | unblockClient(receiver); |
| 379 | zcard--; |
| 380 | |
| 381 | /* Replicate the command. */ |
| 382 | robj *argv[2]; |
| 383 | struct redisCommand *cmd = where == ZSET_MIN ? |
| 384 | cserver.zpopminCommand : |
| 385 | cserver.zpopmaxCommand; |
| 386 | argv[0] = createStringObject(cmd->name,strlen(cmd->name)); |
| 387 | argv[1] = rl->key; |
| 388 | incrRefCount(rl->key); |
| 389 | propagate(cmd,receiver->db->id, |
| 390 | argv,2,PROPAGATE_AOF|PROPAGATE_REPL); |
| 391 | decrRefCount(argv[0]); |
| 392 | decrRefCount(argv[1]); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /* Helper function for handleClientsBlockedOnKeys(). This function is called |
| 398 | * when there may be clients blocked on a stream key, and there may be new |
no test coverage detected