Skip to content

Commit

Permalink
importer: Fix updated < time violations due to clock skew
Browse files Browse the repository at this point in the history
There can be some clock skew between us and logs.tf. This could result in
our local updated time being less than the log's time, violating the check
constraint. Fix this by taking the greatest of now and time. When updating
logs, take the greatest between now and updated + 1 (to ensure updated
always changes).

Fixes: 7aed5b6 ("Add updated field to logs")
Signed-off-by: Sean Anderson <[email protected]>
  • Loading branch information
Forty-Bot committed Feb 23, 2024
1 parent 51f31d2 commit a9ae28b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion trends/importer/link_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def link_logs(args, c):
cur.execute("""UPDATE log
SET
demoid = linked.demoid,
updated = extract(EPOCH FROM now())::BIGINT
updated = greatest(extract(EPOCH FROM now())::BIGINT, log.updated + 1)
FROM linked
WHERE log.logid = linked.logid;""")
cur.execute("COMMIT;")
Expand Down
2 changes: 1 addition & 1 deletion trends/importer/link_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def link_matches(args, c):
cur.execute("""UPDATE log SET
league = log_matches.league,
matchid = log_matches.matchid,
updated = extract(EPOCH FROM now())::BIGINT,
updated = greatest(extract(EPOCH FROM now())::BIGINT, log.updated + 1),
team1_is_red = log_matches.team1_is_red
FROM log_matches
WHERE log.logid = log_matches.logid;""")
Expand Down
2 changes: 1 addition & 1 deletion trends/importer/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def import_log(c, logid, log):
(SELECT mapid FROM map WHERE map = %(map)s),
%(red_score)s, %(blue_score)s, %(AD_scoring)s, %(uploader_playerid)s,
(SELECT nameid FROM name WHERE name = %(uploader_name)s),
extract(EPOCH FROM now())::BIGINT
greatest(extract(EPOCH FROM now())::BIGINT, %(date)s)
);""",
info)
c.execute("INSERT INTO log_json (logid, data) VALUES (%s, %s)", (logid, log))
Expand Down

0 comments on commit a9ae28b

Please sign in to comment.