From 29829b5dcadae9b5f3bbe765f1d828b342cf1d8a Mon Sep 17 00:00:00 2001 From: feiniks <36756310+feiniks@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:51:59 +0800 Subject: [PATCH] Check if repo_id is valid and set repo_id to VRepoInfo (#733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check if repo_id is valid and set repo_id to VRepoInfo * Don't retain when traverse base commit * Skip check blocks when verify base commit --------- Co-authored-by: 杨赫然 --- fileserver/repomgr/repomgr.go | 4 +++- server/gc/gc-core.c | 13 +++++++++++++ server/gc/verify.c | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fileserver/repomgr/repomgr.go b/fileserver/repomgr/repomgr.go index 1d5fd2ba..4c8878e3 100644 --- a/fileserver/repomgr/repomgr.go +++ b/fileserver/repomgr/repomgr.go @@ -110,6 +110,7 @@ func Get(id string) *Repo { if originRepoID.Valid { repo.VirtualInfo = new(VRepoInfo) + repo.VirtualInfo.RepoID = id repo.VirtualInfo.OriginRepoID = originRepoID.String repo.StoreID = originRepoID.String @@ -234,6 +235,7 @@ func GetEx(id string) *Repo { } if originRepoID.Valid { repo.VirtualInfo = new(VRepoInfo) + repo.VirtualInfo.RepoID = id repo.VirtualInfo.OriginRepoID = originRepoID.String repo.StoreID = originRepoID.String @@ -323,7 +325,7 @@ func GetVirtualRepoInfoByOrigin(originRepo string) ([]*VRepoInfo, error) { defer row.Close() for row.Next() { vRepoInfo := new(VRepoInfo) - if err := row.Scan(&vRepoInfo.OriginRepoID, &vRepoInfo.Path, &vRepoInfo.BaseCommitID); err != nil { + if err := row.Scan(&vRepoInfo.RepoID, &vRepoInfo.OriginRepoID, &vRepoInfo.Path, &vRepoInfo.BaseCommitID); err != nil { if err != sql.ErrNoRows { return nil, err } diff --git a/server/gc/gc-core.c b/server/gc/gc-core.c index 0a4fbef2..897c86a4 100644 --- a/server/gc/gc-core.c +++ b/server/gc/gc-core.c @@ -95,6 +95,8 @@ typedef struct { SeafDBTrans *trans; gint64 keep_alive_last_time; gint64 keep_alive_obj_counter; + + gboolean traverse_base_commit; } GCData; static int @@ -166,6 +168,12 @@ fs_callback (SeafFSManager *mgr, add_fs_to_index(data, obj_id); + // If traversing the base_commit, only the fs objects need to be retained, while the block does not. + // This is because only the fs objects are needed when merging virtual repo. + if (data->traverse_base_commit) { + return TRUE; + } + if (type == SEAF_METADATA_TYPE_FILE && add_blocks_to_index (mgr, data, obj_id) < 0) return FALSE; @@ -422,12 +430,14 @@ populate_gc_index_for_repo (GCData *data, SeafDBTrans *trans) if (!vinfo) { continue; } + data->traverse_base_commit = TRUE; res = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, repo->store_id, repo->version, vinfo->base_commit, traverse_commit, data, FALSE); + data->traverse_base_commit = FALSE; seaf_virtual_repo_info_free (vinfo); if (!res) { seaf_warning ("Failed to traverse base commit %s for virtual repo %s.\n", vinfo->base_commit, repo_id); @@ -1002,6 +1012,9 @@ delete_garbaged_repos (int dry_run, int thread_num) for (ptr = del_repos; ptr; ptr = ptr->next) { repo_id = ptr->data; + if (!is_uuid_valid(repo_id)) { + continue; + } /* Confirm repo doesn't exist before removing blocks. */ if (!seaf_repo_manager_repo_exists (seaf->repo_mgr, repo_id)) { diff --git a/server/gc/verify.c b/server/gc/verify.c index 9347557b..67bf9219 100644 --- a/server/gc/verify.c +++ b/server/gc/verify.c @@ -7,6 +7,7 @@ typedef struct VerifyData { gint64 truncate_time; gboolean traversed_head; GHashTable *exist_blocks; + gboolean traverse_base_commit; } VerifyData; static int @@ -47,6 +48,10 @@ fs_callback (SeafFSManager *mgr, { VerifyData *data = user_data; + if (data->traverse_base_commit) { + return TRUE; + } + if (type == SEAF_METADATA_TYPE_FILE && check_blocks (data, obj_id) < 0) return FALSE; @@ -100,6 +105,8 @@ verify_virtual_repos (VerifyData *data) return 0; } + data->traverse_base_commit = TRUE; + GList *vrepo_ids = NULL, *ptr; char *repo_id; SeafVirtRepo *vinfo; @@ -128,6 +135,7 @@ verify_virtual_repos (VerifyData *data) goto out; } } + data->traverse_base_commit = FALSE; out: string_list_free (vrepo_ids);