Skip to content

Commit

Permalink
reset event checkpoint key properly for non sub-page breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xacrimon committed Jul 27, 2021
1 parent d96ea00 commit a675389
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/events/dynamoevents/dynamoevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ func (l *Log) searchEventsRaw(fromUTC, toUTC time.Time, namespace string, eventT
totalSize := 0
dates := daysBetween(fromUTC, toUTC)
query := "CreatedAtDate = :date AND CreatedAt BETWEEN :start and :end"
g := l.WithFields(log.Fields{"From": fromUTC, "To": toUTC, "Namespace": namespace, "EventTypes": eventTypes, "Limit": limit, "StartKey": startKey})
g := l.WithFields(log.Fields{"From": fromUTC, "To": toUTC, "Namespace": namespace, "EventTypes": eventTypes, "Limit": limit, "StartKey": startKey, "Order": order})
var left int64
if limit != 0 {
left = int64(limit)
Expand Down Expand Up @@ -865,7 +865,8 @@ dateLoop:
if err != nil {
return nil, "", trace.Wrap(err)
}
g.WithFields(log.Fields{"duration": time.Since(start), "items": len(out.Items)}).Debugf("Query completed.")
g.WithFields(log.Fields{"duration": time.Since(start), "items": len(out.Items), "forward": forward, "iterator": checkpoint.Iterator}).Debugf("Query completed.")
oldIterator := checkpoint.Iterator
checkpoint.Iterator = out.LastEvaluatedKey

for _, item := range out.Items {
Expand Down Expand Up @@ -896,11 +897,15 @@ dateLoop:
// checkpoint is needed for sub-page breaks.
if totalSize+len(data) >= events.MaxEventBytesInResponse {
hasLeft = i+1 != len(dates) || len(checkpoint.Iterator) != 0

key, err := getSubPageCheckpoint(&e)
if err != nil {
return nil, "", trace.Wrap(err)
}
checkpoint.EventKey = key

// We need to reset the iterator so we get the previous page again.
checkpoint.Iterator = oldIterator
break dateLoop
}

Expand All @@ -910,6 +915,7 @@ dateLoop:

if left == 0 {
hasLeft = i+1 != len(dates) || len(checkpoint.Iterator) != 0
checkpoint.EventKey = ""
break dateLoop
}
}
Expand Down

0 comments on commit a675389

Please sign in to comment.