CVS User Account cvsuser
Thu Oct 26 13:09:57 PDT 2006
Log Message:
-----------
Added a new command to slonik.

    SYNC (id = <nodeid>)

will issue a SYNC event on the specified node. The purpose of this
command is to have a slonik generated event to wait for. This is
needed in order to be able to wait for subscriptions to complete.

Jan

Tags:
----
REL_1_2_STABLE

Modified Files:
--------------
    slony1-engine/src/ducttape:
        test_5_subscribe (r1.1 -> r1.1.6.1)
    slony1-engine/src/slonik:
        parser.y (r1.25 -> r1.25.2.1)
        scan.l (r1.24 -> r1.24.2.1)
        slonik.c (r1.67 -> r1.67.2.1)
        slonik.h (r1.27 -> r1.27.2.1)

-------------- next part --------------
Index: test_5_subscribe
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/ducttape/test_5_subscribe,v
retrieving revision 1.1
retrieving revision 1.1.6.1
diff -Lsrc/ducttape/test_5_subscribe -Lsrc/ducttape/test_5_subscribe -u -w -r1.1 -r1.1.6.1
--- src/ducttape/test_5_subscribe
+++ src/ducttape/test_5_subscribe
@@ -28,10 +28,15 @@
 	on error {
 		exit 1;
 	}
+	echo '***** Waiting for subscribe set to arrive on origin';
+	wait for event (origin = 2, confirmed = 1);
+	echo '***** Subscribe set received on origin - issue SYNC';
+	sync (id = 1);
+	echo '***** Waiting for SYNC to be done on subscriber';
+	wait for event (origin = 1, confirmed = 2);
+	echo '***** Subscription complete';
 _EOF_
 
-sleep 30
-
 echo "**** Merging set 999 into 1"
 slonik <<_EOF_
 	cluster name = T1;
Index: scan.l
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/scan.l,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -Lsrc/slonik/scan.l -Lsrc/slonik/scan.l -u -w -r1.24 -r1.24.2.1
--- src/slonik/scan.l
+++ src/slonik/scan.l
@@ -125,6 +125,7 @@
 subscribe		{ return K_SUBSCRIBE;		}
 success			{ return K_SUCCESS;			}
 switch			{ return K_SWITCH;			}
+sync			{ return K_SYNC;			}
 table			{ return K_TABLE;			}
 timeout			{ return K_TIMEOUT;			}
 trigger			{ return K_TRIGGER;			}
Index: slonik.h
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.h,v
retrieving revision 1.27
retrieving revision 1.27.2.1
diff -Lsrc/slonik/slonik.h -Lsrc/slonik/slonik.h -u -w -r1.27 -r1.27.2.1
--- src/slonik/slonik.h
+++ src/slonik/slonik.h
@@ -49,6 +49,7 @@
 typedef struct SlonikStmt_update_functions_s SlonikStmt_update_functions;
 typedef struct SlonikStmt_wait_event_s SlonikStmt_wait_event;
 typedef struct SlonikStmt_switch_log_s SlonikStmt_switch_log;
+typedef struct SlonikStmt_sync_s SlonikStmt_sync;
 
 typedef enum
 {
@@ -87,7 +88,8 @@
 	STMT_UPDATE_FUNCTIONS,
 	STMT_WAIT_EVENT,
 	STMT_SWITCH_LOG,
-	STMT_ERROR
+	STMT_ERROR,
+	STMT_SYNC
 }	Slonik_stmttype;
 
 struct SlonikScript_s
@@ -431,6 +433,13 @@
 };
 
 
+struct SlonikStmt_sync_s
+{
+	SlonikStmt	hdr;
+	int			no_id;
+};
+
+
 
 
 extern SlonikScript *parser_script;
@@ -553,6 +562,7 @@
 extern int	slonik_update_functions(SlonikStmt_update_functions * stmt);
 extern int	slonik_wait_event(SlonikStmt_wait_event * stmt);
 extern int	slonik_switch_log(SlonikStmt_switch_log * stmt);
+extern int	slonik_sync(SlonikStmt_sync * stmt);
 
 extern int	slon_scanint64(char *str, int64 * result);
 
Index: parser.y
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/parser.y,v
retrieving revision 1.25
retrieving revision 1.25.2.1
diff -Lsrc/slonik/parser.y -Lsrc/slonik/parser.y -u -w -r1.25 -r1.25.2.1
--- src/slonik/parser.y
+++ src/slonik/parser.y
@@ -160,6 +160,7 @@
 %type <statement>	stmt_repair_config
 %type <statement>	stmt_wait_event
 %type <statement>	stmt_switch_log
+%type <statement>	stmt_sync
 %type <opt_list>	option_list
 %type <opt_list>	option_list_item
 %type <opt_list>	option_list_items
@@ -241,6 +242,7 @@
 %token	K_UPDATE
 %token	K_YES
 %token	K_WAIT
+%token	K_SYNC
 
 /*
  * Other scanner tokens
@@ -483,6 +485,8 @@
 					| stmt_error ';' 
 						{ yyerrok;
 						  $$ = $1; }
+					| stmt_sync
+						{ $$ = $1; }
 					;
 
 stmt_echo			: lno K_ECHO literal ';'
@@ -1474,6 +1478,32 @@
 					}
 					;
 
+stmt_sync			: lno K_SYNC option_list
+					{
+						SlonikStmt_sync *new;
+						statement_option opt[] = {
+							STMT_OPTION_INT( O_ID, -1 ),
+							STMT_OPTION_END
+						};
+
+						new = (SlonikStmt_sync *)
+								malloc(sizeof(SlonikStmt_sync));
+						memset(new, 0, sizeof(SlonikStmt_sync));
+						new->hdr.stmt_type		= STMT_SYNC;
+						new->hdr.stmt_filename	= current_file;
+						new->hdr.stmt_lno		= $1;
+
+						if (assign_options(opt, $3) == 0)
+						{
+							new->no_id			= opt[0].ival;
+						}
+						else
+							parser_errors++;
+
+						$$ = (SlonikStmt *)new;
+					}
+					;
+
 option_list			: ';'
 					{ $$ = NULL; }
 					| '(' option_list_items ')' ';'
Index: slonik.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.c,v
retrieving revision 1.67
retrieving revision 1.67.2.1
diff -Lsrc/slonik/slonik.c -Lsrc/slonik/slonik.c -u -w -r1.67 -r1.67.2.1
--- src/slonik/slonik.c
+++ src/slonik/slonik.c
@@ -70,51 +70,8 @@
 static void script_rollback_all(SlonikStmt * stmt,
 					SlonikScript * script);
 static void script_disconnect_all(SlonikScript * script);
-
-/*
- * make a copy of the array of lines, with token replaced by replacement
- * the first time it occurs on each line.
- *
- * This does most of what sed was used for in the shell script, but
- * doesn't need any regexp stuff.
- */
-void
-replace_token(char *resout, char *lines, const char *token, const char *replacement)
-{
-	int			numlines = 1;
-	int			i,
-				o;
-	char		result_set[4096];
-	int			toklen,
-				replen;
-
-	for (i = 0; lines[i]; i++)
-		numlines++;
-
-	toklen = strlen(token);
-	replen = strlen(replacement);
-
-	for (i = o = 0; i < numlines; i++, o++)
-	{
-		/* just copy pointer if NULL or no change needed */
-		if (!lines[i] || (strncmp((const char *)lines + i, token, toklen)))
-		{
-			if (lines[i] == 0x0d)		/* ||(lines[i] == 0x0a)) */
-				break;
-
-			result_set[o] = lines[i];
-			continue;
-		}
-		/* if we get here a change is needed - set up new line */
-		strncpy((char *)result_set + o, replacement, replen);
-		o += replen - 1;
-		i += toklen - 1;
-	}
-
-	result_set[o] = '\0';
-	memcpy(resout, result_set, o);
-
-}
+static void replace_token(char *resout, char *lines, const char *token, 
+					const char *replacement);
 
 /* ----------
  * main
@@ -1139,6 +1096,25 @@
 				}
 				break;
 
+			case STMT_SYNC:
+				{
+					SlonikStmt_sync *stmt =
+					(SlonikStmt_sync *) hdr;
+
+					if (stmt->no_id == -1)
+					{
+						printf("%s:%d: Error: "
+							   "node ID must be specified\n",
+							   hdr->stmt_filename, hdr->stmt_lno);
+						errors++;
+					}
+
+					if (script_check_adminfo(hdr, stmt->no_id) < 0)
+						errors++;
+
+				}
+				break;
+
 		}
 
 		hdr = hdr->next;
@@ -1574,6 +1550,16 @@
 				}
 				break;
 
+			case STMT_SYNC:
+				{
+					SlonikStmt_sync *stmt =
+					(SlonikStmt_sync *) hdr;
+
+					if (slonik_sync(stmt) < 0)
+						errors++;
+				}
+				break;
+
 		}
 
 		if (current_try_level == 0)
@@ -4186,6 +4172,36 @@
 }
 
 
+int
+slonik_sync(SlonikStmt_sync * stmt)
+{
+	SlonikAdmInfo *adminfo1;
+	SlonDString query;
+
+	adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->no_id);
+	if (adminfo1 == NULL)
+		return -1;
+
+	if (db_begin_xact((SlonikStmt *) stmt, adminfo1) < 0)
+		return -1;
+
+	dstring_init(&query);
+
+	slon_mkquery(&query,
+				 "select \"_%s\".createEvent('_%s', 'SYNC'); ",
+				 stmt->hdr.script->clustername,
+				 stmt->hdr.script->clustername);
+	if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
+	{
+		dstring_free(&query);
+		return -1;
+	}
+
+	dstring_free(&query);
+	return 0;
+}
+
+
 /*
  * scanint8 --- try to parse a string into an int8.
  *
@@ -4252,6 +4268,52 @@
 	return true;
 }
 
+
+/*
+ * make a copy of the array of lines, with token replaced by replacement
+ * the first time it occurs on each line.
+ *
+ * This does most of what sed was used for in the shell script, but
+ * doesn't need any regexp stuff.
+ */
+static void
+replace_token(char *resout, char *lines, const char *token, const char *replacement)
+{
+	int			numlines = 1;
+	int			i,
+				o;
+	char		result_set[4096];
+	int			toklen,
+				replen;
+
+	for (i = 0; lines[i]; i++)
+		numlines++;
+
+	toklen = strlen(token);
+	replen = strlen(replacement);
+
+	for (i = o = 0; i < numlines; i++, o++)
+	{
+		/* just copy pointer if NULL or no change needed */
+		if (!lines[i] || (strncmp((const char *)lines + i, token, toklen)))
+		{
+			if (lines[i] == 0x0d)		/* ||(lines[i] == 0x0a)) */
+				break;
+
+			result_set[o] = lines[i];
+			continue;
+		}
+		/* if we get here a change is needed - set up new line */
+		strncpy((char *)result_set + o, replacement, replen);
+		o += replen - 1;
+		i += toklen - 1;
+	}
+
+	result_set[o] = '\0';
+	memcpy(resout, result_set, o);
+}
+
+
 /*
  * Local Variables:
  *	tab-width: 4



More information about the Slony1-commit mailing list