forked from citusdata/citus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request citusdata#2469 from citusdata/refactor/commands-ex…
…tract Refactor the UtilityProcess function into its own module
- Loading branch information
Showing
47 changed files
with
4,945 additions
and
4,779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Commands | ||
|
||
The commands module is modeled after `backend/commands` from the postgres repository and | ||
contains the logic for Citus on how to run these commands on distributed objects. Even | ||
though the structure of the directory has some resemblence to its postgres relative files | ||
here are somewhat more finegrained. This is due to the nature of citus commands that are | ||
heavily focused on distributed tables. Instead of having all commands in `tablecmds.c` | ||
they are often moved to files that are named after the command. | ||
|
||
| File | Description | | ||
|------------------------------|-------------| | ||
| `create_distributed_table.c` | Implementation of UDF's for creating distributed tables | | ||
| `drop_distributed_table.c` | Implementation for dropping metadata for partitions of distributed tables | | ||
| `extension.c` | Implementation of `CREATE EXTENSION` commands for citus specific checks | | ||
| `foreign_constraint.c` | Implementation of and helper functions for foreign key constraints | | ||
| `grant.c` | Placeholder for code granting users access to relations, implemented as enterprise feature | | ||
| `index.c` | Implementation of commands specific to indices on distributed tables | | ||
| `multi_copy.c` | Implementation of `COPY` command. There are multiple different copy modes which are described in detail below | | ||
| `policy.c` | Implementation of `CREATE\ALTER POLICY` commands. | | ||
| `rename.c` | Implementation of `ALTER ... RENAME ...` commands. It implements the renaming of applicable objects, otherwise provides the user with a warning | | ||
| `schema.c` | | | ||
| `sequence.c` | Implementation of `CREATE/ALTER SEQUENCE` commands. Primarily checks correctness of sequence statements as they are not propagated to the worker nodes | | ||
| `table.c` | | | ||
| `transmit.c` | Implementation of `COPY` commands with `format transmit` set in the options. This format is used to transfer files from one node to another node | | ||
| `truncate.c` | Implementation of `TRUNCATE` commands on distributed tables | | ||
| `utility_hook.c` | This is the entry point from postgres into the commands module of citus. It contains the implementation that gets registered in postgres' `ProcessUtility_hook` callback to extends the functionality of the original ProcessUtility. This code is used to route the incomming commands to their respective implementation in Citus | | ||
| `vacuum.c` | Implementation of `VACUUM` commands on distributed tables | | ||
|
||
# COPY | ||
|
||
The copy command is overloaded for a couple of use-cases specific to citus. The syntax of | ||
the command stays the same, however the implementation might slightly differ from the | ||
stock implementation. The overloading is mostly done via extra options that Citus uses to | ||
indicate how to operate the copy. The options used are described below. | ||
|
||
## FORMAT transmit | ||
|
||
Implemented in `transmit.c` | ||
|
||
TODO: to be written by someone with enough knowledge to write how, when and why it is used. | ||
|
||
## FORMAT result | ||
|
||
Implemented in `multi_copy.c` | ||
|
||
TODO: to be written by someone with enough knowledge to write how, when and why it is used. | ||
|
||
## MASTER_HOST host | ||
|
||
Implemented in `multi_copy.c` | ||
|
||
Triggered by the `MASTER_HOST` option being set on the copy command. Also accepts `MASTER_PORT` | ||
|
||
TODO: to be written by someone with enough knowledge to write how, when and why it is used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* cluster.c | ||
* Commands for CLUSTER statement | ||
* | ||
* Copyright (c) 2018, Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "postgres.h" | ||
|
||
#include "catalog/namespace.h" | ||
#include "distributed/commands.h" | ||
#include "distributed/metadata_cache.h" | ||
|
||
|
||
/* placeholder for PlanClusterStmt */ | ||
List * | ||
PlanClusterStmt(ClusterStmt *clusterStmt, const char *clusterCommand) | ||
{ | ||
bool showPropagationWarning = false; | ||
|
||
/* CLUSTER all */ | ||
if (clusterStmt->relation == NULL) | ||
{ | ||
showPropagationWarning = true; | ||
} | ||
else | ||
{ | ||
Oid relationId = InvalidOid; | ||
bool missingOK = false; | ||
|
||
relationId = RangeVarGetRelid(clusterStmt->relation, AccessShareLock, | ||
missingOK); | ||
|
||
if (OidIsValid(relationId)) | ||
{ | ||
showPropagationWarning = IsDistributedTable(relationId); | ||
} | ||
} | ||
|
||
if (showPropagationWarning) | ||
{ | ||
ereport(WARNING, (errmsg("not propagating CLUSTER command to worker nodes"))); | ||
} | ||
|
||
return NIL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* extension.c | ||
* Commands for creating and altering extensions. | ||
* | ||
* Copyright (c) 2018, Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "postgres.h" | ||
|
||
#include "citus_version.h" | ||
#include "distributed/commands.h" | ||
#include "distributed/metadata_cache.h" | ||
#include "nodes/parsenodes.h" | ||
|
||
/* Local functions forward declarations for helper functions */ | ||
static char * ExtractNewExtensionVersion(Node *parsetree); | ||
|
||
|
||
/* | ||
* IsCitusExtensionStmt returns whether a given utility is a CREATE or ALTER | ||
* EXTENSION statement which references the citus extension. This function | ||
* returns false for all other inputs. | ||
*/ | ||
bool | ||
IsCitusExtensionStmt(Node *parsetree) | ||
{ | ||
char *extensionName = ""; | ||
|
||
if (IsA(parsetree, CreateExtensionStmt)) | ||
{ | ||
extensionName = ((CreateExtensionStmt *) parsetree)->extname; | ||
} | ||
else if (IsA(parsetree, AlterExtensionStmt)) | ||
{ | ||
extensionName = ((AlterExtensionStmt *) parsetree)->extname; | ||
} | ||
|
||
return (strcmp(extensionName, "citus") == 0); | ||
} | ||
|
||
|
||
/* | ||
* ErrorIfUnstableCreateOrAlterExtensionStmt compares CITUS_EXTENSIONVERSION | ||
* and version given CREATE/ALTER EXTENSION statement will create/update to. If | ||
* they are not same in major or minor version numbers, this function errors | ||
* out. It ignores the schema version. | ||
*/ | ||
void | ||
ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree) | ||
{ | ||
char *newExtensionVersion = ExtractNewExtensionVersion(parsetree); | ||
|
||
if (newExtensionVersion != NULL) | ||
{ | ||
/* explicit version provided in CREATE or ALTER EXTENSION UPDATE; verify */ | ||
if (!MajorVersionsCompatible(newExtensionVersion, CITUS_EXTENSIONVERSION)) | ||
{ | ||
ereport(ERROR, (errmsg("specified version incompatible with loaded " | ||
"Citus library"), | ||
errdetail("Loaded library requires %s, but %s was specified.", | ||
CITUS_MAJORVERSION, newExtensionVersion), | ||
errhint("If a newer library is present, restart the database " | ||
"and try the command again."))); | ||
} | ||
} | ||
else | ||
{ | ||
/* | ||
* No version was specified, so PostgreSQL will use the default_version | ||
* from the citus.control file. | ||
*/ | ||
CheckAvailableVersion(ERROR); | ||
} | ||
} | ||
|
||
|
||
/* | ||
* ExtractNewExtensionVersion returns the new extension version specified by | ||
* a CREATE or ALTER EXTENSION statement. Other inputs are not permitted. This | ||
* function returns NULL for statements with no explicit version specified. | ||
*/ | ||
static char * | ||
ExtractNewExtensionVersion(Node *parsetree) | ||
{ | ||
char *newVersion = NULL; | ||
List *optionsList = NIL; | ||
ListCell *optionsCell = NULL; | ||
|
||
if (IsA(parsetree, CreateExtensionStmt)) | ||
{ | ||
optionsList = ((CreateExtensionStmt *) parsetree)->options; | ||
} | ||
else if (IsA(parsetree, AlterExtensionStmt)) | ||
{ | ||
optionsList = ((AlterExtensionStmt *) parsetree)->options; | ||
} | ||
else | ||
{ | ||
/* input must be one of the two above types */ | ||
Assert(false); | ||
} | ||
|
||
foreach(optionsCell, optionsList) | ||
{ | ||
DefElem *defElement = (DefElem *) lfirst(optionsCell); | ||
if (strncmp(defElement->defname, "new_version", NAMEDATALEN) == 0) | ||
{ | ||
newVersion = strVal(defElement->arg); | ||
break; | ||
} | ||
} | ||
|
||
return newVersion; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* grant.c | ||
* Commands for granting access to distributed tables. | ||
* | ||
* Copyright (c) 2018, Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "distributed/commands.h" | ||
|
||
|
||
/* placeholder for PlanGrantStmt */ | ||
List * | ||
PlanGrantStmt(GrantStmt *grantStmt) | ||
{ | ||
return NIL; | ||
} |
Oops, something went wrong.