returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */
| 465 | |
| 466 | /* returns 0 if no more work needs to be been done, and 1 if time is up and more work is needed. */ |
| 467 | long 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 | |
| 510 | typedef struct { |
| 511 | zset *zs; |
no test coverage detected