[PATCH 3/5] xlog: allow to limit number of files deleted by xdir_collect_garbage
Vladimir Davydov
vdavydov.dev at gmail.com
Sun Oct 7 23:27:16 MSK 2018
Add an extra argument to xdir_collect_garbage() that specifies the max
number of files to delete. It will be used to delete old WAL files one
by one when running out of disk space.
Needed for #3397
---
src/box/memtx_engine.c | 2 +-
src/box/vy_log.c | 2 +-
src/box/wal.c | 2 +-
src/box/xlog.c | 13 ++++++++++---
src/box/xlog.h | 8 +++++++-
5 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
index ae1f5a0e..04dc052b 100644
--- a/src/box/memtx_engine.c
+++ b/src/box/memtx_engine.c
@@ -834,7 +834,7 @@ memtx_engine_collect_garbage(struct engine *engine, int64_t lsn)
* That said, we have to abort garbage collection if we
* fail to delete a snap file.
*/
- if (xdir_collect_garbage(&memtx->snap_dir, lsn, true) != 0)
+ if (xdir_collect_garbage(&memtx->snap_dir, lsn, -1, true) < 0)
return -1;
return 0;
diff --git a/src/box/vy_log.c b/src/box/vy_log.c
index fc8ede59..bb454eaa 100644
--- a/src/box/vy_log.c
+++ b/src/box/vy_log.c
@@ -1078,7 +1078,7 @@ vy_log_collect_garbage(int64_t signature)
* it is still needed for backups.
*/
signature = vy_log_prev_checkpoint(signature);
- xdir_collect_garbage(&vy_log.dir, signature, true);
+ xdir_collect_garbage(&vy_log.dir, signature, -1, true);
}
int64_t
diff --git a/src/box/wal.c b/src/box/wal.c
index 91c16fb0..2728318a 100644
--- a/src/box/wal.c
+++ b/src/box/wal.c
@@ -538,7 +538,7 @@ static int
wal_collect_garbage_f(struct cbus_call_msg *data)
{
int64_t lsn = ((struct wal_gc_msg *)data)->lsn;
- xdir_collect_garbage(&wal_writer_singleton.wal_dir, lsn, false);
+ xdir_collect_garbage(&wal_writer_singleton.wal_dir, lsn, -1, false);
return 0;
}
diff --git a/src/box/xlog.c b/src/box/xlog.c
index 292c462c..1a6ead7f 100644
--- a/src/box/xlog.c
+++ b/src/box/xlog.c
@@ -669,10 +669,16 @@ xdir_format_filename(struct xdir *dir, int64_t signature,
}
int
-xdir_collect_garbage(struct xdir *dir, int64_t signature, bool use_coio)
+xdir_collect_garbage(struct xdir *dir, int64_t signature,
+ int max_files, bool use_coio)
{
+ if (max_files <= 0)
+ max_files = INT_MAX;
+
+ int count = 0;
struct vclock *vclock;
- while ((vclock = vclockset_first(&dir->index)) != NULL &&
+ while (count < max_files &&
+ (vclock = vclockset_first(&dir->index)) != NULL &&
vclock_sum(vclock) < signature) {
char *filename = xdir_format_filename(dir, vclock_sum(vclock),
NONE);
@@ -694,8 +700,9 @@ xdir_collect_garbage(struct xdir *dir, int64_t signature, bool use_coio)
say_info("removed %s", filename);
vclockset_remove(&dir->index, vclock);
free(vclock);
+ count++;
}
- return 0;
+ return count;
}
void
diff --git a/src/box/xlog.h b/src/box/xlog.h
index f9243935..2233c022 100644
--- a/src/box/xlog.h
+++ b/src/box/xlog.h
@@ -180,10 +180,16 @@ xdir_format_filename(struct xdir *dir, int64_t signature,
/**
* Remove files whose signature is less than specified.
+ * If @max_files > 0, stop after deleting @max_files files.
* If @use_coio is set, files are deleted by coio threads.
+ *
+ * On success, this function returns the number of deleted
+ * files. If it failed to delete a file, it returns -1 and
+ * sets diag.
*/
int
-xdir_collect_garbage(struct xdir *dir, int64_t signature, bool use_coio);
+xdir_collect_garbage(struct xdir *dir, int64_t signature,
+ int max_files, bool use_coio);
/**
* Remove inprogress files in the specified directory.
--
2.11.0
More information about the Tarantool-patches
mailing list