-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
db/syncstrings: mark syncstrings with too large patches as "huge" #5818
Conversation
c0daba3
to
2d322ae
Compare
@@ -609,7 +609,7 @@ exports.extend_PostgreSQL = (ext) -> class PostgreSQL extends ext | |||
dbg("determine inactive syncstring ids") | |||
@_query | |||
query : 'SELECT string_id FROM syncstrings' | |||
where : [{'last_active <= $::TIMESTAMP' : misc.days_ago(opts.age_days)}, 'archived IS NULL'] | |||
where : [{'last_active <= $::TIMESTAMP' : misc.days_ago(opts.age_days)}, 'archived IS NULL', 'huge IS NOT FALSE'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be "huge IS NOT TRUE" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
… ignore them – for now
2d322ae
to
b7949a5
Compare
So, it took me a while to figure out what went wrong. I think this is something to look into. The problem is the following: in
and from there time=null is in the serialized patch stream and well, un-archiving is broken. I added a patch to check if this is a string and convert it to an integer first (there are no fractions). That works. a57cd96 However, I don't understand the dance from Besides that, maybe we should add a check that the time is really a Date (or more general, verifying that all patches to be valid) before packaging up as a blob. |
Usually it is because JSON mangles Date objects, e.g., > JSON.parse(JSON.stringify(new Date()))
'2022-04-01T14:20:44.627Z'
> new Date()
2022-04-01T14:20:46.198Z That said, in this particular case this might have just been a side effect of converting from RethinkDB to PostgreSQL, and not wanting to change too much code.
How is it a string? Maybe we should figure that out... The query is:
and according to the postgresql docs https://www.postgresql.org/docs/current/functions-datetime.html
is definitely a number, not a string. So it's weird that you're getting a string. That must have been painful to debug. In any case, I'm going to merge this as is. |
I've investigated this, and you won't believe it. It's a matter of "integer" vs. "double precision" vs. "numeric" data types. I did a couple of tests, e.g. Then in a node session using our database package:
ok wow. this is brianc/node-pg-types#28 and technically, yes, it's not safe to convert them to plain javascript integers. Although I wonder, aren't there BigInts in Javascript 🤔 In any case, the postgres docs state:
also
I searched for other uses of "extract" in cocalc's code, but I only found this one. |
! That explains things. Gees. Incidentally, I was looking at an older version of the docs (first google hit) when I wrote my message, and only changed the link to the latest version at the last moment. BigInts don't interoperate with anything else -- they're potentially even more annoying that a string. One surprise to me is that multiplication of huge BigInts in recent V8 is very fast, like in serious math software, due to them implementing serious algorithms (unlike Python). |
I use this a lot in our code. Do a case insensitive search. It should be capital letters, and I did use them properly elsewhere... |
I made this issue -- #5824 Hopefully you can fix it? |
Description
if the patches of a syncstring are too large:
testing: well, this is not so trivial. what I did:
raise new Error( ... )
right after the json stringify to simulate a problem. built it again … and thenenv MIN_AGE_DAYS=3 ./node_modules/.bin/cocalc-hub-maintenance-syncstrings
… indeed, the "huge" field got filled up for a few syncstrings.INSERT INTO patches' ... error: null value in column \"time\" of relation \"patches\" violates not-null constraint"
. I hope this is just a side effect of me tinkering around. I'll try to see if I can reproduce this or understand why I saw this error.Checklist: