Ensure that revision is consistent for empty lists

This commit is contained in:
Darren Shepherd 2019-11-14 04:39:04 +00:00
parent 80f81d5089
commit 4018a64c43
4 changed files with 30 additions and 8 deletions

2
go.mod
View File

@ -102,7 +102,7 @@ require (
github.com/rakelkar/gonetsh v0.0.0-20190719023240-501daadcadf8 // indirect
github.com/rancher/dynamiclistener v0.1.1-0.20191113144757-736b5d5d8b51
github.com/rancher/helm-controller v0.2.2
github.com/rancher/kine v0.2.3
github.com/rancher/kine v0.2.4
github.com/rancher/remotedialer v0.2.0
github.com/rancher/wrangler v0.2.0
github.com/rancher/wrangler-api v0.2.0

4
go.sum
View File

@ -592,8 +592,8 @@ github.com/rancher/go-dqlite v1.1.0-k3s.1 h1:w3ghNkY5vqRnnrcqxvHkpBQr6E+R/nIwJfa
github.com/rancher/go-dqlite v1.1.0-k3s.1/go.mod h1:lj8UhpkZddn/Ag0tBsnkbELbxHGMpzrZLMs/nW9/DX4=
github.com/rancher/helm-controller v0.2.2 h1:MUqisy53/Ay1EYOF2uTCYBbGpgtZLNKKrI01BdxIbQo=
github.com/rancher/helm-controller v0.2.2/go.mod h1:0JkL0UjxddNbT4FmLoESarD4Mz8xzA5YlejqJ/U4g+8=
github.com/rancher/kine v0.2.3 h1:ln4Pmtb3ReqCLf6hF7aF1QmMLgnYPbq4/VZ1UyJ9v3A=
github.com/rancher/kine v0.2.3/go.mod h1:SdBUuE7e3XyrJvdBxCl9TMMapF+wyZnMZSP/H59OqNE=
github.com/rancher/kine v0.2.4 h1:Vtv8twV2u3Gh2cOL7vXv69besGc3YahxYeFzICV6GB8=
github.com/rancher/kine v0.2.4/go.mod h1:SdBUuE7e3XyrJvdBxCl9TMMapF+wyZnMZSP/H59OqNE=
github.com/rancher/kubernetes v1.16.2-k3s.1 h1:+oJEecXgQDkEOD/X8z2YUdYVonbXZtGzXsmtKDPYesg=
github.com/rancher/kubernetes v1.16.2-k3s.1/go.mod h1:SmhGgKfQ30imqjFVj8AI+iW+zSyFsswNErKYeTfgoH0=
github.com/rancher/kubernetes/staging/src/k8s.io/api v1.16.2-k3s.1 h1:2kK5KD6MU86txBYKG+tM6j5zbey02DaIDtwpG5JsfnI=

View File

@ -155,7 +155,6 @@ func (l *LogStructured) Delete(ctx context.Context, key string, revision int64)
func (l *LogStructured) List(ctx context.Context, prefix, startKey string, limit, revision int64) (revRet int64, kvRet []*server.KeyValue, errRet error) {
defer func() {
l.adjustRevision(ctx, &revRet)
logrus.Debugf("LIST %s, start=%s, limit=%d, rev=%d => rev=%d, kvs=%d, err=%v", prefix, startKey, limit, revision, revRet, len(kvRet), errRet)
}()
@ -163,7 +162,17 @@ func (l *LogStructured) List(ctx context.Context, prefix, startKey string, limit
if err != nil {
return 0, nil, err
}
if revision != 0 {
if revision == 0 && len(events) == 0 {
// if no revision is requested and no events are returned, then
// get the current revision and relist. Relist is required because
// between now and getting the current revision something could have
// been created.
currentRev, err := l.log.CurrentRevision(ctx)
if err != nil {
return 0, nil, err
}
return l.List(ctx, prefix, startKey, limit, currentRev)
} else if revision != 0 {
rev = revision
}
@ -176,10 +185,23 @@ func (l *LogStructured) List(ctx context.Context, prefix, startKey string, limit
func (l *LogStructured) Count(ctx context.Context, prefix string) (revRet int64, count int64, err error) {
defer func() {
l.adjustRevision(ctx, &revRet)
logrus.Debugf("COUNT %s => rev=%d, count=%d, err=%v", prefix, revRet, count, err)
}()
return l.log.Count(ctx, prefix)
rev, count, err := l.log.Count(ctx, prefix)
if err != nil {
return 0, 0, err
}
if count == 0 {
// if count is zero, then so is revision, so now get the current revision and re-count at that revision
currentRev, err := l.log.CurrentRevision(ctx)
if err != nil {
return 0, 0, err
}
rev, rows, err := l.List(ctx, prefix, prefix, 1000, currentRev)
return rev, int64(len(rows)), err
}
return rev, count, nil
}
func (l *LogStructured) Update(ctx context.Context, key string, value []byte, revision, lease int64) (revRet int64, kvRet *server.KeyValue, updateRet bool, errRet error) {

2
vendor/modules.txt vendored
View File

@ -769,7 +769,7 @@ github.com/rancher/helm-controller/pkg/generated/informers/externalversions/helm
github.com/rancher/helm-controller/pkg/generated/listers/helm.cattle.io/v1
github.com/rancher/helm-controller/pkg/generated/informers/externalversions/internalinterfaces
github.com/rancher/helm-controller/pkg/apis/helm.cattle.io
# github.com/rancher/kine v0.2.3
# github.com/rancher/kine v0.2.4
github.com/rancher/kine/pkg/client
github.com/rancher/kine/pkg/endpoint
github.com/rancher/kine/pkg/drivers/dqlite