Skip to content

Commit 177e46d

Browse files
authored
Feat: Add fallback to PDML API (#50)
* Feat: Add fallback to PDML API * add log
1 parent 23968ef commit 177e46d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

spanner/spanner.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ func (sc *SpannerClient) InsertUpdateOrDeleteStatement(ctx context.Context, quer
226226
return nil
227227
}, spanner.TransactionOptions{CommitOptions: sc.BuildCommitOptions()})
228228

229+
if err != nil && strings.Contains(err.Error(), "The transaction contains too many mutations") {
230+
sc.Logger.Debug("Falling back to partitioned dml API")
231+
_, err = sc.Client.PartitionedUpdate(ctx, *buildStmt(&query))
232+
}
233+
234+
if err != nil {
235+
sc.Logger.Error("Error while InsertUpdateOrDeleteStatement - "+query.Query, zap.Error(err))
236+
}
237+
229238
return &rowsResult, ExecuteStreamingSqlAPI, err
230239
}
231240

@@ -569,7 +578,14 @@ func (sc *SpannerClient) DeleteUsingMutations(ctx context.Context, query respons
569578
spanner.ApplyAtLeastOnce(),
570579
spanner.ApplyCommitOptions(sc.BuildCommitOptions()))
571580
if err != nil {
572-
sc.Logger.Error("Error while Mutation Delete - "+query.Query, zap.Error(err))
581+
if strings.Contains(err.Error(), "The transaction contains too many mutations") {
582+
sc.Logger.Debug("Falling back to partitioned dml API")
583+
_, err = sc.Client.PartitionedUpdate(ctx, *buildStmt(&query))
584+
}
585+
586+
if err != nil {
587+
sc.Logger.Error("Error while Mutation Delete - "+query.Query, zap.Error(err))
588+
}
573589
return nil, CommitAPI, err
574590
}
575591

0 commit comments

Comments
 (0)