Wed Oct 13 19:50:27 PDT 2004
- Previous message: [Slony1-commit] By xfade: Add errno.h include.
- Next message: [Slony1-commit] By wieck: Added checks that ensure that slon is not running against any
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message: ----------- Added checks that ensure that slon is not running against any database that has either the wrong slony schema loaded or the wrong shared module version installed. Jan Tags: ---- REL_1_0_STABLE Modified Files: -------------- slony1-engine: config.h.in (r1.8 -> r1.8.2.1) slony1-engine/src/backend: slony1_funcs.c (r1.17.2.3 -> r1.17.2.4) slony1_funcs.sql (r1.15.2.6 -> r1.15.2.7) slony1-engine/src/slon: dbutils.c (r1.9.2.2 -> r1.9.2.3) remote_listen.c (r1.15.2.1 -> r1.15.2.2) slon.c (r1.27.2.1 -> r1.27.2.2) slon.h (r1.36.2.1 -> r1.36.2.2) slony1-engine/src/slonik: parser.c (r1.16.2.3 -> r1.16.2.4) -------------- next part -------------- Index: slony1_funcs.sql =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.sql,v retrieving revision 1.15.2.6 retrieving revision 1.15.2.7 diff -Lsrc/backend/slony1_funcs.sql -Lsrc/backend/slony1_funcs.sql -u -w -r1.15.2.6 -r1.15.2.7 --- src/backend/slony1_funcs.sql +++ src/backend/slony1_funcs.sql @@ -114,6 +114,19 @@ -- ---------------------------------------------------------------------- +-- FUNCTION getModuleVersion () +-- +-- Returns the compiled in version number of the Slony-I shared +-- object. +-- ---------------------------------------------------------------------- +create or replace function @NAMESPACE at .getModuleVersion () returns text + as '$libdir/slony1_funcs', '_Slony_I_getModuleVersion' + language C + security definer; +grant execute on function @NAMESPACE at .getModuleVersion () to public; + + +-- ---------------------------------------------------------------------- -- FUNCTION setSessionRole (name, role) -- -- Index: slony1_funcs.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.c,v retrieving revision 1.17.2.3 retrieving revision 1.17.2.4 diff -Lsrc/backend/slony1_funcs.c -Lsrc/backend/slony1_funcs.c -u -w -r1.17.2.3 -r1.17.2.4 --- src/backend/slony1_funcs.c +++ src/backend/slony1_funcs.c @@ -35,6 +35,7 @@ PG_FUNCTION_INFO_V1(_Slony_I_createEvent); PG_FUNCTION_INFO_V1(_Slony_I_getLocalNodeId); +PG_FUNCTION_INFO_V1(_Slony_I_getModuleVersion); PG_FUNCTION_INFO_V1(_Slony_I_setSessionRole); PG_FUNCTION_INFO_V1(_Slony_I_getSessionRole); @@ -46,6 +47,7 @@ Datum _Slony_I_createEvent(PG_FUNCTION_ARGS); Datum _Slony_I_getLocalNodeId(PG_FUNCTION_ARGS); +Datum _Slony_I_getModuleVersion(PG_FUNCTION_ARGS); Datum _Slony_I_setSessionRole(PG_FUNCTION_ARGS); Datum _Slony_I_getSessionRole(PG_FUNCTION_ARGS); @@ -255,6 +257,28 @@ } +/* + * _Slony_I_getModuleVersion - + * + * SQL callable function to determine the version number + * of this shared object during the startup checks. + * + */ +Datum +_Slony_I_getModuleVersion(PG_FUNCTION_ARGS) +{ + text *retval; + int len; + + len = strlen(SLONY_I_VERSION_STRING); + retval = palloc(VARHDRSZ + len); + VARATT_SIZEP(retval) = VARHDRSZ + len; + memcpy(VARDATA(retval), SLONY_I_VERSION_STRING, len); + + PG_RETURN_TEXT_P(retval); +} + + Datum _Slony_I_setSessionRole(PG_FUNCTION_ARGS) { Index: remote_listen.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/remote_listen.c,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.2 diff -Lsrc/slon/remote_listen.c -Lsrc/slon/remote_listen.c -u -w -r1.15.2.1 -r1.15.2.2 --- src/slon/remote_listen.c +++ src/slon/remote_listen.c @@ -274,6 +274,25 @@ continue; } + if (db_checkSchemaVersion(dbconn) < 0) + { + slon_log(SLON_ERROR, + "remoteListenThread_%d: db_checkSchemaVersion() " + "failed\n", + node->no_id); + + slon_disconnectdb(conn); + free(conn_conninfo); + conn = NULL; + conn_conninfo = NULL; + + rc = sched_msleep(node, pa_connretry * 1000); + if (rc != SCHED_STATUS_OK && rc != SCHED_STATUS_CANCEL) + break; + + continue; + } + slon_log(SLON_DEBUG1, "remoteListenThread_%d: connected to '%s'\n", node->no_id, conn_conninfo); Index: dbutils.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/dbutils.c,v retrieving revision 1.9.2.2 retrieving revision 1.9.2.3 diff -Lsrc/slon/dbutils.c -Lsrc/slon/dbutils.c -u -w -r1.9.2.2 -r1.9.2.3 --- src/slon/dbutils.c +++ src/slon/dbutils.c @@ -214,6 +214,105 @@ /* ---------- + * db_checkSchemaVersion + * + * Check the Slony schema on a connection for the correct version number + * ---------- + */ +int +db_checkSchemaVersion(PGconn *conn) +{ + char query[1024]; + PGresult *res; + int retval = 0; + + /* + * Select the version number from the schema + */ + snprintf(query, 1024, "select %s.slonyVersion()", + rtcfg_namespace); + res = PQexec(conn, query); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + slon_log(SLON_ERROR, + "cannot get Slony-I schema version - %s", + PQresultErrorMessage(res)); + slon_log(SLON_ERROR, + "please upgrade Slony-I schema to version %s\n", + SLONY_I_VERSION_STRING); + PQclear(res); + return -1; + } + if (PQntuples(res) != 1) + { + slon_log(SLON_ERROR, + "query '%s' returned %d rows (expected 1)\n", + query, PQntuples(res)); + PQclear(res); + return -1; + } + + /* + * Check the version string of the schema + */ + if (strcmp(PQgetvalue(res, 0, 0), SLONY_I_VERSION_STRING) != 0) + { + slon_log(SLON_ERROR, + "Slony-I schema version is %s\n", + PQgetvalue(res, 0, 0)); + slon_log(SLON_ERROR, + "please upgrade Slony-I schema to version %s\n", + SLONY_I_VERSION_STRING); + retval = -1; + } + PQclear(res); + + /* + * Select the version number from the module + */ + snprintf(query, 1024, "select %s.getModuleVersion()", + rtcfg_namespace); + res = PQexec(conn, query); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + slon_log(SLON_ERROR, + "cannot get Slony-I module version - %s", + PQresultErrorMessage(res)); + slon_log(SLON_ERROR, + "please upgrade Slony-I shared module to version %s\n", + SLONY_I_VERSION_STRING); + PQclear(res); + return -1; + } + if (PQntuples(res) != 1) + { + slon_log(SLON_ERROR, + "query '%s' returned %d rows (expected 1)\n", + query, PQntuples(res)); + PQclear(res); + return -1; + } + + /* + * Check the version string of the module + */ + if (strcmp(PQgetvalue(res, 0, 0), SLONY_I_VERSION_STRING) != 0) + { + slon_log(SLON_ERROR, + "Slony-I module version is %s\n", + PQgetvalue(res, 0, 0)); + slon_log(SLON_ERROR, + "please upgrade Slony-I shared module to version %s\n", + SLONY_I_VERSION_STRING); + retval = -1; + } + PQclear(res); + + return retval; +} + + +/* ---------- * slon_mkquery * * A simple query formatting and quoting function using dynamic string Index: slon.c =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/slon.c,v retrieving revision 1.27.2.1 retrieving revision 1.27.2.2 diff -Lsrc/slon/slon.c -Lsrc/slon/slon.c -u -w -r1.27.2.1 -r1.27.2.2 --- src/slon/slon.c +++ src/slon/slon.c @@ -168,6 +168,9 @@ *cp2++ = '"'; *cp2 = '\0'; + slon_log(SLON_CONFIG, "main: slon version %s starting up\n", + SLONY_I_VERSION_STRING); + /* * Remember the connection information for the local node. */ @@ -199,6 +202,11 @@ slon_log(SLON_FATAL, "main: Node is not initialized properly\n"); slon_exit(-1); } + if (db_checkSchemaVersion(startup_conn) < 0) + { + slon_log(SLON_FATAL, "main: Node has wrong Slony-I schema or module version loaded\n"); + slon_exit(-1); + } slon_log(SLON_CONFIG, "main: local node id = %d\n", rtcfg_nodeid); /* Index: slon.h =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slon/slon.h,v retrieving revision 1.36.2.1 retrieving revision 1.36.2.2 diff -Lsrc/slon/slon.h -Lsrc/slon/slon.h -u -w -r1.36.2.1 -r1.36.2.2 --- src/slon/slon.h +++ src/slon/slon.h @@ -474,6 +474,7 @@ extern void slon_free_dummyconn(SlonConn *conn); extern int db_getLocalNodeId(PGconn *conn); +extern int db_checkSchemaVersion(PGconn *conn); extern int slon_mkquery(SlonDString *ds, char *fmt, ...); extern int slon_appendquery(SlonDString *ds, char *fmt, ...); Index: config.h.in =================================================================== RCS file: /usr/local/cvsroot/slony1/slony1-engine/config.h.in,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -Lconfig.h.in -Lconfig.h.in -u -w -r1.8 -r1.8.2.1 --- config.h.in +++ config.h.in @@ -12,6 +12,8 @@ #ifndef SLONY_I_CONFIG_H #define SLONY_I_CONFIG_H +#define SLONY_I_VERSION_STRING "1.0.3" + #undef PGSHARE /* Set to 1 if libpq contains PQfreemem() */
- Previous message: [Slony1-commit] By xfade: Add errno.h include.
- Next message: [Slony1-commit] By wieck: Added checks that ensure that slon is not running against any
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list