-
Notifications
You must be signed in to change notification settings - Fork 324
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
[pkg] panic if no space is left #3636
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3636 +/- ##
==========================================
- Coverage 74.95% 74.67% -0.29%
==========================================
Files 269 267 -2
Lines 23819 23784 -35
==========================================
- Hits 17854 17761 -93
- Misses 5039 5090 +51
- Partials 926 933 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
pkg/fsnotify/fsnotify.go
Outdated
|
||
// checkDiskSpace returns the disk usage info | ||
func checkDiskSpace(ctx context.Context) { | ||
usage, err := disk.Usage("/") |
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.
if os disk partition like this
/ /dev/sda
/run /dev/sdb
and iotex-core run within /run, the check may not work
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.
"/"
checks all disks
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.
pkg/fsnotify/fsnotify.go
Outdated
continue | ||
} | ||
// check disk space per write operation | ||
if ev.Has(fsnotify.Write) { |
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.
fsnotify.Create needed too
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 still left enough space to run program even if Avail
is 0
after run df -h
.
pkg/fsnotify/fsnotify.go
Outdated
} | ||
// check disk space per write operation | ||
if ev.Has(fsnotify.Write) { | ||
checkDiskSpace(ctx) |
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.
all filesystem write ops trig a check, may inefficient
I think we don't need to monitor disk, just need to PANIC when write DB error is |
add log rotate and delete expired logs can be better. |
pkg/fsnotify/fsnotify.go
Outdated
select { | ||
case <-ctx.Done(): | ||
return | ||
case ev, ok := <-watcher.Events: |
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.
when does an event come
pkg/watch/watch.go
Outdated
if err := task.Start(ctx); err != nil { | ||
log.L().Panic("Failed to start watch disk space", zap.Error(err)) | ||
} | ||
return func() { |
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.
why return a func()
here?
server/main.go
Outdated
@@ -103,6 +104,10 @@ func main() { | |||
glog.Fatalln("Cannot config global logger, use default one: ", zap.Error(err)) | |||
} | |||
|
|||
// check device | |||
stopWatch := watch.Start(ctx, 5*time.Minute) | |||
defer stopWatch() |
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.
just call watch.Start()
in server.Start()
, and call watch.Stop()
in server.Stop()
?
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.
Just check like heartbeat. server
contains the major components like api blockchain etc...
pkg/watch/watch.go
Outdated
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache | ||
// License 2.0 that can be found in the LICENSE file. | ||
|
||
package watch |
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.
package disk
pkg/watch/watch.go
Outdated
) | ||
|
||
// Start creates a timer task to check device per watchInternal | ||
func Start(ctx context.Context, watchInternal time.Duration) func() { |
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.
func NewMonitor(time.Duration) *monitor
func (*monitor) Start()
func (*monitor) Stop()
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.
OK.
return | ||
} | ||
// panic if left less than 2% | ||
if usage.UsedPercent > 98.0 || usage.InodesUsedPercent > 98.0 { |
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.
if disk is 20TB, when there is %2=200GB of free disk, can't it be used?
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.
leave enough disk space is required when disk run out soon.
pkg/fsnotify/fsnotify.go
Outdated
|
||
// checkDiskSpace returns the disk usage info | ||
func checkDiskSpace(ctx context.Context) { | ||
usage, err := disk.Usage("/") |
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.
fixed. I have no problem. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Description
Fixes #3629
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: