@@ -493,6 +493,7 @@ func (txn *Transaction) dumpBatchLocked(ctx context.Context, offset int) error {
493
493
"WORKSPACE-QUOTA-ACQUIRE" ,
494
494
zap .Uint64 ("quota" , quota ),
495
495
zap .Uint64 ("remaining" , remaining ),
496
+ zap .String ("txn" , txn .op .Txn ().DebugString ()),
496
497
)
497
498
txn .writeWorkspaceThreshold += quota
498
499
txn .extraWriteWorkspaceThreshold += quota
@@ -513,8 +514,10 @@ func (txn *Transaction) dumpBatchLocked(ctx context.Context, offset int) error {
513
514
"WORKSPACE-QUOTA-RELEASE" ,
514
515
zap .Uint64 ("quota" , txn .extraWriteWorkspaceThreshold ),
515
516
zap .Uint64 ("remaining" , remaining ),
517
+ zap .String ("txn" , txn .op .Txn ().DebugString ()),
516
518
)
517
519
txn .extraWriteWorkspaceThreshold = 0
520
+ txn .writeWorkspaceThreshold = txn .engine .config .writeWorkspaceThreshold
518
521
}
519
522
520
523
if dumpAll {
@@ -544,7 +547,7 @@ func (txn *Transaction) dumpBatchLocked(ctx context.Context, offset int) error {
544
547
}
545
548
546
549
func (txn * Transaction ) dumpInsertBatchLocked (ctx context.Context , offset int , size * uint64 , pkCount * int ) error {
547
- tbSize := make (map [uint64 ]uint64 )
550
+ tbSize := make (map [uint64 ]int )
548
551
tbCount := make (map [uint64 ]int )
549
552
skipTable := make (map [uint64 ]bool )
550
553
@@ -556,8 +559,8 @@ func (txn *Transaction) dumpInsertBatchLocked(ctx context.Context, offset int, s
556
559
continue
557
560
}
558
561
if txn .writes [i ].typ == INSERT && txn .writes [i ].fileName == "" {
562
+ tbSize [txn .writes [i ].tableId ] += txn .writes [i ].bat .Size ()
559
563
tbCount [txn .writes [i ].tableId ] += txn .writes [i ].bat .RowCount ()
560
- tbSize [txn .writes [i ].tableId ] += uint64 (txn .writes [i ].bat .Size ())
561
564
}
562
565
}
563
566
@@ -568,12 +571,12 @@ func (txn *Transaction) dumpInsertBatchLocked(ctx context.Context, offset int, s
568
571
sort .Slice (keys , func (i , j int ) bool {
569
572
return tbSize [keys [i ]] < tbSize [keys [j ]]
570
573
})
571
- sum := uint64 ( 0 )
574
+ sum := 0
572
575
for _ , k := range keys {
573
576
if tbCount [k ] >= txn .engine .config .insertEntryMaxCount {
574
577
continue
575
578
}
576
- if sum + tbSize [k ] >= txn .writeWorkspaceThreshold {
579
+ if uint64 ( sum + tbSize [k ]) >= txn .commitWorkspaceThreshold {
577
580
break
578
581
}
579
582
sum += tbSize [k ]
@@ -612,11 +615,12 @@ func (txn *Transaction) dumpInsertBatchLocked(ctx context.Context, offset int, s
612
615
* size += uint64 (bat .Size ())
613
616
* pkCount += bat .RowCount ()
614
617
// skip rowid
615
- newBat := batch .NewWithSize (len (bat .Vecs ) - 1 )
616
- newBat .SetAttributes (bat .Attrs [1 :])
617
- newBat .Vecs = bat .Vecs [1 :]
618
- newBat .SetRowCount (bat .Vecs [0 ].Length ())
619
- mp [tbKey ] = append (mp [tbKey ], newBat )
618
+ newBatch := batch .NewWithSize (len (bat .Vecs ) - 1 )
619
+ newBatch .SetAttributes (bat .Attrs [1 :])
620
+ newBatch .Vecs = bat .Vecs [1 :]
621
+ newBatch .SetRowCount (bat .Vecs [0 ].Length ())
622
+ mp [tbKey ] = append (mp [tbKey ], newBatch )
623
+ defer bat .Clean (txn .proc .GetMPool ())
620
624
621
625
keepElement = false
622
626
}
@@ -719,12 +723,12 @@ func (txn *Transaction) dumpDeleteBatchLocked(ctx context.Context, offset int, s
719
723
deleteCnt += bat .RowCount ()
720
724
* size += uint64 (bat .Size ())
721
725
722
- newBat := batch .NewWithSize (len (bat .Vecs ))
723
- newBat .SetAttributes (bat .Attrs )
724
- newBat .Vecs = bat .Vecs
725
- newBat .SetRowCount (bat .Vecs [0 ].Length ())
726
+ newBatch := batch .NewWithSize (len (bat .Vecs ))
727
+ newBatch .SetAttributes (bat .Attrs )
728
+ newBatch .Vecs = bat .Vecs
729
+ newBatch .SetRowCount (bat .Vecs [0 ].Length ())
726
730
727
- mp [tbKey ] = append (mp [tbKey ], newBat )
731
+ mp [tbKey ] = append (mp [tbKey ], newBatch )
728
732
defer bat .Clean (txn .proc .GetMPool ())
729
733
730
734
keepElement = false
@@ -1308,6 +1312,22 @@ func (txn *Transaction) Commit(ctx context.Context) ([]txn.TxnRequest, error) {
1308
1312
return nil , nil
1309
1313
}
1310
1314
1315
+ if err := txn .IncrStatementID (ctx , true ); err != nil {
1316
+ return nil , err
1317
+ }
1318
+
1319
+ if err := txn .transferTombstonesByCommit (ctx ); err != nil {
1320
+ return nil , err
1321
+ }
1322
+
1323
+ if err := txn .mergeTxnWorkspaceLocked (ctx ); err != nil {
1324
+ return nil , err
1325
+ }
1326
+ if err := txn .dumpBatchLocked (ctx , - 1 ); err != nil {
1327
+ return nil , err
1328
+ }
1329
+ txn .traceWorkspaceLocked (true )
1330
+
1311
1331
if txn .workspaceSize > 10 * mpool .MB {
1312
1332
logutil .Info (
1313
1333
"BIG-TXN" ,
@@ -1332,23 +1352,6 @@ func (txn *Transaction) Commit(ctx context.Context) ([]txn.TxnRequest, error) {
1332
1352
)
1333
1353
}
1334
1354
1335
- if err := txn .IncrStatementID (ctx , true ); err != nil {
1336
- return nil , err
1337
- }
1338
-
1339
- if err := txn .transferTombstonesByCommit (ctx ); err != nil {
1340
- return nil , err
1341
- }
1342
-
1343
- if err := txn .mergeTxnWorkspaceLocked (ctx ); err != nil {
1344
- return nil , err
1345
- }
1346
- if err := txn .dumpBatchLocked (ctx , - 1 ); err != nil {
1347
- return nil , err
1348
- }
1349
-
1350
- txn .traceWorkspaceLocked (true )
1351
-
1352
1355
if ! txn .hasS3Op .Load () &&
1353
1356
txn .op .TxnOptions ().CheckDupEnabled () {
1354
1357
if err := txn .checkDup (); err != nil {
0 commit comments