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

chore: update UnknownSourceFileLen #888

Merged
merged 1 commit into from
Dec 7, 2021
Merged
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
4 changes: 2 additions & 2 deletions cdn/supervisor/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ func (tm *Manager) AddOrUpdate(registerTask *types.SeedTask) (seedTask *types.Se
synclock.UnLock(registerTask.TaskID, true)
return nil, errors.Wrapf(errTaskIDConflict, "register task %#v is conflict with exist task %#v", registerTask, seedTask)
}
if seedTask.SourceFileLength != source.UnKnownSourceFileLen {
if seedTask.SourceFileLength != source.UnknownSourceFileLen {
synclock.UnLock(registerTask.TaskID, true)
return seedTask, nil
}
synclock.UnLock(registerTask.TaskID, true)
synclock.Lock(registerTask.TaskID, false)
defer synclock.UnLock(registerTask.TaskID, false)
if seedTask.SourceFileLength != source.UnKnownSourceFileLen {
if seedTask.SourceFileLength != source.UnknownSourceFileLen {
return seedTask, nil
}
// get sourceContentLength with req.Header
Expand Down
2 changes: 1 addition & 1 deletion cdn/types/seed_task_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewSeedTask(taskID string, rawURL string, urlMeta *base.UrlMeta) *SeedTask
RequestDigest: urlMeta.Digest,
URL: rawURL,
TaskURL: urlutils.FilterURLParam(rawURL, strings.Split(urlMeta.Filter, "&")),
SourceFileLength: source.UnKnownSourceFileLen,
SourceFileLength: source.UnknownSourceFileLen,
CdnFileLength: 0,
PieceSize: 0,
Range: urlMeta.Range,
Expand Down
4 changes: 2 additions & 2 deletions client/daemon/peer/piece_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (pm *pieceManager) DownloadSource(ctx context.Context, pt Task, request *sc
if err != nil {
log.Warnf("get content length error: %s for %s", err, request.Url)
}
if contentLength == -1 {
if contentLength < 0 {
log.Warnf("can not get content length for %s", request.Url)
} else {
err = pm.storageManager.UpdateTask(ctx,
Expand Down Expand Up @@ -391,7 +391,7 @@ func (pm *pieceManager) DownloadSource(ctx context.Context, pt Task, request *sc
// 2. save to storage
pieceSize := pm.computePieceSize(contentLength)
// handle resource which content length is unknown
if contentLength == -1 {
if contentLength < 0 {
var n int64
for pieceNum := int32(0); ; pieceNum++ {
size := pieceSize
Expand Down
4 changes: 2 additions & 2 deletions pkg/source/hdfsprotocol/hdfs_source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ type HDFSSourceClientOption func(p *hdfsSourceClient)
func (h *hdfsSourceClient) GetContentLength(request *source.Request) (int64, error) {
hdfsClient, path, err := h.getHDFSClientAndPath(request.URL)
if err != nil {
return source.UnKnownSourceFileLen, err
return source.UnknownSourceFileLen, err
}
info, err := hdfsClient.Stat(path)
if err != nil {
return source.UnKnownSourceFileLen, err
return source.UnknownSourceFileLen, err
}
return info.Size(), nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/source/hdfsprotocol/hdfs_source_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const (

const (
hdfsNotExistFileURL = "hdfs://127.0.0.1:9000/user/root/input/f3.txt"
hdfsNotExistFileContentLength int64 = source.UnKnownSourceFileLen
hdfsNotExistFileContentLength int64 = source.UnknownSourceFileLen
)

var fakeHDFSClient = &hdfs.Client{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/source/httpprotocol/http_source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ func WithHTTPClient(client *http.Client) HTTPSourceClientOption {
func (client *httpSourceClient) GetContentLength(request *source.Request) (int64, error) {
resp, err := client.doRequest(http.MethodGet, request)
if err != nil {
return source.UnKnownSourceFileLen, err
return source.UnknownSourceFileLen, err
}
defer resp.Body.Close()
err = source.CheckResponseCode(resp.StatusCode, []int{http.StatusOK, http.StatusPartialContent})
if err != nil {
return source.UnKnownSourceFileLen, err
return source.UnknownSourceFileLen, err
}
return resp.ContentLength, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/source/ossprotocol/oss_source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ type ossSourceClient struct {
func (osc *ossSourceClient) GetContentLength(request *source.Request) (int64, error) {
client, err := osc.getClient(request.Header)
if err != nil {
return source.UnKnownSourceFileLen, err
return source.UnknownSourceFileLen, err
}
bucket, err := client.Bucket(request.URL.Host)
if err != nil {
return source.UnKnownSourceFileLen, errors.Wrapf(err, "get oss bucket: %s", request.URL.Host)
return source.UnknownSourceFileLen, errors.Wrapf(err, "get oss bucket: %s", request.URL.Host)
}
header, err := bucket.GetObjectMeta(request.URL.Path, getOptions(request.Header)...)
if err != nil {
return source.UnKnownSourceFileLen, errors.Wrapf(err, "get oss object %s meta", request.URL.Path)
return source.UnknownSourceFileLen, errors.Wrapf(err, "get oss object %s meta", request.URL.Path)
}
contentLen, err := strconv.ParseInt(header.Get(oss.HTTPHeaderContentLength), 10, 64)
if err != nil {
return source.UnKnownSourceFileLen, errors.Wrapf(err, "parse content-length str to int64")
return source.UnknownSourceFileLen, errors.Wrapf(err, "parse content-length str to int64")
}
return contentLen, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/source/source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func IsNoClientFoundError(err error) bool {
}

const (
UnKnownSourceFileLen = -2
UnknownSourceFileLen = -2
)

// ResourceClient defines the API interface to interact with source.
type ResourceClient interface {

// GetContentLength get length of resource content
// return source.UnKnownSourceFileLen if response status is not StatusOK and StatusPartialContent
// return source.UnknownSourceFileLen if response status is not StatusOK and StatusPartialContent
GetContentLength(request *Request) (int64, error)

// IsSupportRange checks if resource supports breakpoint continuation
Expand Down Expand Up @@ -218,7 +218,7 @@ func (c *clientWrapper) GetLastModified(request *Request) (int64, error) {
func GetContentLength(request *Request) (int64, error) {
client, ok := _defaultManager.GetClient(request.URL.Scheme)
if !ok {
return UnKnownSourceFileLen, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
return UnknownSourceFileLen, errors.Wrapf(ErrNoClientFound, "scheme: %s", request.URL.Scheme)
}
if _, ok := request.Context().Deadline(); !ok {
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
Expand Down