Skip to content

Commit

Permalink
Check if repo_id is valid and set repo_id to VRepoInfo (#733)
Browse files Browse the repository at this point in the history
* 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: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Jan 13, 2025
1 parent e225c23 commit 29829b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fileserver/repomgr/repomgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions server/gc/gc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 8 additions & 0 deletions server/gc/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef struct VerifyData {
gint64 truncate_time;
gboolean traversed_head;
GHashTable *exist_blocks;
gboolean traverse_base_commit;
} VerifyData;

static int
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -128,6 +135,7 @@ verify_virtual_repos (VerifyData *data)
goto out;
}
}
data->traverse_base_commit = FALSE;

out:
string_list_free (vrepo_ids);
Expand Down

0 comments on commit 29829b5

Please sign in to comment.