1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-04-27 19:15:07 +00:00

Check if repo_id is valid and set repo_id to VRepoInfo (#733)

* 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: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks 2025-01-13 17:51:59 +08:00 committed by GitHub
parent e225c236e1
commit 29829b5dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View File

@ -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
}

View File

@ -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)) {

View File

@ -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);