Skip to content

Commit 903e76c

Browse files
authored
Merge pull request dragonflyoss#616 from Starnop/md5-file-format
feature: store piece md5s with native bytes
2 parents d4fca35 + 06903ba commit 903e76c

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

supernode/daemon/mgr/cdn/file_meta_data.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cdn
33
import (
44
"context"
55
"encoding/json"
6+
"strings"
67

78
"github.com/dragonflyoss/Dragonfly/apis/types"
89
cutil "github.com/dragonflyoss/Dragonfly/common/util"
@@ -168,12 +169,9 @@ func (mm *fileMetaDataManager) writePieceMD5s(ctx context.Context, taskID, fileM
168169
// append the the SHA-1 checksum of pieceMD5s
169170
pieceMD5s = append(pieceMD5s, cutil.Sha1(pieceMD5s))
170171

171-
data, err := json.Marshal(pieceMD5s)
172-
if err != nil {
173-
return err
174-
}
172+
pieceMD5Str := strings.Join(pieceMD5s, "\n")
175173

176-
return mm.fileStore.PutBytes(ctx, getMd5DataRawFunc(taskID), data)
174+
return mm.fileStore.PutBytes(ctx, getMd5DataRawFunc(taskID), []byte(pieceMD5Str))
177175
}
178176

179177
// readPieceMD5s read the md5 file of the taskID and returns the pieceMD5s.
@@ -185,9 +183,7 @@ func (mm *fileMetaDataManager) readPieceMD5s(ctx context.Context, taskID, fileMD
185183
if err != nil {
186184
return nil, err
187185
}
188-
if err := json.Unmarshal(bytes, &pieceMD5s); err != nil {
189-
return nil, err
190-
}
186+
pieceMD5s = strings.Split(string(bytes), "\n")
191187

192188
if cutil.IsEmptySlice(pieceMD5s) {
193189
return nil, nil

supernode/daemon/mgr/cdn/file_meta_data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (s *CDNFileMetaDataTestSuite) TestWriteReadFileMetaData(c *check.C) {
130130

131131
func (s *CDNFileMetaDataTestSuite) TestWriteReadPieceMD5s(c *check.C) {
132132
ctx := context.TODO()
133-
pieceMD5s := []string{"91fe186ee566659663232dcd18749cce:1502"}
133+
pieceMD5s := []string{"91fe186ee566659663232dcd18749cce:1502", "11fe186ee566659663232dcd18749cce:1502"}
134134
fileMD5 := "7a19c32d2c75345debe9031cfa9b649a"
135135

136136
err := s.metaDataManager.writePieceMD5s(ctx, taskID, fileMD5, pieceMD5s)

0 commit comments

Comments
 (0)