Repository: dragonflyoss/Dragonfly2
Pull request #535 (2021-08-12 02:43:51)

Method update to unanimous
<!--- Provide a general summary of your changes in the Title above -->

## Description


## Related Issue

Issue: https://github.com/dragonflyoss/Dragonfly2/issues/532


## Motivation and Context



## Screenshots (if appropriate):

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Documentation Update (if none of the other choices apply)

## Checklist:

- [x] Code compiles correctly.
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.


codecov-commenter: # [Codecov](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss) Report
> Merging [#535](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss) (081ea95) into [main](https://codecov.io/gh/dragonflyoss/Dragonfly2/commit/c1c3d652933a6fb48ab66ff1f37fbf89cee44291?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss) (c1c3d65) will **decrease** coverage by `0.15%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/graphs/tree.svg?width=650&height=150&src=pr&token=PUICJYSAT7&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss)](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss)

```diff
@@            Coverage Diff             @@
##             main     #535      +/-   ##
==========================================
- Coverage   39.47%   39.31%   -0.16%     
==========================================
  Files          86       86              
  Lines        6529     6529              
==========================================
- Hits         2577     2567      -10     
- Misses       3581     3592      +11     
+ Partials      371      370       -1     
```

| Flag | Coverage Δ | |
|---|---|---|
| e2etests | `?` | |
| unittests | `39.31% <0.00%> (-0.16%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss) | Coverage Δ | |
|---|---|---|
| [cdnsystem/storedriver/driver.go](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#diff-Y2Ruc3lzdGVtL3N0b3JlZHJpdmVyL2RyaXZlci5nbw==) | `16.66% <0.00%> (ø)` | |
| [cdnsystem/storedriver/local/local\_driver.go](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#diff-Y2Ruc3lzdGVtL3N0b3JlZHJpdmVyL2xvY2FsL2xvY2FsX2RyaXZlci5nbw==) | `51.89% <ø> (ø)` | |
| [cdnsystem/storedriver/mock\_driver.go](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#diff-Y2Ruc3lzdGVtL3N0b3JlZHJpdmVyL21vY2tfZHJpdmVyLmdv) | `0.00% <0.00%> (ø)` | |
| [client/daemon/peer/peertask\_stream.go](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#diff-Y2xpZW50L2RhZW1vbi9wZWVyL3BlZXJ0YXNrX3N0cmVhbS5nbw==) | `55.05% <0.00%> (-2.44%)` | :arrow_down: |
| [client/daemon/peer/peertask\_base.go](https://codecov.io/gh/dragonflyoss/Dragonfly2/pull/535/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dragonflyoss#diff-Y2xpZW50L2RhZW1vbi9wZWVyL3BlZXJ0YXNrX2Jhc2UuZ28=) | `34.33% <0.00%> (-0.65%)` | :arrow_down: |


Patch:
diff --git a/cdnsystem/daemon/cdn/storage/storage_gc.go b/cdnsystem/daemon/cdn/storage/storage_gc.go
index 63dab5bf..06999009 100644
--- a/cdnsystem/daemon/cdn/storage/storage_gc.go
+++ b/cdnsystem/daemon/cdn/storage/storage_gc.go
@@ -48,16 +48,19 @@ func NewStorageCleaner(cfg *GCConfig, driver storedriver.Driver, storageMgr Mana
 }
 
 func (cleaner *Cleaner) GC(storagePattern string, force bool) ([]string, error) {
-	freeSpace, err := cleaner.driver.GetAvailSpace()
+	freeSpace, err := cleaner.driver.GetFreeSpace()
 	if err != nil {
 		if cdnerrors.IsFileNotExist(err) {
 			err = cleaner.driver.CreateBaseDir()
 			if err != nil {
 				return nil, err
 			}
-			freeSpace, _ = cleaner.driver.GetAvailSpace()
+			freeSpace, err = cleaner.driver.GetFreeSpace()
+			if err != nil {
+				return nil, fmt.Errorf("get free space: %v", err)
+			}
 		} else {
-			return nil, fmt.Errorf("get available space: %v", err)
+			return nil, fmt.Errorf("get free space: %v", err)
 		}
 	}
 	fullGC := force
diff --git a/cdnsystem/storedriver/driver.go b/cdnsystem/storedriver/driver.go
index 0b2ad7dc..f0f15a13 100644
--- a/cdnsystem/storedriver/driver.go
+++ b/cdnsystem/storedriver/driver.go
@@ -67,8 +67,8 @@ type Driver interface {
 	// If not, return the ErrFileNotExist.
 	Stat(raw *Raw) (*StorageInfo, error)
 
-	// GetAvailSpace returns the available disk space in B.
-	GetAvailSpace() (unit.Bytes, error)
+	// GetFreeSpace returns the available disk space in B.
+	GetFreeSpace() (unit.Bytes, error)
 
 	// GetTotalAndFreeSpace
 	GetTotalAndFreeSpace() (unit.Bytes, unit.Bytes, error)
@@ -253,9 +253,9 @@ func (s *driverPlugin) MoveFile(src string, dst string) error {
 	return s.instance.MoveFile(src, dst)
 }
 
-// GetAvailSpace returns the available disk space in B.
-func (s *driverPlugin) GetAvailSpace() (unit.Bytes, error) {
-	return s.instance.GetAvailSpace()
+// GetFreeSpace returns the available disk space in B.
+func (s *driverPlugin) GetFreeSpace() (unit.Bytes, error) {
+	return s.instance.GetFreeSpace()
 }
 
 func (s *driverPlugin) GetHomePath() string {
diff --git a/cdnsystem/storedriver/local/local_driver.go b/cdnsystem/storedriver/local/local_driver.go
index ea65930e..57815dce 100644
--- a/cdnsystem/storedriver/local/local_driver.go
+++ b/cdnsystem/storedriver/local/local_driver.go
@@ -316,8 +316,8 @@ func (ds *driver) Remove(raw *storedriver.Raw) error {
 	return err
 }
 
-// GetAvailSpace returns the available disk space in Byte.
-func (ds *driver) GetAvailSpace() (unit.Bytes, error) {
+// GetFreeSpace returns the available disk space in Byte.
+func (ds *driver) GetFreeSpace() (unit.Bytes, error) {
 	path := ds.BaseDir
 	lock(path, -1, true)
 	defer unLock(path, -1, true)
diff --git a/cdnsystem/storedriver/mock_driver.go b/cdnsystem/storedriver/mock_driver.go
index 435f3386..5c1a9a4c 100644
--- a/cdnsystem/storedriver/mock_driver.go
+++ b/cdnsystem/storedriver/mock_driver.go
@@ -78,19 +78,19 @@ func (mr *MockDriverMockRecorder) Get(arg0 interface{}) *gomock.Call {
 	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockDriver)(nil).Get), arg0)
 }
 
-// GetAvailSpace mocks base method.
-func (m *MockDriver) GetAvailSpace() (unit.Bytes, error) {
+// GetFreeSpace mocks base method.
+func (m *MockDriver) GetFreeSpace() (unit.Bytes, error) {
 	m.ctrl.T.Helper()
-	ret := m.ctrl.Call(m, "GetAvailSpace")
+	ret := m.ctrl.Call(m, "GetFreeSpace")
 	ret0, _ := ret[0].(unit.Bytes)
 	ret1, _ := ret[1].(error)
 	return ret0, ret1
 }
 
-// GetAvailSpace indicates an expected call of GetAvailSpace.
-func (mr *MockDriverMockRecorder) GetAvailSpace() *gomock.Call {
+// GetFreeSpace indicates an expected call of GetFreeSpace.
+func (mr *MockDriverMockRecorder) GetFreeSpace() *gomock.Call {
 	mr.mock.ctrl.T.Helper()
-	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAvailSpace", reflect.TypeOf((*MockDriver)(nil).GetAvailSpace))
+	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFreeSpace", reflect.TypeOf((*MockDriver)(nil).GetFreeSpace))
 }
 
 // GetBytes mocks base method.
diff --git a/docs/zh-CN/design/architecture.md b/docs/zh-CN/design/architecture.md
index 2034c8da..dea090f0 100644
--- a/docs/zh-CN/design/architecture.md
+++ b/docs/zh-CN/design/architecture.md
@@ -40,6 +40,12 @@
 
 ![alt][download-process]
 
+### 子模块架构
+
+#### CDN模块
+
+![cdn](../images/cdn.png)
+
 ### 子系统功能
 
 **Manager**


Test patch:
diff --git a/cdnsystem/storedriver/store_mgr_test.go b/cdnsystem/storedriver/store_mgr_test.go
index f37eacce..59bf0ffa 100644
--- a/cdnsystem/storedriver/store_mgr_test.go
+++ b/cdnsystem/storedriver/store_mgr_test.go
@@ -60,7 +60,7 @@ func (m mockDriver) Stat(_ *Raw) (*StorageInfo, error) {
 	panic("implement me")
 }
 
-func (m mockDriver) GetAvailSpace() (unit.Bytes, error) {
+func (m mockDriver) GetFreeSpace() (unit.Bytes, error) {
 	panic("implement me")
 }