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

Function rewriteListObject

src/aof.cpp:1092–1132  ·  view source on GitHub ↗

Emit the commands needed to rebuild a list object. * The function returns 0 on error, 1 on success. */

Source from the content-addressed store, hash-verified

1090/* Emit the commands needed to rebuild a list object.
1091 * The function returns 0 on error, 1 on success. */
1092int rewriteListObject(rio *r, robj *key, robj *o) {
1093 long long count = 0, items = listTypeLength(o);
1094
1095 if (o->encoding == OBJ_ENCODING_QUICKLIST) {
1096 quicklist *list = (quicklist*)ptrFromObj(o);
1097 quicklistIter *li = quicklistGetIterator(list, AL_START_HEAD);
1098 quicklistEntry entry;
1099
1100 while (quicklistNext(li,&entry)) {
1101 if (count == 0) {
1102 int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
1103 AOF_REWRITE_ITEMS_PER_CMD : items;
1104 if (!rioWriteBulkCount(r,'*',2+cmd_items) ||
1105 !rioWriteBulkString(r,"RPUSH",5) ||
1106 !rioWriteBulkObject(r,key))
1107 {
1108 quicklistReleaseIterator(li);
1109 return 0;
1110 }
1111 }
1112
1113 if (entry.value) {
1114 if (!rioWriteBulkString(r,(char*)entry.value,entry.sz)) {
1115 quicklistReleaseIterator(li);
1116 return 0;
1117 }
1118 } else {
1119 if (!rioWriteBulkLongLong(r,entry.longval)) {
1120 quicklistReleaseIterator(li);
1121 return 0;
1122 }
1123 }
1124 if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
1125 items--;
1126 }
1127 quicklistReleaseIterator(li);
1128 } else {
1129 serverPanic("Unknown list encoding");
1130 }
1131 return 1;
1132}
1133
1134/* Emit the commands needed to rebuild a set object.
1135 * The function returns 0 on error, 1 on success. */

Callers 1

rewriteAppendOnlyFileRioFunction · 0.85

Calls 9

listTypeLengthFunction · 0.85
ptrFromObjFunction · 0.85
quicklistGetIteratorFunction · 0.85
quicklistNextFunction · 0.85
rioWriteBulkCountFunction · 0.85
rioWriteBulkStringFunction · 0.85
rioWriteBulkObjectFunction · 0.85
quicklistReleaseIteratorFunction · 0.85
rioWriteBulkLongLongFunction · 0.85

Tested by

no test coverage detected