Skip to content
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

fix: add context to DiskUsage() #100

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion flatfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func combineAccuracy(a, b initAccuracy) initAccuracy {
}

var _ datastore.Datastore = (*Datastore)(nil)
var _ datastore.PersistentDatastore = (*Datastore)(nil)
guseggert marked this conversation as resolved.
Show resolved Hide resolved
var _ datastore.Batching = (*Datastore)(nil)
var _ datastore.Batch = (*flatfsBatch)(nil)

var (
ErrDatastoreExists = errors.New("datastore already exists")
Expand Down Expand Up @@ -1091,7 +1094,7 @@ func (fs *Datastore) readDiskUsageFile() int64 {
//
// The size is approximative and may slightly differ from
// the real disk values.
func (fs *Datastore) DiskUsage() (uint64, error) {
func (fs *Datastore) DiskUsage(ctx context.Context) (uint64, error) {
// it may differ from real disk values if
// the filesystem has allocated for blocks
// for a directory because it has many files in it
Expand Down
26 changes: 13 additions & 13 deletions flatfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func testDiskUsage(dirFunc mkShardFunc, t *testing.T) {
defer fs.Close()

time.Sleep(100 * time.Millisecond)
duNew, err := fs.DiskUsage()
duNew, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand All @@ -558,7 +558,7 @@ func testDiskUsage(dirFunc mkShardFunc, t *testing.T) {
}

time.Sleep(100 * time.Millisecond)
duElems, err := fs.DiskUsage()
duElems, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand All @@ -573,13 +573,13 @@ func testDiskUsage(dirFunc mkShardFunc, t *testing.T) {
}

time.Sleep(100 * time.Millisecond)
duDelete, err := fs.DiskUsage()
duDelete, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
t.Log("duPostDelete:", duDelete)

du, err := fs.DiskUsage()
du, err := fs.DiskUsage(bg)
t.Log("duFinal:", du)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -616,7 +616,7 @@ func testDiskUsage(dirFunc mkShardFunc, t *testing.T) {
t.Fatalf("New fail: %v\n", err)
}

duReopen, err := fs.DiskUsage()
duReopen, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -692,9 +692,9 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
count = 1
wg.Add(2)
put()
du, _ := fs.DiskUsage()
du, _ := fs.DiskUsage(bg)
del()
du2, _ := fs.DiskUsage()
du2, _ := fs.DiskUsage(bg)
if du-10 != du2 {
t.Error("should have deleted exactly 10 bytes:", du, du2)
}
Expand All @@ -708,7 +708,7 @@ func testDiskUsageDoubleCount(dirFunc mkShardFunc, t *testing.T) {
go del()
wg.Wait()

du3, _ := fs.DiskUsage()
du3, _ := fs.DiskUsage(bg)
has, err := fs.Has(bg, testKey)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -780,12 +780,12 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
wg.Add(2)
put()
commit()
du, err := fs.DiskUsage()
du, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
del()
du2, err := fs.DiskUsage()
du2, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand All @@ -800,7 +800,7 @@ func testDiskUsageBatch(dirFunc mkShardFunc, t *testing.T) {
go del()
wg.Wait()

du3, err := fs.DiskUsage()
du3, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -858,7 +858,7 @@ func testDiskUsageEstimation(dirFunc mkShardFunc, t *testing.T) {
t.Fatalf("Open fail: %v\n", err)
}

duReopen, err := fs.DiskUsage()
duReopen, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand All @@ -875,7 +875,7 @@ func testDiskUsageEstimation(dirFunc mkShardFunc, t *testing.T) {
t.Fatalf("Open fail: %v\n", err)
}

duEst, err := fs.DiskUsage()
duEst, err := fs.DiskUsage(bg)
if err != nil {
t.Fatal(err)
}
Expand Down