-
Notifications
You must be signed in to change notification settings - Fork 997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flush dir stat in less transactions #3277
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
01a8695
implement doBatchUpdateDirStat for redis
Hexilee cbf04fa
implement doUpdateDirStat for sql
Hexilee 00312da
implement doUpdateDirStat for tkv
Hexilee 2bea708
fix a bug
Hexilee 4ec7c61
group batch for redis
Hexilee 23baf1a
change seperateBatch
Hexilee ae19f1b
group batch for sql
Hexilee 848615e
group batch for tkv
Hexilee a3cc4b8
sort inos when group batch
Hexilee 1abd245
use gets in tkv
Hexilee 4e54c02
merge from master
Hexilee 945b497
parallelly sync dir stat
Hexilee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2260,26 +2260,60 @@ func (m *redisMeta) doSyncDirStat(ctx Context, ino Ino) (space, inodes uint64, e | |
return | ||
} | ||
|
||
func (m *redisMeta) doUpdateDirStat(ctx Context, ino Ino, space int64, inodes int64) error { | ||
func (m *redisMeta) doUpdateDirStat(ctx Context, batch map[Ino]dirStat) error { | ||
spaceKey := m.dirUsedSpaceKey() | ||
inodesKey := m.dirUsedInodesKey() | ||
field := strconv.FormatUint(uint64(ino), 10) | ||
if !m.rdb.HExists(ctx, spaceKey, field).Val() { | ||
_, _, err := m.doSyncDirStat(ctx, ino) | ||
nonexist := make(map[Ino]*dirStat, 0) | ||
statList := make([]Ino, 0, len(batch)) | ||
|
||
pipeline := m.rdb.Pipeline() | ||
for ino := range batch { | ||
pipeline.HExists(ctx, spaceKey, strconv.FormatUint(uint64(ino), 10)) | ||
statList = append(statList, ino) | ||
} | ||
rets, err := pipeline.Exec(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
return m.txn(ctx, func(tx *redis.Tx) error { | ||
_, err := tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error { | ||
if space != 0 { | ||
pipe.HIncrBy(ctx, spaceKey, field, space) | ||
} | ||
if inodes != 0 { | ||
pipe.HIncrBy(ctx, inodesKey, field, inodes) | ||
for i, ret := range rets { | ||
if ret.Err() != nil { | ||
return ret.Err() | ||
} | ||
if exist, _ := ret.(*redis.BoolCmd).Result(); !exist { | ||
nonexist[statList[i]] = &dirStat{} | ||
} | ||
} | ||
|
||
if len(nonexist) > 0 { | ||
if err := m.batchCalcDirStat(ctx, nonexist); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for _, group := range m.groupBatch(batch, 1000) { | ||
davies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, err := m.rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error { | ||
for _, ino := range group { | ||
field := strconv.FormatUint(uint64(ino), 10) | ||
if stat, ok := nonexist[ino]; ok { | ||
pipe.HSetNX(ctx, spaceKey, field, stat.space) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just ignore it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignored |
||
pipe.HSetNX(ctx, inodesKey, field, stat.inodes) | ||
continue | ||
} | ||
stat := batch[ino] | ||
if stat.space != 0 { | ||
pipe.HIncrBy(ctx, spaceKey, field, stat.space) | ||
} | ||
if stat.inodes != 0 { | ||
pipe.HIncrBy(ctx, inodesKey, field, stat.inodes) | ||
} | ||
} | ||
return nil | ||
}) | ||
return err | ||
}, spaceKey, inodesKey) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *redisMeta) doGetDirStat(ctx Context, ino Ino) (space, inodes uint64, err error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
They are independent, so we should not cancel others if one of them fail
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.
Also, we cant to update the stats right after the calculation, don't wait for other large directories. So it's better to move the parallization out of calculation
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