Skip to content

Commit

Permalink
pkg/auth: remove DeleteUnused from the KV interface
Browse files Browse the repository at this point in the history
DeleteUnused is no longer used (no pun intended!).

Change-Id: Idd55304f463de86a8b925431d87400a83173782a
  • Loading branch information
amwolff committed Jan 20, 2023
1 parent 4c6d2a7 commit 1facd3e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 68 deletions.
10 changes: 0 additions & 10 deletions pkg/auth/authdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,6 @@ func (db *Database) Get(ctx context.Context, accessKeyID EncryptionKey) (accessG
return string(ag), record.Public, secretKey, nil
}

// DeleteUnused deletes expired and invalid records from the key/value store and
// returns any error encountered.
func (db *Database) DeleteUnused(ctx context.Context, asOfSystemInterval time.Duration, selectSize, deleteSize int) (count, rounds int64, deletesPerHead map[string]int64, err error) {
defer mon.Task()(&ctx)(&err)

count, rounds, deletesPerHead, err = db.kv.DeleteUnused(ctx, asOfSystemInterval, selectSize, deleteSize)

return count, rounds, deletesPerHead, errs.Wrap(err)
}

// PingDB attempts to do a DB roundtrip. If it can't it will return an error.
func (db *Database) PingDB(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
Expand Down
13 changes: 4 additions & 9 deletions pkg/auth/authdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ func TestPutSatelliteValidation(t *testing.T) {
type mockKV struct{}

func (mockKV) Put(ctx context.Context, keyHash KeyHash, record *Record) (err error) { return nil }
func (mockKV) Get(ctx context.Context, keyHash KeyHash) (record *Record, err error) {
return nil, nil
}
func (mockKV) DeleteUnused(ctx context.Context, asOfSystemInterval time.Duration, selectSize, deleteSize int) (count, rounds int64, deletesPerHead map[string]int64, err error) {
return 0, 0, nil, nil
}
func (mockKV) PingDB(ctx context.Context) error { return nil }
func (mockKV) Run(ctx context.Context) error { return nil }
func (mockKV) Close() error { return nil }
func (mockKV) Get(ctx context.Context, keyHash KeyHash) (record *Record, err error) { return nil, nil }
func (mockKV) PingDB(ctx context.Context) error { return nil }
func (mockKV) Run(ctx context.Context) error { return nil }
func (mockKV) Close() error { return nil }
7 changes: 0 additions & 7 deletions pkg/auth/authdb/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ type KV interface {
// If the record is invalid, the error contains why.
Get(ctx context.Context, keyHash KeyHash) (record *Record, err error)

// DeleteUnused deletes expired and invalid records from the key/value store
// and returns any error encountered.
//
// Batch deletion and usage of asOfSystemInterval, selectSize and deleteSize
// parameters depends on the implementation.
DeleteUnused(ctx context.Context, asOfSystemInterval time.Duration, selectSize, deleteSize int) (count, rounds int64, deletesPerHead map[string]int64, err error)

// PingDB attempts to do a DB roundtrip. If it can't it will return an
// error.
PingDB(ctx context.Context) error
Expand Down
6 changes: 0 additions & 6 deletions pkg/auth/badgerauth/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ func (db *DB) Get(ctx context.Context, keyHash authdb.KeyHash) (record *authdb.R
}))
}

// DeleteUnused always returns an error because expiring records are deleted by
// default.
func (db *DB) DeleteUnused(context.Context, time.Duration, int, int) (int64, int64, map[string]int64, error) {
return 0, 0, nil, Error.New("expiring records are deleted by default")
}

// PingDB attempts to do a database roundtrip and returns an error if it can't.
func (db *DB) PingDB(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
Expand Down
23 changes: 0 additions & 23 deletions pkg/auth/badgerauth/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,6 @@ func randTime(d time.Duration) time.Time {
return time.Now().Add(time.Duration(testrand.Int63n(int64(d))))
}

func TestDeleteUnusedAlwaysReturnsError(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()

var err error

badgerauthtest.RunSingleNode(t, badgerauth.Config{}, func(ctx *testcontext.Context, t *testing.T, _ *zap.Logger, node *badgerauth.Node) {
db := node.UnderlyingDB()

_, _, _, err = db.DeleteUnused(ctx, 0, 0, 0)
assert.Error(t, err)
_, _, _, err = db.DeleteUnused(ctx, 24*time.Hour, 10000, 1000)
assert.Error(t, err)
})

//nolint: dogsled
_, _, _, err = (&badgerauth.DB{}).DeleteUnused(ctx, 0, 0, 0)
assert.Error(t, err)
//nolint: dogsled
_, _, _, err = (&badgerauth.DB{}).DeleteUnused(ctx, 24*time.Hour, 10000, 1000)
assert.Error(t, err)
}

// TestBasicCycle sequentially tests the basic create → retrieve lifecycle of a
// single record, verifying fundamental KV interface guarantees.
func TestBasicCycle(t *testing.T) {
Expand Down
13 changes: 0 additions & 13 deletions pkg/auth/badgerauth/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,6 @@ func (node *Node) Get(ctx context.Context, keyHash authdb.KeyHash) (record *auth
return nil, Error.Wrap(errGroup.Err())
}

// DeleteUnused proxies DB's DeleteUnused.
func (node *Node) DeleteUnused(
ctx context.Context,
asOfSystemInterval time.Duration,
selectSize, deleteSize int,
) (
count, rounds int64,
deletesPerHead map[string]int64,
err error,
) {
return node.db.DeleteUnused(ctx, asOfSystemInterval, selectSize, deleteSize)
}

// PingDB proxies DB's PingDB.
func (node *Node) PingDB(ctx context.Context) error {
return node.db.PingDB(ctx)
Expand Down

0 comments on commit 1facd3e

Please sign in to comment.