-
Notifications
You must be signed in to change notification settings - Fork 12
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
64 bit key allocation #283
Conversation
build/_build.csproj.DotSettings
Outdated
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue"><Policy><Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy></s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=f9fce829_002De6f4_002D4cb2_002D80f1_002D5497c44f51df/@EntryIndexedValue"><Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy></s: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.
I'm a bit confused about the extra rules here. Was this intentional? (ditto for Nevermore.sln.DotSettings)
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.
The DotSettings file is owned by Rider.
Every so often, a new version of Rider invents some new settings and it decides it wants to write them into these DotSettings files.
I thought that was what was happening here, so I didn't really pay it much attention.
On second look though, I see it has "UserSettings" which means it isn't that. I'll back these out of the branch, thanks
d0fb86a
to
20840f1
Compare
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.
LGTM otherwise, nice stuff!
SELECT @blockSize | ||
SELECT CAST(@blockSize as bigint) -- type must be the same as @result |
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.
nit: is there any particular reason to go for casting rather than changing the type of @blockSize
itself?
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, blocksize is an input parameter to the stored procedure. Changing it to bigint
would likely require callers in C# to change their code from int
to long
and be a breaking change.
We can do breaking changes if we need to, but in that case the block size doesn't need to exceed 2 billion; 32 bit int is perfectly good there, so it's less work for everyone to leave that be. This cast is the tradeoff 😄
For Octopus internal developers: There is an RFC for this here, which has received positive feedback and a green light to move ahead
Background
Nevermore's Key Allocation logic uses 32 bit integers. This means if we ever tried to allocate an ID greater than
2,147,483,647
, anOverflowException
will be thrown from within Nevermore and the operation will fail.Because the nevermore key allocator allocates ID's in blocks of (by default) 20, this could happen before the actual table itself gets 2 billion rows. Alternatively, some tables are transactional in nature, where rows may be inserted/deleted rapidly, causing the ID to reach 2 billion even if there are only a small number of rows at any given time.
Best practice for integer-based database ID's is to use 64-bit rather than 32-bit integers. This corresponds to the
bigint
type in SQL serverResults
This PR updates the
KeyAllocator
andIKeyAllocator
to work in terms of 64 bit values (long
in C#), enabling the use ofbigint
in the underlyingKeyAllocation
SQL database table.The C# code has been deliberately written to work with either the prior 32 bit
KeyAllocation
table, or an updated 64 bit table. This means users of Nevermore can upgrade to this version without requiring any database/schema migrations. They can then (if they would like to) alter their KeyAllocation table to be 64 bit at a future moment of their choosing.Public API Breaking Change
While this is deliberately not breaking at the database level, the
IKeyAllocator
interface,KeyAllocator
class, andStringPrimaryKeyHandler
class have all changed fromint
tolong
. These are public types and if you use them you will need to update your code accordingly. It should be a small and simple change.How to enable 64 bit key allocation
Once upgrading to this version of Nevermore, you will then need to create a database migration to change your
KeyAllocation
table, and theGetNextKeyBlock
stored procedure.It will likely look something like this: