Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

define cache for seed file in seed pattern #1305

Merged
merged 1 commit into from
May 15, 2020

Conversation

wangforthinker
Copy link
Contributor

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

@pouchrobot
Copy link
Collaborator

Thanks for your contribution. 🍻 @wangforthinker
While we thought PR TITLE could be more specific, longer than 20 chars.
Please edit this PR title instead of opening a new one.
More details, please refer to https://github.com/dragonflyoss/Dragonfly/blob/master/CONTRIBUTING.md

@wangforthinker wangforthinker changed the title add cache for seed define cache for seed file in seed pattern Apr 27, 2020
@codecov-io
Copy link

codecov-io commented Apr 27, 2020

Codecov Report

Merging #1305 into master will increase coverage by 0.56%.
The diff coverage is 73.23%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pkg/bitmap/bitmap.go 91.15% <0.00%> (-5.95%) ⬇️
dfdaemon/seed/cache.go 76.47% <76.47%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 734cde5...0aac763. Read the comment docs.

@hhhhsdxxxx
Copy link

lgtm!
Reviewed-by [email protected]

@xujihui1985
Copy link

lgtm
Reviewed-by [email protected]

sizeOf64Bits++
}

fcb.blockMeta, err = bitmap.NewBitMap(sizeOf64Bits, false)
Copy link
Member

@lowzj lowzj Apr 27, 2020

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

@wangforthinker wangforthinker May 9, 2020

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
Copy link
Member

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?

Copy link
Contributor Author

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]
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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()
Copy link
Member

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.

Copy link
Contributor Author

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.

}
fcb.RUnlock()

for i := 0; i < len(offArr); i++ {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@wangforthinker wangforthinker force-pushed the feat/add-seed-cache-prepare-pr branch 4 times, most recently from 0aac763 to afa306e Compare May 12, 2020 12:37
})

for i := 0; i < len(offArr); i++ {
err = fcb.syncBlockToFile(bufArr[i].Bytes(), offArr[i])
Copy link
Member

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.

Copy link
Contributor Author

@wangforthinker wangforthinker May 13, 2020

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.

@wangforthinker wangforthinker force-pushed the feat/add-seed-cache-prepare-pr branch 2 times, most recently from 0e1f1bf to e09f4c8 Compare May 15, 2020 02:38
Signed-off-by: allen.wq <[email protected]>
@wangforthinker wangforthinker force-pushed the feat/add-seed-cache-prepare-pr branch from e09f4c8 to a2a6d82 Compare May 15, 2020 09:41
Copy link
Member

@lowzj lowzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lowzj lowzj merged commit f131b5f into dragonflyoss:master May 15, 2020
@wangforthinker wangforthinker deleted the feat/add-seed-cache-prepare-pr branch May 27, 2020 02:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants