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

Commit d8354e3

Browse files
committed
Shorter var names and int32 node ids.
1 parent 7a7811e commit d8354e3

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

src/include/pg_shardman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern void check_for_sigterm(void);
4141
extern uint64 void_spi(char *sql);
4242
extern void update_cmd_status(int64 id, const char *new_status);
4343
extern void cmd_canceled(Cmd *cmd);
44-
extern char *get_worker_node_connstring(int node_id);
44+
extern char *get_worker_node_connstr(int node_id);
4545
extern int32 get_partition_owner(const char *part_name);
4646

4747
#endif /* PG_SHARDMAN_H */

src/pg_shardman.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void shardmaster_sigusr1(SIGNAL_ARGS);
4242
static void pg_shardman_installed_local(void);
4343

4444
static void add_node(Cmd *cmd);
45-
static int insert_node(const char *connstring, int64 cmd_id);
45+
static int insert_node(const char *connstr, int64 cmd_id);
4646
static bool node_in_cluster(int id);
4747

4848
static void rm_node(Cmd *cmd);
@@ -178,6 +178,8 @@ shardmaster_main(Datum main_arg)
178178
rm_node(cmd);
179179
else if (strcmp(cmd->cmd_type, "create_hash_partitions") == 0)
180180
create_hash_partitions(cmd);
181+
else if (strcmp(cmd->cmd_type, "move_mpart") == 0)
182+
move_mpart(cmd);
181183
else
182184
shmn_elog(FATAL, "Unknown cmd type %s", cmd->cmd_type);
183185
}
@@ -211,12 +213,12 @@ void_spi(char *sql)
211213
PGconn *
212214
listen_cmd_log_inserts(void)
213215
{
214-
char *connstring;
216+
char *connstr;
215217
PGresult *res;
216218

217-
connstring = psprintf("dbname = %s", shardman_master_dbname);
218-
conn = PQconnectdb(connstring);
219-
pfree(connstring);
219+
connstr = psprintf("dbname = %s", shardman_master_dbname);
220+
conn = PQconnectdb(connstr);
221+
pfree(connstr);
220222
/* Check to see that the backend connection was successfully made */
221223
if (PQstatus(conn) != CONNECTION_OK)
222224
shmn_elog(FATAL, "Connection to local database failed: %s",
@@ -442,17 +444,17 @@ void
442444
add_node(Cmd *cmd)
443445
{
444446
PGconn *conn = NULL;
445-
const char *connstring = cmd->opts[0];
447+
const char *connstr = cmd->opts[0];
446448
PGresult *res = NULL;
447449
bool pg_shardman_installed;
448-
int node_id;
450+
int32 node_id;
449451
char *sql;
450452

451-
shmn_elog(INFO, "Adding node %s", connstring);
453+
shmn_elog(INFO, "Adding node %s", connstr);
452454
/* Try to execute command indefinitely until it succeeded or canceled */
453455
while (!got_sigusr1 && !got_sigterm)
454456
{
455-
conn = PQconnectdb(connstring);
457+
conn = PQconnectdb(connstr);
456458
if (PQstatus(conn) != CONNECTION_OK)
457459
{
458460
shmn_elog(NOTICE, "Connection to add_node node failed: %s",
@@ -488,12 +490,12 @@ add_node(Cmd *cmd)
488490
{
489491
/* Node is in cluster. Was it there before we started adding? */
490492
node_id = atoi(PQgetvalue(res, 0, 0));
491-
elog(INFO, "NODE IN CLUSTER, %d", node_id);
493+
elog(DEBUG1, "node in cluster, %d", node_id);
492494
PQclear(res);
493495
if (node_in_cluster(node_id))
494496
{
495497
shmn_elog(WARNING, "node %d with connstring %s is already"
496-
" in cluster, won't add it.", node_id, connstring);
498+
" in cluster, won't add it.", node_id, connstr);
497499
PQfinish(conn);
498500
update_cmd_status(cmd->id, "failed");
499501
return;
@@ -507,7 +509,7 @@ add_node(Cmd *cmd)
507509
* Now add node to 'nodes' table, if we haven't done that yet, and
508510
* record that we did so for this cmd
509511
*/
510-
node_id = insert_node(connstring, cmd->id);
512+
node_id = insert_node(connstr, cmd->id);
511513

512514
/*
513515
* reinstall the extension to reset its state, whether is was
@@ -560,7 +562,7 @@ add_node(Cmd *cmd)
560562

561563
/* done */
562564
elog(INFO, "Node %s successfully added, it is assigned id %d",
563-
connstring, node_id);
565+
connstr, node_id);
564566
return;
565567

566568
attempt_failed: /* clean resources, sleep, check sigusr1 and try again */
@@ -580,12 +582,12 @@ add_node(Cmd *cmd)
580582

581583
/* See sql func */
582584
static int
583-
insert_node(const char *connstring, int64 cmd_id)
585+
insert_node(const char *connstr, int64 cmd_id)
584586
{
585587
char *sql = psprintf("select shardman.insert_node('%s', %ld)",
586-
connstring, cmd_id);
588+
connstr, cmd_id);
587589
int e;
588-
int node_id;
590+
int32 node_id;
589591
bool isnull;
590592

591593
SPI_PROLOG;
@@ -636,7 +638,7 @@ node_in_cluster(int id)
636638
void
637639
rm_node(Cmd *cmd)
638640
{
639-
int node_id = atoi(cmd->opts[0]);
641+
int32 node_id = atoi(cmd->opts[0]);
640642
char *sql;
641643

642644
elog(INFO, "Removing node %d ", node_id);
@@ -678,11 +680,11 @@ rm_node(Cmd *cmd)
678680

679681

680682
/*
681-
* Get connstring of worker node with id node_id. Memory is palloc'ed.
683+
* Get connstr of worker node with id node_id. Memory is palloc'ed.
682684
* NULL is returned, if there is no such node.
683685
*/
684686
char*
685-
get_worker_node_connstring(int node_id)
687+
get_worker_node_connstr(int node_id)
686688
{
687689
MemoryContext oldcxt = CurrentMemoryContext;
688690
char *sql = psprintf("select connstring from shardman.nodes where id = %d"

src/shard.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ static ExecMoveMPartRes exec_move_mpart(MoveMPartState *mmps);
6767
void
6868
create_hash_partitions(Cmd *cmd)
6969
{
70-
int node_id = atoi(cmd->opts[0]);
70+
int32 node_id = atoi(cmd->opts[0]);
7171
const char *relation = cmd->opts[1];
7272
const char *expr = cmd->opts[2];
7373
int partitions_count = atoi(cmd->opts[3]);
74-
char *connstring;
74+
char *connstr;
7575
PGconn *conn = NULL;
7676
PGresult *res = NULL;
7777
char *sql;
@@ -92,8 +92,8 @@ create_hash_partitions(Cmd *cmd)
9292
update_cmd_status(cmd->id, "failed");
9393
return;
9494
}
95-
/* connstring mem freed with ctxt */
96-
if ((connstring = get_worker_node_connstring(node_id)) == NULL)
95+
/* connstr mem freed with ctxt */
96+
if ((connstr = get_worker_node_connstr(node_id)) == NULL)
9797
{
9898
shmn_elog(WARNING, "create_hash_partitions failed, no such worker node: %d",
9999
node_id);
@@ -107,12 +107,12 @@ create_hash_partitions(Cmd *cmd)
107107
"begin; select create_hash_partitions('%s', '%s', %d); end;"
108108
"select shardman.gen_create_table_sql('%s', '%s');",
109109
relation, expr, partitions_count,
110-
relation, connstring);
110+
relation, connstr);
111111

112112
/* Try to execute command indefinitely until it succeeded or canceled */
113113
while (!got_sigusr1 && !got_sigterm)
114114
{
115-
conn = PQconnectdb(connstring);
115+
conn = PQconnectdb(connstr);
116116
if (PQstatus(conn) != CONNECTION_OK)
117117
{
118118
shmn_elog(NOTICE, "Connection to node failed: %s",

0 commit comments

Comments
 (0)