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(subscriptions): fix subscription to use the kv with the max version #7349

Merged
merged 5 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions dgraph/cmd/alpha/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,15 @@ func listenForCorsUpdate(closer *z.Closer) {
// Remove uid from the key, to get the correct prefix
prefix = prefix[:len(prefix)-8]
worker.SubscribeForUpdates([][]byte{prefix}, func(kvs *badgerpb.KVList) {
// Last update contains the latest value. So, taking the last update.
lastIdx := len(kvs.GetKv()) - 1
kv := kvs.GetKv()[lastIdx]
// Iterate over kvs to get the KV with the latest version. It is not necessary that the last
// KV contain the latest value.
var kv badgerpb.KV
for _, Kv := range kvs.GetKv() {
if Kv.GetVersion() > kv.GetVersion() {
NamanJain8 marked this conversation as resolved.
Show resolved Hide resolved
kv = *Kv
}
}

glog.Infof("Updating cors from subscription.")
// Unmarshal the incoming posting list.
pl := &pb.PostingList{}
Expand Down
8 changes: 7 additions & 1 deletion edgraph/access_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,13 @@ func RefreshAcls(closer *z.Closer) {
if kvs == nil || len(kvs.Kv) == 0 {
return
}
NamanJain8 marked this conversation as resolved.
Show resolved Hide resolved
if err := retrieveAcls(kvs.Kv[0].Version); err != nil {
var maxVs uint64
for _, kv := range kvs.GetKv() {
if kv.Version > maxVs {
maxVs = kv.Version
}
}
if err := retrieveAcls(maxVs); err != nil {
NamanJain8 marked this conversation as resolved.
Show resolved Hide resolved
glog.Errorf("Error while retrieving acls: %v", err)
}
}, 1, closer)
Expand Down
11 changes: 8 additions & 3 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,14 @@ func newAdminResolver(
prefix = prefix[:len(prefix)-8]
// Listen for graphql schema changes in group 1.
go worker.SubscribeForUpdates([][]byte{prefix}, func(kvs *badgerpb.KVList) {
// Last update contains the latest value. So, taking the last update.
lastIdx := len(kvs.GetKv()) - 1
kv := kvs.GetKv()[lastIdx]
// Iterate over kvs to get the KV with the latest version. It is not necessary that the last
// KV contain the latest value.
var kv badgerpb.KV
for _, Kv := range kvs.GetKv() {
if Kv.GetVersion() > kv.GetVersion() {
kv = *Kv
}
}

glog.Infof("Updating GraphQL schema from subscription.")

Expand Down