Skip to content

Commit 60a3e1b

Browse files
committed
internal/datastore/pg: template repair batch size
1 parent 7ab5e70 commit 60a3e1b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

internal/datastore/postgres/postgres.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ const (
6969
repairBatchSize = 1_000_000
7070
)
7171

72-
// queryLoopXactID performs pg_current_xact_id() in a server-side loop in the
73-
// database in order to increment the xact_id.
74-
var queryLoopXactID = fmt.Sprintf(`DO $$
75-
BEGIN
76-
FOR i IN 1..%d LOOP
77-
PERFORM pg_current_xact_id(); ROLLBACK;
78-
END LOOP;
79-
END $$;`, repairBatchSize)
80-
8172
var livingTupleConstraints = []string{"uq_relation_tuple_living_xid", "pk_relation_tuple"}
8273

8374
func init() {
@@ -573,8 +564,7 @@ func (pgd *pgDatastore) repairTransactionIDs(ctx context.Context, outputProgress
573564

574565
for i := 0; i < counterDelta; i++ {
575566
batchCount := min(repairBatchSize, counterDelta-i)
576-
577-
if _, err := conn.Exec(ctx, queryLoopXactID); err != nil {
567+
if _, err := conn.Exec(ctx, queryLoopXactID(batchCount)); err != nil {
578568
return err
579569
}
580570

@@ -596,6 +586,17 @@ func (pgd *pgDatastore) repairTransactionIDs(ctx context.Context, outputProgress
596586
return nil
597587
}
598588

589+
// queryLoopXactID performs pg_current_xact_id() in a server-side loop in the
590+
// database in order to increment the xact_id.
591+
func queryLoopXactID(batchSize int) string {
592+
return fmt.Sprintf(`DO $$
593+
BEGIN
594+
FOR i IN 1..%d LOOP
595+
PERFORM pg_current_xact_id(); ROLLBACK;
596+
END LOOP;
597+
END $$;`, batchSize)
598+
}
599+
599600
// RepairOperations returns the available repair operations for the datastore.
600601
func (pgd *pgDatastore) RepairOperations() []datastore.RepairOperation {
601602
return []datastore.RepairOperation{

0 commit comments

Comments
 (0)