[PATCH] vinyl: remove runs not referenced by any checkpoint immediately

Vladimir Davydov vdavydov.dev at gmail.com
Thu May 17 19:35:53 MSK 2018


On Thu, May 17, 2018 at 07:09:52PM +0300, Vladimir Davydov wrote:
> If a compacted run was created after the last checkpoint, it is not
> needed to recover from any checkpoint and hence can be deleted right
> away to save disk space.
> 
> Closes #3407
> ---
> https://github.com/tarantool/tarantool/issues/3407
> https://github.com/tarantool/tarantool/commits/gh-3407-vy-remove-unreferenced-runs-immediately
> 
>  src/box/vy_scheduler.c | 27 +++++++++--------
>  test/vinyl/gc.result   | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  test/vinyl/gc.test.lua | 35 ++++++++++++++++++++++
>  3 files changed, 126 insertions(+), 14 deletions(-)
> 
> diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c
> index e1853e5d..4c9103cf 100644
> --- a/src/box/vy_scheduler.c
> +++ b/src/box/vy_scheduler.c
> @@ -1139,22 +1139,21 @@ vy_task_compact_complete(struct vy_scheduler *scheduler, struct vy_task *task)
>  		return -1;
>  	}
>  
> -	if (gc_lsn < 0) {
> -		/*
> -		 * If there is no last snapshot, i.e. we are in
> -		 * the middle of join, we can delete compacted
> -		 * run files right away.
> -		 */
> -		vy_log_tx_begin();
> -		rlist_foreach_entry(run, &unused_runs, in_unused) {
> -			if (vy_run_remove_files(index->env->path,
> -						index->space_id, index->id,
> -						run->id) == 0) {
> -				vy_log_forget_run(run->id);
> -			}
> +	/*
> +	 * Remove compacted run files that were created after
> +	 * the last checkpoint (and hence are not referenced
> +	 * by any checkpoint) immediately to save disk space.
> +	 */
> +	vy_log_tx_begin();
> +	rlist_foreach_entry(run, &unused_runs, in_unused) {
> +		if (run->dump_lsn > gc_lsn &&
> +		    vy_run_remove_files(index->env->path,
> +					index->space_id, index->id,
> +					run->id) == 0) {
> +			vy_log_forget_run(run->id);
>  		}
> -		vy_log_tx_try_commit();
>  	}
> +	vy_log_tx_try_commit();
>  
>  	/*
>  	 * Account the new run if it is not empty,

Oops, this patch breaks vinyl/errinj_gc test, which doesn't expect
compaction to remove any files if ERRINJ_VY_GC is set. Fixed on the
branch. Here's the incremental diff:

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 55a68104..552d42ba 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -3389,10 +3389,6 @@ vy_gc_cb(const struct vy_log_record *record, void *cb_arg)
 		goto out;
 	}
 
-	ERROR_INJECT(ERRINJ_VY_GC,
-		     {say_error("error injection: vinyl run %lld not deleted",
-				(long long)record->run_id); goto out;});
-
 	/* Try to delete files. */
 	if (vy_run_remove_files(arg->env->path, arg->space_id,
 				arg->index_id, record->run_id) != 0)
diff --git a/src/box/vy_run.c b/src/box/vy_run.c
index edae5270..980bc4d2 100644
--- a/src/box/vy_run.c
+++ b/src/box/vy_run.c
@@ -2434,6 +2434,9 @@ int
 vy_run_remove_files(const char *dir, uint32_t space_id,
 		    uint32_t iid, int64_t run_id)
 {
+	ERROR_INJECT(ERRINJ_VY_GC,
+		     {say_error("error injection: vinyl run %lld not deleted",
+				(long long)run_id); return -1;});
 	int ret = 0;
 	char path[PATH_MAX];
 	for (int type = 0; type < vy_file_MAX; type++) {



More information about the Tarantool-patches mailing list