use real time for events
NOW() is time of transaction start. For long transaction, there could be race and some other transactions which ended earlier can have newer events. clock_timestamp returns real time (changes during transaction), so it should be better for this case. Fixes: https://pagure.io/koji/issue/1747
This commit is contained in:
parent
8172bff053
commit
b54c32af1a
2 changed files with 18 additions and 2 deletions
16
docs/schema-upgrade-1.20-1.21.sql
Normal file
16
docs/schema-upgrade-1.20-1.21.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- upgrade script to migrate the Koji database schema
|
||||
-- from version 1.20 to 1.21
|
||||
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- make better events
|
||||
ALTER TABLE events ALTER COLUMN time SET NOT NULL;
|
||||
ALTER TABLE events ALTER COLUMN time SET DEFAULT clock_timestamp();
|
||||
|
||||
CREATE OR REPLACE FUNCTION get_event() RETURNS INTEGER AS '
|
||||
INSERT INTO events (time) VALUES (clock_timestamp());
|
||||
SELECT currval(''events_id_seq'')::INTEGER;
|
||||
' LANGUAGE SQL;
|
||||
|
||||
COMMIT;
|
||||
|
|
@ -7,12 +7,12 @@ BEGIN WORK;
|
|||
-- in the event that the system clock rolls back, event_ids will retain proper sequencing
|
||||
CREATE TABLE events (
|
||||
id SERIAL NOT NULL PRIMARY KEY,
|
||||
time TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
time TIMESTAMP NOT NULL DEFAULT clock_timestamp()
|
||||
) WITHOUT OIDS;
|
||||
|
||||
-- A function that creates an event and returns the id, used as DEFAULT value for versioned tables
|
||||
CREATE FUNCTION get_event() RETURNS INTEGER AS '
|
||||
INSERT INTO events (time) VALUES (''now'');
|
||||
INSERT INTO events (time) VALUES (clock_timestamp());
|
||||
SELECT currval(''events_id_seq'')::INTEGER;
|
||||
' LANGUAGE SQL;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue