mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-18 14:57:47 +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:
parent
e225c236e1
commit
29829b5dca
@ -110,6 +110,7 @@ func Get(id string) *Repo {
|
|||||||
|
|
||||||
if originRepoID.Valid {
|
if originRepoID.Valid {
|
||||||
repo.VirtualInfo = new(VRepoInfo)
|
repo.VirtualInfo = new(VRepoInfo)
|
||||||
|
repo.VirtualInfo.RepoID = id
|
||||||
repo.VirtualInfo.OriginRepoID = originRepoID.String
|
repo.VirtualInfo.OriginRepoID = originRepoID.String
|
||||||
repo.StoreID = originRepoID.String
|
repo.StoreID = originRepoID.String
|
||||||
|
|
||||||
@ -234,6 +235,7 @@ func GetEx(id string) *Repo {
|
|||||||
}
|
}
|
||||||
if originRepoID.Valid {
|
if originRepoID.Valid {
|
||||||
repo.VirtualInfo = new(VRepoInfo)
|
repo.VirtualInfo = new(VRepoInfo)
|
||||||
|
repo.VirtualInfo.RepoID = id
|
||||||
repo.VirtualInfo.OriginRepoID = originRepoID.String
|
repo.VirtualInfo.OriginRepoID = originRepoID.String
|
||||||
repo.StoreID = originRepoID.String
|
repo.StoreID = originRepoID.String
|
||||||
|
|
||||||
@ -323,7 +325,7 @@ func GetVirtualRepoInfoByOrigin(originRepo string) ([]*VRepoInfo, error) {
|
|||||||
defer row.Close()
|
defer row.Close()
|
||||||
for row.Next() {
|
for row.Next() {
|
||||||
vRepoInfo := new(VRepoInfo)
|
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 {
|
if err != sql.ErrNoRows {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ typedef struct {
|
|||||||
SeafDBTrans *trans;
|
SeafDBTrans *trans;
|
||||||
gint64 keep_alive_last_time;
|
gint64 keep_alive_last_time;
|
||||||
gint64 keep_alive_obj_counter;
|
gint64 keep_alive_obj_counter;
|
||||||
|
|
||||||
|
gboolean traverse_base_commit;
|
||||||
} GCData;
|
} GCData;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -166,6 +168,12 @@ fs_callback (SeafFSManager *mgr,
|
|||||||
|
|
||||||
add_fs_to_index(data, obj_id);
|
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 &&
|
if (type == SEAF_METADATA_TYPE_FILE &&
|
||||||
add_blocks_to_index (mgr, data, obj_id) < 0)
|
add_blocks_to_index (mgr, data, obj_id) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -422,12 +430,14 @@ populate_gc_index_for_repo (GCData *data, SeafDBTrans *trans)
|
|||||||
if (!vinfo) {
|
if (!vinfo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
data->traverse_base_commit = TRUE;
|
||||||
res = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
|
res = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr,
|
||||||
repo->store_id, repo->version,
|
repo->store_id, repo->version,
|
||||||
vinfo->base_commit,
|
vinfo->base_commit,
|
||||||
traverse_commit,
|
traverse_commit,
|
||||||
data,
|
data,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
data->traverse_base_commit = FALSE;
|
||||||
seaf_virtual_repo_info_free (vinfo);
|
seaf_virtual_repo_info_free (vinfo);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
seaf_warning ("Failed to traverse base commit %s for virtual repo %s.\n", vinfo->base_commit, repo_id);
|
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) {
|
for (ptr = del_repos; ptr; ptr = ptr->next) {
|
||||||
repo_id = ptr->data;
|
repo_id = ptr->data;
|
||||||
|
if (!is_uuid_valid(repo_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Confirm repo doesn't exist before removing blocks. */
|
/* Confirm repo doesn't exist before removing blocks. */
|
||||||
if (!seaf_repo_manager_repo_exists (seaf->repo_mgr, repo_id)) {
|
if (!seaf_repo_manager_repo_exists (seaf->repo_mgr, repo_id)) {
|
||||||
|
@ -7,6 +7,7 @@ typedef struct VerifyData {
|
|||||||
gint64 truncate_time;
|
gint64 truncate_time;
|
||||||
gboolean traversed_head;
|
gboolean traversed_head;
|
||||||
GHashTable *exist_blocks;
|
GHashTable *exist_blocks;
|
||||||
|
gboolean traverse_base_commit;
|
||||||
} VerifyData;
|
} VerifyData;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -47,6 +48,10 @@ fs_callback (SeafFSManager *mgr,
|
|||||||
{
|
{
|
||||||
VerifyData *data = user_data;
|
VerifyData *data = user_data;
|
||||||
|
|
||||||
|
if (data->traverse_base_commit) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == SEAF_METADATA_TYPE_FILE && check_blocks (data, obj_id) < 0)
|
if (type == SEAF_METADATA_TYPE_FILE && check_blocks (data, obj_id) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -100,6 +105,8 @@ verify_virtual_repos (VerifyData *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data->traverse_base_commit = TRUE;
|
||||||
|
|
||||||
GList *vrepo_ids = NULL, *ptr;
|
GList *vrepo_ids = NULL, *ptr;
|
||||||
char *repo_id;
|
char *repo_id;
|
||||||
SeafVirtRepo *vinfo;
|
SeafVirtRepo *vinfo;
|
||||||
@ -128,6 +135,7 @@ verify_virtual_repos (VerifyData *data)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data->traverse_base_commit = FALSE;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
string_list_free (vrepo_ids);
|
string_list_free (vrepo_ids);
|
||||||
|
Loading…
Reference in New Issue
Block a user