Skip to content

Commit

Permalink
Merge c80bcbc into 6549fde
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed Mar 3, 2015
2 parents 6549fde + c80bcbc commit 11f9c18
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
endif

EXTENSION = pg_shard
DATA = pg_shard--1.0.sql
DATA = pg_shard--1.1.sql pg_shard--1.0--1.1.sql

# Default to 5432 if PGPORT is undefined. Replace placeholders in our tests
# with actual port number in order to anticipate correct output during tests.
Expand Down
62 changes: 62 additions & 0 deletions pg_shard--1.0--1.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
CREATE FUNCTION partition_column_to_node_string(table_oid oid)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C;

COMMENT ON FUNCTION partition_column_to_node_string(oid)
IS 'return textual form of distributed table''s partition column';

CREATE FUNCTION sync_table_metadata_to_citus(table_name text) RETURNS VOID
AS $sync_table_metadata_to_citus$
DECLARE
table_relation_id CONSTANT oid NOT NULL := table_name::regclass::oid;
dummy_shard_length CONSTANT bigint := 0;
BEGIN
-- copy shard placement metadata
INSERT INTO pg_dist_shard_placement
(shardid,
shardstate,
shardlength,
nodename,
nodeport)
SELECT shard_id,
shard_state,
dummy_shard_length,
node_name,
node_port
FROM pgs_distribution_metadata.shard_placement
WHERE shard_id IN (SELECT id
FROM pgs_distribution_metadata.shard
WHERE relation_id = table_relation_id);

-- copy shard metadata
INSERT INTO pg_dist_shard
(shardid,
logicalrelid,
shardstorage,
shardminvalue,
shardmaxvalue)
SELECT id,
relation_id,
storage,
min_value,
max_value
FROM pgs_distribution_metadata.shard
WHERE relation_id = table_relation_id;

-- copy partition metadata, which also converts the partition column to
-- a node string representation as expected by CitusDB
INSERT INTO pg_dist_partition
(logicalrelid,
partmethod,
partkey)
SELECT relation_id,
partition_method,
partition_column_to_node_string(table_relation_id)
FROM pgs_distribution_metadata.partition
WHERE relation_id = table_relation_id;
END;
$sync_table_metadata_to_citus$ LANGUAGE 'plpgsql';

COMMENT ON FUNCTION sync_table_metadata_to_citus(text)
IS 'synchronize a distributed table''s pg_shard metadata to CitusDB';
2 changes: 1 addition & 1 deletion pg_shard--1.0.sql → pg_shard--1.1.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* pg_shard--1.0.sql */
/* pg_shard--1.1.sql */

-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pg_shard" to load this file. \quit
Expand Down
2 changes: 1 addition & 1 deletion pg_shard.control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pg_shard extension
comment = 'extension for sharding across remote PostgreSQL servers'
default_version = '1.0'
default_version = '1.1'
module_pathname = '$libdir/pg_shard'
relocatable = true

0 comments on commit 11f9c18

Please sign in to comment.