consul: Fixing blocking query if set table is at index 0

This commit is contained in:
Armon Dadgar 2014-03-31 20:00:46 -07:00
parent 96bd58df20
commit 243198e49b
1 changed files with 14 additions and 2 deletions

View File

@ -58,7 +58,13 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er
return 0, err
}
if ent == nil {
reply.Index = index
// Must provide non-zero index to prevent blocking
// Index 1 is impossible anyways (due to Raft internals)
if index == 0 {
reply.Index = 1
} else {
reply.Index = index
}
reply.Entries = nil
} else {
reply.Index = ent.ModifyIndex
@ -84,7 +90,13 @@ func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) e
return 0, err
}
if len(ent) == 0 {
reply.Index = index
// Must provide non-zero index to prevent blocking
// Index 1 is impossible anyways (due to Raft internals)
if index == 0 {
reply.Index = 1
} else {
reply.Index = index
}
reply.Entries = nil
} else {
// Determine the maximum affected index