Skip to content

Commit f559759

Browse files
author
yxq
committed
fix: chunk key when delete
1 parent 898d823 commit f559759

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

system/p2p/dht/protocol/p2pstore/p2pstore.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (p *Protocol) processLocalChunk() {
200200
}
201201
case info := <-p.chunkToDelete:
202202
if localInfo, ok := p.getChunkInfoByHash(info.ChunkHash); ok && time.Since(localInfo.Time) > types2.RefreshInterval*3 {
203-
if err := p.deleteChunkBlock(localInfo.ChunkHash); err != nil {
203+
if err := p.deleteChunkBlock(localInfo.ChunkInfoMsg); err != nil {
204204
log.Error("processLocalChunk", "deleteChunkBlock error", err, "chunkHash", hex.EncodeToString(localInfo.ChunkHash), "start", localInfo.Start)
205205
}
206206
}

system/p2p/dht/protocol/p2pstore/p2pstore_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ func TestInit(t *testing.T) {
119119
require.Equal(t, 223, len(msg.Data.(*types.BlockBodys).Items))
120120

121121
// 删除数据后应该找不到数据
122-
err = p2.deleteChunkBlock([]byte("test0"))
122+
err = p2.deleteChunkBlock(&types.ChunkInfoMsg{
123+
ChunkHash: []byte("test0"),
124+
Start: 0,
125+
End: 999,
126+
})
123127
if err != nil {
124128
t.Fatal(err)
125129
}

system/p2p/dht/protocol/p2pstore/store.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ func (p *Protocol) updateChunk(req *types.ChunkInfoMsg) error {
5353
return types2.ErrNotFound
5454
}
5555

56-
func (p *Protocol) deleteChunkBlock(hash []byte) error {
57-
exist, err := p.deleteLocalChunkInfo(hash)
56+
func (p *Protocol) deleteChunkBlock(msg *types.ChunkInfoMsg) error {
57+
exist, err := p.deleteLocalChunkInfo(msg.ChunkHash)
5858
if err != nil {
5959
return err
6060
}
6161
if !exist {
6262
return nil
6363
}
6464
batch := p.DB.NewBatch(true)
65-
it := p.DB.Iterator(hash, append(hash, ':'+1), false)
65+
it := p.DB.Iterator(genChunkDBKey(msg.Start), genChunkDBKey(msg.End+1), false)
6666
defer it.Close()
6767
for it.Next(); it.Valid(); it.Next() {
6868
batch.Delete(it.Key())

0 commit comments

Comments
 (0)