From 5f15d3ad10e9cfb458050b107cd108bd889de47a Mon Sep 17 00:00:00 2001 From: Lory Cloutier <118481783+lorycloutier@users.noreply.github.com> Date: Thu, 15 Dec 2022 19:36:53 -0600 Subject: [PATCH] Fix bulk ingest queries on multi-node databases (#2375) CLOUD-1252 Implemented Jaffee's fix of checking for b.useShardTransactionalEndpoint and only running the start/finish transaction block if it's false. Moved stats timing to a separate defer so it could stay out of the if. (cherry picked from commit b1f5264a4b7ade6a9a46123f98b71e8895723cd7) --- batch/batch.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/batch/batch.go b/batch/batch.go index fc729f807..9478d8cf4 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -742,23 +742,27 @@ var ErrBatchNowStale = errors.New("batch is stale and needs to be imported (howe func (b *Batch) Import() error { ctx := context.Background() start := time.Now() - trns, err := b.importer.StartTransaction(ctx, "", b.prevDuration*10, false, time.Hour) - if err != nil { - return errors.Wrap(err, "starting transaction") + if !b.useShardTransactionalEndpoint { + trns, err := b.importer.StartTransaction(ctx, "", b.prevDuration*10, false, time.Hour) + if err != nil { + return errors.Wrap(err, "starting transaction") + } + defer func() { + if trns != nil { + if trnsl, err := b.importer.FinishTransaction(ctx, trns.ID); err != nil { + b.log.Errorf("error finishing transaction: %v. trns: %+v", err, trnsl) + } + } + }() } defer func() { - if trns != nil { - if trnsl, err := b.importer.FinishTransaction(ctx, trns.ID); err != nil { - b.log.Errorf("error finishing transaction: %v. trns: %+v", err, trnsl) - } - } b.importer.StatsTiming(MetricBatchImportDurationSeconds, time.Since(start), 1.0) }() size := len(b.ids) transStart := time.Now() // first we need to translate the toTranslate, then fill out the missing row IDs - err = b.doTranslation() + err := b.doTranslation() if err != nil { return errors.Wrap(err, "doing Translation") }