-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use shard split copy code for blocking shard moves
The new shard copy code that was created for shard splits has some advantages over the old code. This one uses binary copy when possible to make the copy faster. When doing a shard move using `block_writes` it now uses this better copy logic.
- Loading branch information
Showing
19 changed files
with
414 additions
and
231 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,70 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* worker_copy_udf.c | ||
* | ||
* Copyright (c) Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "postgres.h" | ||
|
||
#include "utils/builtins.h" | ||
#include "utils/lsyscache.h" | ||
#include "distributed/citus_ruleutils.h" | ||
#include "distributed/metadata_cache.h" | ||
#include "distributed/multi_executor.h" | ||
#include "distributed/worker_shard_copy.h" | ||
|
||
PG_FUNCTION_INFO_V1(worker_copy); | ||
|
||
/* | ||
* worker_copy copies a shard from this worker to another worker | ||
* | ||
* SQL signature: | ||
* | ||
* worker_copy( | ||
* source_table regclass, | ||
* target_node_id integer | ||
* ) RETURNS VOID | ||
*/ | ||
Datum | ||
worker_copy(PG_FUNCTION_ARGS) | ||
{ | ||
Oid relationId = PG_GETARG_OID(0); | ||
uint32_t targetNodeId = PG_GETARG_INT32(1); | ||
|
||
if (IsCitusTable(relationId)) | ||
{ | ||
char *qualifiedRelationName = generate_qualified_relation_name(relationId); | ||
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), | ||
errmsg("table %s is a Citus table, only copies of " | ||
"shards or regular postgres tables are supported", | ||
qualifiedRelationName))); | ||
} | ||
|
||
Oid schemaOid = get_rel_namespace(relationId); | ||
char *relationSchemaName = get_namespace_name(schemaOid); | ||
char *relationName = get_rel_name(relationId); | ||
char *relationQualifiedName = quote_qualified_identifier( | ||
relationSchemaName, | ||
relationName); | ||
|
||
EState *executor = CreateExecutorState(); | ||
DestReceiver *destReceiver = CreateShardCopyDestReceiver( | ||
executor, | ||
list_make2(relationSchemaName, relationName), | ||
targetNodeId); | ||
|
||
StringInfo selectShardQueryForCopy = makeStringInfo(); | ||
appendStringInfo(selectShardQueryForCopy, | ||
"SELECT * FROM %s;", relationQualifiedName); | ||
|
||
ParamListInfo params = NULL; | ||
ExecuteQueryStringIntoDestReceiver(selectShardQueryForCopy->data, params, | ||
destReceiver); | ||
|
||
FreeExecutorState(executor); | ||
|
||
PG_RETURN_VOID(); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
CREATE OR REPLACE FUNCTION pg_catalog.worker_copy( | ||
source_table regclass, | ||
target_node_id integer) | ||
RETURNS void | ||
LANGUAGE C STRICT | ||
AS 'MODULE_PATHNAME', $$worker_copy$$; | ||
COMMENT ON FUNCTION pg_catalog.worker_copy(regclass, integer) | ||
IS 'Perform copy of a shard'; |
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
Oops, something went wrong.