Fri Oct 8 17:31:04 PDT 2004
- Previous message: [Slony1-commit] By wieck: Added SET MOVE TABLE and SET MOVE SEQUENCE commands to change
- Next message: [Slony1-commit] By wieck: Ignore more generated files Jan
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message: ----------- Added SET MOVE TABLE and SET MOVE SEQUENCE commands to change the set a table or sequence belongs to without unsubscribing and resubscribing all nodes. Jan Modified Files: -------------- slony1-engine/doc/howto: slonik_commands.html (r1.8 -> r1.9) slony1-engine/src/backend: slony1_funcs.sql (r1.30 -> r1.31) slony1-engine/src/slon: local_listen.c (r1.25 -> r1.26) remote_worker.c (r1.64 -> r1.65) slony1-engine/src/slonik: parser.y (r1.19 -> r1.20) slonik.c (r1.31 -> r1.32) slonik.h (r1.19 -> r1.20) -------------- next part -------------- Index: remote_worker.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/remote_worker.c,v retrieving revision 1.64 retrieving revision 1.65 diff -Lsrc/slon/remote_worker.c -Lsrc/slon/remote_worker.c -u -w -r1.64 -r1.65 --- src/slon/remote_worker.c +++ src/slon/remote_worker.c @@ -688,15 +688,33 @@ } else if (strcmp(event->ev_type, "SET_DROP_TABLE") == 0) { int tab_id = (int) strtol(event->ev_data1, NULL, 10); + slon_appendquery(&query1, "select %s.setDropTable_int(%d);", rtcfg_namespace, tab_id); } else if (strcmp(event->ev_type, "SET_DROP_SEQUENCE") == 0) { int seq_id = (int) strtol(event->ev_data1, NULL, 10); + slon_appendquery(&query1, "select %s.setDropSequence_int(%d);", rtcfg_namespace, seq_id); + } else if (strcmp(event->ev_type, "SET_MOVE_TABLE") == 0) + { + int tab_id = (int) strtol(event->ev_data1, NULL, 10); + int new_set_id = (int) strtol(event->ev_data2, NULL, 10); + + slon_appendquery(&query1, "select %s.setMoveTable_int(%d, %d);", + rtcfg_namespace, + tab_id, new_set_id); + } else if (strcmp(event->ev_type, "SET_MOVE_SEQUENCE") == 0) + { + int seq_id = (int) strtol(event->ev_data1, NULL, 10); + int new_set_id = (int) strtol(event->ev_data2, NULL, 10); + + slon_appendquery(&query1, "select %s.setMoveSequence_int(%d, %d);", + rtcfg_namespace, + seq_id, new_set_id); } else if (strcmp(event->ev_type, "STORE_TRIGGER") == 0) { int trig_tabid = (int)strtol(event->ev_data1, NULL, 10); Index: local_listen.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/local_listen.c,v retrieving revision 1.25 retrieving revision 1.26 diff -Lsrc/slon/local_listen.c -Lsrc/slon/local_listen.c -u -w -r1.25 -r1.26 --- src/slon/local_listen.c +++ src/slon/local_listen.c @@ -424,6 +424,28 @@ * the runtime configuration. */ } + else if (strcmp(ev_type, "SET_MOVE_TABLE") == 0) + { + /* + * SET_MOVE_TABLE + */ + /* + * Nothing to do ATM ... + * table information is not maintained in + * the runtime configuration. + */ + } + else if (strcmp(ev_type, "SET_MOVE_SEQUENCE") == 0) + { + /* + * SET_MOVE_SEQUENCE + */ + /* + * Nothing to do ATM ... + * table information is not maintained in + * the runtime configuration. + */ + } else if (strcmp(ev_type, "ADJUST_SEQ") == 0) { /* Index: slony1_funcs.sql =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v retrieving revision 1.30 retrieving revision 1.31 diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.30 -r1.31 --- src/backend/slony1_funcs.sql +++ src/backend/slony1_funcs.sql @@ -2713,6 +2713,240 @@ subscribe to the set containing sequence seq_id, drop the sequence from the replication set.'; + +-- ---------------------------------------------------------------------- +-- FUNCTION setMoveTable (tab_id, new_set_id) +-- +-- Generate the SET_MOVE_TABLE event. +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .setMoveTable (int4, int4) +returns bigint +as ' +declare + p_tab_id alias for $1; + p_new_set_id alias for $2; + v_old_set_id int4; + v_origin int4; +begin + -- ---- + -- Grab the central configuration lock + -- ---- + lock table @NAMESPACE at .sl_config_lock; + + -- ---- + -- Get the tables current set + -- ---- + select tab_set into v_old_set_id from @NAMESPACE at .sl_table + where tab_id = p_tab_id; + if not found then + raise exception ''Slony-I: table %d not found'', p_tab_id; + end if; + + -- ---- + -- Check that both sets exist and originate here + -- ---- + if p_new_set_id = v_old_set_id then + raise exception ''Slony-I: set ids cannot be identical''; + end if; + select set_origin into v_origin from @NAMESPACE at .sl_set + where set_id = p_new_set_id; + if not found then + raise exception ''Slony-I: set % not found'', p_new_set_id; + end if; + if v_origin != @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'') then + raise exception ''Slony-I: set % does not originate on local node'', + p_new_set_id; + end if; + + select set_origin into v_origin from @NAMESPACE at .sl_set + where set_id = v_old_set_id; + if not found then + raise exception ''Slony-I: set % not found'', v_old_set_id; + end if; + if v_origin != @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'') then + raise exception ''Slony-I: set % does not originate on local node'', + v_old_set_id; + end if; + + -- ---- + -- Check that both sets are subscribed by the same set of nodes + -- ---- + if exists (select true from @NAMESPACE at .sl_subscribe SUB1 + where SUB1.sub_set = p_new_set_id + and SUB1.sub_receiver not in (select SUB2.sub_receiver + from @NAMESPACE at .sl_subscribe SUB2 + where SUB2.sub_set = v_old_set_id)) + then + raise exception ''Slony-I: subscriber lists of set % and % are different'', + p_new_set_id, v_old_set_id; + end if; + + if exists (select true from @NAMESPACE at .sl_subscribe SUB1 + where SUB1.sub_set = v_old_set_id + and SUB1.sub_receiver not in (select SUB2.sub_receiver + from @NAMESPACE at .sl_subscribe SUB2 + where SUB2.sub_set = p_new_set_id)) + then + raise exception ''Slony-I: subscriber lists of set % and % are different'', + v_old_set_id, p_new_set_id; + end if; + + -- ---- + -- Change the set the table belongs to + -- ---- + perform @NAMESPACE at .createEvent(''_ at CLUSTERNAME@'', ''SYNC'', NULL); + perform @NAMESPACE at .setMoveTable_int(p_tab_id, p_new_set_id); + return @NAMESPACE at .createEvent(''_ at CLUSTERNAME@'', ''SET_MOVE_TABLE'', + p_tab_id, p_new_set_id); +end; +' language plpgsql; + + +-- ---------------------------------------------------------------------- +-- FUNCTION setMoveTable_int (tab_id, new_set_id) +-- +-- Process the SET_MOVE_TABLE event. +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .setMoveTable_int (int4, int4) +returns int4 +as ' +declare + p_tab_id alias for $1; + p_new_set_id alias for $2; +begin + -- ---- + -- Grab the central configuration lock + -- ---- + lock table @NAMESPACE at .sl_config_lock; + + -- ---- + -- Move the table to the new set + -- ---- + update @NAMESPACE at .sl_table + set tab_set = p_new_set_id + where tab_id = p_tab_id; + + return p_tab_id; +end; +' language plpgsql; + + +-- ---------------------------------------------------------------------- +-- FUNCTION setMoveSequence (seq_id, new_set_id) +-- +-- Generate the SET_MOVE_SEQUENCE event. +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .setMoveSequence (int4, int4) +returns bigint +as ' +declare + p_seq_id alias for $1; + p_new_set_id alias for $2; + v_old_set_id int4; + v_origin int4; +begin + -- ---- + -- Grab the central configuration lock + -- ---- + lock table @NAMESPACE at .sl_config_lock; + + -- ---- + -- Get the sequences current set + -- ---- + select seq_set into v_old_set_id from @NAMESPACE at .sl_sequence + where seq_id = p_seq_id; + if not found then + raise exception ''Slony-I: sequence %d not found'', p_seq_id; + end if; + + -- ---- + -- Check that both sets exist and originate here + -- ---- + if p_new_set_id = v_old_set_id then + raise exception ''Slony-I: set ids cannot be identical''; + end if; + select set_origin into v_origin from @NAMESPACE at .sl_set + where set_id = p_new_set_id; + if not found then + raise exception ''Slony-I: set % not found'', p_new_set_id; + end if; + if v_origin != @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'') then + raise exception ''Slony-I: set % does not originate on local node'', + p_new_set_id; + end if; + + select set_origin into v_origin from @NAMESPACE at .sl_set + where set_id = v_old_set_id; + if not found then + raise exception ''Slony-I: set % not found'', v_old_set_id; + end if; + if v_origin != @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'') then + raise exception ''Slony-I: set % does not originate on local node'', + v_old_set_id; + end if; + + -- ---- + -- Check that both sets are subscribed by the same set of nodes + -- ---- + if exists (select true from @NAMESPACE at .sl_subscribe SUB1 + where SUB1.sub_set = p_new_set_id + and SUB1.sub_receiver not in (select SUB2.sub_receiver + from @NAMESPACE at .sl_subscribe SUB2 + where SUB2.sub_set = v_old_set_id)) + then + raise exception ''Slony-I: subscriber lists of set % and % are different'', + p_new_set_id, v_old_set_id; + end if; + + if exists (select true from @NAMESPACE at .sl_subscribe SUB1 + where SUB1.sub_set = v_old_set_id + and SUB1.sub_receiver not in (select SUB2.sub_receiver + from @NAMESPACE at .sl_subscribe SUB2 + where SUB2.sub_set = p_new_set_id)) + then + raise exception ''Slony-I: subscriber lists of set % and % are different'', + v_old_set_id, p_new_set_id; + end if; + + -- ---- + -- Change the set the sequence belongs to + -- ---- + perform @NAMESPACE at .setMoveSequence_int(p_seq_id, p_new_set_id); + return @NAMESPACE at .createEvent(''_ at CLUSTERNAME@'', ''SET_MOVE_SEQUENCE'', + p_seq_id, p_new_set_id); +end; +' language plpgsql; + + +-- ---------------------------------------------------------------------- +-- FUNCTION setMoveSequence_int (seq_id, new_set_id) +-- +-- Process the SET_MOVE_SEQUENCE event. +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .setMoveSequence_int (int4, int4) +returns int4 +as ' +declare + p_seq_id alias for $1; + p_new_set_id alias for $2; +begin + -- ---- + -- Grab the central configuration lock + -- ---- + lock table @NAMESPACE at .sl_config_lock; + + -- ---- + -- Move the sequence to the new set + -- ---- + update @NAMESPACE at .sl_sequence + set seq_set = p_new_set_id + where seq_id = p_seq_id; + + return p_seq_id; +end; +' language plpgsql; + + -- ---------------------------------------------------------------------- -- FUNCTION sequenceSetValue (seq_id, seq_origin, ev_seqno, last_value) -- ---------------------------------------------------------------------- Index: slonik_commands.html =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/doc/howto/slonik_commands.html,v retrieving revision 1.8 retrieving revision 1.9 diff -Ldoc/howto/slonik_commands.html -Ldoc/howto/slonik_commands.html -u -w -r1.8 -r1.9 --- doc/howto/slonik_commands.html +++ doc/howto/slonik_commands.html @@ -39,6 +39,8 @@ <li><a href="#stmt_set_add_sequence">SET ADD SEQUENCE</a> <li><a href="#stmt_set_drop_table">SET DROP TABLE</a> <li><a href="#stmt_set_drop_sequence">SET DROP SEQUENCE</a> + <li><a href="#stmt_set_move_table">SET DROP TABLE</a> + <li><a href="#stmt_set_move_sequence">SET DROP SEQUENCE</a> <li><a href="#stmt_store_trigger">STORE TRIGGER</a> <li><a href="#stmt_drop_trigger">DROP TRIGGER</a> <li><a href="#stmt_subscribe_set">SUBSCRIBE SET</a> @@ -1097,6 +1099,106 @@ <p align="right">Back to <a href="#index">Index</a></p> <!-- **************************************** --> +<a name="stmt_set_move_table"> +<h3>SET MOVE TABLE</h3> +</a> +<div style="margin-left:40px; margin-right:0px;"> +<h3>Synopsis:</h3> + SET MOVE TABLE ( <options> ); +<h3>Description:</h3> +<p> + Change the set a table belongs to. The current set and the new set + must origin on the same node and subscribed by the same nodes. + CAUTION: Due to the way subscribing to new sets works make + absolutely sure that the subscription of all nodes to the sets + is completely processed before moving tables. Moving a table too + early to a new set causes the subscriber to try and add the table + already during the subscription process, which fails with a duplicate + key error and breaks replication. +</p> +<table border="0" cellpadding="10"> +<tr> + <td align="left" valign="top" nowrap><b>ORIGIN = <ival></b></td> + <td align="left" valign="top"><p> + The current origin of the set. A future version of slonik + might figure out this information by itself. + </p></td> +</tr> +<tr> + <td align="left" valign="top" nowrap><b>ID = <ival></b></td> + <td align="left" valign="top"><p> + Unique ID of the table. + </p></td> +</tr> +<tr> + <td align="left" valign="top" nowrap><b>NEW SET = <ival></b></td> + <td align="left" valign="top"><p> + Unique ID of the new set. + </p></td> +</tr> +</table> +<h3>Example:</h3> +<p> + SET MOVE TABLE ( + <br> ORIGIN = 1, + <br> ID = 20, + <br> NEW SET = 3 + <br>); +</p> +</div> +<p align="right">Back to <a href="#index">Index</a></p> + +<!-- **************************************** --> +<a name="stmt_set_move_sequence"> +<h3>SET MOVE SEQUENCE</h3> +</a> +<div style="margin-left:40px; margin-right:0px;"> +<h3>Synopsis:</h3> + SET MOVE SEQUENCE ( <options> ); +<h3>Description:</h3> +<p> + Change the set a sequence belongs to. The current set and the new set + must origin on the same node and subscribed by the same nodes. + CAUTION: Due to the way subscribing to new sets works make + absolutely sure that the subscription of all nodes to the sets + is completely processed before moving sequences. Moving a sequence too + early to a new set causes the subscriber to try and add the sequence + already during the subscription process, which fails with a duplicate + key error and breaks replication. +</p> +<table border="0" cellpadding="10"> +<tr> + <td align="left" valign="top" nowrap><b>ORIGIN = <ival></b></td> + <td align="left" valign="top"><p> + The current origin of the set. A future version of slonik + might figure out this information by itself. + </p></td> +</tr> +<tr> + <td align="left" valign="top" nowrap><b>ID = <ival></b></td> + <td align="left" valign="top"><p> + Unique ID of the sequence. + </p></td> +</tr> +<tr> + <td align="left" valign="top" nowrap><b>NEW SET = <ival></b></td> + <td align="left" valign="top"><p> + Unique ID of the new set. + </p></td> +</tr> +</table> +<h3>Example:</h3> +<p> + SET MOVE SEQUENCE ( + <br> ORIGIN = 1, + <br> ID = 54, + <br> NEW SET = 3 + <br>); +</p> +</div> +<p align="right">Back to <a href="#index">Index</a></p> + +<!-- **************************************** --> <a name="stmt_store_trigger"> <h3>STORE TRIGGER</h3> </a> Index: slonik.h =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.h,v retrieving revision 1.19 retrieving revision 1.20 diff -Lsrc/slonik/slonik.h -Lsrc/slonik/slonik.h -u -w -r1.19 -r1.20 --- src/slonik/slonik.h +++ src/slonik/slonik.h @@ -34,6 +34,8 @@ typedef struct SlonikStmt_set_add_sequence_s SlonikStmt_set_add_sequence; typedef struct SlonikStmt_set_drop_table_s SlonikStmt_set_drop_table; typedef struct SlonikStmt_set_drop_sequence_s SlonikStmt_set_drop_sequence; +typedef struct SlonikStmt_set_move_table_s SlonikStmt_set_move_table; +typedef struct SlonikStmt_set_move_sequence_s SlonikStmt_set_move_sequence; typedef struct SlonikStmt_table_add_key_s SlonikStmt_table_add_key; typedef struct SlonikStmt_store_trigger_s SlonikStmt_store_trigger; typedef struct SlonikStmt_drop_trigger_s SlonikStmt_drop_trigger; @@ -67,6 +69,8 @@ STMT_SET_ADD_TABLE, STMT_SET_DROP_SEQUENCE, STMT_SET_DROP_TABLE, + STMT_SET_MOVE_SEQUENCE, + STMT_SET_MOVE_TABLE, STMT_STORE_LISTEN, STMT_STORE_NODE, STMT_STORE_PATH, @@ -254,6 +258,7 @@ char *seq_comment; }; + struct SlonikStmt_set_drop_table_s { SlonikStmt hdr; int set_origin; @@ -268,6 +273,22 @@ }; +struct SlonikStmt_set_move_table_s { + SlonikStmt hdr; + int set_origin; + int tab_id; + int new_set_id; +}; + + +struct SlonikStmt_set_move_sequence_s { + SlonikStmt hdr; + int set_origin; + int seq_id; + int new_set_id; +}; + + struct SlonikStmt_table_add_key_s { SlonikStmt hdr; int no_id; @@ -462,6 +483,8 @@ extern int slonik_set_add_sequence(SlonikStmt_set_add_sequence *stmt); extern int slonik_set_drop_table(SlonikStmt_set_drop_table *stmt); extern int slonik_set_drop_sequence(SlonikStmt_set_drop_sequence *stmt); +extern int slonik_set_move_table(SlonikStmt_set_move_table *stmt); +extern int slonik_set_move_sequence(SlonikStmt_set_move_sequence *stmt); extern int slonik_table_add_key(SlonikStmt_table_add_key *stmt); extern int slonik_store_trigger(SlonikStmt_store_trigger *stmt); extern int slonik_drop_trigger(SlonikStmt_drop_trigger *stmt); Index: parser.y =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/parser.y,v retrieving revision 1.19 retrieving revision 1.20 diff -Lsrc/slonik/parser.y -Lsrc/slonik/parser.y -u -w -r1.19 -r1.20 --- src/slonik/parser.y +++ src/slonik/parser.y @@ -33,6 +33,7 @@ O_FQNAME, O_ID, O_NEW_ORIGIN, + O_NEW_SET, O_NODE_ID, O_OLD_ORIGIN, O_ORIGIN, @@ -143,6 +144,8 @@ %type <statement> stmt_set_add_sequence %type <statement> stmt_set_drop_table %type <statement> stmt_set_drop_sequence +%type <statement> stmt_set_move_table +%type <statement> stmt_set_move_sequence %type <statement> stmt_table_add_key %type <statement> stmt_store_trigger %type <statement> stmt_drop_trigger @@ -441,6 +444,10 @@ { $$ = $1; } | stmt_set_drop_sequence { $$ = $1; } + | stmt_set_move_table + { $$ = $1; } + | stmt_set_move_sequence + { $$ = $1; } | stmt_store_trigger { $$ = $1; } | stmt_drop_trigger @@ -1042,6 +1049,64 @@ } ; +stmt_set_move_table : lno K_SET K_MOVE K_TABLE option_list + { + SlonikStmt_set_move_table *new; + statement_option opt[] = { + STMT_OPTION_INT( O_ORIGIN, -1 ), + STMT_OPTION_INT( O_ID, -1 ), + STMT_OPTION_INT( O_NEW_SET, -1 ), + STMT_OPTION_END + }; + new = (SlonikStmt_set_move_table *) + malloc(sizeof(SlonikStmt_set_move_table)); + memset(new, 0, sizeof(SlonikStmt_set_move_table)); + new->hdr.stmt_type = STMT_SET_MOVE_TABLE; + new->hdr.stmt_filename = current_file; + new->hdr.stmt_lno = $1; + + if (assign_options(opt, $5) == 0) { + new->set_origin = opt[0].ival; + new->tab_id = opt[1].ival; + new->new_set_id = opt[2].ival; + } + else + parser_errors++; + + $$ = (SlonikStmt *)new; + } + ; + +stmt_set_move_sequence : lno K_SET K_MOVE K_SEQUENCE option_list + { + SlonikStmt_set_move_sequence *new; + statement_option opt[] = { + STMT_OPTION_INT( O_ORIGIN, -1 ), + STMT_OPTION_INT( O_ID, -1 ), + STMT_OPTION_INT( O_NEW_SET, -1 ), + STMT_OPTION_END + }; + + new = (SlonikStmt_set_move_sequence *) + malloc(sizeof(SlonikStmt_set_move_sequence)); + memset(new, 0, sizeof(SlonikStmt_set_move_sequence)); + new->hdr.stmt_type = STMT_SET_MOVE_SEQUENCE; + new->hdr.stmt_filename = current_file; + new->hdr.stmt_lno = $1; + + if (assign_options(opt, $5) == 0) + { + new->set_origin = opt[0].ival; + new->seq_id = opt[1].ival; + new->new_set_id = opt[2].ival; + } + else + parser_errors++; + + $$ = (SlonikStmt *)new; + } + ; + stmt_store_trigger : lno K_STORE K_TRIGGER option_list { SlonikStmt_store_trigger *new; @@ -1391,6 +1456,11 @@ $4->opt_code = O_NEW_ORIGIN; $$ = $4; } + | K_NEW K_SET '=' option_item_id + { + $4->opt_code = O_NEW_SET; + $$ = $4; + } | K_RECEIVER '=' option_item_id { $3->opt_code = O_RECEIVER; @@ -1647,6 +1717,7 @@ case O_FQNAME: return "full qualified name"; case O_ID: return "id"; case O_NEW_ORIGIN: return "new origin"; + case O_NEW_SET: return "new set"; case O_NODE_ID: return "node id"; case O_OLD_ORIGIN: return "old origin"; case O_ORIGIN: return "origin"; Index: slonik.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.c,v retrieving revision 1.31 retrieving revision 1.32 diff -Lsrc/slonik/slonik.c -Lsrc/slonik/slonik.c -u -w -r1.31 -r1.32 --- src/slonik/slonik.c +++ src/slonik/slonik.c @@ -633,6 +633,90 @@ } break; + case STMT_SET_MOVE_TABLE: + { + SlonikStmt_set_move_table *stmt = + (SlonikStmt_set_move_table *)hdr; + + /* + * Check that we have the set_id and set_origin + * and that we can reach the origin. + */ + if (stmt->set_origin < 0) + { + printf("%s:%d: Error: " + "origin must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + else + { + if (script_check_adminfo(hdr, stmt->set_origin) < 0) + errors++; + } + + /* + * Check that we have the table id and new set id + */ + if (stmt->tab_id < 0) + { + printf("%s:%d: Error: " + "table id must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + if (stmt->new_set_id < 0) + { + printf("%s:%d: Error: " + "new set id must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + } + break; + + case STMT_SET_MOVE_SEQUENCE: + { + SlonikStmt_set_move_sequence *stmt = + (SlonikStmt_set_move_sequence *)hdr; + + /* + * Check that we have the set_id and set_origin + * and that we can reach the origin. + */ + if (stmt->set_origin < 0) + { + printf("%s:%d: Error: " + "origin must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + else + { + if (script_check_adminfo(hdr, stmt->set_origin) < 0) + errors++; + } + + /* + * Check that we have the sequence id and new set id + */ + if (stmt->seq_id < 0) + { + printf("%s:%d: Error: " + "sequence id must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + if (stmt->new_set_id < 0) + { + printf("%s:%d: Error: " + "new set id must be specified\n", + hdr->stmt_filename, hdr->stmt_lno); + errors++; + } + } + break; + case STMT_TABLE_ADD_KEY: { SlonikStmt_table_add_key *stmt = @@ -1219,6 +1303,26 @@ } break; + case STMT_SET_MOVE_TABLE: + { + SlonikStmt_set_move_table *stmt = + (SlonikStmt_set_move_table *)hdr; + + if (slonik_set_move_table(stmt) < 0) + errors++; + } + break; + + case STMT_SET_MOVE_SEQUENCE: + { + SlonikStmt_set_move_sequence *stmt = + (SlonikStmt_set_move_sequence *)hdr; + + if (slonik_set_move_sequence(stmt) < 0) + errors++; + } + break; + case STMT_TABLE_ADD_KEY: { SlonikStmt_table_add_key *stmt = @@ -3069,8 +3173,6 @@ { SlonikAdmInfo *adminfo1; SlonDString query; - char *idxname; - PGresult *res; adminfo1 = get_active_adminfo((SlonikStmt *)stmt, stmt->set_origin); if (adminfo1 == NULL) @@ -3086,7 +3188,6 @@ stmt->hdr.script->clustername, stmt->tab_id); if (db_exec_evcommand((SlonikStmt *)stmt, adminfo1, &query) < 0) { - PQclear(res); dstring_free(&query); return -1; } @@ -3131,6 +3232,62 @@ int +slonik_set_move_table(SlonikStmt_set_move_table *stmt) +{ + SlonikAdmInfo *adminfo1; + SlonDString query; + + adminfo1 = get_active_adminfo((SlonikStmt *)stmt, stmt->set_origin); + if (adminfo1 == NULL) + return -1; + + if (db_begin_xact((SlonikStmt *)stmt, adminfo1) < 0) + return -1; + + dstring_init(&query); + + slon_mkquery(&query, + "select \"_%s\".setMoveTable(%d, %d); ", + stmt->hdr.script->clustername, + stmt->tab_id, stmt->new_set_id); + if (db_exec_evcommand((SlonikStmt *)stmt, adminfo1, &query) < 0) { + dstring_free(&query); + return -1; + } + dstring_free(&query); + return 0; +} + + +int +slonik_set_move_sequence(SlonikStmt_set_move_sequence *stmt) +{ + SlonikAdmInfo *adminfo1; + SlonDString query; + + adminfo1 = get_active_adminfo((SlonikStmt *)stmt, stmt->set_origin); + if (adminfo1 == NULL) + return -1; + + if (db_begin_xact((SlonikStmt *)stmt, adminfo1) < 0) + return -1; + + dstring_init(&query); + + slon_mkquery(&query, + "select \"_%s\".setMoveSequence(%d, %d); ", + stmt->hdr.script->clustername, + stmt->seq_id, stmt->new_set_id); + if (db_exec_evcommand((SlonikStmt *)stmt, adminfo1, &query) < 0) { + dstring_free(&query); + return -1; + } + dstring_free(&query); + return 0; +} + + +int slonik_table_add_key(SlonikStmt_table_add_key *stmt) { SlonikAdmInfo *adminfo1;
- Previous message: [Slony1-commit] By wieck: Added SET MOVE TABLE and SET MOVE SEQUENCE commands to change
- Next message: [Slony1-commit] By wieck: Ignore more generated files Jan
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list