CVS User Account cvsuser
Thu Dec 2 21:43:24 PST 2004
Log Message:
-----------
Added option "spoolnode = yes/no" to "store node" command.
If spoolnode=yes is specified, the sl_node entry will have
no_spool=true and slonik does not attempt to initialize a
database for it.

Jan

Modified Files:
--------------
    slony1-engine/src/backend:
        slony1_funcs.sql (r1.47 -> r1.48)
    slony1-engine/src/slon:
        remote_worker.c (r1.66 -> r1.67)
    slony1-engine/src/slonik:
        parser.y (r1.20 -> r1.21)
        scan.l (r1.20 -> r1.21)
        slonik.c (r1.34 -> r1.35)
        slonik.h (r1.20 -> r1.21)

-------------- next part --------------
Index: slony1_funcs.sql
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.47
retrieving revision 1.48
diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.47 -r1.48
--- src/backend/slony1_funcs.sql
+++ src/backend/slony1_funcs.sql
@@ -350,7 +350,7 @@
 	perform setval(''@NAMESPACE at .sl_local_node_id'', p_local_node_id);
 	perform setval(''@NAMESPACE at .sl_rowid_seq'', 
 			p_local_node_id::int8 * ''1000000000000000''::int8);
-	perform @NAMESPACE at .storeNode_int (p_local_node_id, p_comment);
+	perform @NAMESPACE at .storeNode_int (p_local_node_id, p_comment, false);
 	
 	return p_local_node_id;
 end;
@@ -364,41 +364,50 @@
 
 
 -- ----------------------------------------------------------------------
--- FUNCTION storeNode (no_id, no_comment)
+-- FUNCTION storeNode (no_id, no_comment, no_spool)
 --
 --	Generate the STORE_NODE event.
 -- ----------------------------------------------------------------------
-create or replace function @NAMESPACE at .storeNode (int4, text)
+create or replace function @NAMESPACE at .storeNode (int4, text, boolean)
 returns bigint
 as '
 declare
 	p_no_id			alias for $1;
 	p_no_comment	alias for $2;
+	p_no_spool		alias for $3;
+	v_no_spool_txt	text;
 begin
-	perform @NAMESPACE at .storeNode_int (p_no_id, p_no_comment);
+	if p_no_spool then
+		v_no_spool_txt = ''t'';
+	else
+		v_no_spool_txt = ''f'';
+	end if;
+	perform @NAMESPACE at .storeNode_int (p_no_id, p_no_comment, p_no_spool);
 	return  @NAMESPACE at .createEvent(''_ at CLUSTERNAME@'', ''STORE_NODE'',
-									p_no_id, p_no_comment);
+									p_no_id, p_no_comment, v_no_spool_txt);
 end;
 ' language plpgsql
 	called on null input;
 
-comment on function @NAMESPACE at .storeNode(int4, text) is
+comment on function @NAMESPACE at .storeNode(int4, text, boolean) is
 'no_id - Node ID #
 no_comment - Human-oriented comment
+no_spool - Flag for virtual spool nodes
 
 Generate the STORE_NODE event for node no_id';
 
 -- ----------------------------------------------------------------------
--- FUNCTION storeNode_int (no_id, no_comment)
+-- FUNCTION storeNode_int (no_id, no_comment, no_spool)
 --
 --	Process the STORE_NODE event.
 -- ----------------------------------------------------------------------
-create or replace function @NAMESPACE at .storeNode_int (int4, text)
+create or replace function @NAMESPACE at .storeNode_int (int4, text, boolean)
 returns int4
 as '
 declare
 	p_no_id			alias for $1;
 	p_no_comment	alias for $2;
+	p_no_spool		alias for $3;
 	v_old_row		record;
 begin
 	-- ----
@@ -418,24 +427,26 @@
 		-- Node exists, update the existing row.
 		-- ----
 		update @NAMESPACE at .sl_node
-				set no_comment = p_no_comment
+				set no_comment = p_no_comment,
+				no_spool = p_no_spool
 				where no_id = p_no_id;
 	else
 		-- ----
 		-- New node, insert the sl_node row
 		-- ----
 		insert into @NAMESPACE at .sl_node
-				(no_id, no_active, no_comment) values
-				(p_no_id, ''f'', p_no_comment);
+				(no_id, no_active, no_comment, no_spool) values
+				(p_no_id, ''f'', p_no_comment, p_no_spool);
 	end if;
 
 	return p_no_id;
 end;
 ' language plpgsql;
 
-comment on function @NAMESPACE at .storeNode_int(int4, text) is
+comment on function @NAMESPACE at .storeNode_int(int4, text, boolean) is
 'no_id - Node ID #
 no_comment - Human-oriented comment
+no_spool - Flag for virtual spool nodes
 
 Internal function to process the STORE_NODE event for node no_id';
 
Index: remote_worker.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/remote_worker.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -Lsrc/slon/remote_worker.c -Lsrc/slon/remote_worker.c -u -w -r1.66 -r1.67
--- src/slon/remote_worker.c
+++ src/slon/remote_worker.c
@@ -519,14 +519,15 @@
 			{
 				int             no_id = (int)strtol(event->ev_data1, NULL, 10);
 				char           *no_comment = event->ev_data2;
+				char           *no_spool = event->ev_data3;
 
 				if (no_id != rtcfg_nodeid)
 					rtcfg_storeNode(no_id, no_comment);
 
 				slon_appendquery(&query1,
-				      "select %s.storeNode_int(%d, '%q'); ",
+				      "select %s.storeNode_int(%d, '%q', '%s'); ",
 						 rtcfg_namespace,
-						 no_id, no_comment);
+						 no_id, no_comment, no_spool);
 
 				need_reloadListen = true;
 			} else if (strcmp(event->ev_type, "ENABLE_NODE") == 0)
Index: scan.l
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/scan.l,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lsrc/slonik/scan.l -Lsrc/slonik/scan.l -u -w -r1.20 -r1.21
--- src/slonik/scan.l
+++ src/slonik/scan.l
@@ -88,6 +88,7 @@
 serial			{ return K_SERIAL;				}
 server			{ return K_SERVER;				}
 set				{ return K_SET;					}
+spoolnode		{ return K_SPOOLNODE;			}
 store			{ return K_STORE;				}
 subscribe		{ return K_SUBSCRIBE;			}
 success			{ return K_SUCCESS;				}
Index: slonik.h
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lsrc/slonik/slonik.h -Lsrc/slonik/slonik.h -u -w -r1.20 -r1.21
--- src/slonik/slonik.h
+++ src/slonik/slonik.h
@@ -157,6 +157,7 @@
 	SlonikStmt			hdr;
 	int					no_id;
 	char			   *no_comment;
+	int					no_spool;
 	int					ev_origin;
 };
 
Index: parser.y
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/parser.y,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lsrc/slonik/parser.y -Lsrc/slonik/parser.y -u -w -r1.20 -r1.21
--- src/slonik/parser.y
+++ src/slonik/parser.y
@@ -42,6 +42,7 @@
 	O_SERVER,
 	O_SER_KEY,
 	O_SET_ID,
+	O_SPOOLNODE,
 	O_TAB_ID,
 	O_TIMEOUT,
 	O_TRIG_NAME,
@@ -77,7 +78,7 @@
 } statement_option;
 #define	STMT_OPTION_INT(_code,_dfl)		{_code, -1, _dfl, NULL}
 #define	STMT_OPTION_STR(_code,_dfl)		{_code, -1, -1, _dfl}
-#define	STMT_OPTION_YN(_code,_dfl)		{_code, -1, -1, _dfl}
+#define	STMT_OPTION_YN(_code,_dfl)		{_code, -1, _dfl, NULL}
 #define STMT_OPTION_END					{END_OF_OPTIONS, -1, -1, NULL}
 
 
@@ -219,6 +220,7 @@
 %token	K_SERIAL
 %token	K_SERVER
 %token	K_SET
+%token	K_SPOOLNODE
 %token	K_STORE
 %token	K_SUBSCRIBE
 %token	K_SUCCESS
@@ -579,6 +581,7 @@
 						statement_option opt[] = {
 							STMT_OPTION_INT( O_ID, -1 ),
 							STMT_OPTION_STR( O_COMMENT, NULL ),
+							STMT_OPTION_YN( O_SPOOLNODE, 0 ),
 							STMT_OPTION_INT( O_EVENT_NODE, 1 ),
 							STMT_OPTION_END
 						};
@@ -594,7 +597,8 @@
 						{
 							new->no_id			= opt[0].ival;
 							new->no_comment		= opt[1].str;
-							new->ev_origin		= opt[2].ival;
+							new->no_spool		= opt[2].ival;
+							new->ev_origin		= opt[3].ival;
 						}
 						else
 							parser_errors++;
@@ -1590,6 +1594,11 @@
 						$5->opt_code	= O_EXECUTE_ONLY_ON;
 						$$ = $5;
 					}
+					| K_SPOOLNODE '=' option_item_yn
+					{
+						$3->opt_code	= O_SPOOLNODE;
+						$$ = $3;
+					}
 					;
 
 option_item_id		: id
@@ -1726,6 +1735,7 @@
 		case O_SERVER:			return "server";
 		case O_SER_KEY:			return "key";
 		case O_SET_ID:			return "set id";
+		case O_SPOOLNODE:		return "spoolnode";
 		case O_TAB_ID:			return "table id";
 		case O_TIMEOUT:			return "timeout";
 		case O_TRIG_NAME:		return "trigger name";
Index: slonik.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lsrc/slonik/slonik.c -Lsrc/slonik/slonik.c -u -w -r1.34 -r1.35
--- src/slonik/slonik.c
+++ src/slonik/slonik.c
@@ -278,8 +278,11 @@
 								hdr->stmt_filename, hdr->stmt_lno);
 					}
 
+					if (!stmt->no_spool)
+					{
 					if (script_check_adminfo(hdr, stmt->no_id) < 0)
 						errors++;
+					}
 					if (script_check_adminfo(hdr, stmt->ev_origin) < 0)
 						errors++;
 				}
@@ -1958,7 +1961,7 @@
 int
 slonik_store_node(SlonikStmt_store_node *stmt)
 {
-	SlonikAdmInfo  *adminfo1;
+	SlonikAdmInfo  *adminfo1 = NULL;
 	SlonikAdmInfo  *adminfo2;
 	SlonDString		query;
 	int				rc;
@@ -1966,26 +1969,39 @@
 	int				ntuples;
 	int				tupno;
 
+	if (!stmt->no_spool)
+	{
 	adminfo1 = get_active_adminfo((SlonikStmt *)stmt, stmt->no_id);
 	if (adminfo1 == NULL)
 		return -1;
+	}
 
 	adminfo2 = get_checked_adminfo((SlonikStmt *)stmt, stmt->ev_origin);
 	if (adminfo2 == NULL)
 		return -1;
 
-	if (db_begin_xact((SlonikStmt *)stmt, adminfo1) < 0)
-		return -1;
 	if (db_begin_xact((SlonikStmt *)stmt, adminfo2) < 0)
 		return -1;
 
+	dstring_init(&query);
+
+	if (!stmt->no_spool)
+	{
+		if (db_begin_xact((SlonikStmt *)stmt, adminfo1) < 0)
+		{
+			dstring_free(&query);
+			return -1;
+		}
+
 	/* Load the slony base tables */
 	rc = load_slony_base((SlonikStmt *)stmt, stmt->no_id);
 	if (rc < 0)
+		{
+			dstring_free(&query);
 		return -1;
+		}
 
 	/* call initializeLocalNode() and enableNode_int() */
-	dstring_init(&query);
 	slon_mkquery(&query,
 			"select \"_%s\".initializeLocalNode(%d, '%q'); "
 			"select \"_%s\".enableNode_int(%d); ",
@@ -2001,7 +2017,7 @@
 	 * Duplicate the content of sl_node
 	 */
 	slon_mkquery(&query,
-			"select no_id, no_active, no_comment "
+				"select no_id, no_active, no_comment, no_spool "
 			"from \"_%s\".sl_node; ",
 			stmt->hdr.script->clustername);
 	res = db_exec_select((SlonikStmt *)stmt, adminfo2, &query);
@@ -2016,10 +2032,11 @@
 		char   *no_id = PQgetvalue(res, tupno, 0);
 		char   *no_active = PQgetvalue(res, tupno, 1);
 		char   *no_comment = PQgetvalue(res, tupno, 2);
+			char   *no_spool = PQgetvalue(res, tupno, 3);
 
 		slon_mkquery(&query,
-				"select \"_%s\".storeNode_int(%s, '%q'); ",
-				stmt->hdr.script->clustername, no_id, no_comment);
+					"select \"_%s\".storeNode_int(%s, '%q', '%s'); ",
+					stmt->hdr.script->clustername, no_id, no_comment, no_spool);
 		if (*no_active == 't') 
 		{
 			slon_appendquery(&query,
@@ -2259,12 +2276,14 @@
 		}
 	}
 	PQclear(res);
+	}
 
 	/* On the existing node, call storeNode() and enableNode() */
 	slon_mkquery(&query,
-			"select \"_%s\".storeNode(%d, '%q'); "
+			"select \"_%s\".storeNode(%d, '%q', '%s'); "
 			"select \"_%s\".enableNode(%d); ",
 			stmt->hdr.script->clustername, stmt->no_id, stmt->no_comment,
+			(stmt->no_spool != 0) ? "t" : "f",
 			stmt->hdr.script->clustername, stmt->no_id);
 	if (db_exec_evcommand((SlonikStmt *)stmt, adminfo2, &query) < 0)
 	{


More information about the Slony1-commit mailing list