-
Notifications
You must be signed in to change notification settings - Fork 63
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
Switch to SPI for metadata functions #110
Changes from all commits
063a7d2
6a1868a
48e2b64
1825e72
ef7294d
764669f
08c6632
73d449c
54283da
bb55332
7b58b23
8d53d73
f223f68
ce5f2cb
4c6e189
e9a4f9a
c6149bd
4e09d61
54cedf2
87580e2
b22f13e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,14 +236,11 @@ master_create_worker_shards(PG_FUNCTION_ARGS) | |
|
||
for (shardIndex = 0; shardIndex < shardCount; shardIndex++) | ||
{ | ||
uint64 shardId = NextSequenceId(SHARD_ID_SEQUENCE_NAME); | ||
int64 shardId = -1; | ||
int32 placementCount = 0; | ||
uint32 placementIndex = 0; | ||
uint32 roundRobinNodeIndex = shardIndex % workerNodeCount; | ||
|
||
List *extendedDDLCommands = ExtendedDDLCommandList(distributedTableId, shardId, | ||
ddlCommandList); | ||
|
||
/* initialize the hash token space for this shard */ | ||
text *minHashTokenText = NULL; | ||
text *maxHashTokenText = NULL; | ||
|
@@ -256,6 +253,15 @@ master_create_worker_shards(PG_FUNCTION_ARGS) | |
shardMaxHashToken = INT_MAX; | ||
} | ||
|
||
/* insert the shard metadata row along with its min/max values */ | ||
minHashTokenText = IntegerToText(shardMinHashToken); | ||
maxHashTokenText = IntegerToText(shardMaxHashToken); | ||
shardId = CreateShardRow(distributedTableId, shardStorageType, minHashTokenText, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to have switched to associating the id column with its sequence, with an auto-increment. Any reason why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also error out if we were unable to create placements. Thus creating the shard row after that was considered safe. Will the shard row we've created get rolled back if we error out on placement creation? (See line 296 for the error) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By using a default value, the C code can remain ignorant of the names of sequences used by CitusDB or pg_shard. This means the only place that knowledge lives will be in the SQL install script: the C code will not have any CitusDB/pg_shard detection code for metadata functionality.
Both the old and the new approaches are wrapped in a transaction. They aren't actually any different. We never "creat[ed] the shard row after that was considered safe"… we had an atomic transaction that resulted in other readers seeing the shard once placement rows showing up at once. The practical reason for switching the order is because SPI enforces the foreign key constraint, so the old order is impossible (I even tried using a FWIW I tested failures at each point of creation, both with the old and new implementation, and they exhibit identical functionality. I also tested visibility of modifications, and they were and are atomic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed at length over the past few weeks. Sticking with this new approach. (done) |
||
maxHashTokenText); | ||
|
||
List *extendedDDLCommands = ExtendedDDLCommandList(distributedTableId, shardId, | ||
ddlCommandList); | ||
|
||
for (placementIndex = 0; placementIndex < placementAttemptCount; placementIndex++) | ||
{ | ||
int32 candidateNodeIndex = | ||
|
@@ -269,13 +275,7 @@ master_create_worker_shards(PG_FUNCTION_ARGS) | |
extendedDDLCommands); | ||
if (created) | ||
{ | ||
uint64 shardPlacementId = 0; | ||
ShardState shardState = STATE_FINALIZED; | ||
|
||
|
||
shardPlacementId = NextSequenceId(SHARD_PLACEMENT_ID_SEQUENCE_NAME); | ||
InsertShardPlacementRow(shardPlacementId, shardId, shardState, | ||
nodeName, nodePort); | ||
CreateShardPlacementRow(shardId, STATE_FINALIZED, nodeName, nodePort); | ||
placementCount++; | ||
} | ||
else | ||
|
@@ -298,12 +298,6 @@ master_create_worker_shards(PG_FUNCTION_ARGS) | |
"requested replication factor of %d.", | ||
placementCount, replicationFactor))); | ||
} | ||
|
||
/* insert the shard metadata row along with its min/max values */ | ||
minHashTokenText = IntegerToText(shardMinHashToken); | ||
maxHashTokenText = IntegerToText(shardMaxHashToken); | ||
InsertShardRow(distributedTableId, shardId, shardStorageType, | ||
minHashTokenText, maxHashTokenText); | ||
} | ||
|
||
if (QueryCancelPending) | ||
|
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 initially thought we had shardId's defined as unsigned everywhere, but that doesn't seem to be the case. Do you know why NextSequenceId was returning uint64's, but shardId's were int64's everywhere? Do we have other places with this inconsistency?
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.
Some of the CitusDB-inspired code uses unsigned integer types even though all of PostgreSQL's built-in integer types are signed. We kept the code identical before to have it remain identical to CitusDB where possible, but this has been bothering me for some time now, so I've been changing unsigned types to signed as I touch any of the affected lines.
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.
Not changing in this review, but I will go through and eradicate unsigned integers from
pg_shard
in another branch. (done)