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

Function rdbSaveStreamPEL

src/rdb.cpp:734–773  ·  view source on GitHub ↗

This helper function serializes a consumer group Pending Entries List (PEL) * into the RDB file. The 'nacks' argument tells the function if also persist * the informations about the not acknowledged message, or if to persist * just the IDs: this is useful because for the global consumer group PEL * we serialized the NACKs as well, but when serializing the local consumer * PELs we just add the

Source from the content-addressed store, hash-verified

732 * PELs we just add the ID, that will be resolved inside the global PEL to
733 * put a reference to the same structure. */
734ssize_t rdbSaveStreamPEL(rio *rdb, rax *pel, int nacks) {
735 ssize_t n, nwritten = 0;
736
737 /* Number of entries in the PEL. */
738 if ((n = rdbSaveLen(rdb,raxSize(pel))) == -1) return -1;
739 nwritten += n;
740
741 /* Save each entry. */
742 raxIterator ri;
743 raxStart(&ri,pel);
744 raxSeek(&ri,"^",NULL,0);
745 while(raxNext(&ri)) {
746 /* We store IDs in raw form as 128 big big endian numbers, like
747 * they are inside the radix tree key. */
748 if ((n = rdbWriteRaw(rdb,ri.key,sizeof(streamID))) == -1) {
749 raxStop(&ri);
750 return -1;
751 }
752 nwritten += n;
753
754 if (nacks) {
755 streamNACK *nack = (streamNACK*)ri.data;
756 if ((n = rdbSaveMillisecondTime(rdb,nack->delivery_time)) == -1) {
757 raxStop(&ri);
758 return -1;
759 }
760 nwritten += n;
761 if ((n = rdbSaveLen(rdb,nack->delivery_count)) == -1) {
762 raxStop(&ri);
763 return -1;
764 }
765 nwritten += n;
766 /* We don't save the consumer name: we'll save the pending IDs
767 * for each consumer in the consumer PEL, and resolve the consumer
768 * at loading time. */
769 }
770 }
771 raxStop(&ri);
772 return nwritten;
773}
774
775/* Serialize the consumers of a stream consumer group into the RDB. Helper
776 * function for the stream data type serialization. What we do here is to

Callers 2

rdbSaveStreamConsumersFunction · 0.85
rdbSaveObjectFunction · 0.85

Calls 8

rdbSaveLenFunction · 0.85
raxSizeFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
rdbWriteRawFunction · 0.85
raxStopFunction · 0.85
rdbSaveMillisecondTimeFunction · 0.85

Tested by

no test coverage detected