Skip to content

Commit

Permalink
Merge b659a65 into 46bcf2c
Browse files Browse the repository at this point in the history
  • Loading branch information
onderkalaci committed Jan 2, 2015
2 parents 46bcf2c + b659a65 commit ee94147
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
14 changes: 13 additions & 1 deletion create_shards.c
Expand Up @@ -121,6 +121,8 @@ master_create_worker_shards(PG_FUNCTION_ARGS)
int32 replicationFactor = PG_GETARG_INT32(2);

Oid distributedTableId = ResolveRelationId(tableNameText);
char relationKind = get_rel_relkind(distributedTableId);
char shardStorageType = '\0';
int32 shardIndex = 0;
List *workerNodeList = NIL;
List *ddlCommandList = NIL;
Expand Down Expand Up @@ -184,6 +186,16 @@ master_create_worker_shards(PG_FUNCTION_ARGS)
placementAttemptCount++;
}

/* set shard storage type according to relation type */
if (relationKind == RELKIND_FOREIGN_TABLE)
{
shardStorageType = SHARD_STORAGE_FOREIGN;
}
else
{
shardStorageType = SHARD_STORAGE_TABLE;
}

for (shardIndex = 0; shardIndex < shardCount; shardIndex++)
{
uint64 shardId = NextSequenceId(SHARD_ID_SEQUENCE_NAME);
Expand Down Expand Up @@ -248,7 +260,7 @@ master_create_worker_shards(PG_FUNCTION_ARGS)
/* insert the shard metadata row along with its min/max values */
minHashTokenText = IntegerToText(shardMinHashToken);
maxHashTokenText = IntegerToText(shardMaxHashToken);
InsertShardRow(distributedTableId, shardId, SHARD_STORAGE_TABLE,
InsertShardRow(distributedTableId, shardId, shardStorageType,
minHashTokenText, maxHashTokenText);
}

Expand Down
70 changes: 70 additions & 0 deletions expected/create_shards.out.tmpl
Expand Up @@ -155,3 +155,73 @@ SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'throwaway%' AND relkind = 'r';
0
(1 row)

\set VERBOSITY terse
-- test foreign table creation
CREATE FOREIGN TABLE foreign_table_to_distribute
(
name text,
id bigint
)
SERVER fake_fdw_server;
SELECT master_create_distributed_table('foreign_table_to_distribute', 'id');
master_create_distributed_table
---------------------------------

(1 row)

SELECT master_create_worker_shards('foreign_table_to_distribute', 16, 1);
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
master_create_worker_shards
-----------------------------

(1 row)

\set VERBOSITY default
SELECT storage, min_value, max_value FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass
ORDER BY (min_value COLLATE "C") ASC;
storage | min_value | max_value
---------+-------------+-------------
f | -1073741828 | -805306374
f | -1342177283 | -1073741829
f | -1610612738 | -1342177284
f | -1879048193 | -1610612739
f | -2147483648 | -1879048194
f | -268435463 | -9
f | -536870918 | -268435464
f | -8 | 268435446
f | -805306373 | -536870919
f | 1073741812 | 1342177266
f | 1342177267 | 1610612721
f | 1610612722 | 1879048176
f | 1879048177 | 2147483647
f | 268435447 | 536870901
f | 536870902 | 805306356
f | 805306357 | 1073741811
(16 rows)

-- cleanup foreign table, related shards and shard placements
DELETE FROM pgs_distribution_metadata.shard_placement
WHERE shard_id IN (SELECT shard_id FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass);

DELETE FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass;

DELETE FROM pgs_distribution_metadata.partition
WHERE relation_id = 'foreign_table_to_distribute'::regclass;
4 changes: 2 additions & 2 deletions expected/modifications.out.tmpl
Expand Up @@ -63,12 +63,12 @@ ERROR: cannot plan INSERT using row with NULL value in partition column
INSERT INTO limit_orders VALUES (18811, 'BUD', 14962, '2014-04-05 08:32:16', 'sell',
-5.00);
WARNING: Bad result from localhost:$PGPORT
DETAIL: Remote message: new row for relation "limit_orders_10018" violates check constraint "limit_orders_limit_price_check"
DETAIL: Remote message: new row for relation "limit_orders_10034" violates check constraint "limit_orders_limit_price_check"
ERROR: could not modify any active placements
-- insert violating primary key constraint
INSERT INTO limit_orders VALUES (32743, 'LUV', 5994, '2001-04-16 03:37:28', 'buy', 0.58);
WARNING: Bad result from localhost:$PGPORT
DETAIL: Remote message: duplicate key value violates unique constraint "limit_orders_pkey_10019"
DETAIL: Remote message: duplicate key value violates unique constraint "limit_orders_pkey_10035"
ERROR: could not modify any active placements
-- queries with non-constant partition values are unsupported
INSERT INTO limit_orders VALUES (random() * 100, 'ORCL', 152, '2011-08-25 11:50:45',
Expand Down
29 changes: 29 additions & 0 deletions sql/create_shards.sql.tmpl
Expand Up @@ -79,3 +79,32 @@ SELECT sort_names('sumedh', 'jason', 'ozgun');
SELECT create_table_then_fail('localhost', $PGPORT);

SELECT COUNT(*) FROM pg_class WHERE relname LIKE 'throwaway%' AND relkind = 'r';

\set VERBOSITY terse

-- test foreign table creation
CREATE FOREIGN TABLE foreign_table_to_distribute
(
name text,
id bigint
)
SERVER fake_fdw_server;

SELECT master_create_distributed_table('foreign_table_to_distribute', 'id');
SELECT master_create_worker_shards('foreign_table_to_distribute', 16, 1);

\set VERBOSITY default
SELECT storage, min_value, max_value FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass
ORDER BY (min_value COLLATE "C") ASC;

-- cleanup foreign table, related shards and shard placements
DELETE FROM pgs_distribution_metadata.shard_placement
WHERE shard_id IN (SELECT shard_id FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass);

DELETE FROM pgs_distribution_metadata.shard
WHERE relation_id = 'foreign_table_to_distribute'::regclass;

DELETE FROM pgs_distribution_metadata.partition
WHERE relation_id = 'foreign_table_to_distribute'::regclass;

0 comments on commit ee94147

Please sign in to comment.