Rotate srch files as log trees items are reclaimed

The log merging work deletes log trees items once their item roots are
merged back into the fs root.  Those deleted items could still have
populated srch files that would be lost.  We force rotation of the srch
files in the items as they're reclaimed to turn them into rotated srch
files that can be compacted.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2021-06-16 15:52:08 -07:00
parent 5c3fdb48af
commit 28759f3269
3 changed files with 16 additions and 5 deletions

View File

@@ -823,7 +823,7 @@ static int server_commit_log_trees(struct super_block *sb,
/* try to rotate the srch log when big enough */
mutex_lock(&server->srch_mutex);
ret = scoutfs_srch_rotate_log(sb, &server->alloc, &server->wri,
&super->srch_root, &lt.srch_file);
&super->srch_root, &lt.srch_file, false);
mutex_unlock(&server->srch_mutex);
if (ret < 0) {
scoutfs_err(sb, "server error, rotating srch log: %d", ret);
@@ -922,6 +922,16 @@ static int reclaim_open_log_tree(struct super_block *sb, u64 rid)
goto out;
}
/* for srch log file rotation if it's populated */
mutex_lock(&server->srch_mutex);
ret = scoutfs_srch_rotate_log(sb, &server->alloc, &server->wri,
&super->srch_root, &lt.srch_file, true);
mutex_unlock(&server->srch_mutex);
if (ret < 0) {
scoutfs_err(sb, "server error, reclaim rotating srch log: %d", ret);
goto out;
}
/*
* All of these can return errors after having modified the
* allocator trees. We have to try and update the roots in the
@@ -944,7 +954,7 @@ static int reclaim_open_log_tree(struct super_block *sb, u64 rid)
err = scoutfs_btree_update(sb, &server->alloc, &server->wri,
&super->logs_root, &key, &lt, sizeof(lt));
BUG_ON(err != 0); /* alloc and log item roots out of sync */
BUG_ON(err != 0); /* alloc, log, srch items out of sync */
out:
mutex_unlock(&server->logs_mutex);

View File

@@ -989,12 +989,13 @@ int scoutfs_srch_rotate_log(struct super_block *sb,
struct scoutfs_alloc *alloc,
struct scoutfs_block_writer *wri,
struct scoutfs_btree_root *root,
struct scoutfs_srch_file *sfl)
struct scoutfs_srch_file *sfl, bool force)
{
struct scoutfs_key key;
int ret;
if (le64_to_cpu(sfl->blocks) < SCOUTFS_SRCH_LOG_BLOCK_LIMIT)
if (sfl->ref.blkno == 0 ||
(!force && le64_to_cpu(sfl->blocks) < SCOUTFS_SRCH_LOG_BLOCK_LIMIT))
return 0;
init_srch_key(&key, SCOUTFS_SRCH_LOG_TYPE,

View File

@@ -37,7 +37,7 @@ int scoutfs_srch_rotate_log(struct super_block *sb,
struct scoutfs_alloc *alloc,
struct scoutfs_block_writer *wri,
struct scoutfs_btree_root *root,
struct scoutfs_srch_file *sfl);
struct scoutfs_srch_file *sfl, bool force);
int scoutfs_srch_get_compact(struct super_block *sb,
struct scoutfs_alloc *alloc,
struct scoutfs_block_writer *wri,