mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #15101 from serathius/linearizability-history-patch-window
tests: Fix history patch window
This commit is contained in:
commit
d37f9b2092
@ -284,12 +284,14 @@ func (h history) Operations() []porcupine.Operation {
|
|||||||
maxTime = op.Return
|
maxTime = op.Return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Failed requests don't have a known return time.
|
|
||||||
// We simulate Infinity by using return time of latest successfully request.
|
|
||||||
for _, op := range h.failed {
|
for _, op := range h.failed {
|
||||||
if op.Call > maxTime {
|
if op.Call > maxTime {
|
||||||
continue
|
maxTime = op.Call
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Failed requests don't have a known return time.
|
||||||
|
// Simulate Infinity by using last observed time.
|
||||||
|
for _, op := range h.failed {
|
||||||
op.Return = maxTime + 1
|
op.Return = maxTime + 1
|
||||||
operations = append(operations, op)
|
operations = append(operations, op)
|
||||||
}
|
}
|
||||||
|
@ -143,11 +143,11 @@ func patchOperationBasedOnWatchEvents(operations []porcupine.Operation, watchEve
|
|||||||
for _, op := range watchEvents {
|
for _, op := range watchEvents {
|
||||||
persisted[op.Op] = op
|
persisted[op.Op] = op
|
||||||
}
|
}
|
||||||
lastObservedEventTime := watchEvents[len(watchEvents)-1].Time
|
lastObservedOperation := lastOperationObservedInWatch(operations, persisted)
|
||||||
|
|
||||||
for _, op := range operations {
|
for _, op := range operations {
|
||||||
resp := op.Output.(EtcdResponse)
|
resp := op.Output.(EtcdResponse)
|
||||||
if resp.Err == nil || op.Call > lastObservedEventTime.UnixNano() {
|
if resp.Err == nil || op.Call > lastObservedOperation.Call {
|
||||||
// No need to patch successfully requests and cannot patch requests outside observed window.
|
// No need to patch successfully requests and cannot patch requests outside observed window.
|
||||||
newOperations = append(newOperations, op)
|
newOperations = append(newOperations, op)
|
||||||
continue
|
continue
|
||||||
@ -173,6 +173,19 @@ func patchOperationBasedOnWatchEvents(operations []porcupine.Operation, watchEve
|
|||||||
return newOperations
|
return newOperations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func lastOperationObservedInWatch(operations []porcupine.Operation, watchEvents map[EtcdOperation]watchEvent) porcupine.Operation {
|
||||||
|
var maxCallTime int64
|
||||||
|
var lastOperation porcupine.Operation
|
||||||
|
for _, op := range operations {
|
||||||
|
event, _ := matchWatchEvent(op, watchEvents)
|
||||||
|
if event != nil && op.Call > maxCallTime {
|
||||||
|
maxCallTime = op.Call
|
||||||
|
lastOperation = op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastOperation
|
||||||
|
}
|
||||||
|
|
||||||
func matchWatchEvent(op porcupine.Operation, watchEvents map[EtcdOperation]watchEvent) (event *watchEvent, hasUniqueWriteOperation bool) {
|
func matchWatchEvent(op porcupine.Operation, watchEvents map[EtcdOperation]watchEvent) (event *watchEvent, hasUniqueWriteOperation bool) {
|
||||||
request := op.Input.(EtcdRequest)
|
request := op.Input.(EtcdRequest)
|
||||||
for _, etcdOp := range request.Ops {
|
for _, etcdOp := range request.Ops {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user