214
ctx context.Context,
215
request *TrimHistoryBranchRequest,
217
>
218
>
shardID := request.ShardID
219
>
minNodeID := common.FirstEventID
220
>
maxNodeID := request.NodeID + 1
221
>
pageSize := trimHistoryBranchPageSize
222
>
223
>
branch, err := m.GetHistoryBranchUtil().ParseHistoryBranchInfo(request.BranchToken)
224
>
if err != nil {
225
return nil, fmt.Errorf("unable to parse history branch info: %w", err)
226
}
228
>
branchID := branch.BranchId
229
>
branchAncestors := branch.Ancestors
230
>
231
>
// merge tree ID & branch ID into branch ancestors so the processing logic is simple
232
>
beginNodeID := common.FirstEventID
233
>
if len(branch.Ancestors) > 0 {
234
beginNodeID = branch.Ancestors[len(branch.Ancestors)-1].GetEndNodeId()
235
}
236
>
branchAncestors = append(branchAncestors, &persistencespb.HistoryBranchRange{
history_manager.go
237
>
BranchId: branchID,
238
>
BeginNodeId: beginNodeID,
239
>
EndNodeId: maxNodeID,
240
>
})
241
>
242
>
var pageToken []byte
243
>
transactionIDToNode := map[int64]historyNodeMetadata{}
244
>
for doContinue := true; doContinue; doContinue = len(pageToken) > 0 {
245
>
token, err := m.deserializeToken(pageToken, minNodeID-1, defaultLastTransactionID)
246
>
if err != nil {
247
return nil, fmt.Errorf("unable to deserialize token: %w", err)
248
}
249
251
>
ctx,
252
>
request.BranchToken,
253
>
shardID,
254
>
branchAncestors,
255
>
minNodeID,
256
>
maxNodeID,
257
>
token,
258
>
pageSize,
259
>
true,
260
>
)
261
>
if err != nil {
262
return nil, fmt.Errorf("unable to read raw history branch: %w", err)
263
}
264
266
>
for _, node := range nodes {
267
>
transactionIDToNode[node.TransactionID] = historyNodeMetadata{
268
>
branchInfo: &persistencespb.HistoryBranch{
269
>
TreeId: treeID,
270
>
BranchId: branchID,
271
>
Ancestors: branchAncestors[0:token.CurrentRangeIndex],
272
>
},
273
>
nodeID: node.NodeID,
274
>
transactionID: node.TransactionID,
275
>
prevTransactionID: node.PrevTransactionID,
276
>
}
277
>
}
278
280
>
if err != nil {
281
return nil, fmt.Errorf("unable to serialize token: %w", err)
282
}
283
}
284
286
>
request.NodeID,
287
>
request.TransactionID,
288
>
transactionIDToNode,
289
>
)
290
>
if err != nil {
291
m.logger.Debug("unable to trim history branch due to existing history node not fully onboarded", tag.Error(err))
292
return &TrimHistoryBranchResponse{}, nil