-
Notifications
You must be signed in to change notification settings - Fork 38
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
[Streaming Replication - 3rd] Add LSN type and time conversion to and from ms-since-Y2K #53
Conversation
osaxma
commented
Sep 9, 2022
- Adds Log Sequence Number type -- used widely by the Streaming Replication Messages
- Adds conversion form and to microseconds since 2000-01-01 (the baseline time used by PostgreSQL in replication messages).
lib/src/time_converters.dart
Outdated
@@ -0,0 +1,12 @@ | |||
const _microsecFromUnixEpochToY2K = 946684800 * 1000000; |
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.
Nitpicking: This seems to be a magic number. Can we get the same value from DateTime.utc([...?]).microsecondsSinceEpoch
?
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.
Yeah I don't know what I was thinking.. fixed!
lib/src/types.dart
Outdated
} | ||
|
||
static int _parseLSNString(String string) { | ||
int upperhalf; |
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.
delete these two
lib/src/types.dart
Outdated
if (halves.length != 2) { | ||
throw Exception('Invalid LSN String was given ($string)'); | ||
} | ||
upperhalf = int.parse(halves[0], radix: 16) << 32; |
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.
final upperhalf =...
same with lowerhalf
lib/src/types.dart
Outdated
int lowerhalf; | ||
final halves = string.split('/'); | ||
if (halves.length != 2) { | ||
throw Exception('Invalid LSN String was given ($string)'); |
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.
Make it FormatException
or maybe PostgreSQLException
.
test/types_test.dart
Outdated
// These two numbers are equal but in different formats | ||
// | ||
// see: https://www.postgresql.org/docs/current/datatype-pg-lsn.html | ||
const _lsnStringSample = '16/B374D848'; |
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.
I think these could be inlined in the test, with the above comment at the level of the test()
.
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.
fixed.