returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */
| 442 | |
| 443 | /* returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */ |
| 444 | long scanLaterList(robj *ob, unsigned long *cursor, long long endtime, long long *defragged) { |
| 445 | quicklist *ql = ob->ptr; |
| 446 | quicklistNode *node; |
| 447 | long iterations = 0; |
| 448 | int bookmark_failed = 0; |
| 449 | if (ob->type != OBJ_LIST || ob->encoding != OBJ_ENCODING_QUICKLIST) |
| 450 | return 0; |
| 451 | |
| 452 | if (*cursor == 0) { |
| 453 | /* if cursor is 0, we start new iteration */ |
| 454 | node = ql->head; |
| 455 | } else { |
| 456 | node = quicklistBookmarkFind(ql, "_AD"); |
| 457 | if (!node) { |
| 458 | /* if the bookmark was deleted, it means we reached the end. */ |
| 459 | *cursor = 0; |
| 460 | return 0; |
| 461 | } |
| 462 | node = node->next; |
| 463 | } |
| 464 | |
| 465 | (*cursor)++; |
| 466 | while (node) { |
| 467 | (*defragged) += activeDefragQuickListNode(ql, &node); |
| 468 | server.stat_active_defrag_scanned++; |
| 469 | if (++iterations > 128 && !bookmark_failed) { |
| 470 | if (ustime() > endtime) { |
| 471 | if (!quicklistBookmarkCreate(&ql, "_AD", node)) { |
| 472 | bookmark_failed = 1; |
| 473 | } else { |
| 474 | ob->ptr = ql; /* bookmark creation may have re-allocated the quicklist */ |
| 475 | return 1; |
| 476 | } |
| 477 | } |
| 478 | iterations = 0; |
| 479 | } |
| 480 | node = node->next; |
| 481 | } |
| 482 | quicklistBookmarkDelete(ql, "_AD"); |
| 483 | *cursor = 0; |
| 484 | return bookmark_failed? 1: 0; |
| 485 | } |
| 486 | |
| 487 | typedef struct { |
| 488 | zset *zs; |
no test coverage detected