]> git.hungrycats.org Git - bees/commitdiff
context: don't forget to retry locked extents
authorZygo Blaxell <bees@furryterror.org>
Thu, 22 Dec 2022 05:07:49 +0000 (00:07 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 23 Dec 2022 04:46:36 +0000 (23:46 -0500)
The caller of scan_forward has to stop advancing the BeesFileCrawl
position when an extent lock blocks a scan, so that it will resume
from the same position when the Task is scheduled again; otherwise,
bees simply skips over the extent and leave it incompletely deduped.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-context.cc
src/bees-roots.cc
src/bees.h

index 796bfc64b98bcd643bc26db58f8f8ac8d7b7d3fb..ae2075a331ece3a290aec3f68bcd4676db818c8c 100644 (file)
@@ -678,7 +678,7 @@ BeesContext::get_inode_mutex(const uint64_t inode)
        return m_inode_locks(inode);
 }
 
-void
+bool
 BeesContext::scan_forward(const BeesFileRange &bfr_in)
 {
        BEESTRACE("scan_forward " << bfr_in);
@@ -689,7 +689,7 @@ BeesContext::scan_forward(const BeesFileRange &bfr_in)
        // Silently filter out blacklisted files
        if (is_blacklisted(bfr_in.fid())) {
                BEESCOUNT(scan_blacklisted);
-               return;
+               return false;
        }
 
        // Reconstitute FD
@@ -703,14 +703,14 @@ BeesContext::scan_forward(const BeesFileRange &bfr_in)
        if (!bfr.fd()) {
                // BEESLOGINFO("No FD in " << root_path() << " for " << bfr);
                BEESCOUNT(scan_no_fd);
-               return;
+               return false;
        }
 
        // Sanity check
        if (bfr.begin() >= bfr.file_size()) {
                BEESLOGWARN("past EOF: " << bfr);
                BEESCOUNT(scan_eof);
-               return;
+               return false;
        }
 
        BtrfsExtentWalker ew(bfr.fd(), bfr.begin(), root_fd());
@@ -729,7 +729,6 @@ BeesContext::scan_forward(const BeesFileRange &bfr_in)
                                        // BEESLOGDEBUG("Deferring extent bytenr " << to_hex(extent_bytenr) << " from " << bfr);
                                        BEESCOUNT(scanf_deferred_extent);
                                        start_over = true;
-                                       return;
                                }
                                Timer one_extent_timer;
                                scan_one_extent(bfr, e);
@@ -750,7 +749,7 @@ BeesContext::scan_forward(const BeesFileRange &bfr_in)
        BEESCOUNTADD(scanf_total_ms, scan_timer.age() * 1000);
        BEESCOUNT(scanf_total);
 
-       return;
+       return start_over;
 }
 
 BeesResolveAddrResult::BeesResolveAddrResult()
index 9ed8732c4a62889ded5583a14e0ac09e05163715..a048968c6be442b87066ee6344b4145a0498a4ba 100644 (file)
@@ -626,13 +626,20 @@ BeesFileCrawl::crawl_one_extent()
                                        // It might be corrupted data, the file might have been deleted or truncated,
                                        // or we might hit some other recoverable error.  We'll try again with
                                        // the next extent.
+                                       bool scanned_ok = false;
                                        catch_all([&]() {
                                                BEESNOTE("scan_forward " << bfr);
                                                // BEESLOGDEBUG("scan_forward #" << Task::current_task().id() << " " << bfr);
-                                               m_ctx->scan_forward(bfr);
+                                               scanned_ok = m_ctx->scan_forward(bfr);
                                                // BEESLOGDEBUG("done_forward #" << Task::current_task().id() << " " << bfr);
                                        } );
-                                       m_hold = new_holder;
+                                       if (scanned_ok) {
+                                               m_hold = new_holder;
+                                       } else {
+                                               BEESLOGDEBUG("retrying lock for extent at " << bfr);
+                                               BEESCOUNT(crawl_restart);
+                                               return true;
+                                       }
                                }
                        } else {
                                BEESCOUNT(crawl_hole);
index 55b29258376dcddd41f94470683933f4949fec87..41d881413b326159d45f30cafb47d2b6f740ee7d 100644 (file)
@@ -751,7 +751,7 @@ public:
        Fd home_fd();
        string root_path() const { return m_root_path; }
 
-       void scan_forward(const BeesFileRange &bfr);
+       bool scan_forward(const BeesFileRange &bfr);
 
        bool is_root_ro(uint64_t root);
        BeesRangePair dup_extent(const BeesFileRange &src, const shared_ptr<BeesTempFile> &tmpfile);