[tarantool-patches] [PATCH v3 01/11] recovery: clean up WAL dir scan code

  • From: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
  • To: kostja@xxxxxxxxxxxxx
  • Date: Sat, 14 Jul 2018 23:49:16 +0300

 - Remove extra scan of the WAL directory from local_recovery() - we
   scan the directory in recovery_end_vclock() hence we can skip scan in
   recover_remaining_wals() by passing scan_dir = false.

 - Rename recovery_end_vclock() to recovery_scan() to emphasize the fact
   that this function scans the WAL directory. Write a comment to this
   function.

 - Add comments to wal.c explaining why we scan the WAL directory there.

Follow-up 0695fbbb96aa ("box: retrieve end vclock before starting local
recovery").
---
 src/box/box.cc      | 4 ++--
 src/box/recovery.cc | 2 +-
 src/box/recovery.h  | 7 ++++++-
 src/box/wal.c       | 9 +++++++++
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index e15d121f..7fc15f33 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1819,7 +1819,7 @@ local_recovery(const struct tt_uuid *instance_uuid,
         * so we must reflect this in replicaset vclock to
         * not attempt to apply these rows twice.
         */
-       recovery_end_vclock(recovery, &replicaset.vclock);
+       recovery_scan(recovery, &replicaset.vclock);
 
        if (wal_dir_lock >= 0) {
                box_listen();
@@ -1855,7 +1855,7 @@ local_recovery(const struct tt_uuid *instance_uuid,
        memtx_engine_recover_snapshot_xc(memtx, checkpoint_vclock);
 
        engine_begin_final_recovery_xc();
-       recover_remaining_wals(recovery, &wal_stream.base, NULL, true);
+       recover_remaining_wals(recovery, &wal_stream.base, NULL, false);
        /*
         * Leave hot standby mode, if any, only after
         * acquiring the lock.
diff --git a/src/box/recovery.cc b/src/box/recovery.cc
index 7267b345..fe14defe 100644
--- a/src/box/recovery.cc
+++ b/src/box/recovery.cc
@@ -117,7 +117,7 @@ recovery_new(const char *wal_dirname, bool force_recovery,
 }
 
 void
-recovery_end_vclock(struct recovery *r, struct vclock *end_vclock)
+recovery_scan(struct recovery *r, struct vclock *end_vclock)
 {
        xdir_scan_xc(&r->wal_dir);
 
diff --git a/src/box/recovery.h b/src/box/recovery.h
index 1ae6f2c3..5882d969 100644
--- a/src/box/recovery.h
+++ b/src/box/recovery.h
@@ -68,8 +68,13 @@ recovery_new(const char *wal_dirname, bool force_recovery,
 void
 recovery_delete(struct recovery *r);
 
+/**
+ * Scan the WAL directory, build an index of all found
+ * WAL files, then scan the most recent WAL file to find
+ * the vclock of the last record (returned in @end_vclock).
+ */
 void
-recovery_end_vclock(struct recovery *r, struct vclock *end_vclock);
+recovery_scan(struct recovery *r, struct vclock *end_vclock);
 
 void
 recovery_follow_local(struct recovery *r, struct xstream *stream,
diff --git a/src/box/wal.c b/src/box/wal.c
index 19c9138e..41762a59 100644
--- a/src/box/wal.c
+++ b/src/box/wal.c
@@ -400,6 +400,11 @@ wal_init(enum wal_mode wal_mode, const char *wal_dirname,
        wal_writer_create(writer, wal_mode, wal_dirname, instance_uuid,
                          vclock, wal_max_rows, wal_max_size);
 
+       /*
+        * Scan the WAL directory to build an index of all
+        * existing WAL files. Required for garbage collection,
+        * see wal_collect_garbage().
+        */
        if (xdir_scan(&writer->wal_dir))
                return -1;
 
@@ -589,6 +594,10 @@ wal_opt_rotate(struct wal_writer *writer)
                free(vclock);
                return -1;
        }
+       /*
+        * Keep track of the new WAL vclock. Required for garbage
+        * collection, see wal_collect_garbage().
+        */
        xdir_add_vclock(&writer->wal_dir, vclock);
 
        wal_notify_watchers(writer, WAL_EVENT_ROTATE);
-- 
2.11.0


Other related posts: