etcdserver: Fix panic for v3 transaction compares on non-existent keys

Fixes #3920
release-2.3
Barak Michener 2015-11-24 16:49:45 -05:00
parent 2762e1f3f7
commit 452e5bffc0
1 changed files with 13 additions and 2 deletions

View File

@ -301,8 +301,19 @@ func applyCompare(txnID int64, kv dstorage.KV, c *pb.Compare) (int64, bool) {
}
return rev, false
}
ckv := ckvs[0]
var ckv storagepb.KeyValue
if len(ckvs) != 0 {
ckv = ckvs[0]
} else {
// Use the zero value of ckv normally. However...
if c.Target == pb.Compare_VALUE {
// Always fail if we're comparing a value on a key that doesn't exist.
// We can treat non-existence as the empty set explicitly, such that
// even a key with a value of length 0 bytes is still a real key
// that was written that way
return rev, false
}
}
// -1 is less, 0 is equal, 1 is greater
var result int