This is an helper function for streamReplyWithRange() when called with * group and consumer arguments, but with a range that is referring to already * delivered messages. In this case we just emit messages that are already * in the history of the consumer, fetching the IDs from its PEL. * * Note that this function does not have a 'rev' argument because it's not * possible to iterate in rever
| 1617 | * to the client. However clients only reach this code path when they are |
| 1618 | * fetching the history of already retrieved messages, which is rare. */ |
| 1619 | size_t streamReplyWithRangeFromConsumerPEL(client *c, stream *s, streamID *start, streamID *end, size_t count, streamConsumer *consumer) { |
| 1620 | raxIterator ri; |
| 1621 | unsigned char startkey[sizeof(streamID)]; |
| 1622 | unsigned char endkey[sizeof(streamID)]; |
| 1623 | streamEncodeID(startkey,start); |
| 1624 | if (end) streamEncodeID(endkey,end); |
| 1625 | |
| 1626 | size_t arraylen = 0; |
| 1627 | void *arraylen_ptr = addReplyDeferredLen(c); |
| 1628 | raxStart(&ri,consumer->pel); |
| 1629 | raxSeek(&ri,">=",startkey,sizeof(startkey)); |
| 1630 | while(raxNext(&ri) && (!count || arraylen < count)) { |
| 1631 | if (end && memcmp(ri.key,end,ri.key_len) > 0) break; |
| 1632 | streamID thisid; |
| 1633 | streamDecodeID(ri.key,&thisid); |
| 1634 | if (streamReplyWithRange(c,s,&thisid,&thisid,1,0,NULL,NULL, |
| 1635 | STREAM_RWR_RAWENTRIES,NULL) == 0) |
| 1636 | { |
| 1637 | /* Note that we may have a not acknowledged entry in the PEL |
| 1638 | * about a message that's no longer here because was removed |
| 1639 | * by the user by other means. In that case we signal it emitting |
| 1640 | * the ID but then a NULL entry for the fields. */ |
| 1641 | addReplyArrayLen(c,2); |
| 1642 | addReplyStreamID(c,&thisid); |
| 1643 | addReplyNullArray(c); |
| 1644 | } else { |
| 1645 | streamNACK *nack = (streamNACK*)ri.data; |
| 1646 | nack->delivery_time = mstime(); |
| 1647 | nack->delivery_count++; |
| 1648 | } |
| 1649 | arraylen++; |
| 1650 | } |
| 1651 | raxStop(&ri); |
| 1652 | setDeferredArrayLen(c,arraylen_ptr,arraylen); |
| 1653 | return arraylen; |
| 1654 | } |
| 1655 | |
| 1656 | /* ----------------------------------------------------------------------- |
| 1657 | * Stream commands implementation |
no test coverage detected