-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
2 deletions.
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package main | |
|
||
import ( | ||
"context" | ||
|
||
badger4 "github.com/ipfs/go-ds-badger4" | ||
) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build !windows | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"syscall" | ||
) | ||
|
||
func (nd *Node) periodicGC(ctx context.Context, threshold float64) error { | ||
var stat syscall.Statfs_t | ||
|
||
err := syscall.Statfs(nd.dataDir, &stat) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
totalBytes := uint64(stat.Blocks) * uint64(stat.Bsize) | ||
availableBytes := stat.Bfree * uint64(stat.Bsize) | ||
|
||
// Calculate % of the total space | ||
minFreeBytes := uint64((float64(totalBytes) * threshold)) | ||
|
||
goLog.Infow("fileystem data collected", "total_bytes", totalBytes, "available_bytes", availableBytes, "min_free_bytes", minFreeBytes) | ||
|
||
// If there's enough free space, do nothing. | ||
if minFreeBytes > availableBytes { | ||
return nil | ||
} | ||
|
||
bytesToFree := (minFreeBytes - availableBytes) | ||
if bytesToFree <= 0 { | ||
return nil | ||
} | ||
|
||
return nd.GC(ctx, int64(bytesToFree)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
func (nd *Node) periodicGC(ctx context.Context, threshold float64) error { | ||
return errors.New("feature not implemented on windows") | ||
} |
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