Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 25bb8d1

Browse files
committed
movempart in progress, fixed unpleasant bug in timeutils
1 parent 9512e73 commit 25bb8d1

File tree

5 files changed

+167
-63
lines changed

5 files changed

+167
-63
lines changed

pg_shardman--0.0.1.sql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,12 @@ BEGIN
301301
END;
302302
$$ LANGUAGE plpgsql;
303303

304-
-- Create logical pgoutput replication slot, if not exists
304+
-- Recreate logical pgoutput replication slot. Drops existing slot.
305305
CREATE FUNCTION create_repslot(slot_name text) RETURNS void AS $$
306-
DECLARE
307-
slot_exists bool;
308306
BEGIN
309-
EXECUTE format('SELECT EXISTS (SELECT * FROM pg_replication_slots
310-
WHERE slot_name=%L)', slot_name) INTO slot_exists;
311-
IF NOT slot_exists THEN
312-
EXECUTE format('SELECT pg_create_logical_replication_slot(%L, %L)',
313-
slot_name, 'pgoutput');
314-
END IF;
307+
PERFORM shardman.drop_repslot(slot_name);
308+
EXECUTE format('SELECT pg_create_logical_replication_slot(%L, %L)',
309+
slot_name, 'pgoutput');
315310
END
316311
$$ LANGUAGE plpgsql;
317312

@@ -321,7 +316,7 @@ DECLARE
321316
slot_exists bool;
322317
BEGIN
323318
EXECUTE format('SELECT EXISTS (SELECT * FROM pg_replication_slots
324-
WHERE slot_name=%L)', slot_name) INTO slot_exists;
319+
WHERE slot_name = %L)', slot_name) INTO slot_exists;
325320
IF slot_exists THEN
326321
EXECUTE format('SELECT pg_drop_replication_slot(%L)', slot_name);
327322
END IF;

src/include/pg_shardman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ extern void update_cmd_status(int64 id, const char *new_status);
4343
extern void cmd_canceled(Cmd *cmd);
4444
extern char *get_worker_node_connstr(int node_id);
4545
extern int32 get_partition_owner(const char *part_name);
46+
extern char *get_partition_relation(const char *part_name);
4647

4748
#endif /* PG_SHARDMAN_H */

src/pg_shardman.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,13 @@ add_node(Cmd *cmd)
525525
}
526526
PQclear(res);
527527

528-
/* Create replication slot, if not yet */
528+
/* Create replication slot */
529529
sql = psprintf("select shardman.create_repslot('shardman_meta_sub_%d');",
530530
node_id);
531531
void_spi(sql);
532532
pfree(sql);
533533

534-
/* Create subscription and set node it on itself */
534+
/* Create subscription and set node id on itself */
535535
sql = psprintf(
536536
"create subscription shardman_meta_sub connection '%s'"
537537
"publication shardman_meta_pub with (create_slot = false,"
@@ -752,3 +752,41 @@ get_partition_owner(const char *part_name)
752752
SPI_EPILOG;
753753
return owner;
754754
}
755+
756+
/*
757+
* Get relation name of partition part_name. Memory is palloc'ed.
758+
* NULL is returned, if there is no such partition.
759+
*/
760+
char*
761+
get_partition_relation(const char *part_name)
762+
{
763+
MemoryContext oldcxt = CurrentMemoryContext;
764+
char *sql = psprintf("select relation from shardman.partitions"
765+
" where part_name = '%s';", part_name);
766+
char *res;
767+
768+
SPI_PROLOG;
769+
770+
if (SPI_execute(sql, true, 0) < 0)
771+
{
772+
shmn_elog(FATAL, "Stmt failed : %s", sql);
773+
}
774+
pfree(sql);
775+
776+
if (SPI_processed == 0)
777+
{
778+
res = NULL;
779+
}
780+
else
781+
{
782+
HeapTuple tuple = SPI_tuptable->vals[0];
783+
TupleDesc rowdesc = SPI_tuptable->tupdesc;
784+
/* We need to allocate connstring in our ctxt, not spi's */
785+
MemoryContext spicxt = MemoryContextSwitchTo(oldcxt);
786+
res = SPI_getvalue(tuple, rowdesc, 1);
787+
MemoryContextSwitchTo(spicxt);
788+
}
789+
790+
SPI_EPILOG;
791+
return res;
792+
}

0 commit comments

Comments
 (0)