597
ctx context.Context,
598
reqs []*writeTaskRequest,
599
>
) (createFairTasksResponse, error) {
db.go
600
>
if db.isDraining {
601
return createFairTasksResponse{}, softassert.UnexpectedInternalErr(db.logger, "CreateTasks can't be used in draining mode", nil)
602
}
603
605
>
defer db.Unlock()
606
>
607
>
if len(reqs) == 0 {
608
return nil, nil
609
}
610
611
>
newTasks := make(createFairTasksResponse)
db.go
612
>
newMaxLevel := make(map[subqueueIndex]fairLevel)
613
>
allTasks := make([]*persistencespb.AllocatedTaskInfo, len(reqs))
614
>
allSubqueues := make([]int, len(reqs))
615
>
for i, req := range reqs {
616
>
task := &persistencespb.AllocatedTaskInfo{
617
>
TaskId: req.id,
618
>
TaskPass: req.pass,
619
>
Data: req.taskInfo,
620
>
}
621
>
allTasks[i] = task
622
>
allSubqueues[i] = int(req.subqueue)
623
>
newTasks[req.subqueue] = append(newTasks[req.subqueue], task)
624
>
newMaxLevel[req.subqueue] = newMaxLevel[req.subqueue].max(req.fairLevel)
625
>
}
626
627
>
for sq, tasks := range newTasks {
db.go
628
>
db.subqueues[sq].ApproximateBacklogCount += int64(len(tasks))
629
>
}
630
631
// Unlike in CreateTasks, we can set the persisted FairMaxReadLevel before persisting.