-
Notifications
You must be signed in to change notification settings - Fork 68
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
CitusDB metadata interoperability #103
Conversation
055bd20
to
31a99da
Compare
I'm aware that this work in progress, but some early feedback. We were trying this out today to see if it would help make the CitusDB -> pg_shard migration path easier for CitusDB documentation purposes, since that seems to be the more common direction. We created a table using CitusDB with DISTRIBUTE BY APPEND and used this branch of pg_shard. One problem we ran into is that when doing an INSERT in an non-existing range we got "ERROR: cannot execute INSERT on a distributed table on master node", because pg_shard ExecutorStart executor hook falls back to CitusDB for zero-shard queries. This led to some confusion. The next problem we ran into is that pg_shard caches the metadata. Any change made to the metadata by CitusDB is not visible to pg_shard until a new session is started, this also led to some confusion. For example, performing \STAGE and then INSERT into the range would give "ERROR: no placements exist for shard with ID". Finally, we added a new shard using \STAGE, the range of which overlapped with an existing the shard. We then tried an INSERT on the overlapping range. It went to the first shard. We then started a new session to clear the cache, after which we got "ERROR: cannot modify multiple shards during a single query". This was expected, but I guess an INSERT should always go to at most one shard. It seems the more fundamental issue here is the caching. We might have to make changes to CitusDB to help pg_shard clear its cache or set up a trigger on the catalog table. |
Thanks @marcocitus… there was no intention of As far as caching goes… bleh. I forgot we had added caching. Do we anticipate having |
I had a quick clarification question. With these changes, which migration scenario do we intend to handle? (a) pg_shard -> CitusDB, (b) CitusDB -> pg_shard (shard rebalancer?), or (c) CitusDB <-> pg_shard CitusDB currently observes state changes when we \stage to a new shard (append partitioned), append to an existing shard, or rebalance a table. pg_shard observes state changes when we create shards for a new table, or fail to write to a shard placement (hash partitioned). Two other questions -- don't know, just asking. Who has the authoritative metadata, CitusDB or pg_shard with these changes? Under what conditions does the authority change? |
Because this PR actually causes That means the only possibility is stale metadata (i.e. from caching). So we'll want to address that. |
@ozgune what do you mean "migration scenario"? I can see:
Am I missing any other possibilities? |
@jasonmp85 Yup, I was curious more about the use-cases, where we needed to sync metadata between pg_shard and CitusDB.
I'm wonder if we can simplify the problem down to (pg_shard -> CitusDB). If we could and wanted to, could we then put a trigger on the pg_shard metadata to propagate the update to CitusDB system catalogs? |
Let's stop using the word sync. There is no syncing here. |
To clarify, everything is always in sync… there is no sync step. |
By the way, the migration step is to write out all normal tables except the |
If you're using |
I'm still figuring out how I want to test the CitusDB-specific parts of this, but the main code is complete. |
* sequence name. | ||
*/ | ||
static uint64 | ||
NextSequenceId(char *sequenceName) |
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 we pass the schema name as an argument to this function?
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.
We don't pass it into any other functions, and in the previous implementation of this function (essentially unchanged here) it was just a #define
we passed into makeRangeVar
or whatnot, so I don't see why it needs to be exposed: this function is for getting sequence values related to metadata (see the previous implementation, which was locked to the metadata schema), so it should encapsulate the knowledge of where they live.
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.
Function no longer exists; no problem.
c559161
to
befe15c
Compare
partkey) | ||
VALUES (NEW.relation_id, | ||
NEW.partition_method, | ||
column_name_to_column(NEW.relation_id, NEW.key)); |
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.
@jasonmp85 We need to add explicit cast at this line. My tests with pg_dump showed me that we need to do following:
column_name_to_column(NEW.relation_id::Oid, NEW.key));
The reason is that pg_dump dumps it as int (at least with no special configuration), so we see an error here.
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.
Actually, I think the column type of the view and table should just be regclass
. It will solve that.
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.
But I'll add the Oid
cast for this code review. (done)
ON ( shardid = shard_placement.shard_id AND | ||
nodename = shard_placement.node_name AND | ||
nodeport = shard_placement.node_port ) | ||
WHERE shardid IS NULL AND |
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.
Could we add aliases (like pg_shard_table.shardid / citusdb_table.shard_id)? Makes it a bit easier to grok.
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.
Again, since this method does not change (apart from the deprecation warning) in this version, I'd prefer to leave it alone. In fact, there is no reason to change it at all anymore, since it's no longer needed.
856592f
to
182e8be
Compare
Code rebased on latest develop, tests fixed, and changes from feedback made (denoted by (done) in one of my replies). @sumedhpathak, can you see what else needs attention on this PR? |
Going to need this in the view stuff.
Allows upgrades from PostgreSQL + pg_shard to CitusDB to flow smoothly.
Error out if we see a partition type we don't understand.
More obvious than checking for some GUC.
Copies over existing metadata to CitusDB catalogs, then redefines the pg_shard relations as views. Postcondition is that an upgraded install is indistinguishable from a fresh one.
Necessary due to unused parameters in SPI includes.
Clarified a function contracts, added a comment, and inserted explicit cast to oid for better `pg_dump` compatibility.
Needed since the key column isn't a direct mapping.
We abandoned pg_dump support in this release regardless, so might as well remove the cast, which was only here to accomodate pg_dump.
Because the old tables were config tables, we need to explicitly remove them from the extension's dependencies before dropping the schema. Then we can recreate the schema (using views) in a nice compound statement.
Per IWYU's suggestions.
182e8be
to
f7213a0
Compare
Exercised an arcane bug wherein we'd begin a PL/pgSQL trigger without pg_shard loaded, load it partway through, and crash because we have a PL/pgSQL plugin that expects to be called during function entry and exit being called only on exit.
54767fd
to
405027e
Compare
CitusDB metadata interoperability cr: @sumedhpathak
OK, so this has been entirely rebased on top of the changes from #110, i.e. we're using SPI everywhere now. This review is now all about the triggers and views needed to adapt CitusDB's metadata tables to be used within
pg_shard
.Travis is building this under PostgreSQL 9.3/9.4, and CitusDB 4.0, so there is some assurance this actually works.
Code Review Tasks
pg_shard
tables into views when Citus present (to prevent them from appearing blank), or just error out when queried.pg_shard
to CitusDB. Users mightpg_dump
from a PostgreSQLpg_shard
install and try to load into CitusDB. This must work seamlessly.\STAGE
and using an existing CitusDB-distributed table withpg_shard
Resolves #11.
Resolves #27.