mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Lease support for linearizability tests : Updated as per review feedback.
Signed-off-by: Geeta Gharpure <geetagh@amazon.com>
This commit is contained in:
parent
715a0047fa
commit
6106912338
@ -240,16 +240,7 @@ func initState(request EtcdRequest, response EtcdResponse) EtcdState {
|
|||||||
state.KeyValues[op.Key] = op.Value
|
state.KeyValues[op.Key] = op.Value
|
||||||
case Delete:
|
case Delete:
|
||||||
case PutWithLease:
|
case PutWithLease:
|
||||||
if _, ok := state.Leases[op.LeaseID]; ok {
|
//nop here since lease wont be there
|
||||||
state.KeyValues[op.Key] = op.Value
|
|
||||||
//detach from old lease id but we dont expect that at init
|
|
||||||
if _, ok := state.KeyLeases[op.Key]; ok {
|
|
||||||
panic("old lease id found at init")
|
|
||||||
}
|
|
||||||
//attach to new lease id
|
|
||||||
state.KeyLeases[op.Key] = op.LeaseID
|
|
||||||
state.Leases[op.LeaseID].Keys[op.Key] = leased
|
|
||||||
}
|
|
||||||
case LeaseGrant:
|
case LeaseGrant:
|
||||||
lease := EtcdLease{
|
lease := EtcdLease{
|
||||||
LeaseID: op.LeaseID,
|
LeaseID: op.LeaseID,
|
||||||
@ -312,12 +303,12 @@ func applyRequestToSingleState(s EtcdState, request EtcdRequest) (EtcdState, Etc
|
|||||||
case Put:
|
case Put:
|
||||||
s.KeyValues[op.Key] = op.Value
|
s.KeyValues[op.Key] = op.Value
|
||||||
increaseRevision = true
|
increaseRevision = true
|
||||||
s = detachFromOldLease(s, op)
|
s = detachFromOldLease(s, op.Key)
|
||||||
case Delete:
|
case Delete:
|
||||||
if _, ok := s.KeyValues[op.Key]; ok {
|
if _, ok := s.KeyValues[op.Key]; ok {
|
||||||
delete(s.KeyValues, op.Key)
|
delete(s.KeyValues, op.Key)
|
||||||
increaseRevision = true
|
increaseRevision = true
|
||||||
s = detachFromOldLease(s, op)
|
s = detachFromOldLease(s, op.Key)
|
||||||
opResp[i].Deleted = 1
|
opResp[i].Deleted = 1
|
||||||
}
|
}
|
||||||
case PutWithLease:
|
case PutWithLease:
|
||||||
@ -325,8 +316,8 @@ func applyRequestToSingleState(s EtcdState, request EtcdRequest) (EtcdState, Etc
|
|||||||
//handle put op.
|
//handle put op.
|
||||||
s.KeyValues[op.Key] = op.Value
|
s.KeyValues[op.Key] = op.Value
|
||||||
increaseRevision = true
|
increaseRevision = true
|
||||||
s = detachFromOldLease(s, op)
|
s = detachFromOldLease(s, op.Key)
|
||||||
s = attachToNewLease(s, op)
|
s = attachToNewLease(s, op.LeaseID, op.Key)
|
||||||
}
|
}
|
||||||
case LeaseRevoke:
|
case LeaseRevoke:
|
||||||
//Delete the keys attached to the lease
|
//Delete the keys attached to the lease
|
||||||
@ -364,16 +355,16 @@ func applyRequestToSingleState(s EtcdState, request EtcdRequest) (EtcdState, Etc
|
|||||||
return s, EtcdResponse{OpsResult: opResp, Revision: s.Revision}
|
return s, EtcdResponse{OpsResult: opResp, Revision: s.Revision}
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachFromOldLease(s EtcdState, op EtcdOperation) EtcdState {
|
func detachFromOldLease(s EtcdState, key string) EtcdState {
|
||||||
if oldLeaseId, ok := s.KeyLeases[op.Key]; ok {
|
if oldLeaseId, ok := s.KeyLeases[key]; ok {
|
||||||
delete(s.Leases[oldLeaseId].Keys, op.Key)
|
delete(s.Leases[oldLeaseId].Keys, key)
|
||||||
delete(s.KeyLeases, op.Key)
|
delete(s.KeyLeases, key)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func attachToNewLease(s EtcdState, op EtcdOperation) EtcdState {
|
func attachToNewLease(s EtcdState, leaseID int64, key string) EtcdState {
|
||||||
s.KeyLeases[op.Key] = op.LeaseID
|
s.KeyLeases[key] = leaseID
|
||||||
s.Leases[op.LeaseID].Keys[op.Key] = leased
|
s.Leases[leaseID].Keys[key] = leased
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user