This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 774
define the interface of seed #1286
Merged
lowzj
merged 1 commit into
dragonflyoss:master
from
antsystem:feat/define-seed-interface
Apr 22, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package seed | ||
|
||
import "time" | ||
|
||
// Manager is an interface which manages the seeds. | ||
type Manager interface { | ||
// Register a seed. | ||
Register(key string, info BaseInfo) (Seed, error) | ||
|
||
// UnRegister seed by key. | ||
UnRegister(key string) error | ||
|
||
// RefreshExpireTime refreshes expire time of seed. | ||
RefreshExpireTime(key string, expireTimeDur time.Duration) error | ||
|
||
// NotifyExpired get the expired chan of seed, it will be notified if seed expired. | ||
NotifyExpired(key string) (<-chan struct{}, error) | ||
|
||
// Prefetch will add seed to the prefetch list, and then prefetch by the concurrent limit. | ||
Prefetch(key string, perDownloadSize int64) (<-chan struct{}, error) | ||
|
||
// GetPrefetchResult should be called after notify by prefetch chan. | ||
GetPrefetchResult(key string) (PreFetchResult, error) | ||
|
||
// SetPrefetchLimit limits the concurrency of prefetching seed. | ||
// Default is defaultDownloadConcurrency. | ||
SetConcurrentLimit(limit int) (validLimit int) | ||
|
||
// Get gets the seed by key. | ||
Get(key string) (Seed, error) | ||
|
||
// List lists the seeds. | ||
List() ([]Seed, error) | ||
|
||
// Stop stops the SeedManager. | ||
Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package seed | ||
|
||
import "io" | ||
|
||
// Seed describes the seed file which represents the resource file defined by taskUrl. | ||
type Seed interface { | ||
// Prefetch will start to download seed file to local cache. | ||
Prefetch(perDownloadSize int64) (<-chan struct{}, error) | ||
|
||
// GetPrefetchResult should be called after notify by prefetch chan. | ||
GetPrefetchResult() (PreFetchResult, error) | ||
|
||
// Delete will delete the local cache and release the resource. | ||
Delete() error | ||
|
||
// Download providers the range download, if local cache of seed do not include the range, | ||
// it will download the range data from rss and reply to request. | ||
Download(off int64, size int64) (io.ReadCloser, error) | ||
|
||
// stop the internal loop and release execution resource. | ||
Stop() | ||
|
||
// GetFullSize gets the full size of seed file. | ||
GetFullSize() int64 | ||
|
||
// GetStatus gets the status of seed file. | ||
GetStatus() string | ||
|
||
// GetURL gets the url of seed file. | ||
GetURL() string | ||
|
||
// GetHeaders gets the headers of seed file. | ||
GetHeaders() map[string][]string | ||
|
||
// GetHeaders gets the taskID of seed file. | ||
GetTaskID() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package seed | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// BaseInfo describes the base info of seed. | ||
type BaseInfo struct { | ||
// the url of seed file. | ||
URL string | ||
|
||
// the taskID of seed file. | ||
TaskID string | ||
|
||
// the header of seed file. | ||
Header map[string][]string | ||
|
||
// URL may contains some changeful query parameters such as authentication parameters. Dragonfly will | ||
// filter these parameter via 'filter'. The usage of it is that different URL may generate the same | ||
// download url. | ||
Filters []string | ||
|
||
// the full length of seed file. | ||
FullLength int64 | ||
|
||
// Seed will download data from rss which is divided by blocks. | ||
// And block size is defined by BlockOrder. It should be limited [10, 31]. | ||
BlockOrder uint32 | ||
wangforthinker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// expire time duration of seed file. | ||
ExpireTimeDur time.Duration | ||
wangforthinker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// PreFetchResult shows the result of prefetch. | ||
type PreFetchResult struct { | ||
Success bool | ||
Err error | ||
// if canceled, caller need not to do other. | ||
Canceled bool | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the meaning of
perDownloadSize
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when a seed prefetch,
perDownloadSize
is the maximum size of concurrent downloading for a seed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add taskID in BaseInfo.