95
func (i *historyIterator) Next(
96
ctx context.Context,
98
>
if !i.HasNext() {
99
return nil, errIteratorDepleted
100
}
101
102
>
historyBatches, newIterState, err := i.readHistoryBatches(ctx, i.NextEventID)
history_iterator.go
103
>
if err != nil {
104
return nil, err
105
}
106
108
>
firstEvent := historyBatches[0].Events[0]
109
>
lastBatch := historyBatches[len(historyBatches)-1]
110
>
lastEvent := lastBatch.Events[len(lastBatch.Events)-1]
111
>
eventCount := int64(0)
112
>
for _, batch := range historyBatches {
113
>
eventCount += int64(len(batch.Events))
114
>
}
115
>
header := &archiverspb.HistoryBlobHeader{
116
>
Namespace: i.request.Namespace,
117
>
NamespaceId: i.request.NamespaceID,
118
>
WorkflowId: i.request.WorkflowID,
119
>
RunId: i.request.RunID,
120
>
IsLast: i.FinishedIteration,
121
>
FirstFailoverVersion: firstEvent.Version,
122
>
LastFailoverVersion: lastEvent.Version,
123
>
FirstEventId: firstEvent.EventId,
124
>
LastEventId: lastEvent.EventId,
125
>
EventCount: eventCount,
126
>
}
127
>
128
>
return &archiverspb.HistoryBlob{
129
>
Header: header,
130
>
Body: historyBatches,
131
>
}, nil
132
}
133
134
// HasNext returns true if there are more items to iterate over.
136
>
return !i.FinishedIteration
137
>
}
138
139
// GetState returns the encoded iterator state