Commit Graph

541 Commits (065d167d2ee14a849e07fbbd11f7b6f026dec6cb)

Author SHA1 Message Date
Jason Petersen 73e0e2a79a Revert "Remove unused SendCommandToWorker"
This reverts commit c8c308c109.
2017-03-13 15:48:51 -06:00
Murat Tuncer 7abc7080f2 Enable router planner for queries on range partitioned tables
Router planner now supports queries using range partitioned
tables. Queries on append partitioned tables are still not
supported.
2017-03-09 16:39:15 +03:00
Brian Cloutier ebc7779457 Remove unused SendCommandToWorker 2017-03-08 16:30:23 +03:00
Brian Cloutier aed36acfeb Remove unused master_stage_shard_{placement_,}row 2017-03-07 11:59:26 +03:00
Brian Cloutier 9f876986e2 Remove unused master_get_round_robin_candidate_nodes 2017-03-07 11:51:24 +03:00
Brian Cloutier c3e9bb880b Remove master_get_local_first_candidate_nodes 2017-03-07 11:50:59 +03:00
Andres Freund 99d660c45f Fix SendRemoteCommandParams() handling of a NULL MultiConnection->pgConn. (#1271)
Previously we'd segfault in PQisnonblocking() which, contrary to other
libpq calls, doesn't handle a NULL PQconn (because there'd be no
appropriate return value for that).

cr: @jasonmp85
2017-03-03 12:02:15 -07:00
Murat Tuncer e718b10ce9 Remove default clause from shard DDL when sequences are used 2017-03-01 17:32:48 +03:00
Marco Slot 0a31d33cf9 Fix spelling in master_initialize_node_metadata comment 2017-03-01 12:27:50 +01:00
Jason Petersen d3653051ab Rename misleading allowEmpty parameter
Last bit of PR feedback.
2017-02-28 22:48:00 -07:00
Marco Slot ba764be3bb Address review feedback in create_distributed_table data loading 2017-02-28 17:39:45 +01:00
Marco Slot 29b1fb97c5 Address review feedback in COPY refactoring 2017-02-28 17:39:45 +01:00
Marco Slot 92c8d6cf54 Use CitusCopyDestReceiver for regular COPY 2017-02-28 17:24:45 +01:00
Marco Slot 10e1131516 Load data into distributed table on creation 2017-02-28 17:24:45 +01:00
Marco Slot ae9d2be84e Add CitusCopyDestReceiver infrastructure 2017-02-28 17:24:45 +01:00
Burak Velioglu 291f6f3bd2 Merge branch 'master' into disallow_master_appy_delete_on_hash 2017-02-24 10:40:23 +02:00
velioglu a19770c6c8 Fix error message of start_metadata_sync_to_node
Single quotation mark is added around nodename to make the
error code consistent with master_add_node usage.
2017-02-22 18:03:58 +03:00
Metin Doslu f73c0c2ab5 Get reproducible costs between different PostgreSQL versions 2017-02-22 15:40:02 +02:00
Burak Velioglu fa112e9c99 Disallow master_apply_delete_command on hash distributed table
Delete operation is blocked for any table distributed by hash using master_apply_delete_command. Suggested master_modify_multiple_shards command as a hint.
2017-02-22 11:54:46 +03:00
Andres Freund a4f2bf1266 Use DEBUG2 instead of DEBUG4 in INSERT SELECT tests & debug message.
During later work the transaction debug output will change (as it will
in postgres 10), which makes it hard to see actual changes in the
INSERT ... SELECT ... test.  Reduce to DEBUG2 after changing a debug
message to that log level.
2017-02-20 12:56:16 +02:00
Eren Basak 99ebe06af5 Enforce statement based replication on old APIs and non-hash tables
This change ignores `citus.replication_model` setting and uses the
statement based replication in

- Tables distributed via the old `master_create_distributed_table` function
- Append and range partitioned tables, even if created via
`create_distributed_table` function

This seems like the easiest solution to #1191, without changing the existing
behavior and harming existing users with custom scripts.

This change also prevents RF>1 on streaming replicated tables on `master_create_worker_shards`

Prior to this change, `master_create_worker_shards` command was not checking
the replication model of the target table, thus allowing RF>1 with streaming
replicated tables. With this change, `master_create_worker_shards` errors
out on the case.
2017-02-16 10:37:53 -08:00
Jason Petersen 10afe08cd9 Fix tests broken by new PostgreSQL patch releases (#1220)
PostgreSQL 9.5.6 and 9.6.2 were released today and broke several tests
by adding TABLESPACE pg_default output to some DDL commands. Fixed all
occurrences.

cr: @anarazel
2017-02-09 16:53:02 -07:00
Onder Kalaci 49ed391b3e Bugfix for creating foreign key
This commit fixes crash for adding foreign keys without
specifying the referenced column crashes the backend.
2017-02-07 09:34:24 +02:00
Brian Cloutier 0c5373c28e Utility hook does nothing if the extension is not loaded 2017-02-02 17:48:31 +02:00
Brian Cloutier bd6c39215b Set a memory context when throwing deferred errors 2017-02-02 15:14:21 +02:00
Brian Cloutier 911137ce66 Start remote transactions in master_append_table_to_shard
Add a call to RemoteTransactionBeginIfNecessary so that BEGIN is
actually sent to the remote connections. This means that ROLLBACK and
Ctrl-C are respected and don't leave the table in a partial state.
2017-02-01 18:12:19 +02:00
Eren Basak 8efb00768e Fix Random Fails on Travis
This change fixes the random failures on Travis, which is a bug introduced
with citus/#1124. Before this fix, travis was failing randomly on `check_multi_mx`
test schedule, specifically in the parallel group of `multi_mx_metadata`,
'multi_mx_modifications` and `multi_mx_modifying_xacts` tests. This change fixes this
by serializing these three test cases.
2017-01-31 15:23:06 -08:00
Eren Basak b458832416 Allow dropping sequences on mx workers
This change allows users to drop sequences on MX workers. Previously, Citus didn't allow dropping
sequences on MX workers because it could cause shards to be dropped if `DROP SEQUENCE ... CASCADE`
is used. We now allow that since allowing sequence creation but not dropping hurts user experience
and also may cause problems with custom Citus solutions.
2017-01-31 14:51:44 -08:00
Brian Cloutier 0e135dfd72 Fix bug where router executor sends query to failed connections 2017-01-27 09:40:30 +02:00
Brian Cloutier 24654ac7e1 Refactor CheckShardPlacements
- Break CheckShardPlacements into multiple functions (The most important
  is MarkFailedShardPlacements), so that we can get rid of the global
  CoordinatedTransactionUses2PC.
- Call MarkFailedShardPlacements in the router executor, so we mark
  shards as invalid and stop using them while inside transaction blocks.
2017-01-26 13:20:45 +02:00
Murat Tuncer 59ca49a826 Add copy failure tests inside transactions 2017-01-26 11:54:40 +03:00
Murat Tuncer 0500c31a30 Fix dependent tests 2017-01-25 19:19:39 +03:00
Murat Tuncer 5a8bc76912 Add failure case for regression tests 2017-01-25 19:19:39 +03:00
Marco Slot e55faf10f0 Mark failed placements as inactive immediately after COPY 2017-01-25 19:19:39 +03:00
Marco Slot b4c5a0781b Don't mark placements inactive in COPY after successful connection 2017-01-25 19:19:38 +03:00
Marco Slot 83cb58bf40 Set placement to inactive on connection failure in COPY 2017-01-25 19:19:38 +03:00
Marco Slot 8971b3ed75 Short circuit in multi_ProcessUtility on ABORT/COMMIT 2017-01-25 11:57:00 +01:00
Marco Slot 5f61d8ea5a Always skip foreign key validation when enable_ddl_propagation is off 2017-01-25 11:56:59 +01:00
Marco Slot 8adb9c3ec1 Use coordinator instead of schema node in terminology 2017-01-25 11:07:23 +01:00
Marco Slot 46487dd583 Use bigserial instead of BIGINT in sequence error 2017-01-25 11:07:23 +01:00
Burak Yucesoy 240520d063 Add ORDER BY to some tests to have consistent output 2017-01-25 11:43:25 +02:00
Eren Basak 2536c77ef0 Add Regression Tests For Querying MX Tables from Workers 2017-01-24 10:36:59 +03:00
Burak Yucesoy 46547e67cc Convert DropShards to use new connection API
With this change DropShards function started to use new connection API. DropShards
function is used by DROP TABLE, master_drop_all_shards and master_apply_delete_command,
therefore all of these functions now support transactional operations. In DropShards
function, if we cannot reach a node, we mark shard state of related placements as
FILE_TO_DELETE and continue to drop remaining shards; however if any error occurs after
establishing the connection, we ROLLBACK whole operation.
2017-01-23 21:08:41 +03:00
Burak Yucesoy 4efeeb50c3 In case of failed transactions update shard state only if it is FILE_FINALIZED
Before this change, when a transaction failed, we update related placements shard states
to FILE_INACTIVE during XACT_EVENT_PRE_COMMIT. However that means if another code block
changed shard state to something else (e.g. FILE_TO_DELETE) before XACT_EVENT_PRE_COMMIT
we overwrite that. To prevent that problem, in case of failure we started to change
shard state, only if its current shard state is FILE_FINALIZED.
2017-01-23 21:04:57 +03:00
Burak Yucesoy 02880a717b Add LoadShardPlacement UDF
This UDF returns a shard placement from cache given shard id and placement id. At the
moment it iterates over all shard placements of given shard by ShardPlacementList and
searches given placement id in that list, which is not a good solution performance-wise.
However, currently, this function will be used only when there is a failed transaction.
If a need arises we can optimize this function in the future.
2017-01-23 21:04:57 +03:00
Marco Slot cff95c310e Use placement connection API for multi-shard transactions 2017-01-23 18:34:50 +01:00
Andres Freund 970c81f589 Hack up PREPARE/EXECUTE for nearly all distributed queries.
All router, real-time, task-tracker plannable queries should now have
full prepared statement support (and even use router when possible),
unless they don't go through the custom plan interface (which
basically just affects LANGUAGE SQL (not plpgsql) functions).

This is achieved by forcing postgres' planner to always choose a
custom plan, by assigning very low costs to plans with bound
parameters (i.e. ones were the postgres planner replanned the query
upon EXECUTE with all parameter values provided), instead of the
generic one.

This requires some trickery, because for custom plans to work the
costs for a non-custom plan have to be known, which means we can't
error out when planning the generic plan.  Instead we have to return a
"faux" plan, that'd trigger an error message if executed.  But due to
the custom plan logic that plan will likely (unless called by an SQL
function, or because we can't support that query for some reason) not
be executed; instead the custom plan will be chosen.
2017-01-23 09:23:50 -08:00
Andres Freund 67da5611f7 Make router planner error handling more flexible.
So far router planner had encapsulated different functionality in
MultiRouterPlanCreate. Modifications always go through router, selects
sometimes. Modifications always error out if the query is unsupported,
selects return NULL.  Especially the error handling is a problem for
the upcoming extension of prepared statement support.

Split MultiRouterPlanCreate into CreateRouterPlan and
CreateModifyPlan, and change them to not throw errors.

Instead errors are now reported by setting the new
MultiPlan->plannigError.

Callers of router planner functionality now have to throw errors
themselves if desired, but also can skip doing so.

This is a pre-requisite for expanding prepared statement support.

While touching all those lines, improve a number of error messages by
getting them closer to the postgres error message guidelines.
2017-01-23 09:23:50 -08:00
Andres Freund e531d69e92 Centralize more of distributed planning into CreateDistributedPlan().
The name CreatePhysicalPlan() hasn't been accurate for a while, and
the split of work between multi_planner() and CreatePhysicalPlan()
doesn't seem perfect.  So rename to CreateDistributedPlan() and move a
bit more logic in there.
2017-01-23 09:23:50 -08:00
Andres Freund 83fe9bf489 Support for deferred error messages.
It can be useful, e.g. in the upcoming prepared statement support, to
be able to return an error from a function that is not raised
immediately, but can later be thrown.  That allows e.g. to attempt to
plan a statment using different methods and to create good error
messages in each planner, but to only error out after all planners
have been run.

To enable that create support for deferred error messages that can be
created (supporting errorcode, message, detail, hint) in one function,
and then thrown in different place.
2017-01-23 09:23:50 -08:00
Andres Freund 52249a3a19 Make usage of static a bit more consistent in multi_planner.c. 2017-01-23 09:23:50 -08:00
Jason Petersen b5734eb11f Add replication_model GUC
This adds a replication_model GUC which is used as the replication
model for any new distributed table that is not a reference table.
With this change, tables with replication factor 1 are no longer
implicitly MX tables.

The GUC is similarly respected during empty shard creation for e.g.
existing append-partitioned tables. If the model is set to streaming
while replication factor is greater than one, table and shard creation
routines will error until this invalid combination is corrected.

Changing this parameter requires superuser permissions.
2017-01-23 09:05:14 -07:00
Brian Cloutier e4b65d03a2 Port master_append_table_to_shard to new connection API (#1149)
If any placements fail it doesn't update shard statistics on those placements.

A minor enabling refactor: Make CoordinatedTransactionUses2PC public (it used to be CoordinatedTransactionUse2PC but that symbol already existed, so renamed it as well)
2017-01-23 15:57:44 +02:00
Burak Yucesoy 4bb9842660 Reword error message for outer joins requiring repartition
We changed error message which appears when user tries to execute outer join command and
that command requires repartitioning. Old error message mentioned about 1-to-1 shard
partitioning which may not be clear to user.
2017-01-23 10:42:36 +03:00
Marco Slot ac919337f1 Add an enable_deadlock_prevention flag to allow router transactions to expand to multiple nodes 2017-01-22 17:31:24 +01:00
Marco Slot 190fce2f70 Ensure job IDs are unique across workers 2017-01-22 16:55:14 +01:00
Andres Freund a596858463 Remove connection_cache.[ch]. 2017-01-21 09:01:15 -08:00
Andres Freund 0bdb22268f Remove remnants of commit_protocol.[ch]. 2017-01-21 09:01:15 -08:00
Andres Freund 9d3d6a2c22 Consistently libpq forward declaration in remote_commands.h. 2017-01-21 09:01:14 -08:00
Andres Freund f3cbe57c60 Minimal citus tools conversion to new connection API. 2017-01-21 09:01:14 -08:00
Önder Kalacı 5a7ba99abf Merge branch 'master' into fix_command_counter_increment 2017-01-21 09:21:19 +02:00
Murat Tuncer 299d002f1c Convert multi copy to use new connection api
This enables proper transactional behaviour for copy and relaxes some
restrictions like combining COPY with single-row modifications. It
also provides the basis for relaxing restrictions further, and for
optionally allowing connection caching.
2017-01-20 19:15:19 -08:00
Jason Petersen 5a66dc8278 Change default replication factor to one
Took the quick-and-dirty approach of changing it back to two during
test runs. Can update tests to expect one in due time.
2017-01-20 18:56:43 -07:00
Andres Freund 2b58ac24dc Mark some now unnecessarily exposed multi_planner.c functions static. 2017-01-20 12:31:56 -08:00
Andres Freund 14ecb58159 Don't duplicate planning logic in citus' explain hook.
Instead use pg_plan_query() like the normal explain does, and use that
to explain the query.  That's important because it allows to remove
the duplicated planner logic from multi_explain - and that logic is
about to get more complicated.
2017-01-20 12:31:28 -08:00
Andres Freund 2ec404a122 Remove citus.explain_multi_logical/physical_plan.
They make fixing explain for prepared statement harder, and they don't
really fit into EXPLAIN in the first place.  Additionally they're
currently not exercised in any tests.
2017-01-20 12:31:19 -08:00
Onder Kalaci 472ac3e37d Improve heap access methods
This commit improves heap access methods for reference table
upgrade and colocation group modifications.
2017-01-20 14:53:29 +02:00
Metin Doslu 099ef88238 Add a function to delete shard metadata from MX nodes 2017-01-20 14:38:01 +02:00
Metin Doslu 09ca6a464f Refactor get_shard_id_for_distribution_column() and other minor changes 2017-01-20 14:38:01 +02:00
Metin Doslu 08e285dd67 Return a deep copy shard list from ColocatedShardIntervalList() 2017-01-20 14:38:01 +02:00
Metin Doslu dd7c0bcb0c Add worker_hash() and a stub for isolate_tenant_to_new_shard() 2017-01-20 14:38:01 +02:00
Murat Tuncer d9dd275700 Remove hint message from master_remove_node UDF
Hint about master_disable_node  was giving wrong
impression to users. Removal is better than keeping it.
2017-01-18 22:33:00 -07:00
Eren Basak 0fa203b150 Prevent COPY to reference tables from worker nodes 2017-01-18 17:38:01 +03:00
Eren Basak ce8f9d0819 Make `upgrade_to_reference_table` function MX-compatible 2017-01-18 16:49:50 +03:00
Eren Basak 4c8c5da7f1 Propagate metadata changes for deleted reference table placements on master_remove_node call 2017-01-18 16:00:07 +03:00
Eren Basak fa0b36b28c Propagate new reference table placement metadata on `master_add_node` 2017-01-18 15:59:06 +03:00
Eren Basak c8fafa1ffb Make reference table metadata synced to workers 2017-01-18 15:59:05 +03:00
Eren Basak 86e772e4ae Propagate Metadata to Workers on `create_reference_table` call. 2017-01-18 11:05:24 +03:00
Eren Basak 096be1dde5 Add Sequence Support for MX Tables
This change adds support for serial columns to be used with MX tables.
Prior to this change, sequences of serial columns were created in all
workers (for being able to create shards) but never used. With MX, we
need to set the sequences so that sequences in each worker create
unique values. This is done by setting the MINVALUE, MAXVALUE and
START values of the sequence.
2017-01-18 09:43:38 +03:00
Eren Basak 139e87a0ad Create Invalidation Trigger for pg_dist_local_group Table Updates 2017-01-18 09:43:38 +03:00
Andres Freund 5f4c85f1c4 Query placementId in RemoteFinalizedShardPlacementList().
Not having the id in the ShardPlacement struct causes issues while
making copy use the placement aware connection management.
2017-01-17 13:27:26 -08:00
Brian Cloutier b74fe324bc Port WorkerShardStats to new connection API
Part of the work in citusdata/citus#1101, this is a pretty direct port
over to the new functions and shouldn't result in any behavior changes.
2017-01-17 17:04:37 +02:00
Brian Cloutier 213c24524d Create ExecuteOptionalRemoteCommand
A small refactor which pulls some code out of `RecoverWorkerTransactions`
and into `remote_commands.c`. This code block currently only occurs in
`RecoverWorkerTransactions` but will be useful to other functions
shortly.

Unfortunately we couldn't call it `ExecuteRemoteCommand`, that name was
already taken.
2017-01-17 17:04:37 +02:00
Brian Cloutier da976e42ba Pass entire ShardPlacement into WorkerShardStats
A small refactor so we'll be able to call the new connection API (which
requires having a ShardPlacement) from within WorkerShardStats.
2017-01-17 17:04:37 +02:00
Andres Freund 650f25d01a Make placement_connection.c colocation aware.
Because of foreign keys and similar concerns there should only be a
single modifying/DDL connection for a set of colocated placements to a
node.  To enforce placement_connection.c now has an additional
hash-table keeping track of the connections to a set of colocated
placements.  In addition to enforcing per placement restrictions on
connections, there's now very similar restrictions for sets of
colocated placements.
2017-01-16 13:47:01 -08:00
Andres Freund 9d43ad7b07 Add ShardPlacement fields required for colocated placement connection mapping. 2017-01-16 13:42:54 -08:00
Andres Freund cdc4e22be7 Fix use of wrong constant.
This could potentially lead to spuriously shared connections if the
first 63 characters of a hostname are the same.
2017-01-16 13:42:53 -08:00
Andres Freund a9acf8c790 Remove fields used in earlier revisions of placement_connection.c. 2017-01-16 13:42:53 -08:00
Onder Kalaci 169fb5943e Improve error messages for INSERT INTO .. SELECT
This commit is intended to improve the error messages while planning
INSERT INTO .. SELECT queries. The main motivation for this change is
that we used to map multiple cases into a single message. With this change,
we added explicit error messages for many cases.
2017-01-16 12:16:14 -07:00
Burak Yucesoy 96b55249a4 Remove placement metadata of reference tables after master_remove_node
With this change, we start to delete placement of reference tables at given worker node
after master_remove_node UDF call. We remove placement metadata at master node but we do
not drop actual shard from the worker node. There are two reasons for that decision,
first, it is not critical to DROP the shards in the workers because Citus will ignore them
as long as node is removed from cluster and if we add that node back to cluster we will
DROP and recreate all reference tables. Second, if node is unreachable, it becomes
complicated to cover failure cases and have a transaction support.
2017-01-16 11:24:56 +03:00
Murat Tuncer 3339240aa7 Report error when original range table id is not found in NewTableId() 2017-01-13 09:39:43 +03:00
Murat Tuncer 3b9a579a63 Add view support
Enables use views within distributed queries.
User can create and use a view on distributed tables/queries
as he/she would use with regular queries.

After this change router queries will have full support for views,
insert into select queries will support reading from views, not
writing into. Outer joins would have a limited support, and would
error out at certain cases such as when a view is in the inner side
of the outer join.

Although PostgreSQL supports writing into views under certain circumstances.
We disallowed that for distributed views.
2017-01-13 09:39:42 +03:00
Burak Yucesoy 324d2262a0 Add ORDER BY clause to shard state tests to have consistent output
In tests related to automatic reference table creation and deletion, there were some
tests whose output may change order thus creating inconsistent test results. With this
change we add ORDER BY clause to related tests to have consistent output.
2017-01-13 02:42:28 +03:00
Onder Kalaci 119b691eb4 Refactor CheckShardPlacements() and improve support for node removal
This commit refactors CheckShardPlacements() so that it only considers
modifyingConnection. Also, it skips nodes which are removed from the
cluster.
2017-01-12 20:10:10 +02:00
Murat Tuncer 32b64efdc0 Add hint to errored real time queries 2017-01-12 11:33:35 +03:00
Onder Kalaci 08abe1b213 Copy on reference tables should never mark placements invalid
This commit ensures that COPY does not mark any placement
of reference's state as INVALID in case of an error.
2017-01-12 02:43:41 +02:00
Eren Basak 218af2d5d4 Fix escaping of workerrack in NodeListInsertCommand
This change fixes a small bug about quoting of workerrack column in
NodeListInsertCommand:

Previous: `"..., '%s'", workerRack`
Now: `"..., %s", quote_literal_cstr(workerRack)`
2017-01-11 10:18:48 +03:00
Andres Freund ab0629ae4a Cache ShardPlacements in metadata cache.
So far we've reloaded them frequently. Besides avoiding that cost -
noticeable for some workloads with large shard counts - it makes it
easier to add information to ShardPlacements that help us make
placement_connection.c colocation aware.
2017-01-10 18:14:18 -08:00
Andres Freund 39c760ae7b Make LoadShardInterval() backed by the metadata cache.
Doing so requires adding a mapping from shardId to the cache
entries. For that metadata_cache.c now maintains an additional
hashtable. That hashtable only references shard intervals in the
dist table cache.
2017-01-10 17:00:19 -08:00
Andres Freund 25c3719ccb Split DistTableCacheEntry() into separate functions.
Previously the function was getting too large. Thus this splits the
function into separate parts for looking up the cache entry and
building the cache contents.
2017-01-10 15:23:18 -08:00