Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 409 when gc conflict #731

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -1745,8 +1745,12 @@ func postMultiFiles(rsp http.ResponseWriter, r *http.Request, repoID, parentDir,

retStr, err := postFilesAndGenCommit(fileNames, repo.ID, user, canonPath, replace, ids, sizes, lastModify, gcID)
if err != nil {
err := fmt.Errorf("failed to post files and gen commit: %v", err)
return &appError{err, "", http.StatusInternalServerError}
if errors.Is(err, ErrGCConflict) {
return &appError{nil, "GC Conflict.\n", http.StatusConflict}
} else {
err := fmt.Errorf("failed to post files and gen commit: %v", err)
return &appError{err, "", http.StatusInternalServerError}
}
}

_, ok := r.Form["ret-json"]
Expand Down Expand Up @@ -1848,7 +1852,7 @@ retry:
_, err = genNewCommit(repo, headCommit, rootID, user, buf, handleConncurrentUpdate, lastGCID, true)
if err != nil {
if err != ErrConflict {
err := fmt.Errorf("failed to generate new commit: %v", err)
err := fmt.Errorf("failed to generate new commit: %w", err)
return "", err
}
retryCnt++
Expand Down Expand Up @@ -1907,7 +1911,10 @@ func getCanonPath(p string) string {
return filepath.Join(formatPath)
}

var ErrConflict = fmt.Errorf("Concurent upload conflict")
var (
ErrConflict = errors.New("Concurent upload conflict")
ErrGCConflict = errors.New("GC Conflict")
)

func genNewCommit(repo *repomgr.Repo, base *commitmgr.Commit, newRoot, user, desc string, handleConncurrentUpdate bool, lastGCID string, checkGC bool) (string, error) {
var retryCnt int
Expand Down Expand Up @@ -2094,7 +2101,7 @@ func updateBranch(repoID, originRepoID, newCommitID, oldCommitID, secondParentID
if lastGCID != gcID.String {
err = fmt.Errorf("Head branch update for repo %s conflicts with GC.", repoID)
trans.Rollback()
return true, err
return true, ErrGCConflict
}
}

Expand Down Expand Up @@ -3247,8 +3254,12 @@ func putFile(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user,
desc := fmt.Sprintf("Modified \"%s\"", fileName)
_, err = genNewCommit(repo, headCommit, rootID, user, desc, true, gcID, true)
if err != nil {
err := fmt.Errorf("failed to generate new commit: %v", err)
return &appError{err, "", http.StatusInternalServerError}
if errors.Is(err, ErrGCConflict) {
return &appError{nil, "GC Conflict.\n", http.StatusConflict}
} else {
err := fmt.Errorf("failed to generate new commit: %v", err)
return &appError{err, "", http.StatusInternalServerError}
}
}

if isAjax {
Expand Down Expand Up @@ -3485,8 +3496,12 @@ func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fi
desc := fmt.Sprintf("Added \"%s\"", fileName)
_, err = genNewCommit(repo, headCommit, rootID, user, desc, true, gcID, true)
if err != nil {
err := fmt.Errorf("failed to generate new commit: %v", err)
return "", &appError{err, "", http.StatusInternalServerError}
if errors.Is(err, ErrGCConflict) {
return "", &appError{nil, "GC Conflict.\n", http.StatusConflict}
} else {
err := fmt.Errorf("failed to generate new commit: %v", err)
return "", &appError{err, "", http.StatusInternalServerError}
}
}

return fileID, nil
Expand Down
1 change: 1 addition & 0 deletions include/seafile-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
#define POST_FILE_ERR_QUOTA_FULL 519
#define SEAF_ERR_CONCURRENT_UPLOAD 520
#define SEAF_ERR_FILES_WITH_SAME_NAME 521
#define SEAF_ERR_GC_CONFLICT 522

#endif
2 changes: 1 addition & 1 deletion server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ gen_new_commit (const char *repo_id,
if (check_gc && gc_conflict) {
seaf_warning ("Head branch update for repo %s conflicts with GC.\n",
repo->id);
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "GC Conflict");
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GC_CONFLICT, "GC Conflict");
ret = -1;
goto out;
}
Expand Down
15 changes: 15 additions & 0 deletions server/upload-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ upload_api_cb(evhtp_request_t *req, void *arg)
} else if (error->code == SEAF_ERR_FILES_WITH_SAME_NAME) {
error_code = -1;
send_error_reply (req, EVHTP_RES_BADREQ, "Too many files with same name.\n");
} else if (error->code == SEAF_ERR_GC_CONFLICT) {
error_code = -1;
send_error_reply (req, EVHTP_RES_CONFLICT, "GC Conflict.\n");
}
g_clear_error (&error);
}
Expand Down Expand Up @@ -811,6 +814,9 @@ upload_blks_api_cb(evhtp_request_t *req, void *arg)
error_code = ERROR_BLOCK_MISSING;
} else if (error->code == POST_FILE_ERR_QUOTA_FULL) {
error_code = ERROR_QUOTA;
} else if (error->code == SEAF_ERR_GC_CONFLICT) {
error_code = -1;
send_error_reply (req, EVHTP_RES_CONFLICT, "GC Conflict.\n");
}
g_clear_error (&error);
}
Expand Down Expand Up @@ -1243,6 +1249,9 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
} else if (error->code == SEAF_ERR_FILES_WITH_SAME_NAME) {
error_code = -1;
send_error_reply (req, EVHTP_RES_BADREQ, "Too many files with same name.\n");
} else if (error->code == SEAF_ERR_GC_CONFLICT) {
error_code = -1;
send_error_reply (req, EVHTP_RES_CONFLICT, "GC Conflict.\n");
}
g_clear_error (&error);
}
Expand Down Expand Up @@ -1527,6 +1536,9 @@ update_blks_api_cb(evhtp_request_t *req, void *arg)
error_code = ERROR_NOT_EXIST;
} else if (error->code == POST_FILE_ERR_QUOTA_FULL) {
error_code = ERROR_QUOTA;
} else if (error->code == SEAF_ERR_GC_CONFLICT) {
error_code = -1;
send_error_reply (req, EVHTP_RES_CONFLICT, "GC Conflict.\n");
}
g_clear_error (&error);
}
Expand Down Expand Up @@ -1788,6 +1800,9 @@ update_ajax_cb(evhtp_request_t *req, void *arg)
if (error) {
if (g_strcmp0 (error->message, "file does not exist") == 0) {
error_code = ERROR_NOT_EXIST;
} else if (error->code == SEAF_ERR_GC_CONFLICT) {
error_code = -1;
send_error_reply (req, EVHTP_RES_CONFLICT, "GC Conflict.\n");
}
g_clear_error (&error);
}
Expand Down
Loading