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

Function scanLaterList

src/defrag.cpp:467–508  ·  view source on GitHub ↗

returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */

Source from the content-addressed store, hash-verified

465
466/* returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */
467long scanLaterList(robj *ob, unsigned long *cursor, long long endtime, long long *defragged) {
468 quicklist *ql = (quicklist*)ptrFromObj(ob);
469 quicklistNode *node;
470 long iterations = 0;
471 int bookmark_failed = 0;
472 if (ob->type != OBJ_LIST || ob->encoding != OBJ_ENCODING_QUICKLIST)
473 return 0;
474
475 if (*cursor == 0) {
476 /* if cursor is 0, we start new iteration */
477 node = ql->head;
478 } else {
479 node = quicklistBookmarkFind(ql, "_AD");
480 if (!node) {
481 /* if the bookmark was deleted, it means we reached the end. */
482 *cursor = 0;
483 return 0;
484 }
485 node = node->next;
486 }
487
488 (*cursor)++;
489 while (node) {
490 (*defragged) += activeDefragQuickListNode(ql, &node);
491 g_pserver->stat_active_defrag_scanned++;
492 if (++iterations > 128 && !bookmark_failed) {
493 if (ustime() > endtime) {
494 if (!quicklistBookmarkCreate(&ql, "_AD", node)) {
495 bookmark_failed = 1;
496 } else {
497 ob->m_ptr = ql; /* bookmark creation may have re-allocated the quicklist */
498 return 1;
499 }
500 }
501 iterations = 0;
502 }
503 node = node->next;
504 }
505 quicklistBookmarkDelete(ql, "_AD");
506 *cursor = 0;
507 return bookmark_failed? 1: 0;
508}
509
510typedef struct {
511 zset *zs;

Callers 1

defragLaterItemFunction · 0.85

Calls 6

ptrFromObjFunction · 0.85
quicklistBookmarkFindFunction · 0.85
quicklistBookmarkCreateFunction · 0.85
quicklistBookmarkDeleteFunction · 0.85
ustimeFunction · 0.70

Tested by

no test coverage detected