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.
This commit is contained in:
Lory Cloutier 2022-12-15 19:36:53 -06:00 committed by GitHub
parent 27963441ab
commit b1f5264a4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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")
}