Skip to content

Commit 010be60

Browse files
authored
Merge pull request #561 from cybertec-postgresql/560-txid-over-max-int4
[-] alter timetable.execution_log.txid column type to bigint, fixes #560
2 parents f391cfe + 7b6c853 commit 010be60

File tree

8 files changed

+27
-18
lines changed

8 files changed

+27
-18
lines changed

internal/pgengine/migration.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ var Migrations func() migrator.Option = func() migrator.Option {
117117
return ExecuteMigrationScript(ctx, tx, "00534.sql")
118118
},
119119
},
120+
&migrator.Migration{
121+
Name: "00560 Alter txid column to bigint",
122+
Func: func(ctx context.Context, tx pgx.Tx) error {
123+
return ExecuteMigrationScript(ctx, tx, "00560.sql")
124+
},
125+
},
120126
// adding new migration here, update "timetable"."migration" in "sql/init.sql"
121127
// and "dbapi" variable in main.go!
122128

internal/pgengine/pgengine_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestSchedulerFunctions(t *testing.T) {
142142
var chains []pgengine.ChainTask
143143
tx, txid, err := pge.StartTransaction(ctx, 0)
144144
assert.NoError(t, err, "Should start transaction")
145-
assert.Greater(t, txid, 0, "Should return transaction id")
145+
assert.Greater(t, txid, int64(0), "Should return transaction id")
146146
assert.NoError(t, pge.GetChainElements(ctx, &chains, 0), "Should no error in clean database")
147147
assert.Empty(t, chains, "Should be empty in clean database")
148148
pge.CommitTransaction(ctx, tx)
@@ -152,7 +152,7 @@ func TestSchedulerFunctions(t *testing.T) {
152152
var paramVals []string
153153
tx, txid, err := pge.StartTransaction(ctx, 0)
154154
assert.NoError(t, err, "Should start transaction")
155-
assert.Greater(t, txid, 0, "Should return transaction id")
155+
assert.Greater(t, txid, int64(0), "Should return transaction id")
156156
assert.NoError(t, pge.GetChainParamValues(ctx, &paramVals, &pgengine.ChainTask{
157157
TaskID: 0,
158158
ChainID: 0}), "Should no error in clean database")
@@ -170,7 +170,7 @@ func TestSchedulerFunctions(t *testing.T) {
170170
t.Run("Check ExecuteSQLCommand function", func(t *testing.T) {
171171
tx, txid, err := pge.StartTransaction(ctx, 0)
172172
assert.NoError(t, err, "Should start transaction")
173-
assert.Greater(t, txid, 0, "Should return transaction id")
173+
assert.Greater(t, txid, int64(0) , "Should return transaction id")
174174
f := func(sql string, params []string) error {
175175
_, err := pge.ExecuteSQLCommand(ctx, tx, sql, params)
176176
return err

internal/pgengine/sql/ddl.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ COMMENT ON TABLE timetable.log IS
106106
CREATE TABLE timetable.execution_log (
107107
chain_id BIGINT,
108108
task_id BIGINT,
109-
txid INTEGER NOT NULL,
109+
txid BIGINT NOT NULL,
110110
last_run TIMESTAMPTZ DEFAULT now(),
111111
finished TIMESTAMPTZ,
112112
pid BIGINT,

internal/pgengine/sql/init.sql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ CREATE TABLE timetable.migration(
1313
INSERT INTO
1414
timetable.migration (id, version)
1515
VALUES
16-
(0, '00259 Restart migrations for v4'),
17-
(1, '00305 Fix timetable.is_cron_in_time'),
18-
(2, '00323 Append timetable.delete_job function'),
19-
(3, '00329 Migration required for some new added functions'),
20-
(4, '00334 Refactor timetable.task as plain schema without tree-like dependencies'),
21-
(5, '00381 Rewrite active chain handling'),
22-
(6, '00394 Add started_at column to active_session and active_chain tables'),
23-
(7, '00417 Rename LOG database log level to INFO'),
24-
(8, '00436 Add txid column to timetable.execution_log'),
25-
(9, '00534 Use cron_split_to_arrays() in cron domain check');
16+
(0, '00259 Restart migrations for v4'),
17+
(1, '00305 Fix timetable.is_cron_in_time'),
18+
(2, '00323 Append timetable.delete_job function'),
19+
(3, '00329 Migration required for some new added functions'),
20+
(4, '00334 Refactor timetable.task as plain schema without tree-like dependencies'),
21+
(5, '00381 Rewrite active chain handling'),
22+
(6, '00394 Add started_at column to active_session and active_chain tables'),
23+
(7, '00417 Rename LOG database log level to INFO'),
24+
(8, '00436 Add txid column to timetable.execution_log'),
25+
(9, '00534 Use cron_split_to_arrays() in cron domain check'),
26+
(10, '00560 Alter txid column to bigint');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE timetable.execution_log
2+
ALTER txid TYPE BIGINT;

internal/pgengine/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ type ChainTask struct {
5454
Timeout int `db:"timeout"` // in milliseconds
5555
StartedAt time.Time `db:"-"`
5656
Duration int64 `db:"-"` // in microseconds
57-
Txid int `db:"-"`
57+
Txid int64 `db:"-"`
5858
}
5959

6060
// StartTransaction returns transaction object, transaction id and error
61-
func (pge *PgEngine) StartTransaction(ctx context.Context, chainID int) (tx pgx.Tx, txid int, err error) {
61+
func (pge *PgEngine) StartTransaction(ctx context.Context, chainID int) (tx pgx.Tx, txid int64, err error) {
6262
tx, err = pge.ConfigDb.Begin(ctx)
6363
if err != nil {
6464
return

internal/scheduler/chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (sch *Scheduler) executeChain(ctx context.Context, chain Chain) {
172172
var ChainTasks []pgengine.ChainTask
173173
var bctx context.Context
174174
var cancel context.CancelFunc
175-
var txid int
175+
var txid int64
176176

177177
ctx, cancel = getTimeoutContext(ctx, sch.Config().Resource.ChainTimeout, chain.Timeout)
178178
if cancel != nil {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252
commit = "000000"
5353
version = "master"
5454
date = "unknown"
55-
dbapi = "00534"
55+
dbapi = "00560"
5656
)
5757

5858
func printVersion() {

0 commit comments

Comments
 (0)