-
Notifications
You must be signed in to change notification settings - Fork 773
define cache for seed file in seed pattern #1305
define cache for seed file in seed pattern #1305
Conversation
Thanks for your contribution. 🍻 @wangforthinker |
Codecov Report
@@ Coverage Diff @@
## master #1305 +/- ##
==========================================
+ Coverage 51.20% 51.76% +0.56%
==========================================
Files 124 125 +1
Lines 8152 8365 +213
==========================================
+ Hits 4174 4330 +156
- Misses 3639 3674 +35
- Partials 339 361 +22
Continue to review full report at Codecov.
|
lgtm! |
lgtm |
dfdaemon/seed/cache.go
Outdated
sizeOf64Bits++ | ||
} | ||
|
||
fcb.blockMeta, err = bitmap.NewBitMap(sizeOf64Bits, false) |
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.
It's a little wired to calculate the sizeOf64Bits
. Actually, the sizeOf64Bits
is part of the bitmap's concrete implementation and the caller doesn't care about it when using the bitmap
. Could we just directly provide a constructor with the argument numberOfBits
? WDYT.
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.
done.
|
||
fcb := &fileCacheBuffer{path: path, fw: fw, fullSize: fullSize, memoryCache: memoryCache} | ||
if memoryCache { | ||
fcb.blockOrder = blockOrder |
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.
I remember that the blockOrder
is in range [10,31], should it check 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.
In this object, the range of blockOrder
is not concerned. And for the convenience of unit test, blockOrder
may less than 10.
// Close closes the file writer. | ||
func (fcb *fileCacheBuffer) Close() error { | ||
if err := fcb.Sync(); err != nil { | ||
return err |
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.
Should it close the fw
no matter whether the err
is nil?
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.
In some case, Close() may be called again if first close failed.
off = 0 | ||
} | ||
|
||
// if size <= 0, set range to [off, fullSize-1] |
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.
Is there any consideration about supporting the case of empty files or data? HTTP Range request doesn't support empty files.
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.
In the case, if size <=0, it set range from off to the end of file. Not empty data.
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.
So it means that the empty data is not supported here.
offArr := []int64{} | ||
bufArr := []*bytes.Buffer{} | ||
|
||
fcb.RLock() |
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.
The Lock
operation in this method and syncMemoryCache
cannot prevent concurrency writing problem.
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.
the elem of memCacheMap represents a buffer cache, if buffer cache stores in memCacheMap, its content could not be changed util buffer gc.
So the Lock aims to protect the memCacheMap not the buffer content.
dfdaemon/seed/cache.go
Outdated
} | ||
fcb.RUnlock() | ||
|
||
for i := 0; i < len(offArr); i++ { |
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.
It's better to sort the offArr
in order to merge and write blocks sequentially to improve the performance when the number of blocks is large.
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.
done.
0aac763
to
afa306e
Compare
dfdaemon/seed/cache.go
Outdated
}) | ||
|
||
for i := 0; i < len(offArr); i++ { | ||
err = fcb.syncBlockToFile(bufArr[i].Bytes(), offArr[i]) |
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.
It will introduce a bug here after sorting offArr
only because that the element in offArr
and bufArr
with the same index are belonged to different data. Maybe the sort
step should be removed if no other good solution.
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.
Fix it by define struct {off int, buf *bytes.buffer} and sort.
0e1f1bf
to
e09f4c8
Compare
Signed-off-by: allen.wq <[email protected]>
e09f4c8
to
a2a6d82
Compare
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.
LGTM
Signed-off-by: allen.wq [email protected]
Ⅰ. Describe what this PR did
Add implementation for seed cache. Please see refer #1284.
Ⅱ. Does this pull request fix one issue?
NONE.
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Add unit test.
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews