-
Notifications
You must be signed in to change notification settings - Fork 402
/
limitedspace.go
58 lines (47 loc) · 1.46 KB
/
limitedspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package testblobs
import (
"context"
"go.uber.org/zap"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/blobstore"
)
// ensures that limitedSpaceDB implements storagenode.DB.
var _ storagenode.DB = (*limitedSpaceDB)(nil)
// limitedSpaceDB implements storage node DB with limited free space.
type limitedSpaceDB struct {
storagenode.DB
log *zap.Logger
blobs *LimitedSpaceBlobs
}
// NewLimitedSpaceDB creates a new storage node DB with limited free space.
func NewLimitedSpaceDB(log *zap.Logger, db storagenode.DB, freeSpace int64) storagenode.DB {
return &limitedSpaceDB{
DB: db,
blobs: newLimitedSpaceBlobs(log, db.Pieces(), freeSpace),
log: log,
}
}
// Pieces returns the blob store.
func (lim *limitedSpaceDB) Pieces() blobstore.Blobs {
return lim.blobs
}
// LimitedSpaceBlobs implements a limited space blob store.
type LimitedSpaceBlobs struct {
blobstore.Blobs
log *zap.Logger
freeSpace int64
}
// newLimitedSpaceBlobs creates a new limited space blob store wrapping the provided blobs.
func newLimitedSpaceBlobs(log *zap.Logger, blobs blobstore.Blobs, freeSpace int64) *LimitedSpaceBlobs {
return &LimitedSpaceBlobs{
log: log,
Blobs: blobs,
freeSpace: freeSpace,
}
}
// FreeSpace returns how much free space left for writing.
func (limspace *LimitedSpaceBlobs) FreeSpace(ctx context.Context) (int64, error) {
return limspace.freeSpace, nil
}