MCPcopy Create free account
hub / github.com/F-Stack/f-stack / streamIteratorGetID

Function streamIteratorGetID

app/redis-6.2.6/src/t_stream.c:1092–1230  ·  view source on GitHub ↗

Return 1 and store the current item ID at 'id' if there are still * elements within the iteration range, otherwise return 0 in order to * signal the iteration terminated. */

Source from the content-addressed store, hash-verified

1090 * elements within the iteration range, otherwise return 0 in order to
1091 * signal the iteration terminated. */
1092int streamIteratorGetID(streamIterator *si, streamID *id, int64_t *numfields) {
1093 while(1) { /* Will stop when element > stop_key or end of radix tree. */
1094 /* If the current listpack is set to NULL, this is the start of the
1095 * iteration or the previous listpack was completely iterated.
1096 * Go to the next node. */
1097 if (si->lp == NULL || si->lp_ele == NULL) {
1098 if (!si->rev && !raxNext(&si->ri)) return 0;
1099 else if (si->rev && !raxPrev(&si->ri)) return 0;
1100 serverAssert(si->ri.key_len == sizeof(streamID));
1101 /* Get the master ID. */
1102 streamDecodeID(si->ri.key,&si->master_id);
1103 /* Get the master fields count. */
1104 si->lp = si->ri.data;
1105 si->lp_ele = lpFirst(si->lp); /* Seek items count */
1106 si->lp_ele = lpNext(si->lp,si->lp_ele); /* Seek deleted count. */
1107 si->lp_ele = lpNext(si->lp,si->lp_ele); /* Seek num fields. */
1108 si->master_fields_count = lpGetInteger(si->lp_ele);
1109 si->lp_ele = lpNext(si->lp,si->lp_ele); /* Seek first field. */
1110 si->master_fields_start = si->lp_ele;
1111 /* We are now pointing to the first field of the master entry.
1112 * We need to seek either the first or the last entry depending
1113 * on the direction of the iteration. */
1114 if (!si->rev) {
1115 /* If we are iterating in normal order, skip the master fields
1116 * to seek the first actual entry. */
1117 for (uint64_t i = 0; i < si->master_fields_count; i++)
1118 si->lp_ele = lpNext(si->lp,si->lp_ele);
1119 } else {
1120 /* If we are iterating in reverse direction, just seek the
1121 * last part of the last entry in the listpack (that is, the
1122 * fields count). */
1123 si->lp_ele = lpLast(si->lp);
1124 }
1125 } else if (si->rev) {
1126 /* If we are iterating in the reverse order, and this is not
1127 * the first entry emitted for this listpack, then we already
1128 * emitted the current entry, and have to go back to the previous
1129 * one. */
1130 int lp_count = lpGetInteger(si->lp_ele);
1131 while(lp_count--) si->lp_ele = lpPrev(si->lp,si->lp_ele);
1132 /* Seek lp-count of prev entry. */
1133 si->lp_ele = lpPrev(si->lp,si->lp_ele);
1134 }
1135
1136 /* For every radix tree node, iterate the corresponding listpack,
1137 * returning elements when they are within range. */
1138 while(1) {
1139 if (!si->rev) {
1140 /* If we are going forward, skip the previous entry
1141 * lp-count field (or in case of the master entry, the zero
1142 * term field) */
1143 si->lp_ele = lpNext(si->lp,si->lp_ele);
1144 if (si->lp_ele == NULL) break;
1145 } else {
1146 /* If we are going backward, read the number of elements this
1147 * entry is composed of, and jump backward N times to seek
1148 * its start. */
1149 int64_t lp_count = lpGetInteger(si->lp_ele);

Callers 7

rewriteStreamObjectFunction · 0.85
xorObjectDigestFunction · 0.85
RM_StreamIteratorNextIDFunction · 0.85
streamDeleteItemFunction · 0.85
streamLastValidIDFunction · 0.85
streamReplyWithRangeFunction · 0.85
xclaimCommandFunction · 0.85

Calls 8

raxNextFunction · 0.85
raxPrevFunction · 0.85
streamDecodeIDFunction · 0.85
lpFirstFunction · 0.85
lpNextFunction · 0.85
lpLastFunction · 0.85
lpPrevFunction · 0.85
streamEncodeIDFunction · 0.85

Tested by

no test coverage detected