diff --git a/supernode/daemon/mgr/cdn/path_util.go b/supernode/daemon/mgr/cdn/path_util.go index c9f5def0b..ab850e7db 100644 --- a/supernode/daemon/mgr/cdn/path_util.go +++ b/supernode/daemon/mgr/cdn/path_util.go @@ -25,14 +25,9 @@ import ( "github.com/dragonflyoss/Dragonfly/supernode/store" ) -var getDownloadKeyFunc = getDownloadKey -var getMetaDataKeyFunc = getMetaDataKey -var getMd5DataKeyFunc = getMd5DataKey -var getUploadKeyFunc = getUploadKey var getDownloadRawFunc = getDownloadRaw var getMetaDataRawFunc = getMetaDataRaw var getMd5DataRawFunc = getMd5DataRaw -var getUploadRawFunc = getUploadRaw func getDownloadKey(taskID string) string { return path.Join(cutil.SubString(taskID, 0, 3), taskID) diff --git a/supernode/daemon/mgr/cdn/super_writer_test.go b/supernode/daemon/mgr/cdn/super_writer_test.go index 77fa40c3a..3d8edf2f5 100644 --- a/supernode/daemon/mgr/cdn/super_writer_test.go +++ b/supernode/daemon/mgr/cdn/super_writer_test.go @@ -29,14 +29,12 @@ import ( "github.com/dragonflyoss/Dragonfly/supernode/store" "github.com/go-check/check" - "github.com/prashantv/gostub" ) type SuperWriterTestSuite struct { - workHome string - config string - writer *superWriter - downloadPathStub *gostub.Stubs + workHome string + config string + writer *superWriter } func init() { @@ -49,13 +47,9 @@ func (s *SuperWriterTestSuite) SetUpSuite(c *check.C) { fileStore, err := store.NewStore(store.LocalStorageDriver, store.NewLocalStorage, s.config) c.Check(err, check.IsNil) s.writer = newSuperWriter(fileStore, nil) - - s.downloadPathStub = gostub.Stub(&getDownloadKeyFunc, getDownloadKeyFuncMock) } func (s *SuperWriterTestSuite) TearDownSuite(c *check.C) { - s.downloadPathStub.Reset() - if s.workHome != "" { if err := os.RemoveAll(s.workHome); err != nil { fmt.Printf("remove path: %s error", s.workHome) @@ -107,12 +101,8 @@ func (s *SuperWriterTestSuite) TestWriteToFile(c *check.C) { func checkFileSize(cdnStore *store.Store, taskID string, expectedSize int64, c *check.C) { storageInfo, err := cdnStore.Stat(context.TODO(), &store.Raw{ Bucket: config.DownloadHome, - Key: getDownloadKeyFuncMock(taskID), + Key: getDownloadKey(taskID), }) c.Check(err, check.IsNil) c.Check(storageInfo.Size, check.Equals, expectedSize) } - -func getDownloadKeyFuncMock(taskID string) string { - return taskID -} diff --git a/supernode/daemon/mgr/cdn/super_writer_util.go b/supernode/daemon/mgr/cdn/super_writer_util.go index 337163576..204b1bd5e 100644 --- a/supernode/daemon/mgr/cdn/super_writer_util.go +++ b/supernode/daemon/mgr/cdn/super_writer_util.go @@ -103,7 +103,7 @@ func (cw *superWriter) writeToFile(ctx context.Context, bytesBuffer *bytes.Buffe // write to the storage return cw.cdnStore.Put(ctx, &store.Raw{ Bucket: config.DownloadHome, - Key: getDownloadKeyFunc(taskID), + Key: getDownloadKey(taskID), Offset: int64(pieceNum) * int64(PieceSize), }, resultBuf) } diff --git a/supernode/daemon/mgr/cdn_mgr.go b/supernode/daemon/mgr/cdn_mgr.go index deff23ea0..6e385e34d 100644 --- a/supernode/daemon/mgr/cdn_mgr.go +++ b/supernode/daemon/mgr/cdn_mgr.go @@ -10,10 +10,13 @@ import ( // operates on the underlying files stored on the local disk, etc. type CDNMgr interface { // TriggerCDN will trigger CDN to download the file from sourceUrl. - // In common, it will including the following steps: + // It will including the following steps: // 1). download the source file - // 2). update the taskInfo - // 3). write the file to disk + // 2). write the file to disk + // + // In fact, it's a very time consuming operation. + // So if not necessary, it should usually be executed concurrently. + // In addition, it's not thread-safe. TriggerCDN(ctx context.Context, taskInfo *types.TaskInfo) (*types.TaskInfo, error) // GetStatus get the status of the file.