Skip to content

Commit

Permalink
Backport: non mutating requests pass through quotaKVServer when NOSPACE
Browse files Browse the repository at this point in the history
This is a backport of #13435 and is
part of the work for 3.4.20
#14232.

The original change had a second commit that modifies a changelog file.
The 3.4 branch does not include any changelog file, so that part was not
cherry-picked.

Local Testing:

- `make build`
- `make test`

Both succeed.
  • Loading branch information
chaochn47 authored and ramses committed Jul 21, 2022
1 parent 7ee7029 commit a3a60f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion etcdserver/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ func NewBackendQuota(s *EtcdServer, name string) Quota {
}

func (b *backendQuota) Available(v interface{}) bool {
cost := b.Cost(v)
// if there are no mutating requests, it's safe to pass through
if cost == 0 {
return true
}

// TODO: maybe optimize backend.Size()
return b.s.Backend().Size()+int64(b.Cost(v)) < b.maxBackendBytes
return b.s.Backend().Size()+int64(cost) < b.maxBackendBytes
}

func (b *backendQuota) Cost(v interface{}) int {
Expand Down
24 changes: 24 additions & 0 deletions integration/v3_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ func TestV3StorageQuotaApply(t *testing.T) {
}
}

// txn with non-mutating Ops should go through when NOSPACE alarm is raised
_, err = kvc0.Txn(context.TODO(), &pb.TxnRequest{
Compare: []*pb.Compare{
{
Key: key,
Result: pb.Compare_EQUAL,
Target: pb.Compare_CREATE,
TargetUnion: &pb.Compare_CreateRevision{CreateRevision: 0},
},
},
Success: []*pb.RequestOp{
{
Request: &pb.RequestOp_RequestDeleteRange{
RequestDeleteRange: &pb.DeleteRangeRequest{
Key: key,
},
},
},
},
})
if err != nil {
t.Fatal(err)
}

ctx, cancel := context.WithTimeout(context.TODO(), RequestWaitTimeout)
defer cancel()

Expand Down

0 comments on commit a3a60f0

Please sign in to comment.