Ran pgindent against the codebase:
authorChristopher Browne <cbbrowne@ca.afilias.info>
Wed, 7 Mar 2012 17:37:11 +0000 (12:37 -0500)
committerChristopher Browne <cbbrowne@ca.afilias.info>
Wed, 7 Mar 2012 17:37:11 +0000 (12:37 -0500)
 pgindent /var/lib/postgresql/postgresql/src/tools/pgindent/typedefs.list  src/*/*.{c,h}

30 files changed:
src/backend/slony1_funcs.c
src/misc/avl_tree.c
src/misc/avl_tree.h
src/parsestatements/scanner.c
src/parsestatements/scanner.h
src/parsestatements/test-scanner.c
src/slevent/slevent.c
src/slon/conf-file.h
src/slon/confoptions.c
src/slon/confoptions.h
src/slon/dbutils.c
src/slon/local_listen.c
src/slon/misc.c
src/slon/misc.h
src/slon/monitor_thread.c
src/slon/remote_listen.c
src/slon/remote_worker.c
src/slon/runtime_config.c
src/slon/scheduler.c
src/slon/slon.c
src/slon/slon.h
src/slon/sync_thread.c
src/slonik/dbutil.c
src/slonik/slonik.c
src/slonik/slonik.h
src/slonik/types.h
src/slony_logshipper/dbutil.c
src/slony_logshipper/ipcutil.c
src/slony_logshipper/slony_logshipper.c
src/slony_logshipper/slony_logshipper.h

index 9883b9587ec028d2f200b54763ae5093c5e9dab1..ac78a6900908c2ad8f000b91878101cd3d114733 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
@@ -144,7 +144,7 @@ typedef struct slony_I_cluster_status
        text       *cmdtype_D;
 
        struct slony_I_cluster_status *next;
-} Slony_I_ClusterStatus;
+}      Slony_I_ClusterStatus;
 
 
 /*
@@ -168,34 +168,34 @@ typedef struct apply_cache_entry
        char       *verifyKey;
        int                     evicted;
 #endif
-} ApplyCacheEntry;
+}      ApplyCacheEntry;
 
 
-static MemoryContext           applyCacheContext = NULL;
-static HTAB                               *applyCacheHash = NULL;
-static ApplyCacheEntry    *applyCacheHead = NULL;
-static ApplyCacheEntry    *applyCacheTail = NULL;
-static int                                     applyCacheSize = 100;
-static int                                     applyCacheUsed = 0;
+static MemoryContext applyCacheContext = NULL;
+static HTAB *applyCacheHash = NULL;
+static ApplyCacheEntry *applyCacheHead = NULL;
+static ApplyCacheEntry *applyCacheTail = NULL;
+static int     applyCacheSize = 100;
+static int     applyCacheUsed = 0;
 
 static uint32 applyCache_hash(const void *kp, Size ksize);
-static int applyCache_cmp(const void *kp1, const void *kp2, Size ksize);
+static int     applyCache_cmp(const void *kp1, const void *kp2, Size ksize);
 
-static char               *applyQuery = NULL;
-static char               *applyQueryPos = NULL;
-static int                     applyQuerySize = 8192;
+static char *applyQuery = NULL;
+static char *applyQueryPos = NULL;
+static int     applyQuerySize = 8192;
 
 static void applyQueryReset(void);
 static void applyQueryIncrease(void);
 
-static int64           apply_num_insert;
-static int64           apply_num_update;
-static int64           apply_num_delete;
-static int64           apply_num_truncate;
-static int64           apply_num_script;
-static int64           apply_num_prepare;
-static int64           apply_num_hit;
-static int64           apply_num_evict;
+static int64 apply_num_insert;
+static int64 apply_num_update;
+static int64 apply_num_delete;
+static int64 apply_num_truncate;
+static int64 apply_num_script;
+static int64 apply_num_prepare;
+static int64 apply_num_hit;
+static int64 apply_num_evict;
 
 
 /*@null@*/
@@ -205,7 +205,7 @@ getClusterStatus(Name cluster_name,
                                 int need_plan_mask);
 static const char *slon_quote_identifier(const char *ident);
 static int prepareLogPlan(Slony_I_ClusterStatus * cs,
-                                          int log_status);
+                          int log_status);
 
 Datum
 _Slony_I_createEvent(PG_FUNCTION_ARGS)
@@ -425,7 +425,7 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
        if (!TransactionIdEquals(cs->currentXid, newXid))
        {
                int32           log_status;
-               bool isnull;
+               bool            isnull;
 
                /*
                 * Determine the currently active log table
@@ -436,9 +436,9 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                        elog(ERROR, "Slony-I: cannot determine log status");
 
                log_status = DatumGetInt32(SPI_getbinval(SPI_tuptable->vals[0],
-                                                                                       SPI_tuptable->tupdesc, 1, &isnull));
+                                                                                SPI_tuptable->tupdesc, 1, &isnull));
                SPI_freetuptable(SPI_tuptable);
-               prepareLogPlan(cs,log_status);
+               prepareLogPlan(cs, log_status);
                switch (log_status)
                {
                        case 0:
@@ -465,11 +465,11 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
        olddatestyle = GetConfigOptionByName("DateStyle", NULL);
        if (!strstr(olddatestyle, "ISO"))
 #ifdef SETCONFIGOPTION_6
-               set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION, 
-                               true, true);
+               set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION,
+                                                 true, true);
 #else
-               set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION, 
-                               true, true, 0);
+               set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION,
+                                                 true, true, 0);
 #endif
 
 
@@ -491,10 +491,10 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                 */
                cmdtype = cs->cmdtype_I;
 
-               cmdargselem = cmdargs = (Datum *)palloc(sizeof(Datum) * 
-                               ((tg->tg_relation->rd_att->natts * 2) + 2));
-               cmdnullselem = cmdnulls = (bool *)palloc(sizeof(bool) *
-                               ((tg->tg_relation->rd_att->natts * 2) + 2));
+               cmdargselem = cmdargs = (Datum *) palloc(sizeof(Datum) *
+                                                                ((tg->tg_relation->rd_att->natts * 2) + 2));
+               cmdnullselem = cmdnulls = (bool *) palloc(sizeof(bool) *
+                                                                ((tg->tg_relation->rd_att->natts * 2) + 2));
 
                /*
                 * Specify all the columns
@@ -511,7 +511,7 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                         * Add the column name
                         */
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(SPI_fname(tupdesc, i + 1)));
+                                                                CStringGetDatum(SPI_fname(tupdesc, i + 1)));
                        *cmdnullselem++ = false;
 
                        /*
@@ -524,8 +524,8 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                        }
                        else
                        {
-                               *cmdargselem++ = DirectFunctionCall1(textin, 
-                                               CStringGetDatum(col_value));
+                               *cmdargselem++ = DirectFunctionCall1(textin,
+                                                                                                CStringGetDatum(col_value));
                                *cmdnullselem++ = false;
                        }
                }
@@ -548,15 +548,15 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                /*
                 * UPDATE
                 *
-                * cmdtype = 'U' cmdargs = pkcolname, oldval [, ...]
-                *                                                 colname, newval [, ...]
+                * cmdtype = 'U' cmdargs = pkcolname, oldval [, ...] colname, newval
+                * [, ...]
                 */
                cmdtype = cs->cmdtype_U;
 
-               cmdargselem = cmdargs = (Datum *)palloc(sizeof(Datum) * 
-                               ((tg->tg_relation->rd_att->natts * 4) + 3));
-               cmdnullselem = cmdnulls = (bool *)palloc(sizeof(bool) *
-                               ((tg->tg_relation->rd_att->natts * 4) + 3));
+               cmdargselem = cmdargs = (Datum *) palloc(sizeof(Datum) *
+                                                                ((tg->tg_relation->rd_att->natts * 4) + 3));
+               cmdnullselem = cmdnulls = (bool *) palloc(sizeof(bool) *
+                                                                ((tg->tg_relation->rd_att->natts * 4) + 3));
 
                /*
                 * For all changed columns, add name+value pairs and count them.
@@ -637,9 +637,9 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                        }
 
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(SPI_fname(tupdesc, i + 1)));
+                                                                CStringGetDatum(SPI_fname(tupdesc, i + 1)));
                        *cmdnullselem++ = false;
-                       if (new_isnull) 
+                       if (new_isnull)
                        {
                                *cmdnullselem++ = true;
                                cmdargselem++;
@@ -647,7 +647,7 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                        else
                        {
                                *cmdargselem++ = DirectFunctionCall1(textin,
-                                               CStringGetDatum(SPI_getvalue(new_row, tupdesc, i + 1)));
+                                        CStringGetDatum(SPI_getvalue(new_row, tupdesc, i + 1)));
                                *cmdnullselem++ = false;
                        }
                        cmdupdncols++;
@@ -676,11 +676,11 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                                         NameStr(tg->tg_relation->rd_rel->relname), col_ident);
 
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(col_ident));
+                                                                                                CStringGetDatum(col_ident));
                        *cmdnullselem++ = false;
 
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(col_value));
+                                                                                                CStringGetDatum(col_value));
                        *cmdnullselem++ = false;
                }
 
@@ -700,10 +700,10 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                 */
                cmdtype = cs->cmdtype_D;
 
-               cmdargselem = cmdargs = (Datum *)palloc(sizeof(Datum) * 
-                               ((tg->tg_relation->rd_att->natts * 2) + 2));
-               cmdnullselem = cmdnulls = (bool *)palloc(sizeof(bool) *
-                               ((tg->tg_relation->rd_att->natts * 2) + 2));
+               cmdargselem = cmdargs = (Datum *) palloc(sizeof(Datum) *
+                                                                ((tg->tg_relation->rd_att->natts * 2) + 2));
+               cmdnullselem = cmdnulls = (bool *) palloc(sizeof(bool) *
+                                                                ((tg->tg_relation->rd_att->natts * 2) + 2));
 
                /*
                 * Add the PK columns
@@ -720,7 +720,7 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                                continue;
 
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(col_ident = SPI_fname(tupdesc, i + 1)));
+                                        CStringGetDatum(col_ident = SPI_fname(tupdesc, i + 1)));
                        *cmdnullselem++ = false;
 
                        col_value = SPI_getvalue(old_row, tupdesc, i + 1);
@@ -728,7 +728,7 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
                                elog(ERROR, "Slony-I: old key column %s.%s IS NULL on DELETE",
                                         NameStr(tg->tg_relation->rd_rel->relname), col_ident);
                        *cmdargselem++ = DirectFunctionCall1(textin,
-                                       CStringGetDatum(col_value));
+                                                                                                CStringGetDatum(col_value));
                        *cmdnullselem++ = false;
                }
        }
@@ -740,11 +740,11 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
         */
        if (!strstr(olddatestyle, "ISO"))
 #ifdef SETCONFIGOPTION_6
-               set_config_option("DateStyle", olddatestyle, 
-                               PGC_USERSET, PGC_S_SESSION, true, true);
+               set_config_option("DateStyle", olddatestyle,
+                                                 PGC_USERSET, PGC_S_SESSION, true, true);
 #else
-               set_config_option("DateStyle", olddatestyle, 
-                               PGC_USERSET, PGC_S_SESSION, true, true, 0);
+               set_config_option("DateStyle", olddatestyle,
+                                                 PGC_USERSET, PGC_S_SESSION, true, true, 0);
 #endif
 
        /*
@@ -754,15 +754,15 @@ _Slony_I_logTrigger(PG_FUNCTION_ARGS)
        cmdlbs[0] = 1;
 
        log_param[0] = Int32GetDatum(tab_id);
-       log_param[1] = DirectFunctionCall1(textin, 
-                               CStringGetDatum(get_namespace_name(
-                                       RelationGetNamespace(tg->tg_relation))));
+       log_param[1] = DirectFunctionCall1(textin,
+                                                                          CStringGetDatum(get_namespace_name(
+                                                                       RelationGetNamespace(tg->tg_relation))));
        log_param[2] = DirectFunctionCall1(textin,
-                               CStringGetDatum(RelationGetRelationName(tg->tg_relation)));
+                                 CStringGetDatum(RelationGetRelationName(tg->tg_relation)));
        log_param[3] = PointerGetDatum(cmdtype);
        log_param[4] = Int32GetDatum(cmdupdncols);
        log_param[5] = PointerGetDatum(construct_md_array(cmdargs, cmdnulls, 1,
-                       cmddims, cmdlbs, TEXTOID, -1, false, 'i'));
+                                                                 cmddims, cmdlbs, TEXTOID, -1, false, 'i'));
 
        SPI_execp(cs->plan_active_log, log_param, NULL, 0);
 
@@ -834,24 +834,24 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
        Datum           dat;
        char            cmdtype;
        int32           tableid;
-       char            *nspname;
-       char            *relname;
+       char       *nspname;
+       char       *relname;
        int32           cmdupdncols;
-       Datum           *cmdargs;
-       bool            *cmdargsnulls;
+       Datum      *cmdargs;
+       bool       *cmdargsnulls;
        int                     cmdargsn;
        int                     querynvals = 0;
-       Datum           *queryvals = NULL;
-       Oid                     *querytypes = NULL;
-       char            *querynulls = NULL;
-       char            **querycolnames = NULL;
+       Datum      *queryvals = NULL;
+       Oid                *querytypes = NULL;
+       char       *querynulls = NULL;
+       char      **querycolnames = NULL;
        int                     i;
        int                     spi_rc;
 
-       MemoryContext           oldContext;
-       ApplyCacheEntry    *cacheEnt;
-       char                       *cacheKey;
-       bool                            found;
+       MemoryContext oldContext;
+       ApplyCacheEntry *cacheEnt;
+       char       *cacheKey;
+       bool            found;
 
        /*
         * Get the trigger call context
@@ -921,8 +921,8 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                hctl.hash = applyCache_hash;
                hctl.match = applyCache_cmp;
                applyCacheHash = hash_create("Slony-I apply cache",
-                                       50, &hctl, 
-                                       HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+                                                                        50, &hctl,
+                                                                  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
 
                /*
                 * Reset or create the apply cache key memory context.
@@ -930,11 +930,11 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                if (applyCacheContext == NULL)
                {
                        applyCacheContext = AllocSetContextCreate(
-                                               TopMemoryContext,
-                                               "Slony-I apply query keys",
-                                               ALLOCSET_DEFAULT_MINSIZE,
-                                               ALLOCSET_DEFAULT_INITSIZE,
-                                               ALLOCSET_DEFAULT_MAXSIZE);
+                                                                                                         TopMemoryContext,
+                                                                                                 "Slony-I apply query keys",
+                                                                                                       ALLOCSET_DEFAULT_MINSIZE,
+                                                                                                  ALLOCSET_DEFAULT_INITSIZE,
+                                                                                                  ALLOCSET_DEFAULT_MAXSIZE);
                }
                else
                {
@@ -962,15 +962,15 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
        new_row = tg->tg_trigtuple;
        tupdesc = tg->tg_relation->rd_att;
 
-       dat = SPI_getbinval(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
+       dat = SPI_getbinval(new_row, tupdesc,
+                                               SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
        if (isnull)
                elog(ERROR, "Slony-I: log_cmdtype is NULL");
        cmdtype = DatumGetChar(dat);
 
        /*
-        * Rows coming from sl_log_script are handled different from
-        * regular data log rows since they don't have all the columns.
+        * Rows coming from sl_log_script are handled different from regular data
+        * log rows since they don't have all the columns.
         */
        if (cmdtype == 'S')
        {
@@ -983,31 +983,33 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                /*
                 * Turn the log_cmdargs into a plain array of Text Datums.
                 */
-               dat = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
+               dat = SPI_getbinval(new_row, tupdesc,
+                                                       SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
                if (isnull)
                        elog(ERROR, "Slony-I: log_cmdargs is NULL");
 
-               deconstruct_array(DatumGetArrayTypeP(dat), 
-                               TEXTOID, -1, false, 'i', 
-                               &cmdargs, &cmdargsnulls, &cmdargsn);
-               
+               deconstruct_array(DatumGetArrayTypeP(dat),
+                                                 TEXTOID, -1, false, 'i',
+                                                 &cmdargs, &cmdargsnulls, &cmdargsn);
+
                /*
                 * The first element is the DDL statement itself.
                 */
                ddl_script = DatumGetCString(DirectFunctionCall1(
-                                               textout, cmdargs[0]));
-               
+                                                                                                          textout, cmdargs[0]));
+
                /*
                 * If there is an optional node ID list, check that we are in it.
                 */
-               if (cmdargsn > 1) {
+               if (cmdargsn > 1)
+               {
                        localNodeFound = false;
                        for (i = 1; i < cmdargsn; i++)
                        {
-                               int32   nodeId = DatumGetInt32(
-                                                                       DirectFunctionCall1(int4in,
-                                                                       DirectFunctionCall1(textout, cmdargs[i])));
+                               int32           nodeId = DatumGetInt32(
+                                                                                                  DirectFunctionCall1(int4in,
+                                                                 DirectFunctionCall1(textout, cmdargs[i])));
+
                                if (nodeId == cs->localNodeId)
                                {
                                        localNodeFound = true;
@@ -1017,38 +1019,37 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                }
 
                /*
-                * Execute the DDL statement if the node list is empty or our
-                * local node ID appears in it.
+                * Execute the DDL statement if the node list is empty or our local
+                * node ID appears in it.
                 */
                if (localNodeFound)
                {
                        if (SPI_exec(ddl_script, 0) < 0)
                        {
                                elog(ERROR, "SPI_exec() failed for DDL statement '%s'",
-                                       ddl_script);
+                                        ddl_script);
                        }
 
                        /*
-                        * Set the currentXid to invalid to flush the apply
-                        * query cache.
+                        * Set the currentXid to invalid to flush the apply query cache.
                         */
                        cs->currentXid = InvalidTransactionId;
                }
 
                /*
-                * Build the parameters for the insert into sl_log_script
-                * and execute the query.
+                * Build the parameters for the insert into sl_log_script and execute
+                * the query.
                 */
-               script_insert_args[0] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_origin"), &isnull);
-               script_insert_args[1] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_txid"), &isnull);
-               script_insert_args[2] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_actionseq"), &isnull);
-               script_insert_args[3] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
-               script_insert_args[4] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
+               script_insert_args[0] = SPI_getbinval(new_row, tupdesc,
+                                                               SPI_fnumber(tupdesc, "log_origin"), &isnull);
+               script_insert_args[1] = SPI_getbinval(new_row, tupdesc,
+                                                                 SPI_fnumber(tupdesc, "log_txid"), &isnull);
+               script_insert_args[2] = SPI_getbinval(new_row, tupdesc,
+                                                        SPI_fnumber(tupdesc, "log_actionseq"), &isnull);
+               script_insert_args[3] = SPI_getbinval(new_row, tupdesc,
+                                                          SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
+               script_insert_args[4] = SPI_getbinval(new_row, tupdesc,
+                                                          SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
                if (SPI_execp(cs->plan_insert_log_script, script_insert_args, NULL, 0) < 0)
                        elog(ERROR, "Execution of sl_log_script insert plan failed");
 
@@ -1072,25 +1073,27 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                /*
                 * Turn the log_cmdargs into a plain array of Text Datums.
                 */
-               dat = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
+               dat = SPI_getbinval(new_row, tupdesc,
+                                                       SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
                if (isnull)
                        elog(ERROR, "Slony-I: log_cmdargs is NULL");
 
-               deconstruct_array(DatumGetArrayTypeP(dat), 
-                               TEXTOID, -1, false, 'i', 
-                               &cmdargs, &cmdargsnulls, &cmdargsn);
-               
+               deconstruct_array(DatumGetArrayTypeP(dat),
+                                                 TEXTOID, -1, false, 'i',
+                                                 &cmdargs, &cmdargsnulls, &cmdargsn);
+
                /*
                 * If there is an optional node ID list, check that we are in it.
                 */
-               if (cmdargsn > 1) {
+               if (cmdargsn > 1)
+               {
                        localNodeFound = false;
                        for (i = 1; i < cmdargsn; i++)
                        {
-                               int32   nodeId = DatumGetInt32(
-                                                                       DirectFunctionCall1(int4in,
-                                                                       DirectFunctionCall1(textout, cmdargs[i])));
+                               int32           nodeId = DatumGetInt32(
+                                                                                                  DirectFunctionCall1(int4in,
+                                                                 DirectFunctionCall1(textout, cmdargs[i])));
+
                                if (nodeId == cs->localNodeId)
                                {
                                        localNodeFound = true;
@@ -1104,39 +1107,38 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                 */
                if (localNodeFound)
                {
-                       char    query[1024];
+                       char            query[1024];
 
                        snprintf(query, sizeof(query),
-                               "select %s.ddlScript_complete_int();",
-                               cs->clusterident);
+                                        "select %s.ddlScript_complete_int();",
+                                        cs->clusterident);
 
                        if (SPI_exec(query, 0) < 0)
                        {
                                elog(ERROR, "SPI_exec() failed for statement '%s'",
-                                       query);
+                                        query);
                        }
 
                        /*
-                        * Set the currentXid to invalid to flush the apply
-                        * query cache.
+                        * Set the currentXid to invalid to flush the apply query cache.
                         */
                        cs->currentXid = InvalidTransactionId;
                }
 
                /*
-                * Build the parameters for the insert into sl_log_script
-                * and execute the query.
+                * Build the parameters for the insert into sl_log_script and execute
+                * the query.
                 */
-               script_insert_args[0] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_origin"), &isnull);
-               script_insert_args[1] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_txid"), &isnull);
-               script_insert_args[2] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_actionseq"), &isnull);
-               script_insert_args[3] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
-               script_insert_args[4] = SPI_getbinval(new_row, tupdesc, 
-                               SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
+               script_insert_args[0] = SPI_getbinval(new_row, tupdesc,
+                                                               SPI_fnumber(tupdesc, "log_origin"), &isnull);
+               script_insert_args[1] = SPI_getbinval(new_row, tupdesc,
+                                                                 SPI_fnumber(tupdesc, "log_txid"), &isnull);
+               script_insert_args[2] = SPI_getbinval(new_row, tupdesc,
+                                                        SPI_fnumber(tupdesc, "log_actionseq"), &isnull);
+               script_insert_args[3] = SPI_getbinval(new_row, tupdesc,
+                                                          SPI_fnumber(tupdesc, "log_cmdtype"), &isnull);
+               script_insert_args[4] = SPI_getbinval(new_row, tupdesc,
+                                                          SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
                if (SPI_execp(cs->plan_insert_log_script, script_insert_args, NULL, 0) < 0)
                        elog(ERROR, "Execution of sl_log_script insert plan failed");
 
@@ -1150,43 +1152,43 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
        /*
         * Normal data log row. Get all the relevant data from the log row.
         */
-       dat = SPI_getbinval(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_tableid"), &isnull);
+       dat = SPI_getbinval(new_row, tupdesc,
+                                               SPI_fnumber(tupdesc, "log_tableid"), &isnull);
        if (isnull)
                elog(ERROR, "Slony-I: log_tableid is NULL");
        tableid = DatumGetInt32(dat);
-       nspname = SPI_getvalue(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_tablenspname"));
+       nspname = SPI_getvalue(new_row, tupdesc,
+                                                  SPI_fnumber(tupdesc, "log_tablenspname"));
        if (nspname == NULL)
                elog(ERROR, "Slony-I: log_tablenspname is NULL on INSERT/UPDATE/DELETE");
 
        relname = SPI_getvalue(new_row, tupdesc,
-                       SPI_fnumber(tupdesc, "log_tablerelname"));
+                                                  SPI_fnumber(tupdesc, "log_tablerelname"));
        if (relname == NULL)
                elog(ERROR, "Slony-I: log_tablerelname is NULL on INSERT/UPDATE/DELETE");
 
-       dat = SPI_getbinval(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_cmdupdncols"), &isnull);
+       dat = SPI_getbinval(new_row, tupdesc,
+                                               SPI_fnumber(tupdesc, "log_cmdupdncols"), &isnull);
        if (isnull && cmdtype == 'U')
                elog(ERROR, "Slony-I: log_cmdupdncols is NULL on UPDATE");
        cmdupdncols = DatumGetInt32(dat);
 
-       dat = SPI_getbinval(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
+       dat = SPI_getbinval(new_row, tupdesc,
+                                               SPI_fnumber(tupdesc, "log_cmdargs"), &isnull);
        if (isnull)
                elog(ERROR, "Slony-I: log_cmdargs is NULL");
 
        /*
         * Turn the log_cmdargs into a plain array of Text Datums.
         */
-       deconstruct_array(DatumGetArrayTypeP(dat), 
-                       TEXTOID, -1, false, 'i', 
-                       &cmdargs, &cmdargsnulls, &cmdargsn);
+       deconstruct_array(DatumGetArrayTypeP(dat),
+                                         TEXTOID, -1, false, 'i',
+                                         &cmdargs, &cmdargsnulls, &cmdargsn);
 
        /*
-        * Build the query cache key. This is for insert, update and truncate
-        * just the operation type and the table ID. For update we also append
-        * the fully quoted names of updated columns.
+        * Build the query cache key. This is for insert, update and truncate just
+        * the operation type and the table ID. For update we also append the
+        * fully quoted names of updated columns.
         */
        applyQueryReset();
        sprintf(applyQueryPos, "%c,%d", cmdtype, tableid);
@@ -1194,36 +1196,37 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 
        if (cmdtype == 'U')
        {
-               char   *colname;
+               char       *colname;
 
-               for (i = 0; i < cmdupdncols * 2; i+= 2)
+               for (i = 0; i < cmdupdncols * 2; i += 2)
                {
                        applyQueryIncrease();
 
                        colname = DatumGetCString(DirectFunctionCall1(
-                                                       textout, cmdargs[i]));
+                                                                                                          textout, cmdargs[i]));
                        snprintf(applyQueryPos, applyQuerySize - (applyQueryPos - applyQuery),
-                               ",%s", slon_quote_identifier(colname));
+                                        ",%s", slon_quote_identifier(colname));
                        applyQueryPos += strlen(applyQueryPos);
                }
        }
 
        /*
-        * We now need to copy this cache key into the cache context because
-        * the hash_search() call will eventually create the hash entry pointing
-        * to this string.
+        * We now need to copy this cache key into the cache context because the
+        * hash_search() call will eventually create the hash entry pointing to
+        * this string.
         */
        oldContext = MemoryContextSwitchTo(applyCacheContext);
        cacheKey = pstrdup(applyQuery);
        MemoryContextSwitchTo(oldContext);
 
-// elog(NOTICE, "looking for key=%s", cacheKey);
+/*     elog(NOTICE, "looking for key=%s", cacheKey); */
        cacheEnt = hash_search(applyCacheHash, &cacheKey, HASH_ENTER, &found);
        if (found)
        {
                apply_num_hit++;
 
-               // elog(NOTICE, "cache entry for %s found", cacheKey);
+               /* elog(NOTICE, "cache entry for %s found", cacheKey); */
+
                /*
                 * Free the cacheKey copy.
                 */
@@ -1231,18 +1234,18 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 #ifdef APPLY_CACHE_VERIFY
                if (cacheEnt->evicted)
                        elog(ERROR, "Slony-I: query cache returned evicted entry for '%s'",
-                                       cacheKey);
+                                cacheKey);
                if (strcmp(cacheEnt->verifyKey, cacheKey) != 0)
                        elog(ERROR, "Slony-I: query cache key verification failed - "
-                                       "searched='%s' found='%s'", cacheKey,
-                                       cacheEnt->verifyKey);
+                                "searched='%s' found='%s'", cacheKey,
+                                cacheEnt->verifyKey);
 #endif
                pfree(cacheKey);
                MemoryContextSwitchTo(oldContext);
 
                /*
-                * We are reusing an existing query plan. Just move it
-                * to the end of the list.
+                * We are reusing an existing query plan. Just move it to the end of
+                * the list.
                 */
                if (cacheEnt != applyCacheTail)
                {
@@ -1279,13 +1282,14 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
        }
        else
        {
-               Datum   query_args[2];
+               Datum           query_args[2];
 
                apply_num_prepare++;
 
-               // elog(NOTICE, "cache entry for %s NOT found", cacheKey);
+               /* elog(NOTICE, "cache entry for %s NOT found", cacheKey); */
 
 #ifdef APPLY_CACHE_VERIFY
+
                /*
                 * Save a second copy of the query key for verification/debugging
                 */
@@ -1294,16 +1298,17 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                MemoryContextSwitchTo(oldContext);
                cacheEnt->evicted = 0;
 #endif
+
                /*
-                * Find the target relation in the system cache. We need this to
-                * find the data types of the target columns for casting.
+                * Find the target relation in the system cache. We need this to find
+                * the data types of the target columns for casting.
                 */
                target_rel = RelationIdGetRelation(
-                               get_relname_relid(relname, LookupExplicitNamespace(nspname)));
+                          get_relname_relid(relname, LookupExplicitNamespace(nspname)));
                if (target_rel == NULL)
                        elog(ERROR, "Slony-I: cannot find table %s.%s in logApply()",
-                                       slon_quote_identifier(nspname),
-                                       slon_quote_identifier(relname));
+                                slon_quote_identifier(nspname),
+                                slon_quote_identifier(relname));
 
                /*
                 * Create the saved SPI plan for this query
@@ -1314,14 +1319,15 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                 * Build the query string and parameter type array for the
                 * SPI_prepare() call.
                 */
-               switch (cmdtype) 
+               switch (cmdtype)
                {
                        case 'I':
+
                                /*
                                 * INSERT
                                 */
-                               querycolnames = (char **)palloc(sizeof(char *) * cmdargsn / 2);
-                               querytypes = (Oid *)palloc(sizeof(Oid) * cmdargsn / 2);
+                               querycolnames = (char **) palloc(sizeof(char *) * cmdargsn / 2);
+                               querytypes = (Oid *) palloc(sizeof(Oid) * cmdargsn / 2);
 
                                sprintf(applyQueryPos, "INSERT INTO %s.%s (",
                                                slon_quote_identifier(nspname),
@@ -1333,7 +1339,7 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                 */
                                for (i = 0; i < cmdargsn; i += 2)
                                {
-                                       char    *colname;
+                                       char       *colname;
 
                                        applyQueryIncrease();
 
@@ -1346,40 +1352,40 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                        if (cmdargsnulls[i])
                                                elog(ERROR, "Slony-I: column name in log_cmdargs is NULL");
                                        querycolnames[i / 2] = DatumGetCString(DirectFunctionCall1(
-                                                                       textout, cmdargs[i]));
-                                       colname = (char *)slon_quote_identifier(querycolnames[i / 2]);
+                                                                                                          textout, cmdargs[i]));
+                                       colname = (char *) slon_quote_identifier(querycolnames[i / 2]);
                                        strcpy(applyQueryPos, colname);
                                        applyQueryPos += strlen(applyQueryPos);
                                }
 
-                               /* 
+                               /*
                                 * Add ") VALUES ("
                                 */
                                strcpy(applyQueryPos, ") VALUES (");
                                applyQueryPos += strlen(applyQueryPos);
 
                                /*
-                                * Add $n::<coltype> placeholders for all the values. 
+                                * Add $n::<coltype> placeholders for all the values.
                                 */
                                for (i = 0; i < cmdargsn; i += 2)
                                {
-                                       char *coltype;
+                                       char       *coltype;
 
                                        applyQueryIncrease();
 
                                        /*
                                         * Lookup the column data type in the target relation.
                                         */
-                                       coltype = SPI_gettype(target_rel->rd_att, 
-                                                       SPI_fnumber(target_rel->rd_att, querycolnames[i / 2]));
+                                       coltype = SPI_gettype(target_rel->rd_att,
+                                         SPI_fnumber(target_rel->rd_att, querycolnames[i / 2]));
                                        if (coltype == NULL)
                                                elog(ERROR, "Slony-I: type lookup for column %s failed in logApply()",
-                                                               querycolnames[i / 2]);
+                                                        querycolnames[i / 2]);
 
                                        /*
                                         * Add the parameter to the query string
                                         */
-                                       sprintf(applyQueryPos, "%s$%d::%s", (i == 0) ? "" : ", ", 
+                                       sprintf(applyQueryPos, "%s$%d::%s", (i == 0) ? "" : ", ",
                                                        i / 2 + 1, coltype);
                                        applyQueryPos += strlen(applyQueryPos);
 
@@ -1396,11 +1402,12 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                break;
 
                        case 'U':
+
                                /*
                                 * UPDATE
                                 */
-                               querycolnames = (char **)palloc(sizeof(char *) * cmdargsn / 2);
-                               querytypes = (Oid *)palloc(sizeof(Oid) * cmdargsn / 2);
+                               querycolnames = (char **) palloc(sizeof(char *) * cmdargsn / 2);
+                               querytypes = (Oid *) palloc(sizeof(Oid) * cmdargsn / 2);
 
                                sprintf(applyQueryPos, "UPDATE ONLY %s.%s SET ",
                                                slon_quote_identifier(nspname),
@@ -1408,14 +1415,14 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                applyQueryPos += strlen(applyQueryPos);
 
                                /*
-                                * This can all be done in one pass over the cmdargs array.
-                                * We just have to switch the behavior slightly between
-                                * the SET clause and the WHERE clause.
+                                * This can all be done in one pass over the cmdargs array. We
+                                * just have to switch the behavior slightly between the SET
+                                * clause and the WHERE clause.
                                 */
                                for (i = 0; i < cmdargsn; i += 2)
                                {
-                                       char *colname;
-                                       char *coltype;
+                                       char       *colname;
+                                       char       *coltype;
 
                                        applyQueryIncrease();
 
@@ -1425,16 +1432,16 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                        if (cmdargsnulls[i])
                                                elog(ERROR, "Slony-I: column name in log_cmdargs is NULL");
                                        colname = DatumGetCString(DirectFunctionCall1(
-                                                                       textout, cmdargs[i]));
-                                       coltype = SPI_gettype(target_rel->rd_att, 
-                                                       SPI_fnumber(target_rel->rd_att, colname));
+                                                                                                          textout, cmdargs[i]));
+                                       coltype = SPI_gettype(target_rel->rd_att,
+                                                                  SPI_fnumber(target_rel->rd_att, colname));
                                        if (coltype == NULL)
                                                elog(ERROR, "Slony-I: type lookup for column %s failed in logApply()",
-                                                               colname);
+                                                        colname);
 
                                        /*
-                                        * Special case if there were no columns updated.
-                                        * We tell it to set the first PK column to itself.
+                                        * Special case if there were no columns updated. We tell
+                                        * it to set the first PK column to itself.
                                         */
                                        if (cmdupdncols == 0)
                                        {
@@ -1457,9 +1464,8 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                        if (i < cmdupdncols * 2)
                                        {
                                                /*
-                                                * This is inside the SET clause.
-                                                * Add the <colname> = $n::<coltype> separated by
-                                                * comma.
+                                                * This is inside the SET clause. Add the <colname> =
+                                                * $n::<coltype> separated by comma.
                                                 */
                                                sprintf(applyQueryPos, "%s%s = $%d::%s",
                                                                (i > 0) ? ", " : "",
@@ -1472,7 +1478,7 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                                 * This is in the WHERE clause. Same as above but
                                                 * separated by AND.
                                                 */
-                                               sprintf(applyQueryPos, "%s%s = $%d::%s", 
+                                               sprintf(applyQueryPos, "%s%s = $%d::%s",
                                                                (i > cmdupdncols * 2) ? " AND " : "",
                                                                slon_quote_identifier(colname),
                                                                i / 2 + 1, coltype);
@@ -1489,11 +1495,12 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                break;
 
                        case 'D':
+
                                /*
                                 * DELETE
                                 */
-                               querycolnames = (char **)palloc(sizeof(char *) * cmdargsn / 2);
-                               querytypes = (Oid *)palloc(sizeof(Oid) * cmdargsn / 2);
+                               querycolnames = (char **) palloc(sizeof(char *) * cmdargsn / 2);
+                               querytypes = (Oid *) palloc(sizeof(Oid) * cmdargsn / 2);
 
                                sprintf(applyQueryPos, "DELETE FROM ONLY %s.%s WHERE ",
                                                slon_quote_identifier(nspname),
@@ -1502,8 +1509,8 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 
                                for (i = 0; i < cmdargsn; i += 2)
                                {
-                                       char *colname;
-                                       char *coltype;
+                                       char       *colname;
+                                       char       *coltype;
 
                                        applyQueryIncrease();
 
@@ -1513,13 +1520,13 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                        if (cmdargsnulls[i])
                                                elog(ERROR, "Slony-I: column name in log_cmdargs is NULL");
                                        colname = DatumGetCString(DirectFunctionCall1(
-                                                                       textout, cmdargs[i]));
-                                       coltype = SPI_gettype(target_rel->rd_att, 
-                                                       SPI_fnumber(target_rel->rd_att, colname));
+                                                                                                          textout, cmdargs[i]));
+                                       coltype = SPI_gettype(target_rel->rd_att,
+                                                                  SPI_fnumber(target_rel->rd_att, colname));
                                        if (coltype == NULL)
                                                elog(ERROR, "Slony-I: type lookup for column %s failed in logApply()",
-                                                               colname);
-                                       sprintf(applyQueryPos, "%s%s = $%d::%s", 
+                                                        colname);
+                                       sprintf(applyQueryPos, "%s%s = $%d::%s",
                                                        (i > 0) ? " AND " : "",
                                                        slon_quote_identifier(colname),
                                                        i / 2 + 1, coltype);
@@ -1537,10 +1544,11 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                                break;
 
                        case 'T':
+
                                /*
                                 * TRUNCATE
                                 */
-                               querytypes = (Oid *)palloc(sizeof(Oid) * 2);
+                               querytypes = (Oid *) palloc(sizeof(Oid) * 2);
 
                                sprintf(applyQueryPos, "SELECT %s.TruncateOnlyTable("
                                                "%s.slon_quote_brute($1) || '.' || "
@@ -1557,7 +1565,7 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 
                        default:
                                elog(ERROR, "Slony-I: unhandled log cmdtype '%c' in logApply()",
-                                               cmdtype);
+                                        cmdtype);
                                break;
                }
 
@@ -1569,12 +1577,12 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                /*
                 * Prepare the saved SPI query plan.
                 */
-               cacheEnt->plan  = SPI_saveplan(
-                               SPI_prepare(applyQuery, querynvals, querytypes));
+               cacheEnt->plan = SPI_saveplan(
+                                                       SPI_prepare(applyQuery, querynvals, querytypes));
                if (cacheEnt->plan == NULL)
-                       elog(ERROR, "Slony-I: SPI_prepare() failed for query '%s'", 
-                                       applyQuery);
-// elog(NOTICE, "key=%s nvals=%d query=%s ", cacheEnt->verifyKey, querynvals, applyQuery);
+                       elog(ERROR, "Slony-I: SPI_prepare() failed for query '%s'",
+                                applyQuery);
+/*     elog(NOTICE, "key=%s nvals=%d query=%s ", cacheEnt->verifyKey, querynvals, applyQuery); */
 
                /*
                 * Add the plan to the double linked LRU list
@@ -1596,8 +1604,8 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                applyCacheUsed++;
 
                /*
-                * If that pushes us over the maximum allowed cached plans,
-                * evict the one that wasn't used the longest.
+                * If that pushes us over the maximum allowed cached plans, evict the
+                * one that wasn't used the longest.
                 */
                if (applyCacheUsed > applyCacheSize)
                {
@@ -1612,7 +1620,7 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 #endif
 
                        if (evict->prev == NULL)
-                               applyCacheHead = evict->next; 
+                               applyCacheHead = evict->next;
                        else
                                evict->prev->next = evict->next;
                        if (evict->next == NULL)
@@ -1623,17 +1631,17 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                        hash_search(applyCacheHash, &(evict->queryKey), HASH_REMOVE, &found);
                        if (!found)
                                elog(ERROR, "Slony-I: cached queries hash entry not found "
-                                               "on evict");
-                       
+                                        "on evict");
+
                        applyCacheUsed--;
                }
 
                /*
-                * We also need to determine if this table belongs to a
-                * set, that we are a forwarder of.
+                * We also need to determine if this table belongs to a set, that we
+                * are a forwarder of.
                 */
-               query_args[0] = SPI_getbinval(new_row, tupdesc, 
-                       SPI_fnumber(tupdesc, "log_tableid"), &isnull);
+               query_args[0] = SPI_getbinval(new_row, tupdesc,
+                                                          SPI_fnumber(tupdesc, "log_tableid"), &isnull);
                query_args[1] = Int32GetDatum(cs->localNodeId);
 
                if (SPI_execp(cs->plan_table_info, query_args, NULL, 0) < 0)
@@ -1641,27 +1649,28 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 
                if (SPI_processed != 1)
                        elog(ERROR, "forwarding lookup for table %d failed",
-                                       DatumGetInt32(query_args[1]));
+                                DatumGetInt32(query_args[1]));
 
                cacheEnt->forward = DatumGetBool(
-                               SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc,
-                                       SPI_fnumber(SPI_tuptable->tupdesc, "sub_forward"), &isnull));
+                                 SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc,
+                               SPI_fnumber(SPI_tuptable->tupdesc, "sub_forward"), &isnull));
        }
 
        /*
-        * We now have a cached SPI plan. Construct the call parameter
-        * and null flag arrays.
+        * We now have a cached SPI plan. Construct the call parameter and null
+        * flag arrays.
         */
-       switch (cmdtype) 
+       switch (cmdtype)
        {
                case 'I':
                case 'U':
                case 'D':
+
                        /*
                         * INSERT, UPDATE and DELETE
                         */
-                       queryvals = (Datum *)palloc(sizeof(Datum) * cmdargsn / 2);
-                       querynulls = (char *)palloc(cmdargsn / 2 + 1);
+                       queryvals = (Datum *) palloc(sizeof(Datum) * cmdargsn / 2);
+                       querynulls = (char *) palloc(cmdargsn / 2 + 1);
 
                        for (i = 0; i < cmdargsn; i += 2)
                        {
@@ -1676,11 +1685,12 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
                        break;
 
                case 'T':
+
                        /*
                         * TRUNCATE
                         */
-                       queryvals = (Datum *)palloc(sizeof(Datum) * 2);
-                       querynulls = (char *)palloc(3);
+                       queryvals = (Datum *) palloc(sizeof(Datum) * 2);
+                       querynulls = (char *) palloc(3);
 
                        queryvals[0] = DirectFunctionCall1(textin, CStringGetDatum(nspname));
                        queryvals[1] = DirectFunctionCall1(textin, CStringGetDatum(relname));
@@ -1692,11 +1702,11 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
 
                default:
                        elog(ERROR, "Slony-I: unhandled log cmdtype '%c' in logApply()",
-                                       cmdtype);
+                                cmdtype);
                        break;
        }
 
-// elog(NOTICE, "using key=%s nvals=%d", cacheEnt->verifyKey, cmdargsn / 2);
+/*     elog(NOTICE, "using key=%s nvals=%d", cacheEnt->verifyKey, cmdargsn / 2); */
 
        /*
         * Execute the query.
@@ -1707,22 +1717,27 @@ _Slony_I_logApply(PG_FUNCTION_ARGS)
        /*
         * Count operations
         */
-       switch(cmdtype)
+       switch (cmdtype)
        {
-               case 'I':               apply_num_insert++;
-                                               break;
-               case 'U':               apply_num_update++;
-                                               break;
-               case 'D':               apply_num_delete++;
-                                               break;
-               case 'T':               apply_num_truncate++;
-                                               break;
-               default:                break;
+               case 'I':
+                       apply_num_insert++;
+                       break;
+               case 'U':
+                       apply_num_update++;
+                       break;
+               case 'D':
+                       apply_num_delete++;
+                       break;
+               case 'T':
+                       apply_num_truncate++;
+                       break;
+               default:
+                       break;
        }
 
        /*
-        * Disconnect from SPI manager and return either the new tuple
-        * or NULL according to the forwarding of log data.
+        * Disconnect from SPI manager and return either the new tuple or NULL
+        * according to the forwarding of log data.
         */
        SPI_finish();
        if (cacheEnt->forward)
@@ -1789,9 +1804,9 @@ _Slony_I_logApplySaveStats(PG_FUNCTION_ARGS)
         */
        cs = getClusterStatus(PG_GETARG_NAME(0), PLAN_APPLY_QUERIES);
 
-       /* 
-        * Setup the parameter array. Note that both queries use the
-        * same parameters in exactly the same order.
+       /*
+        * Setup the parameter array. Note that both queries use the same
+        * parameters in exactly the same order.
         */
        params[0] = Int32GetDatum(PG_GETARG_INT32(1));
 
@@ -1801,19 +1816,19 @@ _Slony_I_logApplySaveStats(PG_FUNCTION_ARGS)
        params[4] = Int64GetDatum(apply_num_truncate);
        params[5] = Int64GetDatum(apply_num_script);
        params[6] = Int64GetDatum(apply_num_insert + apply_num_update +
-                                       apply_num_delete + apply_num_truncate * apply_num_script);
+                                  apply_num_delete + apply_num_truncate * apply_num_script);
        params[7] = PointerGetDatum(PG_GETARG_INTERVAL_P(2));
        params[8] = Int64GetDatum(apply_num_prepare);
        params[9] = Int64GetDatum(apply_num_hit);
        params[10] = Int64GetDatum(apply_num_evict);
 
        /*
-        * Perform the UPDATE of sl_apply_stats. If that doesn't update
-        * any row(s), try to INSERT one.
+        * Perform the UPDATE of sl_apply_stats. If that doesn't update any
+        * row(s), try to INSERT one.
         */
        if ((spi_rc = SPI_execp(cs->plan_apply_stats_update, params, nulls, 0)) < 0)
                elog(ERROR, "Slony-I: SPI_execp() to update apply stats failed"
-                               " - rc=%d", spi_rc);
+                        " - rc=%d", spi_rc);
        if (SPI_processed > 0)
        {
                rc = 2;
@@ -1822,7 +1837,7 @@ _Slony_I_logApplySaveStats(PG_FUNCTION_ARGS)
        {
                if ((spi_rc = SPI_execp(cs->plan_apply_stats_insert, params, nulls, 0)) < 0)
                        elog(ERROR, "Slony-I: SPI_execp() to insert apply stats failed"
-                                       " - rc=%d", spi_rc);
+                                " - rc=%d", spi_rc);
                if (SPI_processed > 0)
                        rc = 1;
        }
@@ -1850,17 +1865,17 @@ _Slony_I_logApplySaveStats(PG_FUNCTION_ARGS)
 static uint32
 applyCache_hash(const void *kp, Size ksize)
 {
-       char   *key = *((char **)kp);
+       char       *key = *((char **) kp);
 
-       return hash_any((void *)key, strlen(key));
+       return hash_any((void *) key, strlen(key));
 }
 
 
 static int
 applyCache_cmp(const void *kp1, const void *kp2, Size ksize)
 {
-       char   *key1 = *((char **)kp1);
-       char   *key2 = *((char **)kp2);
+       char       *key1 = *((char **) kp1);
+       char       *key2 = *((char **) kp2);
 
        return strcmp(key1, key2);
 }
@@ -1885,7 +1900,8 @@ applyQueryIncrease(void)
 {
        if (applyQueryPos - applyQuery + 1024 > applyQuerySize)
        {
-               size_t offset = applyQueryPos - applyQuery;
+               size_t          offset = applyQueryPos - applyQuery;
+
                applyQuerySize *= 2;
                applyQuery = realloc(applyQuery, applyQuerySize);
                if (applyQuery == NULL)
@@ -1966,7 +1982,7 @@ typedef struct
 {
        int32           seqid;
        int64           seqval;
-} SeqTrack_elem;
+}      SeqTrack_elem;
 
 static int
 seqtrack_cmp(void *seq1, void *seq2)
@@ -2088,10 +2104,10 @@ slon_quote_identifier(const char *ident)
 #ifdef SCANKEYWORDLOOKUP_1
                if (ScanKeywordLookup(ident) != NULL)
 #endif
-#ifdef SCANKEYWORDLOOKUP_3                
-                       if (ScanKeywordLookup(ident,ScanKeywords,NumScanKeywords) != NULL)
+#ifdef SCANKEYWORDLOOKUP_3
+                       if (ScanKeywordLookup(ident, ScanKeywords, NumScanKeywords) != NULL)
 #endif
-                       safe = false;
+                               safe = false;
        }
 
        if (safe)
@@ -2343,7 +2359,7 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
                 * The plan to insert into sl_log_script.
                 */
                sprintf(query, "insert into %s.sl_log_script "
-                               "(log_origin, log_txid, log_actionseq, log_cmdtype, log_cmdargs) "
+                  "(log_origin, log_txid, log_actionseq, log_cmdtype, log_cmdargs) "
                                "values ($1, $2, $3, $4, $5);",
                                slon_quote_identifier(NameStr(*cluster_name)));
                plan_types[0] = INT4OID;
@@ -2353,7 +2369,7 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
                plan_types[4] = TEXTARRAYOID;
 
                cs->plan_insert_log_script = SPI_saveplan(
-                               SPI_prepare(query, 5, plan_types));
+                                                                                 SPI_prepare(query, 5, plan_types));
                if (cs->plan_insert_log_script == NULL)
                        elog(ERROR, "Slony-I: SPI_prepare() failed");
 
@@ -2367,12 +2383,12 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
                                " and sub_receiver = $2;",
                                slon_quote_identifier(NameStr(*cluster_name)),
                                slon_quote_identifier(NameStr(*cluster_name)));
-               
+
                plan_types[0] = INT4OID;
                plan_types[1] = INT4OID;
 
                cs->plan_table_info = SPI_saveplan(
-                               SPI_prepare(query, 2, plan_types));
+                                                                                  SPI_prepare(query, 2, plan_types));
                if (cs->plan_table_info == NULL)
                        elog(ERROR, "Slony-I: SPI_prepare() failed");
 
@@ -2411,7 +2427,7 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
                plan_types[10] = INT8OID;
 
                cs->plan_apply_stats_update = SPI_saveplan(
-                               SPI_prepare(query, 11, plan_types));
+                                                                                SPI_prepare(query, 11, plan_types));
                if (cs->plan_apply_stats_update == NULL)
                        elog(ERROR, "Slony-I: SPI_prepare() failed");
 
@@ -2445,7 +2461,7 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
                plan_types[10] = INT8OID;
 
                cs->plan_apply_stats_insert = SPI_saveplan(
-                               SPI_prepare(query, 11, plan_types));
+                                                                                SPI_prepare(query, 11, plan_types));
                if (cs->plan_apply_stats_insert == NULL)
                        elog(ERROR, "Slony-I: SPI_prepare() failed");
 
@@ -2461,17 +2477,17 @@ getClusterStatus(Name cluster_name, int need_plan_mask)
  *
  */
 
-int prepareLogPlan(Slony_I_ClusterStatus * cs,
-                               int log_status)
+int
+prepareLogPlan(Slony_I_ClusterStatus * cs,
+                          int log_status)
 {
        char            query[1024];
        Oid                     plan_types[9];
 
-       if( (log_status==0 ||
-                log_status==2) &&
-               cs->plan_insert_log_1==NULL)
+       if ((log_status == 0 ||
+                log_status == 2) &&
+               cs->plan_insert_log_1 == NULL)
        {
-
                /*
                 * Create the saved plan's
                 */
@@ -2493,9 +2509,9 @@ int prepareLogPlan(Slony_I_ClusterStatus * cs,
                if (cs->plan_insert_log_1 == NULL)
                        elog(ERROR, "Slony-I: SPI_prepare() failed");
        }
-       else if ( (log_status==1 ||
-                          log_status==3) &&
-                         cs->plan_insert_log_2==NULL)
+       else if ((log_status == 1 ||
+                         log_status == 3) &&
+                        cs->plan_insert_log_2 == NULL)
        {
                sprintf(query, "INSERT INTO %s.sl_log_2 "
                                "(log_origin, log_txid, log_tableid, log_actionseq,"
@@ -2518,8 +2534,9 @@ int prepareLogPlan(Slony_I_ClusterStatus * cs,
 
        return 0;
 }
+
 /* Provide a way to reset the per-session data structure that stores
-   the cluster status in the C functions. 
+   the cluster status in the C functions.
 
  * This is used to rectify the case where CLONE NODE updates the node
  * ID, but calls to getLocalNodeId() could continue to return the old
@@ -2528,37 +2545,38 @@ int prepareLogPlan(Slony_I_ClusterStatus * cs,
 Datum
 _Slony_I_resetSession(PG_FUNCTION_ARGS)
 {
-  Slony_I_ClusterStatus *cs;
-  
-  cs = clusterStatusList; 
-  while(cs != NULL)
-  {
-         Slony_I_ClusterStatus *previous;
-         if(cs->cmdtype_I)
-                 free(cs->cmdtype_I);
-         if(cs->cmdtype_D)
-                 free(cs->cmdtype_D);
-         if(cs->cmdtype_U)
-                 free(cs->cmdtype_D);
-         free(cs->clusterident);
-         if(cs->plan_insert_event)
-                 SPI_freeplan(cs->plan_insert_event);
-         if(cs->plan_insert_log_1)
-                 SPI_freeplan(cs->plan_insert_log_1);
-         if(cs->plan_insert_log_2)
-                 SPI_freeplan(cs->plan_insert_log_2);
-         if(cs->plan_record_sequences)
-                 SPI_freeplan(cs->plan_record_sequences);
-         if(cs->plan_get_logstatus)
-                 SPI_freeplan(cs->plan_get_logstatus);
-         previous=cs;
-         cs=cs->next;
-         free(previous);
-
-
-  }
-  clusterStatusList=NULL;
-  PG_RETURN_NULL();
+       Slony_I_ClusterStatus *cs;
+
+       cs = clusterStatusList;
+       while (cs != NULL)
+       {
+               Slony_I_ClusterStatus *previous;
+
+               if (cs->cmdtype_I)
+                       free(cs->cmdtype_I);
+               if (cs->cmdtype_D)
+                       free(cs->cmdtype_D);
+               if (cs->cmdtype_U)
+                       free(cs->cmdtype_D);
+               free(cs->clusterident);
+               if (cs->plan_insert_event)
+                       SPI_freeplan(cs->plan_insert_event);
+               if (cs->plan_insert_log_1)
+                       SPI_freeplan(cs->plan_insert_log_1);
+               if (cs->plan_insert_log_2)
+                       SPI_freeplan(cs->plan_insert_log_2);
+               if (cs->plan_record_sequences)
+                       SPI_freeplan(cs->plan_record_sequences);
+               if (cs->plan_get_logstatus)
+                       SPI_freeplan(cs->plan_get_logstatus);
+               previous = cs;
+               cs = cs->next;
+               free(previous);
+
+
+       }
+       clusterStatusList = NULL;
+       PG_RETURN_NULL();
 
 }
 
@@ -2570,38 +2588,40 @@ _Slony_I_resetSession(PG_FUNCTION_ARGS)
 Datum
 _slon_decode_tgargs(PG_FUNCTION_ARGS)
 {
-       const char * arg;
-       size_t elem_size=0;
-       ArrayType out_array;
-       int idx;
+       const char *arg;
+       size_t          elem_size = 0;
+       ArrayType  *out_array;
+       int                     idx;
        bytea      *t = PG_GETARG_BYTEA_P(0);
 
-       int arg_size = VARSIZE(t)- VARHDRSZ;
-       const char * in_args = VARDATA(t);
-       int array_size = 0;
-       out_array=construct_empty_array(TEXTOID);
-       arg=in_args;
+       int                     arg_size = VARSIZE(t) - VARHDRSZ;
+       const char *in_args = VARDATA(t);
+       int                     array_size = 0;
 
-       for(idx = 0; idx < arg_size; idx++)
+       out_array = construct_empty_array(TEXTOID);
+       arg = in_args;
+
+       for (idx = 0; idx < arg_size; idx++)
        {
-               
-               if(in_args[idx ]=='\0')
+
+               if (in_args[idx] == '\0')
                {
-                       text * one_arg = palloc(elem_size+VARHDRSZ);
-                       SET_VARSIZE(one_arg,elem_size + VARHDRSZ);
-                       memcpy(VARDATA(one_arg),arg,elem_size);
+                       text       *one_arg = palloc(elem_size + VARHDRSZ);
+
+                       SET_VARSIZE(one_arg, elem_size + VARHDRSZ);
+                       memcpy(VARDATA(one_arg), arg, elem_size);
                        out_array = array_set(out_array,
                                                                  1, &array_size,
                                                                  PointerGetDatum(one_arg),
                                                                  false,
                                                                  -1,
                                                                  -1,
-                                                                 false , /*typbyval for TEXT*/
-                                                                 'i' /*typalign for TEXT */
+                                                                 false,                /* typbyval for TEXT */
+                                                                 'i'   /* typalign for TEXT */
                                );
-                       elem_size=0;
+                       elem_size = 0;
                        array_size++;
-                       arg=&in_args[idx+1];
+                       arg = &in_args[idx + 1];
                }
                else
                {
@@ -2612,9 +2632,9 @@ _slon_decode_tgargs(PG_FUNCTION_ARGS)
 
        PG_RETURN_ARRAYTYPE_P(out_array);
 }
-       
-       
-       
+
+
+
 /*
  * Local Variables:
  *     tab-width: 4
index 0848c51ce9ff9246d745fc1b5d9b0439167f91c2..2a66c54b5e3eccfe1c3acfff7c80137061c815bd 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2007-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
  * ----
  */
 static AVLnode *avl_makenode(void);
-static void avl_reset_node(AVLnode *node, AVLfreefunc *freefunc);
-static int avl_insertinto(AVLtree *tree, AVLnode **node,
-                          void *cdata, AVLnode **result);
-static void avl_rotate_left(AVLnode **node);
-static void avl_rotate_right(AVLnode **node);
+static void avl_reset_node(AVLnode * node, AVLfreefunc * freefunc);
+static int avl_insertinto(AVLtree * tree, AVLnode ** node,
+                          void *cdata, AVLnode ** result);
+static void avl_rotate_left(AVLnode ** node);
+static void avl_rotate_right(AVLnode ** node);
 
 
 /* ----
@@ -38,7 +38,7 @@ static void avl_rotate_right(AVLnode **node);
  * ----
  */
 void
-avl_init(AVLtree *tree, AVLcompfunc *compfunc, AVLfreefunc *freefunc)
+avl_init(AVLtree * tree, AVLcompfunc * compfunc, AVLfreefunc * freefunc)
 {
        tree->root = NULL;
        tree->compfunc = compfunc;
@@ -55,7 +55,7 @@ avl_init(AVLtree *tree, AVLcompfunc *compfunc, AVLfreefunc *freefunc)
  * ----
  */
 void
-avl_reset(AVLtree *tree)
+avl_reset(AVLtree * tree)
 {
        avl_reset_node(tree->root, tree->freefunc);
        tree->root = NULL;
@@ -69,7 +69,7 @@ avl_reset(AVLtree *tree)
  * ----
  */
 void
-avl_reset_node(AVLnode *node, AVLfreefunc *freefunc)
+avl_reset_node(AVLnode * node, AVLfreefunc * freefunc)
 {
        if (node == NULL)
                return;
@@ -77,8 +77,9 @@ avl_reset_node(AVLnode *node, AVLfreefunc *freefunc)
        avl_reset_node(node->lnode, freefunc);
        avl_reset_node(node->rnode, freefunc);
 
-       if (freefunc != NULL)
-               freefunc(node->cdata);
+       if (freefunc !=NULL)
+               freefunc        (node->cdata);
+
        free(node);
 }
 
@@ -93,7 +94,7 @@ avl_reset_node(AVLnode *node, AVLfreefunc *freefunc)
  * ----
  */
 AVLnode *
-avl_insert(AVLtree *tree, void *cdata)
+avl_insert(AVLtree * tree, void *cdata)
 {
        AVLnode    *result;
 
@@ -119,7 +120,7 @@ avl_insert(AVLtree *tree, void *cdata)
  * ----
  */
 AVLnode *
-avl_lookup(AVLtree *tree, void *cdata)
+avl_lookup(AVLtree * tree, void *cdata)
 {
        AVLnode    *node;
        int                     cmp;
@@ -166,7 +167,7 @@ avl_lookup(AVLtree *tree, void *cdata)
  * ----
  */
 int
-avl_delete(AVLtree *tree, void *cdata)
+avl_delete(AVLtree * tree, void *cdata)
 {
        AVLnode    *node;
 
@@ -185,8 +186,8 @@ avl_delete(AVLtree *tree, void *cdata)
  * ----
  */
 static int
-avl_insertinto(AVLtree *tree, AVLnode **node,
-                          void *cdata, AVLnode **result)
+avl_insertinto(AVLtree * tree, AVLnode ** node,
+                          void *cdata, AVLnode ** result)
 {
        int                     cmp;
 
@@ -302,7 +303,7 @@ avl_insertinto(AVLtree *tree, AVLnode **node,
                 * deletion, free the user element data now. The caller is supposed to
                 * replace it with a new element having the the key.
                 */
-               if ((*node)->deleted && tree->freefunc != NULL)
+               if ((*node)->deleted && tree->freefunc !=NULL)
                {
                        (tree->freefunc) ((*node)->cdata);
                        (*node)->cdata = NULL;
@@ -339,7 +340,7 @@ avl_makenode(void)
  * ----
  */
 static void
-avl_rotate_left(AVLnode **node)
+avl_rotate_left(AVLnode ** node)
 {
        AVLnode    *rtmp;
 
@@ -377,7 +378,7 @@ avl_rotate_left(AVLnode **node)
  * ----
  */
 static void
-avl_rotate_right(AVLnode **node)
+avl_rotate_right(AVLnode ** node)
 {
        AVLnode    *ltmp;
 
index aad1e1f4db2cb793d2996b8bc9e79f3246b5bed6..0b8bdf1686da18aa04e54e563e96331d616274b3 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
@@ -33,14 +33,14 @@ typedef struct AVLnode_s
                                rdepth;
        void       *cdata;
        int                     deleted;
-} AVLnode;
+}      AVLnode;
 
 typedef struct AVLtree_s
 {
        AVLnode    *root;
        AVLcompfunc *compfunc;
        AVLfreefunc *freefunc;
-} AVLtree;
+}      AVLtree;
 
 /* ----
  * Macros
@@ -58,11 +58,11 @@ typedef struct AVLtree_s
  * Public functions
  * ----
  */
-void avl_init(AVLtree *tree, AVLcompfunc *compfunc,
-                AVLfreefunc *freefunc);
-void           avl_reset(AVLtree *tree);
-AVLnode    *avl_insert(AVLtree *tree, void *cdata);
-AVLnode    *avl_lookup(AVLtree *tree, void *cdata);
-int                    avl_delete(AVLtree *tree, void *cdata);
+void avl_init(AVLtree * tree, AVLcompfunc * compfunc,
+                AVLfreefunc * freefunc);
+void           avl_reset(AVLtree * tree);
+AVLnode    *avl_insert(AVLtree * tree, void *cdata);
+AVLnode    *avl_lookup(AVLtree * tree, void *cdata);
+int                    avl_delete(AVLtree * tree, void *cdata);
 
 #endif   /* _AVL_TREE_H_INCLUDED_ */
index 4b5c5d6f0ccdf8c48198baffa666ff0dfc0ecbc5..ba1c25b6ba90d8f9f673fd85be4e72ae4b16964a 100644 (file)
-/*  */
+/*     */
 #include <stdio.h>
 #include "scanner.h"
 
-int STMTS[MAXSTATEMENTS];
-int scan_for_statements (const char *extended_statement) {
-  int cpos;
-  int bquote;
-  int bpos;
-  enum quote_states state;
-  char cchar;
-  int d1start, d1end, d2start, d2end, d1stemp;
-  int statements;
-  int nparens;
-  int nbrokets;
-  int nsquigb;
-  
-  /* Initialize */
-  cpos = 0;
-  statements = 0;
-  bquote = 0;
-  bpos = 0;  /* Location of last backquote */
-  d1start = 0;
-  d2start = 0;
-  d1end = 0;
-  state = Q_NORMAL_STATE;
-  nparens = 0;
-  nbrokets = 0;
-  nsquigb = 0;
-  
-  while (state != Q_DONE) {
-    cchar = extended_statement[cpos];
-    switch (cchar) {
-    case '\0':
-      STMTS[statements++] = cpos;
-      state = Q_DONE;
-      break;
+int                    STMTS[MAXSTATEMENTS];
+int
+scan_for_statements(const char *extended_statement)
+{
+       int                     cpos;
+       int                     bquote;
+       int                     bpos;
+       enum quote_states state;
+       char            cchar;
+       int                     d1start,
+                               d1end,
+                               d2start,
+                               d2end,
+                               d1stemp;
+       int                     statements;
+       int                     nparens;
+       int                     nbrokets;
+       int                     nsquigb;
 
-    case '(':
-      if (state == Q_NORMAL_STATE) {
-       nparens ++;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      
-    case ')':
-      if (state == Q_NORMAL_STATE) {
-       nparens --;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-    case '[':
-      if (state == Q_NORMAL_STATE) {
-       nbrokets ++;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-    case ']':
-      if (state == Q_NORMAL_STATE) {
-       nbrokets --;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-    case '{':
-      if (state == Q_NORMAL_STATE) {
-       nsquigb ++;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
+       /* Initialize */
+       cpos = 0;
+       statements = 0;
+       bquote = 0;
+       bpos = 0;                                       /* Location of last backquote */
+       d1start = 0;
+       d2start = 0;
+       d1end = 0;
+       state = Q_NORMAL_STATE;
+       nparens = 0;
+       nbrokets = 0;
+       nsquigb = 0;
 
-    case '}':
-      if (state == Q_NORMAL_STATE) {
-       nsquigb --;
-       break;
-      }
+       while (state != Q_DONE)
+       {
+               cchar = extended_statement[cpos];
+               switch (cchar)
+               {
+                       case '\0':
+                               STMTS[statements++] = cpos;
+                               state = Q_DONE;
+                               break;
 
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-    case '/':
-      if (state == Q_NORMAL_STATE) {
-       state = Q_HOPE_TO_CCOMMENT;
-       break;
-      }
-      if (state == Q_HOPE_CEND) {
-       state = Q_NORMAL_STATE;
-       break;
-      }
-      break;
-    case '*':
-      if (state == Q_HOPE_TO_CCOMMENT) {
-       state = Q_CCOMMENT;
-       break;
-      }
-      if (state == Q_CCOMMENT) {
-       state = Q_HOPE_CEND;
-       break;
-      }
+                       case '(':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nparens++;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
 
-      break;
-    case '\\':
-      if ((state == Q_DOUBLE_QUOTING) || (state == Q_SINGLE_QUOTING)) {
-       if (bquote == 0) {
-         bquote = 1;
-         bpos = cpos;
-         break;
-       }
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '$':
-      if (state == Q_NORMAL_STATE) {
-       d1start = cpos;
-       state = Q_DOLLAR_BUILDING;
-       break;
-      }
-      if (state == Q_DOLLAR_BUILDING) {
-       d1end = cpos;
-       state = Q_DOLLAR_QUOTING;
-       break;
-      }
-      if (state == Q_DOLLAR_QUOTING) {
-       d2start = cpos;
-       state = Q_DOLLAR_UNBUILDING;
-       break;
-      }
-      if (state == Q_DOLLAR_UNBUILDING) {
-       d2end = cpos;
-       /* Compare strings - is this the delimiter the imperials are looking for? */
-       if ((d1end - d1start) != (d2end - d2start)) {
-         /* Lengths don't even match - these aren't the droids we're looking for */
-         state = Q_DOLLAR_QUOTING;   /* Return to dollar quoting mode */
-         break;
-       }
-       d1stemp = d1start;
-       while (d1stemp < d1end) {
-         if (extended_statement[d1stemp] != extended_statement[d2start]) {
-           /* mismatch - these aren't the droids... */
-           state = Q_DOLLAR_QUOTING;
-           break;
-         }
-         d1stemp++;   /* Step forward to the next character */
-         d2start++;
-       }
-       if ((d1stemp >= d1end) && (state == Q_DOLLAR_UNBUILDING)) {  /* No mismatches */
-         state = Q_NORMAL_STATE;
-         break;
-       }
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '"':
-      if (state == Q_NORMAL_STATE) {
-       state = Q_DOUBLE_QUOTING;
-       break;
-      }
-      if (state == Q_DOUBLE_QUOTING) {
-       /* But a backquote hides this! */
-       if ((bquote == 1) && (bpos == cpos -1)) {
-         break;   /* Ignore the quote */
-       }
-       state = Q_NORMAL_STATE;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '\'':
-      if (state == Q_NORMAL_STATE) {
-       state = Q_SINGLE_QUOTING;
-       break;
-      }
-      if (state == Q_SINGLE_QUOTING) {
-       /* But a backquote hides this! */
-       if ((bquote == 1) && (bpos == cpos -1)) {
-         break;   /* Ignore the quote */
-       }
-       state = Q_NORMAL_STATE;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '-':
-      if (state == Q_NORMAL_STATE && extended_statement[cpos+1] == '-') {
-       state = Q_HOPE_TO_DASH;
-       break;
-      }
-      if (state == Q_HOPE_TO_DASH) {
-       state = Q_DASHING_STATE;
-       break;
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '\n':
-      if (state == Q_DASHING_STATE) {
-       state = Q_NORMAL_STATE;
-      }
-      if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
-      if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case '\r':
-      if (state == Q_DASHING_STATE) {
-       state = Q_NORMAL_STATE;
-      }
-      if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
-      if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
-      if (state == Q_HOPE_CEND) state = Q_CCOMMENT;
-      break;
-    case ' ':
-      if (state == Q_DOLLAR_BUILDING) state = Q_NORMAL_STATE;
-      if (state == Q_DOLLAR_UNBUILDING) state = Q_DOLLAR_QUOTING;
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    case ';':
-      if ((state == Q_NORMAL_STATE) && (nparens == 0) && (nbrokets == 0) && (nsquigb == 0)) {
-       STMTS[statements++] = cpos + 1;
-       if (statements >= MAXSTATEMENTS) {
-         return statements;
+                       case ')':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nparens--;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                       case '[':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nbrokets++;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                       case ']':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nbrokets--;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                       case '{':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nsquigb++;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+
+                       case '}':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       nsquigb--;
+                                       break;
+                               }
+
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                       case '/':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       state = Q_HOPE_TO_CCOMMENT;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                               {
+                                       state = Q_NORMAL_STATE;
+                                       break;
+                               }
+                               break;
+                       case '*':
+                               if (state == Q_HOPE_TO_CCOMMENT)
+                               {
+                                       state = Q_CCOMMENT;
+                                       break;
+                               }
+                               if (state == Q_CCOMMENT)
+                               {
+                                       state = Q_HOPE_CEND;
+                                       break;
+                               }
+
+                               break;
+                       case '\\':
+                               if ((state == Q_DOUBLE_QUOTING) || (state == Q_SINGLE_QUOTING))
+                               {
+                                       if (bquote == 0)
+                                       {
+                                               bquote = 1;
+                                               bpos = cpos;
+                                               break;
+                                       }
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '$':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       d1start = cpos;
+                                       state = Q_DOLLAR_BUILDING;
+                                       break;
+                               }
+                               if (state == Q_DOLLAR_BUILDING)
+                               {
+                                       d1end = cpos;
+                                       state = Q_DOLLAR_QUOTING;
+                                       break;
+                               }
+                               if (state == Q_DOLLAR_QUOTING)
+                               {
+                                       d2start = cpos;
+                                       state = Q_DOLLAR_UNBUILDING;
+                                       break;
+                               }
+                               if (state == Q_DOLLAR_UNBUILDING)
+                               {
+                                       d2end = cpos;
+
+                                       /*
+                                        * Compare strings - is this the delimiter the imperials
+                                        * are looking for?
+                                        */
+                                       if ((d1end - d1start) != (d2end - d2start))
+                                       {
+                                               /*
+                                                * Lengths don't even match - these aren't the droids
+                                                * we're looking for
+                                                */
+                                               state = Q_DOLLAR_QUOTING;               /* Return to dollar
+                                                                                                                * quoting mode */
+                                               break;
+                                       }
+                                       d1stemp = d1start;
+                                       while (d1stemp < d1end)
+                                       {
+                                               if (extended_statement[d1stemp] != extended_statement[d2start])
+                                               {
+                                                       /* mismatch - these aren't the droids... */
+                                                       state = Q_DOLLAR_QUOTING;
+                                                       break;
+                                               }
+                                               d1stemp++;              /* Step forward to the next character */
+                                               d2start++;
+                                       }
+                                       if ((d1stemp >= d1end) && (state == Q_DOLLAR_UNBUILDING))
+                                       {                       /* No mismatches */
+                                               state = Q_NORMAL_STATE;
+                                               break;
+                                       }
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '"':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       state = Q_DOUBLE_QUOTING;
+                                       break;
+                               }
+                               if (state == Q_DOUBLE_QUOTING)
+                               {
+                                       /* But a backquote hides this! */
+                                       if ((bquote == 1) && (bpos == cpos - 1))
+                                       {
+                                               break;  /* Ignore the quote */
+                                       }
+                                       state = Q_NORMAL_STATE;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '\'':
+                               if (state == Q_NORMAL_STATE)
+                               {
+                                       state = Q_SINGLE_QUOTING;
+                                       break;
+                               }
+                               if (state == Q_SINGLE_QUOTING)
+                               {
+                                       /* But a backquote hides this! */
+                                       if ((bquote == 1) && (bpos == cpos - 1))
+                                       {
+                                               break;  /* Ignore the quote */
+                                       }
+                                       state = Q_NORMAL_STATE;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '-':
+                               if (state == Q_NORMAL_STATE && extended_statement[cpos + 1] == '-')
+                               {
+                                       state = Q_HOPE_TO_DASH;
+                                       break;
+                               }
+                               if (state == Q_HOPE_TO_DASH)
+                               {
+                                       state = Q_DASHING_STATE;
+                                       break;
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '\n':
+                               if (state == Q_DASHING_STATE)
+                               {
+                                       state = Q_NORMAL_STATE;
+                               }
+                               if (state == Q_DOLLAR_BUILDING)
+                                       state = Q_NORMAL_STATE;
+                               if (state == Q_DOLLAR_UNBUILDING)
+                                       state = Q_DOLLAR_QUOTING;
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case '\r':
+                               if (state == Q_DASHING_STATE)
+                               {
+                                       state = Q_NORMAL_STATE;
+                               }
+                               if (state == Q_DOLLAR_BUILDING)
+                                       state = Q_NORMAL_STATE;
+                               if (state == Q_DOLLAR_UNBUILDING)
+                                       state = Q_DOLLAR_QUOTING;
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case ' ':
+                               if (state == Q_DOLLAR_BUILDING)
+                                       state = Q_NORMAL_STATE;
+                               if (state == Q_DOLLAR_UNBUILDING)
+                                       state = Q_DOLLAR_QUOTING;
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       case ';':
+                               if ((state == Q_NORMAL_STATE) && (nparens == 0) && (nbrokets == 0) && (nsquigb == 0))
+                               {
+                                       STMTS[statements++] = cpos + 1;
+                                       if (statements >= MAXSTATEMENTS)
+                                       {
+                                               return statements;
+                                       }
+                               }
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+                       default:
+                               if (state == Q_HOPE_CEND)
+                                       state = Q_CCOMMENT;
+                               break;
+               }
+               cpos++;
        }
-      }
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    default:
-      if (state == Q_HOPE_CEND)        state = Q_CCOMMENT;
-      break;
-    }
-    cpos++;
-  }
-  return statements;
+       return statements;
 }
index f3b6e3df75fdcff0d637ffc418b5a0a950a72918..95264aebf2463e01d5333cdd70e445e42274b98c 100644 (file)
@@ -1,18 +1,24 @@
-/*  */
+/*     */
 #define MAXSTATEMENTS 1000
-enum quote_states {
+enum quote_states
+{
        Q_NORMAL_STATE,
-       Q_HOPE_TO_DASH,      /* If next char is -, then start a -- comment 'til the end of the line */
-       Q_DASHING_STATE,     /* comment using -- to the end of the line */
-       Q_HOPE_TO_CCOMMENT,  /* If next char is *, then start a C-style comment */
-       Q_CCOMMENT,          /* Inside a C-style comment */
-       Q_HOPE_CEND,         /* expecting the end of a C-style comment */
-       Q_DOUBLE_QUOTING,    /* inside a "double-quoted" quoting */
-       Q_SINGLE_QUOTING,    /* inside a 'single-quoted' quoting */
-       Q_DOLLAR_QUOTING,    /* inside a $doll$ dollar quoted $doll$ section */
-       Q_DOLLAR_BUILDING,   /* inside the $doll$ of a dollar quoted section */
-       Q_DOLLAR_UNBUILDING, /* inside a possible closing $doll$ of a dollar quoted section */
-       Q_DONE               /* NULL ends it all... */
+       Q_HOPE_TO_DASH,                         /* If next char is -, then start a -- comment
+                                                                * 'til the end of the line */
+       Q_DASHING_STATE,                        /* comment using -- to the end of the line */
+       Q_HOPE_TO_CCOMMENT,                     /* If next char is *, then start a C-style
+                                                                * comment */
+       Q_CCOMMENT,                                     /* Inside a C-style comment */
+       Q_HOPE_CEND,                            /* expecting the end of a C-style comment */
+       Q_DOUBLE_QUOTING,                       /* inside a "double-quoted" quoting */
+       Q_SINGLE_QUOTING,                       /* inside a 'single-quoted' quoting */
+       Q_DOLLAR_QUOTING,                       /* inside a $doll$ dollar quoted $doll$
+                                                                * section */
+       Q_DOLLAR_BUILDING,                      /* inside the $doll$ of a dollar quoted
+                                                                * section */
+       Q_DOLLAR_UNBUILDING,            /* inside a possible closing $doll$ of a
+                                                                * dollar quoted section */
+       Q_DONE                                          /* NULL ends it all... */
 };
 
-extern int scan_for_statements (const char *extended_statement);
+extern int     scan_for_statements(const char *extended_statement);
index 0665ff73bf7b507f9b99be8c07122aef5a62cbb5..74f7700b429b9cbb9c3261ae6159f183036e1e08 100644 (file)
@@ -2,28 +2,34 @@
 #include <stdlib.h>
 #include "scanner.h"
 
-char foo[65536];
-extern int STMTS[1024];
-extern int statements;
+char           foo[65536];
+extern int     STMTS[1024];
+extern int     statements;
 
-int main (int argc, char *const argv[]) {
+int
+main(int argc, char *const argv[])
+{
 
-  int i, j, START;
-  int nstatements = 0;
+       int                     i,
+                               j,
+                               START;
+       int                     nstatements = 0;
 
-  fread(foo, sizeof(char), 65536, stdin);
-  printf("Input: %s\n", foo);
-  
-  nstatements = scan_for_statements (foo);
-  
-  START = 0;
-  for (i = 0; i < nstatements; i++) {
-    printf("\nstatement %d\n-------------------------------------------\n", i);
-    for (j = START; j < STMTS[i]; j++) {
-      printf("%c", foo[j]);
-    }
-    START = STMTS[i];
-  }
+       fread(foo, sizeof(char), 65536, stdin);
+       printf("Input: %s\n", foo);
 
-  return 0;
+       nstatements = scan_for_statements(foo);
+
+       START = 0;
+       for (i = 0; i < nstatements; i++)
+       {
+               printf("\nstatement %d\n-------------------------------------------\n", i);
+               for (j = START; j < STMTS[i]; j++)
+               {
+                       printf("%c", foo[j]);
+               }
+               START = STMTS[i];
+       }
+
+       return 0;
 }
index 328b091e3a8b77ccad5cf019d499a3ced62b418a..4c476fda75f2f1ee7e6d8cc5a20800155cea55b2 100644 (file)
@@ -2,12 +2,12 @@
  *
  * slevent.c
  *             Defines the entry point for slevent dll.
- *             The DLL defines event source for Slony tools 
+ *             The DLL defines event source for Slony tools
  *
  *
  * IDENTIFICATION
  *       $PostgreSQL: pgsql/src/bin/pgevent/pgevent.c,v 1.4 2004/09/27 19:16:01 momjian Exp $
- *    
+ *
  *
  *-------------------------------------------------------------------------
  */
@@ -45,8 +45,8 @@ DllRegisterServer(void)
        }
 
        /*
-        * Add PostgreSQL source name as a subkey under the Application key in
-        * the EventLog registry key.
+        * Add PostgreSQL source name as a subkey under the Application key in the
+        * EventLog registry key.
         */
        if (RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\Slony", &key))
        {
@@ -73,7 +73,7 @@ DllRegisterServer(void)
                                          "TypesSupported",
                                          0,
                                          REG_DWORD,
-                                         (LPBYTE) & data,
+                                         (LPBYTE) &data,
                                          sizeof(DWORD)))
        {
                MessageBox(NULL, "Could not set the supported types.", "Slony error", MB_OK | MB_ICONSTOP);
@@ -92,8 +92,8 @@ STDAPI
 DllUnregisterServer(void)
 {
        /*
-        * Remove PostgreSQL source name as a subkey under the Application key
-        * in the EventLog registry key.
+        * Remove PostgreSQL source name as a subkey under the Application key in
+        * the EventLog registry key.
         */
 
        if (RegDeleteKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\Slony"))
index ae121414994b0f8de0c7f410057fe6360523deba..0d36150cf2c6a68df6dee3786603263911eb9aaa 100644 (file)
@@ -1,4 +1,4 @@
-/*  */
+/*     */
 #ifndef __CONF_FILE_H__
 #define __CONF_FILE_H__
 
index 4d82e1379d24d0135583d1959b7fe5f87f9b6ffc..56de55a7f8e21e9966ff93f19efd80f6a1125e75 100644 (file)
@@ -22,7 +22,7 @@ void     *get_config_option(const char *name);
 static double real_placeholder;
 
 void           dump_configuration(void);
-void build_conf_variables(void);
+void           build_conf_variables(void);
 
 
 
@@ -145,51 +145,51 @@ static struct config_int ConfigureNamesInt[] =
                12000
        },
        {
-               {         
-                       (const char *) "explain_interval",              /* conf name */
-                       gettext_noop("Interval in seconds in which the remote worker will report an explain of the log selection query"),               /* short desc */
-                       gettext_noop("Interval in seconds in which the remote worker will report an explain of the log selection query"),               /* long desc */
+               {
+                       (const char *) "explain_interval",      /* conf name */
+                       gettext_noop("Interval in seconds in which the remote worker will report an explain of the log selection query"),       /* short desc */
+                       gettext_noop("Interval in seconds in which the remote worker will report an explain of the log selection query"),       /* long desc */
                        SLON_C_INT                      /* config type */
-           },
-               &explain_interval, /* var name */
+               },
+               &explain_interval,              /* var name */
                0,                                              /* default val (never) */
                0,                                              /* min val */
                86400                                   /* max val (1 day) */
        },
+       {
                {
-               {
-                       (const char*) "tcp_keepalive_idle",
+                       (const char *) "tcp_keepalive_idle",
                        gettext_noop("The number of seconds after which a TCP keep alive "
                                                 "is sent across an idle connection. tcp_keepalive "
                                                 "must be enabled for this to take effect.  Default "
                                                 "of 0 means use operating system default"
-                                                "use default" ),
+                                                "use default"),
                        NULL,
                        SLON_C_INT,
                },
                &keep_alive_idle,
-               0, /*default val */
-               0, /* min val */
-               1073741824      /*max val*/
+               0,                                              /* default val */
+               0,                                              /* min val */
+               1073741824                              /* max val */
        },
        {
                {
-                       (const char*) "tcp_keepalive_interval",
+                       (const char *) "tcp_keepalive_interval",
                        gettext_noop("The number of seconds in between TCP keep alive "
                                                 "requests. tcp_keepalive "
                                                 "must be enabled. Default value of 0 means use "
-                         "operating system defaut"),
+                                                "operating system defaut"),
                        NULL,
                        SLON_C_INT,
                },
                &keep_alive_interval,
                0,
-               0, /* min val */
-               1073741824      /*max val*/
+               0,                                              /* min val */
+               1073741824                              /* max val */
        },
        {
                {
-                       (const char*) "tcp_keepalive_count",
+                       (const char *) "tcp_keepalive_count",
                        gettext_noop("The number of keep alive requests to the server "
                                                 "that can be lost before the connection is declared "
                                                 "dead. tcp_keep_alive must be on. Default value "
@@ -199,8 +199,8 @@ static struct config_int ConfigureNamesInt[] =
                },
                &keep_alive_count,
                0,
-               0, /* min val */
-               1073741824      /*max val*/
+               0,                                              /* min val */
+               1073741824                              /* max val */
        },
        {
                {
@@ -240,10 +240,10 @@ static struct config_bool ConfigureNamesBool[] =
                true
        },
 
-       {  
-       
+       {
+
                {
-                       (const char*) "tcp_keepalive",
+                       (const char *) "tcp_keepalive",
                        gettext_noop("Enables sending of TCP KEEP alive between slon "
                                                 "and the PostgreSQL backends. "),
                        NULL,
@@ -254,7 +254,7 @@ static struct config_bool ConfigureNamesBool[] =
        },
        {
                {
-                       (const char*) "monitor_threads",
+                       (const char *) "monitor_threads",
                        gettext_noop("Should the monitoring thread be run?"),
                        NULL,
                        SLON_C_BOOL,
@@ -438,7 +438,7 @@ dump_configuration(void)
        for (i = 0; ConfigureNamesString[i].gen.name; i++)
        {
                slon_log(SLON_CONFIG, "main: String option %s = %s\n",
-                                ConfigureNamesString[i].gen.name, ((*ConfigureNamesString[i].variable)==NULL)?"[NULL]":*(ConfigureNamesString[i].variable));
+                                ConfigureNamesString[i].gen.name, ((*ConfigureNamesString[i].variable) == NULL) ? "[NULL]" : *(ConfigureNamesString[i].variable));
        }
 
 
@@ -528,7 +528,7 @@ build_conf_variables(void)
 
 #ifdef NEED_ADD_CONF_VARIABLE
 static bool
-add_conf_variable(struct config_generic *var, int elevel)
+add_conf_variable(struct config_generic * var, int elevel)
 {
        if (num_conf_variables + 1 >= size_conf_variables)
        {
index 7f09af349e55fb64cff725b4e88bb0480b4755f1..75bfbfba1664765574092315cdf1bfc9b5abde79 100644 (file)
@@ -1,4 +1,4 @@
-/*  */
+/*     */
 #ifndef _CONFOPTIONS_H_
 #define _CONFOPTIONS_H_
 
@@ -25,10 +25,10 @@ extern int  desired_sync_time;
 
 extern int     quit_sync_provider;
 extern int     quit_sync_finalsync;
-extern bool  keep_alive;
-extern int  keep_alive_idle;
-extern int  keep_alive_interval;
-extern int  keep_alive_count;
+extern bool keep_alive;
+extern int     keep_alive_idle;
+extern int     keep_alive_interval;
+extern int     keep_alive_count;
 
 extern int     apply_cache_size;
 
index f87755ad89bcad423a459277a94c375e6586e2b3..726b45869caf76a972ef2b9950bcb7e473b5ab54 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
 
 #include "slon.h"
 
-bool keep_alive;
-int keep_alive_idle;
-int keep_alive_count;
-int keep_alive_interval;
+bool           keep_alive;
+int                    keep_alive_idle;
+int                    keep_alive_count;
+int                    keep_alive_interval;
 
-static int     slon_appendquery_int(SlonDString *dsp, char *fmt, va_list ap);
+static int     slon_appendquery_int(SlonDString * dsp, char *fmt, va_list ap);
 static int     db_get_version(PGconn *conn);
 
 #if (PG_VERSION_MAJOR < 8)
@@ -63,7 +63,7 @@ slon_connectdb(char *conninfo, char *symname)
        SlonConn   *conn;
        PGresult   *res;
        SlonDString query;
-       int         connpid = -1;
+       int                     connpid = -1;
 
        /*
         * Create the native database connection
@@ -91,52 +91,52 @@ slon_connectdb(char *conninfo, char *symname)
                return NULL;
        }
 
-       setsockopt(PQsocket(dbconn),SOL_SOCKET,SO_KEEPALIVE,&keep_alive,
+       setsockopt(PQsocket(dbconn), SOL_SOCKET, SO_KEEPALIVE, &keep_alive,
                           sizeof(int));
 #ifndef WIN32
-       if(keep_alive)
+       if (keep_alive)
        {
-               
-               if(keep_alive_idle > 0)
+
+               if (keep_alive_idle > 0)
 #ifdef TCP_KEEPIDLE
-                       setsockopt(PQsocket(dbconn),IPPROTO_TCP,TCP_KEEPIDLE,
-                                          &keep_alive_idle,sizeof(keep_alive_idle));
+                       setsockopt(PQsocket(dbconn), IPPROTO_TCP, TCP_KEEPIDLE,
+                                          &keep_alive_idle, sizeof(keep_alive_idle));
 #else
-                       slon_log(SLON_WARN,"keep_alive_idle is not supported on this platform");
+                       slon_log(SLON_WARN, "keep_alive_idle is not supported on this platform");
 #endif
-               if(keep_alive_interval > 0)
+               if (keep_alive_interval > 0)
 #ifdef TCP_KEEPINTVL
-                       setsockopt(PQsocket(dbconn),IPPROTO_TCP,TCP_KEEPINTVL,
-                                          &keep_alive_interval,sizeof(keep_alive_interval));
+                       setsockopt(PQsocket(dbconn), IPPROTO_TCP, TCP_KEEPINTVL,
+                                          &keep_alive_interval, sizeof(keep_alive_interval));
 #else
-                       slon_log(SLON_WARN,"keep_alive_interval is not supported on this platform");
+                       slon_log(SLON_WARN, "keep_alive_interval is not supported on this platform");
 #endif
-               if(keep_alive_count > 0)
+               if (keep_alive_count > 0)
 #ifdef TCP_KEEPCNT
-                       setsockopt(PQsocket(dbconn),IPPROTO_TCP,TCP_KEEPCNT,
-                                          &keep_alive_count,sizeof(keep_alive_count));
+                       setsockopt(PQsocket(dbconn), IPPROTO_TCP, TCP_KEEPCNT,
+                                          &keep_alive_count, sizeof(keep_alive_count));
 #else
-                       slon_log(SLON_WARN,"keep_alive_count is not supported on this platform");
+                       slon_log(SLON_WARN, "keep_alive_count is not supported on this platform");
 #endif
-               
+
        }
 #else
        /**
         * Win32 does not support the setsockopt calls for setting keep alive
-        * parameters.  On Win32 this can be adjusted via the registry.
+        * parameters.  On Win32 this can be adjusted via the registry.
         * libpq 9.0 and above provide functions for doing this.
         * If we ever require libpq9.0 or above we could start to use them.
         * Alternativly someone could re-implement that functionality inside
         * of slony.
         */
-       if(keep_alive)
+       if (keep_alive)
        {
-               if(keep_alive_idle > 0 )
-                       slon_log(SLON_WARN,"keep_alive_idle is not supported by Slony on Win32");
-               if(keep_alive_interval > 0) 
-                       slon_log(SLON_WARN,"keep_alive_interval is not supported by Slony on Win32");
-               if(keep_alive_count > 0) 
-                       slon_log(SLON_WARN,"keep_alive_count is not supported by Slony Win32");
+               if (keep_alive_idle > 0)
+                       slon_log(SLON_WARN, "keep_alive_idle is not supported by Slony on Win32");
+               if (keep_alive_interval > 0)
+                       slon_log(SLON_WARN, "keep_alive_interval is not supported by Slony on Win32");
+               if (keep_alive_count > 0)
+                       slon_log(SLON_WARN, "keep_alive_count is not supported by Slony Win32");
 
        }
 #endif
@@ -172,9 +172,11 @@ slon_connectdb(char *conninfo, char *symname)
        res = PQexec(dbconn, dstring_data(&query));
        if (!(PQresultStatus(res) == PGRES_TUPLES_OK))
        {
-                       slon_log(SLON_ERROR, "Unable to check connection PID\n");
-       } else {
-                       connpid = strtol(PQgetvalue(res, 0, 0), NULL, 10);
+               slon_log(SLON_ERROR, "Unable to check connection PID\n");
+       }
+       else
+       {
+               connpid = strtol(PQgetvalue(res, 0, 0), NULL, 10);
        }
        PQclear(res);
 
@@ -222,7 +224,7 @@ slon_connectdb(char *conninfo, char *symname)
        res = PQexec(dbconn, dstring_data(&query));
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
-                       slon_log(SLON_ERROR, "Unable to submit application_name store request\n");
+               slon_log(SLON_ERROR, "Unable to submit application_name store request\n");
        }
        PQclear(res);
 
@@ -234,12 +236,12 @@ slon_connectdb(char *conninfo, char *symname)
                if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
                {
                        slon_log(SLON_ERROR, "%s: Unable to get backend pid - %s\n",
-                               symname, PQresultErrorMessage(res));
+                                        symname, PQresultErrorMessage(res));
                }
                else
                {
                        slon_log(SLON_DEBUG1, "%s \"%s\": backend pid = %s\n",
-                               symname, conninfo, PQgetvalue(res, 0, 0));
+                                        symname, conninfo, PQgetvalue(res, 0, 0));
                }
                PQclear(res);
        }
@@ -254,7 +256,7 @@ slon_connectdb(char *conninfo, char *symname)
  * ----------
  */
 void
-slon_disconnectdb(SlonConn *conn)
+slon_disconnectdb(SlonConn * conn)
 {
        /*
         * Disconnect the native database connection
@@ -308,7 +310,7 @@ slon_make_dummyconn(char *symname)
  * ----------
  */
 void
-slon_free_dummyconn(SlonConn *conn)
+slon_free_dummyconn(SlonConn * conn)
 {
        /*
         * Destroy and unlock the condition and mutex variables
@@ -484,7 +486,7 @@ db_checkSchemaVersion(PGconn *conn)
  * ----------
  */
 void
-slon_mkquery(SlonDString *dsp, char *fmt,...)
+slon_mkquery(SlonDString * dsp, char *fmt,...)
 {
        va_list         ap;
 
@@ -505,7 +507,7 @@ slon_mkquery(SlonDString *dsp, char *fmt,...)
  * ----------
  */
 void
-slon_appendquery(SlonDString *dsp, char *fmt,...)
+slon_appendquery(SlonDString * dsp, char *fmt,...)
 {
        va_list         ap;
 
@@ -524,7 +526,7 @@ slon_appendquery(SlonDString *dsp, char *fmt,...)
  * ----------
  */
 static int
-slon_appendquery_int(SlonDString *dsp, char *fmt, va_list ap)
+slon_appendquery_int(SlonDString * dsp, char *fmt, va_list ap)
 {
        char       *s;
        char            buf[64];
index 727ec3563dc55fd91258dbc5c41293a3ba97e93a..46a01c4eb70fc046c269df6bc3afc3241e39a04a 100644 (file)
@@ -7,7 +7,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -28,7 +28,7 @@
 
 #include "slon.h"
 
-extern int worker_restarted;
+extern int     worker_restarted;
 
 /* ----------
  * slon_localListenThread
@@ -38,7 +38,7 @@ extern int worker_restarted;
  * ----------
  */
 void *
-localListenThread_main(/* @unused@ */ void *dummy)
+localListenThread_main( /* @unused@ */ void *dummy)
 {
        SlonConn   *conn;
        SlonDString query1;
@@ -49,8 +49,8 @@ localListenThread_main(/* @unused@ */ void *dummy)
        PGnotify   *notification;
        char            restart_notify[256];
        int                     restart_request;
-       int poll_sleep = 0;
-       int         node_lock_obtained=0;
+       int                     poll_sleep = 0;
+       int                     node_lock_obtained = 0;
 
        slon_log(SLON_INFO, "localListenThread: thread starts\n");
 
@@ -73,8 +73,8 @@ localListenThread_main(/* @unused@ */ void *dummy)
         * Listen for local events
         */
        (void) slon_mkquery(&query1,
-                    "listen \"_%s_Restart\"; ",
-                    rtcfg_cluster_name);
+                                               "listen \"_%s_Restart\"; ",
+                                               rtcfg_cluster_name);
        res = PQexec(dbconn, dstring_data(&query1));
        if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
@@ -84,7 +84,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                PQclear(res);
                dstring_free(&query1);
                pthread_mutex_lock(&slon_wait_listen_lock);
-               slon_listen_started=0;
+               slon_listen_started = 0;
                pthread_cond_signal(&slon_wait_listen_cond);
                pthread_mutex_unlock(&slon_wait_listen_lock);
                slon_retry();
@@ -97,12 +97,12 @@ localListenThread_main(/* @unused@ */ void *dummy)
 #define NODELOCKERROR "ERROR:  duplicate key violates unique constraint \"sl_nodelock-pkey\""
 
        (void) slon_mkquery(&query1,
-                                "select %s.cleanupNodelock(); "
-                                "insert into %s.sl_nodelock values ("
-                                "    %d, 0, \"pg_catalog\".pg_backend_pid()); ",
-                                rtcfg_namespace, rtcfg_namespace,
-                                rtcfg_nodeid);
-       while(!node_lock_obtained)
+                                               "select %s.cleanupNodelock(); "
+                                               "insert into %s.sl_nodelock values ("
+                                               "    %d, 0, \"pg_catalog\".pg_backend_pid()); ",
+                                               rtcfg_namespace, rtcfg_namespace,
+                                               rtcfg_nodeid);
+       while (!node_lock_obtained)
        {
                res = PQexec(dbconn, dstring_data(&query1));
                if (PQresultStatus(res) != PGRES_COMMAND_OK)
@@ -110,35 +110,36 @@ localListenThread_main(/* @unused@ */ void *dummy)
                        slon_log(SLON_FATAL,
                                         "localListenThread: \"%s\" - %s\n",
                                         dstring_data(&query1), PQresultErrorMessage(res));
-                       if (strncmp(NODELOCKERROR, PQresultErrorMessage(res), strlen(NODELOCKERROR)) == 0) {
+                       if (strncmp(NODELOCKERROR, PQresultErrorMessage(res), strlen(NODELOCKERROR)) == 0)
+                       {
                                slon_log(SLON_FATAL,
-                                                "Do you already have a slon running against this node?\n");
+                                 "Do you already have a slon running against this node?\n");
                                slon_log(SLON_FATAL,
                                                 "Or perhaps a residual idle backend connection from a dead slon?\n");
                                PQclear(res);
-                               if(worker_restarted)
+                               if (worker_restarted)
                                {
                                        sleep(5);
                                        continue;
                                }
                                else
                                {
-                                       dstring_free(&query1);                                  
+                                       dstring_free(&query1);
                                        pthread_mutex_lock(&slon_wait_listen_lock);
-                                       slon_listen_started=0;
+                                       slon_listen_started = 0;
                                        pthread_cond_signal(&slon_wait_listen_cond);
                                        pthread_mutex_unlock(&slon_wait_listen_lock);
                                        slon_abort();
                                }
                        }
-                   
+
                        PQclear(res);
                        dstring_free(&query1);
                        slon_abort();
                }
                PQclear(res);
-               node_lock_obtained=1;
-       
+               node_lock_obtained = 1;
+
        }
 
        /*
@@ -146,7 +147,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
         * other threads.
         */
        pthread_mutex_lock(&slon_wait_listen_lock);
-       slon_listen_started=1;
+       slon_listen_started = 1;
        pthread_cond_signal(&slon_wait_listen_cond);
        pthread_mutex_unlock(&slon_wait_listen_lock);
 
@@ -201,16 +202,16 @@ localListenThread_main(/* @unused@ */ void *dummy)
                 * Query the database for new local events
                 */
                (void) slon_mkquery(&query1,
-                                        "select ev_seqno, ev_timestamp, "
-                                        "       'dummy', 'dummy', 'dummy', "
-                                        "       ev_type, "
-                                        "       ev_data1, ev_data2, ev_data3, ev_data4, "
-                                        "       ev_data5, ev_data6, ev_data7, ev_data8 "
-                                        "from %s.sl_event "
-                                        "where  ev_origin = '%d' "
-                                        "       and ev_seqno > '%s' "
-                                        "order by ev_seqno",
-                                        rtcfg_namespace, rtcfg_nodeid, rtcfg_lastevent);
+                                                       "select ev_seqno, ev_timestamp, "
+                                                       "       'dummy', 'dummy', 'dummy', "
+                                                       "       ev_type, "
+                                                       "       ev_data1, ev_data2, ev_data3, ev_data4, "
+                                                       "       ev_data5, ev_data6, ev_data7, ev_data8 "
+                                                       "from %s.sl_event "
+                                                       "where  ev_origin = '%d' "
+                                                       "       and ev_seqno > '%s' "
+                                                       "order by ev_seqno",
+                                                       rtcfg_namespace, rtcfg_nodeid, rtcfg_lastevent);
                res = PQexec(dbconn, dstring_data(&query1));
                if (PQresultStatus(res) != PGRES_TUPLES_OK)
                {
@@ -259,7 +260,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     no_id;
                                char       *no_comment;
 
-                               no_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               no_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
                                no_comment = PQgetvalue(res, tupno, 7);
 
                                if (no_id != rtcfg_nodeid)
@@ -274,7 +275,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                 */
                                int                     no_id;
 
-                               no_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               no_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
 
                                if (no_id != rtcfg_nodeid)
                                        rtcfg_enableNode(no_id);
@@ -290,7 +291,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                char            notify_query[256];
                                PGresult   *notify_res;
 
-                               no_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               no_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
 
                                /*
                                 * Deactivate the node in the runtime configuration
@@ -324,7 +325,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     no_id;
                                char       *no_comment;
 
-                               no_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               no_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
                                no_comment = PQgetvalue(res, tupno, 8);
 
                                rtcfg_storeNode(no_id, no_comment);
@@ -339,10 +340,10 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                char       *pa_conninfo;
                                int                     pa_connretry;
 
-                               pa_server = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               pa_client = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               pa_server = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               pa_client = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
                                pa_conninfo = PQgetvalue(res, tupno, 8);
-                               pa_connretry = (int)strtol(PQgetvalue(res, tupno, 9), NULL, 10);
+                               pa_connretry = (int) strtol(PQgetvalue(res, tupno, 9), NULL, 10);
 
                                if (pa_client == rtcfg_nodeid)
                                        rtcfg_storePath(pa_server, pa_conninfo, pa_connretry);
@@ -357,8 +358,8 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     pa_server;
                                int                     pa_client;
 
-                               pa_server = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               pa_client = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               pa_server = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               pa_client = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
 
                                if (pa_client == rtcfg_nodeid)
                                        rtcfg_dropPath(pa_server);
@@ -374,9 +375,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     li_provider;
                                int                     li_receiver;
 
-                               li_origin = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               li_provider = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
-                               li_receiver = (int)strtol(PQgetvalue(res, tupno, 8), NULL, 10);
+                               li_origin = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               li_provider = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               li_receiver = (int) strtol(PQgetvalue(res, tupno, 8), NULL, 10);
 
                                if (li_receiver == rtcfg_nodeid)
                                        rtcfg_storeListen(li_origin, li_provider);
@@ -390,9 +391,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     li_provider;
                                int                     li_receiver;
 
-                               li_origin = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               li_provider = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
-                               li_receiver = (int)strtol(PQgetvalue(res, tupno, 8), NULL, 10);
+                               li_origin = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               li_provider = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               li_receiver = (int) strtol(PQgetvalue(res, tupno, 8), NULL, 10);
 
                                if (li_receiver == rtcfg_nodeid)
                                        rtcfg_dropListen(li_origin, li_provider);
@@ -406,8 +407,8 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     set_origin;
                                char       *set_comment;
 
-                               set_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               set_origin = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               set_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               set_origin = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
                                set_comment = PQgetvalue(res, tupno, 8);
 
                                rtcfg_storeSet(set_id, set_origin, set_comment);
@@ -419,7 +420,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                 */
                                int                     set_id;
 
-                               set_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               set_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
 
                                rtcfg_dropSet(set_id);
                        }
@@ -430,7 +431,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                 */
                                int                     add_id;
 
-                               add_id = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               add_id = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
 
                                rtcfg_dropSet(add_id);
                        }
@@ -540,9 +541,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                SlonDString query2;
                                int                     sub_provider;
 
-                               set_id = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               old_origin = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
-                               new_origin = (int)strtol(PQgetvalue(res, tupno, 8), NULL, 10);
+                               set_id = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               old_origin = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               new_origin = (int) strtol(PQgetvalue(res, tupno, 8), NULL, 10);
 
                                /*
                                 * We have been the old origin of the set, so according to the
@@ -550,9 +551,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                 */
                                dstring_init(&query2);
                                (void) slon_mkquery(&query2,
-                                                        "select sub_provider from %s.sl_subscribe "
-                                            "    where sub_receiver = %d and sub_set = %d",
-                                            rtcfg_namespace, rtcfg_nodeid, set_id);
+                                                                 "select sub_provider from %s.sl_subscribe "
+                                                         "    where sub_receiver = %d and sub_set = %d",
+                                                                       rtcfg_namespace, rtcfg_nodeid, set_id);
                                res2 = PQexec(dbconn, dstring_data(&query2));
                                if (PQresultStatus(res2) != PGRES_TUPLES_OK)
                                {
@@ -574,7 +575,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                }
 
                                sub_provider =
-                                       (int)strtol(PQgetvalue(res2, 0, 0), NULL, 10);
+                                       (int) strtol(PQgetvalue(res2, 0, 0), NULL, 10);
                                PQclear(res2);
                                dstring_free(&query2);
 
@@ -603,9 +604,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     sub_receiver;
                                char       *sub_forward;
 
-                               sub_set = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               sub_provider = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
-                               sub_receiver = (int)strtol(PQgetvalue(res, tupno, 8), NULL, 10);
+                               sub_set = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               sub_provider = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               sub_receiver = (int) strtol(PQgetvalue(res, tupno, 8), NULL, 10);
                                sub_forward = PQgetvalue(res, tupno, 9);
 
                                if (sub_receiver == rtcfg_nodeid)
@@ -623,9 +624,9 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     sub_receiver;
                                char       *sub_forward;
 
-                               sub_set = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               sub_provider = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
-                               sub_receiver = (int)strtol(PQgetvalue(res, tupno, 8), NULL, 10);
+                               sub_set = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               sub_provider = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               sub_receiver = (int) strtol(PQgetvalue(res, tupno, 8), NULL, 10);
                                sub_forward = PQgetvalue(res, tupno, 9);
 
                                if (sub_receiver == rtcfg_nodeid)
@@ -641,8 +642,8 @@ localListenThread_main(/* @unused@ */ void *dummy)
                                int                     sub_set;
                                int                     sub_receiver;
 
-                               sub_set = (int)strtol(PQgetvalue(res, tupno, 6), NULL, 10);
-                               sub_receiver = (int)strtol(PQgetvalue(res, tupno, 7), NULL, 10);
+                               sub_set = (int) strtol(PQgetvalue(res, tupno, 6), NULL, 10);
+                               sub_receiver = (int) strtol(PQgetvalue(res, tupno, 7), NULL, 10);
 
                                if (sub_receiver == rtcfg_nodeid)
                                        rtcfg_unsubscribeSet(sub_set);
@@ -687,7 +688,7 @@ localListenThread_main(/* @unused@ */ void *dummy)
                 */
                if (ntuples > 0)
                {
-                       poll_sleep = 0;  /* drop polling time back to 0... */
+                       poll_sleep = 0;         /* drop polling time back to 0... */
                        res = PQexec(dbconn, "commit transaction");
                        if (PQresultStatus(res) != PGRES_COMMAND_OK)
                        {
@@ -707,16 +708,20 @@ localListenThread_main(/* @unused@ */ void *dummy)
                         * No database events received. Rollback instead.
                         */
 
-                       /* Increase the amount of time to sleep, to a max of sync_interval_timeout */
+                       /*
+                        * Increase the amount of time to sleep, to a max of
+                        * sync_interval_timeout
+                        */
                        poll_sleep += sync_interval;
-                       if (poll_sleep > sync_interval_timeout) {
+                       if (poll_sleep > sync_interval_timeout)
+                       {
                                poll_sleep = sync_interval_timeout;
                        }
                        res = PQexec(dbconn, "rollback transaction;");
                        if (PQresultStatus(res) != PGRES_COMMAND_OK)
                        {
                                slon_log(SLON_FATAL,
-                                                "localListenThread: \"rollback transaction;\" - %s\n",
+                                          "localListenThread: \"rollback transaction;\" - %s\n",
                                                 PQresultErrorMessage(res));
                                PQclear(res);
                                slon_retry();
index 38b1b02b1cffd4a25e290084d316b515b8ef0da5..8a4201bfc6e80358d6254bf48bb8c3d02359e8a5 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -59,8 +59,7 @@ extern char *Syslog_facility; /* openlog() parameters */
 extern char *Syslog_ident;
 
 static void write_syslog(int level, const char *line);
-
-#else    /* HAVE_SYSLOG */
+#else                                                  /* HAVE_SYSLOG */
 #define Use_syslog 0
 #endif   /* HAVE_SYSLOG */
 
@@ -76,76 +75,76 @@ slon_log(Slon_Log_Level level, char *fmt,...)
        static char *outbuf = NULL;
        static int      outsize = -1;
        int                     off;
-       int  len;
+       int                     len;
        char       *level_c = NULL;
 
-       char            time_buf[128];   /* Buffer to hold timestamp */
-       char        ps_buf[20];      /* Buffer to hold PID */
+       char            time_buf[128];  /* Buffer to hold timestamp */
+       char            ps_buf[20];             /* Buffer to hold PID */
        time_t          stamp_time = time(NULL);
-       va_list apcopy;
-       
+       va_list         apcopy;
+
 #ifdef HAVE_SYSLOG
        int                     syslog_level = LOG_ERR;
 #endif
        if (level > slon_log_level)
                return;
-    switch (level)
-    {
-        case SLON_DEBUG4:
-            level_c = "DEBUG4";
+       switch (level)
+       {
+               case SLON_DEBUG4:
+                       level_c = "DEBUG4";
+#ifdef HAVE_SYSLOG
+                       syslog_level = LOG_DEBUG;
+#endif
+                       break;
+               case SLON_DEBUG3:
+                       level_c = "DEBUG3";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_DEBUG;
+                       syslog_level = LOG_DEBUG;
 #endif
-            break;
-        case SLON_DEBUG3:
-            level_c = "DEBUG3";
+                       break;
+               case SLON_DEBUG2:
+                       level_c = "DEBUG2";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_DEBUG;
+                       syslog_level = LOG_DEBUG;
 #endif
-            break;
-        case SLON_DEBUG2:
-            level_c = "DEBUG2";
+                       break;
+               case SLON_DEBUG1:
+                       level_c = "DEBUG1";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_DEBUG;
+                       syslog_level = LOG_DEBUG;
 #endif
-            break;
-        case SLON_DEBUG1:
-            level_c = "DEBUG1";
+                       break;
+               case SLON_INFO:
+                       level_c = "INFO";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_DEBUG;
-#endif                                                                          
-            break;                                                              
-        case SLON_INFO:                                                         
-            level_c = "INFO";                                                   
-#ifdef HAVE_SYSLOG                                                              
-            syslog_level = LOG_INFO;                                            
-#endif                                                                          
-            break;                                                              
-        case SLON_CONFIG:                                                       
-            level_c = "CONFIG";                                                 
+                       syslog_level = LOG_INFO;
+#endif
+                       break;
+               case SLON_CONFIG:
+                       level_c = "CONFIG";
+#ifdef HAVE_SYSLOG
+                       syslog_level = LOG_WARNING;
+#endif
+                       break;
+               case SLON_WARN:
+                       level_c = "WARN";
+#ifdef HAVE_SYSLOG
+                       syslog_level = LOG_WARNING;
+#endif
+                       break;
+               case SLON_ERROR:
+                       level_c = "ERROR";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_WARNING;
+                       syslog_level = LOG_ERR;
 #endif
-            break;                                                              
-        case SLON_WARN:                                                         
-            level_c = "WARN";                                                   
+                       break;
+               case SLON_FATAL:
+                       level_c = "FATAL";
 #ifdef HAVE_SYSLOG
-            syslog_level = LOG_WARNING;
+                       syslog_level = LOG_ERR;
 #endif
-            break;                                                              
-        case SLON_ERROR:                                                        
-            level_c = "ERROR";                                                  
-#ifdef HAVE_SYSLOG                                                              
-            syslog_level = LOG_ERR;                                             
-#endif                                                                          
-            break;                                                              
-        case SLON_FATAL:                                                        
-            level_c = "FATAL";                                                  
-#ifdef HAVE_SYSLOG                                                              
-            syslog_level = LOG_ERR;                                             
-#endif                                                                          
-            break;                                                              
-    }
+                       break;
+       }
 
        va_start(ap, fmt);
 
@@ -170,25 +169,30 @@ slon_log(Slon_Log_Level level, char *fmt,...)
                )
        {
                len = (int) strftime(time_buf, sizeof(time_buf), log_timestamp_format, localtime(&stamp_time));
-               if (len == 0 && time_buf[0] != '\0') {
+               if (len == 0 && time_buf[0] != '\0')
+               {
                        perror("slon_log: problem with strftime()");
                        slon_retry();
                }
-       } else {
+       }
+       else
+       {
                time_buf[0] = (char) 0;
        }
 
        if (logpid == true)
        {
                sprintf(ps_buf, "[%d] ", slon_pid);
-       } else {
+       }
+       else
+       {
                ps_buf[0] = (char) 0;
        }
 
        sprintf(outbuf, "%s%s%-6.6s ", time_buf, ps_buf, level_c);
 
        off = (int) strlen(outbuf);
-       va_copy(apcopy,ap);
+       va_copy(apcopy, ap);
        while (vsnprintf(&outbuf[off], (size_t) (outsize - off), fmt, apcopy) >= outsize - off - 1)
        {
                outsize *= 2;
@@ -215,9 +219,10 @@ slon_log(Slon_Log_Level level, char *fmt,...)
                win32_eventlog(level, outbuf);
 #endif
 #ifdef HAVE_SYSLOG
-       if (Use_syslog != 2) {
-                       (void) fwrite(outbuf, strlen(outbuf), 1, stdout);
-                       (void) fflush(stdout);
+       if (Use_syslog != 2)
+       {
+               (void) fwrite(outbuf, strlen(outbuf), 1, stdout);
+               (void) fflush(stdout);
        }
 #else
        (void) fwrite(outbuf, strlen(outbuf), 1, stdout);
@@ -237,7 +242,7 @@ slon_log(Slon_Log_Level level, char *fmt,...)
  * ----------
  */
 int
-slon_scanint64(char *str, int64 * result)
+slon_scanint64(char *str, int64 *result)
 {
        char       *ptr = str;
        int64           tmp = 0;
@@ -249,7 +254,7 @@ slon_scanint64(char *str, int64 * result)
         */
 
        /* skip leading spaces */
-       while (*ptr && isspace((unsigned char)*ptr))
+       while (*ptr && isspace((unsigned char) *ptr))
                ptr++;
 
        /* handle sign */
@@ -274,11 +279,11 @@ slon_scanint64(char *str, int64 * result)
                ptr++;
 
        /* require at least one digit */
-       if (!isdigit((unsigned char)*ptr))
+       if (!isdigit((unsigned char) *ptr))
                return false;
 
        /* process digits */
-       while (*ptr && isdigit((unsigned char)*ptr))
+       while (*ptr && isdigit((unsigned char) *ptr))
        {
                int64           newtmp = tmp * 10 + (*ptr++ - '0');
 
@@ -373,12 +378,12 @@ write_syslog(int level, const char *line)
                        buf[buflen] = '\0';
 
                        /* already word boundary? */
-                       if (!isspace((unsigned char)line[buflen]) &&
+                       if (!isspace((unsigned char) line[buflen]) &&
                                line[buflen] != '\0')
                        {
                                /* try to divide at word boundary */
                                i = buflen - 1;
-                               while (i > 0 && !isspace((unsigned char)buf[i]))
+                               while (i > 0 && !isspace((unsigned char) buf[i]))
                                        i--;
 
                                if (i > 0)              /* else couldn't divide word boundary */
@@ -403,5 +408,3 @@ write_syslog(int level, const char *line)
 }
 
 #endif   /* HAVE_SYSLOG */
-
-
index 4b5c5f04e40117c21a414323bf28f685cff68f4e..b65b00953ef7d76a7fd23a3517ad37e9f4d5ca91 100644 (file)
@@ -20,7 +20,7 @@ typedef enum
 
 extern void slon_log(Slon_Log_Level level, char *fmt,...);
 
-extern int     slon_scanint64(char *str, int64 * result);
+extern int     slon_scanint64(char *str, int64 *result);
 #endif
 
 #ifdef WIN32
index 1f23f1613bc940f6b3075c759c174a41761c067a..9afb834fc953cdf853f07fb772fdf0fb7a0ef065 100644 (file)
@@ -30,7 +30,7 @@ static void stack_init(void);
 static bool stack_pop(SlonState * current);
 static void stack_dump();
 static void entry_dump(int i, SlonState * tos);
-static int initial_stack_size=6;
+static int     initial_stack_size = 6;
 
 /* ----------
  * Global variables
@@ -53,7 +53,8 @@ void *
 monitorThread_main(void *dummy)
 {
        SlonConn   *conn;
-       SlonDString beginquery, commitquery;
+       SlonDString beginquery,
+                               commitquery;
        SlonDString monquery;
 
        PGconn     *dbconn;
@@ -99,11 +100,13 @@ monitorThread_main(void *dummy)
                        slon_log(SLON_ERROR, "monitorThread: exit monitoring thread\n");
                        pthread_exit(NULL);
                        return (void *) 0;
-               } else {
+               }
+               else
+               {
                        PQclear(res);
                        dstring_free(&monquery);
                }
-               
+
                monitor_state("local_monitor", 0, (pid_t) conn->conn_pid, "thread main loop", 0, "n/a");
 
                /*
@@ -130,7 +133,7 @@ monitorThread_main(void *dummy)
                                {
                                        slon_log(SLON_ERROR,
                                                         "monitorThread: \"%s\" - %s",
-                                                        dstring_data(&beginquery), PQresultErrorMessage(res));
+                                          dstring_data(&beginquery), PQresultErrorMessage(res));
                                        PQclear(res);
                                        break;
                                }
@@ -207,7 +210,9 @@ monitorThread_main(void *dummy)
                                                         PQresultErrorMessage(res));
                                        PQclear(res);
                                        dstring_free(&monquery);
-                               } else {
+                               }
+                               else
+                               {
                                        dstring_free(&monquery);
                                }
 
@@ -257,7 +262,7 @@ monitor_state(const char *actor, int node, pid_t conn_pid, /* @null@ */ const ch
        char       *ns;
        pid_t           mypid;
 
-       if (!monitor_threads)   /* Don't collect if this thread is shut off */
+       if (!monitor_threads)           /* Don't collect if this thread is shut off */
                return;
 
        mypid = getpid();
@@ -269,7 +274,7 @@ monitor_state(const char *actor, int node, pid_t conn_pid, /* @null@ */ const ch
        if (stack_size >= stack_maxlength)
        {
                /* Need to reallocate stack */
-               if (stack_size > 100) 
+               if (stack_size > 100)
                {
                        slon_log(SLON_WARN, "monitorThread: stack reallocation - size %d > warning threshold of 100.  Stack perhaps isn't getting processed properly by monitoring thread\n", stack_size);
                }
@@ -321,13 +326,13 @@ monitor_state(const char *actor, int node, pid_t conn_pid, /* @null@ */ const ch
        tos->event = event;
 
 /* It might seem somewhat desirable for the database to record
- *  DB-centred timestamps, unfortunately that would only be the
- *  correct time if each thread were responsible for stowing its own
- *  activities in sl_components in the database.  This would multiply
- *  database activity, and the implementation instead passes requests
- *  to a single thread that uses a single DB connection to record
- *  things, with the consequence that timestamps must be captured
- *  based on the system clock of the slon process. */
+ *     DB-centred timestamps, unfortunately that would only be the
+ *     correct time if each thread were responsible for stowing its own
+ *     activities in sl_components in the database.  This would multiply
+ *     database activity, and the implementation instead passes requests
+ *     to a single thread that uses a single DB connection to record
+ *     things, with the consequence that timestamps must be captured
+ *     based on the system clock of the slon process. */
 
        tos->start_time = time(NULL);
        if (actor != NULL)
@@ -423,7 +428,7 @@ stack_pop( /* @out@ */ SlonState * qentry)
                /* entry_dump(stack_size, qentry); */
                stack_size--;
                pthread_mutex_unlock(&stack_lock);
-               return  true;
+               return true;
        }
 }
 
index 6ff48d160742b70cfb55913316ad329920b7d1af..3ba6151a53cd5d29dbf6dadaf99321247700c7d1 100644 (file)
@@ -7,7 +7,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
@@ -44,31 +44,31 @@ struct listat
 
 
 /* ----------
- * Local functions 
+ * Local functions
  * ----------
  */
 static void remoteListen_adjust_listat(SlonNode * node,
-                                       struct listat ** listat_head,
-                                       struct listat ** listat_tail);
+                                                  struct listat ** listat_head,
+                                                  struct listat ** listat_tail);
 static void remoteListen_cleanup(struct listat ** listat_head,
-                                       struct listat ** listat_tail);
+                                        struct listat ** listat_tail);
 static int remoteListen_forward_confirm(SlonNode * node,
-                                       SlonConn * conn);
+                                                        SlonConn * conn);
 static int remoteListen_receive_events(SlonNode * node,
-                                       SlonConn * conn, struct listat * listat);
+                                                       SlonConn * conn, struct listat * listat);
 
-static int                     poll_sleep;
+static int     poll_sleep;
 
 extern char *lag_interval;
-int remote_listen_timeout;
+int                    remote_listen_timeout;
 
-static int sel_max_events = 0;
+static int     sel_max_events = 0;
 
 /* ----------
  * slon_remoteListenThread
  *
  * Listen for events on a remote database connection. This means, events
- * generated by every other node we listen for on this one. 
+ * generated by every other node we listen for on this one.
  * ----------
  */
 void *
@@ -78,12 +78,12 @@ remoteListenThread_main(void *cdata)
        SlonConn   *conn = NULL;
        char       *conn_conninfo = NULL;
        char            conn_symname[64];
-       ScheduleStatus                  rc;
-       int         retVal;
+       ScheduleStatus rc;
+       int                     retVal;
        SlonDString query1;
        PGconn     *dbconn = NULL;
        PGresult   *res;
-       
+
        struct listat *listat_head;
        struct listat *listat_tail;
        int64           last_config_seq = 0;
@@ -143,7 +143,7 @@ remoteListenThread_main(void *cdata)
                         */
                        if (node->listen_status == SLON_TSTAT_NONE ||
                                node->listen_status == SLON_TSTAT_SHUTDOWN ||
-                           !((bool) node->no_active))
+                               !((bool) node->no_active))
                        {
                                rtcfg_unlock();
                                break;
@@ -215,9 +215,9 @@ remoteListenThread_main(void *cdata)
                                conn_conninfo = NULL;
 
                                slon_log(SLON_WARN,
-                                        "remoteListenThread_%d: DB connection failed - "
-                                        "sleep %d seconds\n",
-                                        node->no_id, pa_connretry);
+                                                "remoteListenThread_%d: DB connection failed - "
+                                                "sleep %d seconds\n",
+                                                node->no_id, pa_connretry);
 
                                rc = sched_msleep(node, pa_connretry * 1000);
                                if (rc != SCHED_STATUS_OK && rc != SCHED_STATUS_CANCEL)
@@ -233,22 +233,22 @@ remoteListenThread_main(void *cdata)
                         * register the node connection.
                         */
                        (void) slon_mkquery(&query1,
-                                    "select %s.registerNodeConnection(%d); ",
-                                    rtcfg_namespace, rtcfg_nodeid);
+                                                               "select %s.registerNodeConnection(%d); ",
+                                                               rtcfg_namespace, rtcfg_nodeid);
 
                        res = PQexec(dbconn, dstring_data(&query1));
                        if (PQresultStatus(res) != PGRES_TUPLES_OK)
                        {
                                slon_log(SLON_ERROR,
-                                        "remoteListenThread_%d: \"%s\" - %s",
-                                        node->no_id,
+                                                "remoteListenThread_%d: \"%s\" - %s",
+                                                node->no_id,
                                                 dstring_data(&query1), PQresultErrorMessage(res));
                                PQclear(res);
                                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;
@@ -293,16 +293,16 @@ remoteListenThread_main(void *cdata)
 
                                continue;
                        }
-                       if(PQserverVersion(dbconn) >= 90100) 
+                       if (PQserverVersion(dbconn) >= 90100)
                        {
-                               slon_mkquery(&query1,"SET SESSION CHARACTERISTICS AS TRANSACTION read only deferrable");
+                               slon_mkquery(&query1, "SET SESSION CHARACTERISTICS AS TRANSACTION read only deferrable");
                                res = PQexec(dbconn, dstring_data(&query1));
                                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                                {
                                        slon_log(SLON_ERROR,
                                                         "remoteListenThread_%d: \"%s\" - %s",
                                                         node->no_id,
-                                                        dstring_data(&query1), PQresultErrorMessage(res));
+                                                  dstring_data(&query1), PQresultErrorMessage(res));
                                        PQclear(res);
                                        slon_disconnectdb(conn);
                                        free(conn_conninfo);
@@ -311,21 +311,21 @@ remoteListenThread_main(void *cdata)
                                        rc = sched_msleep(node, pa_connretry * 1000);
                                        if (rc != SCHED_STATUS_OK && rc != SCHED_STATUS_CANCEL)
                                                break;
-                                       
+
                                        continue;
-                               }                                               
-                       
+                               }
+
                        }
-                       if(PQserverVersion(dbconn) >= 90100)
+                       if (PQserverVersion(dbconn) >= 90100)
                        {
-                               slon_mkquery(&query1,"SET SESSION CHARACTERISTICS AS TRANSACTION read only isolation level serializable deferrable");
+                               slon_mkquery(&query1, "SET SESSION CHARACTERISTICS AS TRANSACTION read only isolation level serializable deferrable");
                                res = PQexec(dbconn, dstring_data(&query1));
                                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                                {
                                        slon_log(SLON_ERROR,
                                                         "remoteListenThread_%d: \"%s\" - %s",
                                                         node->no_id,
-                                                        dstring_data(&query1), PQresultErrorMessage(res));
+                                                  dstring_data(&query1), PQresultErrorMessage(res));
                                        PQclear(res);
                                        slon_disconnectdb(conn);
                                        free(conn_conninfo);
@@ -368,7 +368,7 @@ remoteListenThread_main(void *cdata)
                 * queue them into the remote worker for storage in our local
                 * database.
                 */
-               
+
                retVal = remoteListen_forward_confirm(node, conn);
                if (retVal < 0)
                {
@@ -376,13 +376,14 @@ remoteListenThread_main(void *cdata)
                        free(conn_conninfo);
                        conn = NULL;
                        conn_conninfo = NULL;
-                       
+
                        rc = sched_msleep(node, 10000);
                        if (rc != SCHED_STATUS_OK && rc != SCHED_STATUS_CANCEL)
                                break;
-                       
-                               continue;
+
+                       continue;
                }
+
                /*
                 * Wait for notification.
                 */
@@ -530,7 +531,7 @@ remoteListen_adjust_listat(SlonNode * node, struct listat ** listat_head,
 /* ----------
  * remoteListen_cleanup
  *
- * Free resources used by the remoteListen thread 
+ * Free resources used by the remoteListen thread
  * ----------
  */
 static void
@@ -552,9 +553,9 @@ remoteListen_cleanup(struct listat ** listat_head, struct listat ** listat_tail)
 /* ----------
  * remoteListen_forward_confirm
  *
- * Read the last confirmed event sequence for all nodes from the remote 
- * database and forward it to the local database so that the cleanup 
- * process can know when all nodes have confirmed an event so it may 
+ * Read the last confirmed event sequence for all nodes from the remote
+ * database and forward it to the local database so that the cleanup
+ * process can know when all nodes have confirmed an event so it may
  * be safely thrown away (together with its log data).
  * ----------
  */
@@ -574,13 +575,13 @@ remoteListen_forward_confirm(SlonNode * node, SlonConn * conn)
         * the sl_confirm table.
         */
        (void) slon_mkquery(&query,
-                                "select con_origin, con_received, "
-                                "    max(con_seqno) as con_seqno, "
-                                "    max(con_timestamp) as con_timestamp "
-                                "from %s.sl_confirm "
-                                "where con_received <> %d "
-                                "group by con_origin, con_received",
-                                rtcfg_namespace, rtcfg_nodeid);
+                                               "select con_origin, con_received, "
+                                               "    max(con_seqno) as con_seqno, "
+                                               "    max(con_timestamp) as con_timestamp "
+                                               "from %s.sl_confirm "
+                                               "where con_received <> %d "
+                                               "group by con_origin, con_received",
+                                               rtcfg_namespace, rtcfg_nodeid);
        res = PQexec(conn->dbconn, dstring_data(&query));
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
@@ -652,17 +653,17 @@ remoteListen_receive_events(SlonNode * node, SlonConn * conn,
         */
        monitor_state("remote listener", node->no_id, conn->conn_pid, "receiving events", 0, "n/a");
        (void) slon_mkquery(&query,
-                                "select ev_origin, ev_seqno, ev_timestamp, "
-                                "       ev_snapshot, "
-                                "       \"pg_catalog\".txid_snapshot_xmin(ev_snapshot), "
-                                "       \"pg_catalog\".txid_snapshot_xmax(ev_snapshot), "
-                                "       ev_type, "
-                                "       ev_data1, ev_data2, "
-                                "       ev_data3, ev_data4, "
-                                "       ev_data5, ev_data6, "
-                                "       ev_data7, ev_data8 "
-                                "from %s.sl_event e",
-                                rtcfg_namespace);
+                                               "select ev_origin, ev_seqno, ev_timestamp, "
+                                               "       ev_snapshot, "
+                                       "       \"pg_catalog\".txid_snapshot_xmin(ev_snapshot), "
+                                       "       \"pg_catalog\".txid_snapshot_xmax(ev_snapshot), "
+                                               "       ev_type, "
+                                               "       ev_data1, ev_data2, "
+                                               "       ev_data3, ev_data4, "
+                                               "       ev_data5, ev_data6, "
+                                               "       ev_data7, ev_data8 "
+                                               "from %s.sl_event e",
+                                               rtcfg_namespace);
 
        rtcfg_lock();
 
@@ -696,11 +697,13 @@ remoteListen_receive_events(SlonNode * node, SlonConn * conn,
        {
                slon_appendquery(&query, ")");
        }
-       /* Limit the result set size to:
-            sync_group_maxsize * 2, if it's set
-                       100, if sync_group_maxsize isn't set */
+
+       /*
+        * Limit the result set size to: sync_group_maxsize * 2, if it's set 100,
+        * if sync_group_maxsize isn't set
+        */
        slon_appendquery(&query, " order by e.ev_origin, e.ev_seqno limit %d",
-                                        (sync_group_maxsize>0)? sync_group_maxsize * 2 : 100);
+                                        (sync_group_maxsize > 0) ? sync_group_maxsize * 2 : 100);
 
        rtcfg_unlock();
 
@@ -721,8 +724,8 @@ remoteListen_receive_events(SlonNode * node, SlonConn * conn,
                if (now >= timeout)
                {
                        slon_log(SLON_ERROR,
-                                "remoteListenThread_%d: timeout (%d s) for event selection\n",
-                                node->no_id, remote_listen_timeout);
+                          "remoteListenThread_%d: timeout (%d s) for event selection\n",
+                                        node->no_id, remote_listen_timeout);
                        dstring_free(&query);
                        return -1;
                }
@@ -759,10 +762,10 @@ remoteListen_receive_events(SlonNode * node, SlonConn * conn,
        ntuples = PQntuples(res);
 
        /* If we drew in the maximum number of events */
-       if (ntuples == ((sync_group_maxsize>0)? sync_group_maxsize * 2 : 100))
-                       sel_max_events++;   /* Add to the count... */
+       if (ntuples == ((sync_group_maxsize > 0) ? sync_group_maxsize * 2 : 100))
+               sel_max_events++;               /* Add to the count... */
        else
-                       sel_max_events=0;   /* reset the count */
+               sel_max_events = 0;             /* reset the count */
 
        for (tupno = 0; tupno < ntuples; tupno++)
        {
@@ -794,19 +797,26 @@ remoteListen_receive_events(SlonNode * node, SlonConn * conn,
                  (PQgetisnull(res, tupno, 14)) ? NULL : PQgetvalue(res, tupno, 14));
        }
 
-       if (ntuples > 0) {
-                       if ((sel_max_events > 2) && (sync_group_maxsize > 100)) {
-                                       slon_log(SLON_INFO, "remoteListenThread_%d: drew maximum # of events for %d iterations\n",
-                                                        node->no_id, sel_max_events);
-                                       sched_msleep(node, 10000 + (1000 * sel_max_events));
-                       } else {
-                                       poll_sleep = 0;
-                       }
-       } else {
-                       poll_sleep = poll_sleep * 2 + sync_interval;
-                       if (poll_sleep > sync_interval_timeout) {
-                                       poll_sleep = sync_interval_timeout;
-                       }
+       if (ntuples > 0)
+       {
+               if ((sel_max_events > 2) && (sync_group_maxsize > 100))
+               {
+                       slon_log(SLON_INFO, "remoteListenThread_%d: drew maximum # of events for %d iterations\n",
+                                        node->no_id, sel_max_events);
+                       sched_msleep(node, 10000 + (1000 * sel_max_events));
+               }
+               else
+               {
+                       poll_sleep = 0;
+               }
+       }
+       else
+       {
+               poll_sleep = poll_sleep * 2 + sync_interval;
+               if (poll_sleep > sync_interval_timeout)
+               {
+                       poll_sleep = sync_interval_timeout;
+               }
        }
        PQclear(res);
        monitor_state("remote listener", node->no_id, conn->conn_pid, "thread main loop", 0, "n/a");
index e61c779151895ae7ba898df340afcbec94bcc24b..87a6c09330d6d677accf0569dfa53cb48c9cdabe 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -30,7 +30,7 @@
 extern int     STMTS[MAXSTATEMENTS];
 
 #define MAXGROUPSIZE 10000             /* What is the largest number of SYNCs we'd
-                                        * want to group together??? */
+                                                                * want to group together??? */
 
 
 /* ----------
@@ -43,10 +43,10 @@ extern int  STMTS[MAXSTATEMENTS];
  */
 typedef enum
 {
-               WMSG_EVENT,
-               WMSG_WAKEUP,
-               WMSG_CONFIRM
-} MessageType;
+       WMSG_EVENT,
+       WMSG_WAKEUP,
+       WMSG_CONFIRM
+}      MessageType;
 
 
 /*
@@ -55,7 +55,7 @@ typedef enum
 typedef struct SlonWorkMsg_event_s SlonWorkMsg_event;
 struct SlonWorkMsg_event_s
 {
-       MessageType                     msg_type;
+       MessageType msg_type;
        SlonWorkMsg_event *prev;
        SlonWorkMsg_event *next;
 
@@ -86,7 +86,7 @@ struct SlonWorkMsg_event_s
 typedef struct SlonWorkMsg_confirm_s SlonWorkMsg_confirm;
 struct SlonWorkMsg_confirm_s
 {
-       MessageType                     msg_type;
+       MessageType msg_type;
        SlonWorkMsg_confirm *prev;
        SlonWorkMsg_confirm *next;
 
@@ -102,7 +102,7 @@ struct SlonWorkMsg_confirm_s
  */
 struct SlonWorkMsg_s
 {
-       MessageType                     msg_type;
+       MessageType msg_type;
        SlonWorkMsg *prev;
        SlonWorkMsg *next;
 };
@@ -131,7 +131,7 @@ typedef enum
        SLON_WG_DONE,
        SLON_WG_EXIT,
        SLON_WG_ABORT
-} WorkGroupStatus;
+}      WorkGroupStatus;
 
 
 typedef enum
@@ -139,25 +139,30 @@ typedef enum
        SLON_WGLC_ACTION,
        SLON_WGLC_DONE,
        SLON_WGLC_ERROR
-} WorkGroupLineCode;
+}      WorkGroupLineCode;
 
-typedef struct PerfMon_s PerfMon;   /* Structure for doing performance monitoring */
-struct PerfMon_s 
+typedef struct PerfMon_s PerfMon;              /* Structure for doing performance
+                                                                                * monitoring */
+struct PerfMon_s
 {
        struct timeval prev_t;
        struct timeval now_t;
-       double prov_query_t;      /* Time spent running queries against the provider */
-       int prov_query_c;         /* Number of queries run against the provider */
-       double subscr_query_t;      /* Time spent running prep queries against the subscriber */
-       int subscr_query_c;         /* Number of prep queries run against the subscriber */
-       double subscr_iud__t;    /* Time spent running IUD against subscriber */
-       int subscr_iud__c;       /* Number of IUD requests run against subscriber */
-       double large_tuples_t;          /* Number of large tuples processed */
-       int large_tuples_c;          /* Number of large tuples processed */
-       int num_inserts;
-       int num_updates;
-       int num_deletes;
-       int num_truncates;
+       double          prov_query_t;   /* Time spent running queries against the
+                                                                * provider */
+       int                     prov_query_c;   /* Number of queries run against the provider */
+       double          subscr_query_t; /* Time spent running prep queries against the
+                                                                * subscriber */
+       int                     subscr_query_c; /* Number of prep queries run against the
+                                                                * subscriber */
+       double          subscr_iud__t;  /* Time spent running IUD against subscriber */
+       int                     subscr_iud__c;  /* Number of IUD requests run against
+                                                                * subscriber */
+       double          large_tuples_t; /* Number of large tuples processed */
+       int                     large_tuples_c; /* Number of large tuples processed */
+       int                     num_inserts;
+       int                     num_updates;
+       int                     num_deletes;
+       int                     num_truncates;
 };
 
 struct ProviderInfo_s
@@ -170,7 +175,7 @@ struct ProviderInfo_s
        WorkerGroupData *wd;
 
        SlonDString helper_query;
-       int log_status;
+       int                     log_status;
 
        ProviderSet *set_head;
        ProviderSet *set_tail;
@@ -221,7 +226,7 @@ typedef enum
        SYNC_INITIAL = 1,
        SYNC_PENDING,
        SYNC_SUCCESS
-} SlonSyncStatus;
+}      SlonSyncStatus;
 
 int                    quit_sync_provider;
 int                    quit_sync_finalsync;
@@ -234,39 +239,39 @@ int                       quit_sync_finalsync;
  * Monitoring data structure
  */
 
-static void init_perfmon(PerfMon *pm);
-static void start_monitored_event(PerfMon *pm);
-static void monitor_provider_query(PerfMon *pm);
-static void monitor_subscriber_query(PerfMon *pm);
-static void monitor_subscriber_iud(PerfMon *pm);
-
-static void adjust_provider_info(SlonNode *node,
-                                        WorkerGroupData *wd, int cleanup, int event_provider);
-static int query_execute(SlonNode *node, PGconn *dbconn,
-                         SlonDString *dsp);
-static void query_append_event(SlonDString *dsp,
-                                                          SlonWorkMsg_event *event);
-static void store_confirm_forward(SlonNode *node, SlonConn *conn,
-                                         SlonWorkMsg_confirm *confirm);
+static void init_perfmon(PerfMon * pm);
+static void start_monitored_event(PerfMon * pm);
+static void monitor_provider_query(PerfMon * pm);
+static void monitor_subscriber_query(PerfMon * pm);
+static void monitor_subscriber_iud(PerfMon * pm);
+
+static void adjust_provider_info(SlonNode * node,
+                                        WorkerGroupData * wd, int cleanup, int event_provider);
+static int query_execute(SlonNode * node, PGconn *dbconn,
+                         SlonDString * dsp);
+static void query_append_event(SlonDString * dsp,
+                                  SlonWorkMsg_event * event);
+static void store_confirm_forward(SlonNode * node, SlonConn * conn,
+                                         SlonWorkMsg_confirm * confirm);
 static int64 get_last_forwarded_confirm(int origin, int receiver);
-static int copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
-                SlonWorkMsg_event *event);
-static int sync_event(SlonNode *node, SlonConn *local_conn,
-                  WorkerGroupData *wd, SlonWorkMsg_event *event);
-static int sync_helper(void *cdata,PGconn * local_dbconn);
+static int copy_set(SlonNode * node, SlonConn * local_conn, int set_id,
+                SlonWorkMsg_event * event);
+static int sync_event(SlonNode * node, SlonConn * local_conn,
+                  WorkerGroupData * wd, SlonWorkMsg_event * event);
+static int     sync_helper(void *cdata, PGconn *local_dbconn);
 
 
-static int archive_open(SlonNode *node, char *seqbuf,
+static int archive_open(SlonNode * node, char *seqbuf,
                         PGconn *dbconn);
-static int     archive_close(SlonNode *node);
-static void archive_terminate(SlonNode *node);
+static int     archive_close(SlonNode * node);
+static void archive_terminate(SlonNode * node);
 
-static int     archive_append_ds(SlonNode *node, SlonDString *ds);
-static int     archive_append_str(SlonNode *node, const char *s);
-static int     archive_append_data(SlonNode *node, const char *s, int len);
+static int     archive_append_ds(SlonNode * node, SlonDString * ds);
+static int     archive_append_str(SlonNode * node, const char *s);
+static int     archive_append_data(SlonNode * node, const char *s, int len);
 
 
-static void compress_actionseq(const char *ssy_actionseq, SlonDString *action_subquery);
+static void compress_actionseq(const char *ssy_actionseq, SlonDString * action_subquery);
 
 static int     check_set_subscriber(int set_id, int node_id, PGconn *local_dbconn);
 
@@ -297,9 +302,9 @@ remoteWorkerThread_main(void *cdata)
        char            conn_symname[32];
 
        SlonSyncStatus sync_status = SYNC_INITIAL;
-       int sg_proposed = 1;
-       int sg_last_grouping = 0;
-       int sync_group_size = 0;
+       int                     sg_proposed = 1;
+       int                     sg_last_grouping = 0;
+       int                     sync_group_size = 0;
 
        slon_log(SLON_INFO,
                         "remoteWorkerThread_%d: thread starts\n",
@@ -312,7 +317,7 @@ remoteWorkerThread_main(void *cdata)
        if (wd == 0)
        {
                slon_log(SLON_ERROR, "remoteWorkerThread_%d: could not malloc() space for WorkerGroupData\n",
-                               node->no_id);
+                                node->no_id);
                slon_retry();
        }
        else
@@ -360,7 +365,7 @@ remoteWorkerThread_main(void *cdata)
         * Work until shutdown or node destruction
         */
        while (true)
-         {
+       {
                /*
                 * If we got the special WMSG_WAKEUP, check the current runmode of the
                 * scheduler and the status of our node.
@@ -514,15 +519,14 @@ remoteWorkerThread_main(void *cdata)
                                 event->ev_type);
 
                /*
-                * Construct the queries to begin a transaction, insert the event 
-                * into our local sl_event
-                * table and confirm it in our local sl_confirm table. When this
-                * transaction commits, every other remote node listening for events
-                * with us as a provider will pick up the news.
+                * Construct the queries to begin a transaction, insert the event into
+                * our local sl_event table and confirm it in our local sl_confirm
+                * table. When this transaction commits, every other remote node
+                * listening for events with us as a provider will pick up the news.
                 */
                (void) slon_mkquery(&query1,
                                                        "begin transaction; "
-                                                       "set transaction isolation level read committed; ");
+                                                "set transaction isolation level read committed; ");
 
                monitor_state(conn_symname, node->no_id, local_conn->conn_pid, event->ev_type, event->ev_seqno, event->ev_type);
 
@@ -533,7 +537,7 @@ remoteWorkerThread_main(void *cdata)
                {
                        SlonWorkMsg_event *sync_group[MAXGROUPSIZE + 1];
                        int                     seconds;
-                       ScheduleStatus                  rc;
+                       ScheduleStatus rc;
                        int                     i;
 
                        /*
@@ -544,23 +548,25 @@ remoteWorkerThread_main(void *cdata)
                        sync_group_size = 1;
                        if (true)
                        {
-                               int initial_proposed = sg_proposed;
-                               if (sync_status == SYNC_SUCCESS) 
+                               int                     initial_proposed = sg_proposed;
+
+                               if (sync_status == SYNC_SUCCESS)
                                        sg_proposed = sg_last_grouping * 2;
-                               else 
-                                       sg_proposed /= 2;   /* This case, at this point, amounts to
-                                                                                * "reset to 1", since when there is a
-                                                                                * failure, the remote worker thread
-                                                                                * restarts, resetting group size to
-                                                                                * 1 */
+                               else
+                                       sg_proposed /= 2;       /* This case, at this point, amounts
+                                                                                * to "reset to 1", since when there
+                                                                                * is a failure, the remote worker
+                                                                                * thread restarts, resetting group
+                                                                                * size to 1 */
                                if (sg_proposed < 1)
                                        sg_proposed = 1;
-                               if (sg_proposed > sync_group_maxsize) 
+                               if (sg_proposed > sync_group_maxsize)
                                        sg_proposed = sync_group_maxsize;
                                slon_log(SLON_DEBUG2, "SYNC Group sizing: prev state: %d initial proposed:%d k:%d maxsize:%d ultimately proposed n:%d\n",
                                                 sync_status,
                                                 initial_proposed, sg_last_grouping, sync_group_maxsize, sg_proposed);
-                               sync_status = SYNC_PENDING;    /* Indicate that we're now working on a group of SYNCs */
+                               sync_status = SYNC_PENDING;             /* Indicate that we're now
+                                                                                                * working on a group of SYNCs */
 
                                /*
                                 * Quit upon receiving event # quit_sync_number from node #
@@ -587,7 +593,7 @@ remoteWorkerThread_main(void *cdata)
                                }
 
                                pthread_mutex_lock(&(node->message_lock));
-                               sg_last_grouping = 1;   /* reset sizes */
+                               sg_last_grouping = 1;   /* reset sizes */
                                sync_group_size = 1;
                                while (sync_group_size < sg_proposed && sync_group_size < MAXGROUPSIZE && node->message_head != NULL)
                                {
@@ -608,8 +614,8 @@ remoteWorkerThread_main(void *cdata)
                        while (true)
                        {
                                /*
-                                * Execute the forwarding stuff, but do not commit
-                                * the transaction yet.
+                                * Execute the forwarding stuff, but do not commit the
+                                * transaction yet.
                                 */
                                if (query_execute(node, local_dbconn, &query1) < 0)
                                        slon_retry();
@@ -621,7 +627,8 @@ remoteWorkerThread_main(void *cdata)
                                seconds = sync_event(node, local_conn, wd, event);
                                if (seconds == 0)
                                {
-                                       sync_status = SYNC_SUCCESS;   /* The group of SYNCs have succeeded!  Hurray! */
+                                       sync_status = SYNC_SUCCESS; /* The group of SYNCs have
+                                                                                                * succeeded!  Hurray! */
                                        rc = SCHED_STATUS_OK;
                                        break;
                                }
@@ -631,8 +638,8 @@ remoteWorkerThread_main(void *cdata)
                                 * specified timeout.
                                 */
                                archive_terminate(node);
-                               slon_log(SLON_DEBUG2,"remoteWorkerThread_%d: rollback SYNC"
-                                        " transaction\n",node->no_id);
+                               slon_log(SLON_DEBUG2, "remoteWorkerThread_%d: rollback SYNC"
+                                                " transaction\n", node->no_id);
                                (void) slon_mkquery(&query2, "rollback transaction");
                                if (query_execute(node, local_dbconn, &query2) < 0)
                                        slon_retry();
@@ -645,31 +652,31 @@ remoteWorkerThread_main(void *cdata)
 
                        /*
                         * replace query1 with the forwarding of all the grouped sync
-                        * events, the call to logApplySaveStats()  and a commit.
+                        * events, the call to logApplySaveStats()      and a commit.
                         */
                        dstring_reset(&query1);
                        sg_last_grouping = 0;
                        for (i = 0; i < sync_group_size; i++)
                        {
-                               slon_log(SLON_DEBUG2,"remoteWorkerThread_%d: before query_append_event"
-                                        " transaction\n",node->no_id);
-                                       query_append_event(&query1, sync_group[i]);
-                                       if (i < (sync_group_size - 1))
-                                                       free(sync_group[i]);
-                                       sg_last_grouping++;
+                               slon_log(SLON_DEBUG2, "remoteWorkerThread_%d: before query_append_event"
+                                                " transaction\n", node->no_id);
+                               query_append_event(&query1, sync_group[i]);
+                               if (i < (sync_group_size - 1))
+                                       free(sync_group[i]);
+                               sg_last_grouping++;
                        }
 
                        if (monitor_threads)
                        {
                                slon_appendquery(&query1, "select %s.logApplySaveStats("
-                                               "'_%s', %d, '%s'::interval); ",
-                                               rtcfg_namespace, rtcfg_cluster_name,
-                                               node->no_id, wd->duration_buf);
+                                                                "'_%s', %d, '%s'::interval); ",
+                                                                rtcfg_namespace, rtcfg_cluster_name,
+                                                                node->no_id, wd->duration_buf);
                        }
                        strcpy(wd->duration_buf, "0 s");
 
-                       slon_log(SLON_DEBUG2,"remoteWorkerThread_%d: committing SYNC"
-                                        " transaction\n",node->no_id);
+                       slon_log(SLON_DEBUG2, "remoteWorkerThread_%d: committing SYNC"
+                                        " transaction\n", node->no_id);
                        slon_appendquery(&query1, "commit transaction;");
 
                        if (query_execute(node, local_dbconn, &query1) < 0)
@@ -682,13 +689,14 @@ remoteWorkerThread_main(void *cdata)
                }
                else    /* not SYNC */
                {
-               
+
                        /**
                         * open the transaction.
                         */
                        if (query_execute(node, local_dbconn, &query1) < 0)
                                slon_retry();
                        dstring_reset(&query1);
+
                        /*
                         * For all non-SYNC events, we write at least a standard event
                         * tracking log file and adjust the ssy_seqno in our internal
@@ -799,32 +807,32 @@ remoteWorkerThread_main(void *cdata)
                                int                     no_id = (int) strtol(event->ev_data1, NULL, 10);
                                int                     no_provider = (int) strtol(event->ev_data2, NULL, 10);
                                char       *no_comment = event->ev_data3;
-                               int64       last_event_id;
+                               int64           last_event_id;
                                PGresult   *res;
 
                                rtcfg_storeNode(no_id, no_comment);
                                slon_appendquery(&query1,
                                                                 "lock table %s.sl_config_lock;"
-                                                                "select %s.cloneNodePrepare_int(%d, %d, '%q'); ",
+                                                       "select %s.cloneNodePrepare_int(%d, %d, '%q'); ",
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
                                                                 no_id, no_provider, no_comment);
-                               slon_appendquery(&query1,"select coalesce(max(con_seqno),0)"
+                               slon_appendquery(&query1, "select coalesce(max(con_seqno),0)"
                                                                 "from %s.sl_confirm "
                                                                 "  where con_origin = %d  and con_received"
                                                                 "= %d", rtcfg_namespace, node->no_id, no_id);
                                res = PQexec(local_dbconn, dstring_data(&query1));
-                               if (PQresultStatus(res) != PGRES_TUPLES_OK )
+                               if (PQresultStatus(res) != PGRES_TUPLES_OK)
                                {
-                                 slon_log(SLON_ERROR,"remoteWorkerThread_%d error querying "
-                                                  "last confirmed id for node %d in CLONE NODE\n",
-                                                  node->no_id, no_id);
-                                 slon_retry();
+                                       slon_log(SLON_ERROR, "remoteWorkerThread_%d error querying "
+                                                        "last confirmed id for node %d in CLONE NODE\n",
+                                                        node->no_id, no_id);
+                                       slon_retry();
                                }
-                               if( PQntuples(res)      != 0)
+                               if (PQntuples(res) != 0)
                                {
-                                 last_event_id = strtoll(PQgetvalue(res, 0, 0),NULL,10);
-                                 rtcfg_setNodeLastEvent(no_id, last_event_id);
+                                       last_event_id = strtoll(PQgetvalue(res, 0, 0), NULL, 10);
+                                       rtcfg_setNodeLastEvent(no_id, last_event_id);
                                }
                                PQclear(res);
                                dstring_reset(&query1);
@@ -843,7 +851,7 @@ remoteWorkerThread_main(void *cdata)
 
                                slon_appendquery(&query1,
                                                                 "lock table %s.sl_config_lock;"
-                                                                "select %s.storePath_int(%d, %d, '%q', %d); ",
+                                                          "select %s.storePath_int(%d, %d, '%q', %d); ",
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
                                                        pa_server, pa_client, pa_conninfo, pa_connretry);
@@ -924,8 +932,8 @@ remoteWorkerThread_main(void *cdata)
                                slon_appendquery(&query1,
                                                                 "lock table %s.sl_config_lock;"
                                                                 "select %s.dropSet_int(%d); ",
-                                                                rtcfg_namespace, 
-                                                                rtcfg_namespace, 
+                                                                rtcfg_namespace,
+                                                                rtcfg_namespace,
                                                                 set_id);
                        }
                        else if (strcmp(event->ev_type, "MERGE_SET") == 0)
@@ -973,7 +981,7 @@ remoteWorkerThread_main(void *cdata)
                        {
                                int                     seq_id = (int) strtol(event->ev_data1, NULL, 10);
 
-                               slon_appendquery(&query1, 
+                               slon_appendquery(&query1,
                                                                 "lock table %s.sl_config_lock;"
                                                                 "select %s.setDropSequence_int(%d);",
                                                                 rtcfg_namespace,
@@ -997,7 +1005,7 @@ remoteWorkerThread_main(void *cdata)
                                int                     seq_id = (int) strtol(event->ev_data1, NULL, 10);
                                int                     new_set_id = (int) strtol(event->ev_data2, NULL, 10);
 
-                               slon_appendquery(&query1, 
+                               slon_appendquery(&query1,
                                                                 "lock table %s.sl_config_lock;"
                                                                 "select %s.setMoveSequence_int(%d, %d);",
                                                                 rtcfg_namespace,
@@ -1026,13 +1034,13 @@ remoteWorkerThread_main(void *cdata)
 
                                /*
                                 * If we're a remote node, and haven't yet received the
-                                * MOVE_SET event from the new origin, then we'll
-                                * need to sleep a bit...  This avoids a race condition where
-                                * new SYNCs take place on the new origin, and are ignored on
-                                * some subscribers (and their children) because the MOVE_SET
+                                * MOVE_SET event from the new origin, then we'll need to
+                                * sleep a bit...  This avoids a race condition where new
+                                * SYNCs take place on the new origin, and are ignored on some
+                                * subscribers (and their children) because the MOVE_SET
                                 * wasn't yet received and processed
                                 */
-                               
+
 
                                if ((rtcfg_nodeid != old_origin) && (rtcfg_nodeid != new_origin))
                                {
@@ -1048,7 +1056,7 @@ remoteWorkerThread_main(void *cdata)
                                                                                "      ev_data3 = '%d') ",
 
                                                                                rtcfg_namespace,
-                                         old_origin, wait_seqno, set_id, old_origin, new_origin);
+                                        old_origin, wait_seqno, set_id, old_origin, new_origin);
 
                                        res = PQexec(local_dbconn, dstring_data(&query2));
                                        while (PQntuples(res) == 0)
@@ -1068,10 +1076,10 @@ remoteWorkerThread_main(void *cdata)
 
                                                /* Start the transaction again */
                                                (void) slon_mkquery(&query3,
-                                                       "begin transaction; "
-                                                       "set transaction isolation level read committed; ");
+                                                                                       "begin transaction; "
+                                                "set transaction isolation level read committed; ");
                                                slon_appendquery(&query1,
-                                                                                "lock table %s.sl_event_lock,%s.sl_config_lock;",
+                                                       "lock table %s.sl_event_lock,%s.sl_config_lock;",
                                                                                 rtcfg_namespace,
                                                                                 rtcfg_namespace);
                                                if (query_execute(node, local_dbconn, &query3) < 0)
@@ -1138,7 +1146,7 @@ remoteWorkerThread_main(void *cdata)
                                 */
 
                                slon_appendquery(&query1,
-                                                                "lock table %s.sl_event_lock,%s.sl_config_lock;"
+                                                        "lock table %s.sl_event_lock,%s.sl_config_lock;"
                                                                 "select %s.moveSet_int(%d, %d, %d, %s); ",
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
@@ -1179,9 +1187,9 @@ remoteWorkerThread_main(void *cdata)
                        else if (strcmp(event->ev_type, "FAILOVER_NODE") == 0)
                        {
                                int                     failed_node = (int) strtol(event->ev_data1, NULL, 10);
-                               char*           seq_no_c = event->ev_data2;
-                               PGresult *res;
-                               
+                               char       *seq_no_c = event->ev_data2;
+                               PGresult   *res;
+
                                /**
                                 * call failNode() to make sure this node listens for
                                 * events from the failed node from all other nodes.
@@ -1191,12 +1199,12 @@ remoteWorkerThread_main(void *cdata)
                                 * The most-ahead failover canidate is the node that
                                 * created the FAILOVER_NODE event (node->id)
                                 */
-                               slon_mkquery(&query2,"select %s.failedNode(%d,%d);"
-                                                        ,rtcfg_namespace,                                                       
+                               slon_mkquery(&query2, "select %s.failedNode(%d,%d);"
+                                                        ,rtcfg_namespace,
                                                         failed_node, node->no_id);
-                               
-                               res=PQexec(local_dbconn,dstring_data(&query2));
-                               if(PQresultStatus(res) != PGRES_TUPLES_OK )
+
+                               res = PQexec(local_dbconn, dstring_data(&query2));
+                               if (PQresultStatus(res) != PGRES_TUPLES_OK)
                                {
                                        slon_log(SLON_FATAL, "remoteWorkerThread_%d: \"%s\" %s",
                                                         node->no_id, dstring_data(&query2),
@@ -1204,9 +1212,9 @@ remoteWorkerThread_main(void *cdata)
                                        PQclear(res);
                                        slon_retry();
                                }
-                               slon_mkquery(&query2,"commit transaction;start transaction");
-                               res=PQexec(local_dbconn,dstring_data(&query2));
-                               if(PQresultStatus(res) != PGRES_COMMAND_OK )
+                               slon_mkquery(&query2, "commit transaction;start transaction");
+                               res = PQexec(local_dbconn, dstring_data(&query2));
+                               if (PQresultStatus(res) != PGRES_COMMAND_OK)
                                {
                                        slon_log(SLON_FATAL, "remoteWorkerThread_%d: \"%s\" %s",
                                                         node->no_id, dstring_data(&query2),
@@ -1215,40 +1223,40 @@ remoteWorkerThread_main(void *cdata)
                                        slon_retry();
                                }
 
-                               slon_mkquery(&query2," select * FROM %s.sl_event "
+                               slon_mkquery(&query2, " select * FROM %s.sl_event "
                                                         " where "
                                                         "       ev_origin=%d and "
                                                         "       ev_seqno>=%s"
-                                                        ,       rtcfg_namespace, failed_node,
+                                                        ,rtcfg_namespace, failed_node,
                                                         seq_no_c);
-                               res=PQexec(local_dbconn,dstring_data(&query2));
+                               res = PQexec(local_dbconn, dstring_data(&query2));
                                while (PQntuples(res) == 0)
                                {
                                        slon_log(SLON_INFO, "remoteWorkerThread_%d FAILOVER_NODE waiting for event %d,%s\n"
                                                         ,node->no_id,
-                                                        failed_node,seq_no_c);
+                                                        failed_node, seq_no_c);
                                        PQclear(res);
-                                               (void) slon_mkquery(&query3, "rollback transaction");
-                                               if (query_execute(node, local_dbconn, &query3) < 0)
-                                                       slon_retry();
+                                       (void) slon_mkquery(&query3, "rollback transaction");
+                                       if (query_execute(node, local_dbconn, &query3) < 0)
+                                               slon_retry();
 
-                                               /* Sleep */
-                                               if (sched_msleep(node, 10000) != SCHED_STATUS_OK)
-                                                       slon_retry();
+                                       /* Sleep */
+                                       if (sched_msleep(node, 10000) != SCHED_STATUS_OK)
+                                               slon_retry();
 
-                                               /* Start the transaction again */
-                                               (void) slon_mkquery(&query3,
-                                                       "begin transaction; "
-                                                       "set transaction isolation level read committed; ");
-                                               slon_appendquery(&query1,
-                                                                                "lock table %s.sl_event_lock,%s.sl_config_lock;",
-                                                                                rtcfg_namespace,
-                                                                                rtcfg_namespace);
-                                               if (query_execute(node, local_dbconn, &query3) < 0)
-                                                       slon_retry();
+                                       /* Start the transaction again */
+                                       (void) slon_mkquery(&query3,
+                                                                               "begin transaction; "
+                                                "set transaction isolation level read committed; ");
+                                       slon_appendquery(&query1,
+                                                       "lock table %s.sl_event_lock,%s.sl_config_lock;",
+                                                                        rtcfg_namespace,
+                                                                        rtcfg_namespace);
+                                       if (query_execute(node, local_dbconn, &query3) < 0)
+                                               slon_retry();
 
-                                               /* See if we have the missing event now */
-                                               res = PQexec(local_dbconn, dstring_data(&query2));
+                                       /* See if we have the missing event now */
+                                       res = PQexec(local_dbconn, dstring_data(&query2));
 
                                }
                                PQclear(res);
@@ -1257,9 +1265,9 @@ remoteWorkerThread_main(void *cdata)
                                                                 "lock %s.sl_config_lock;"
                                                                 "select %s.failoverSet_int(%d, %d,'%s'); ",
                                                                 rtcfg_namespace,
-                                                                rtcfg_namespace, 
-                                                                failed_node, node->no_id,seq_no_c);
-                               
+                                                                rtcfg_namespace,
+                                                                failed_node, node->no_id, seq_no_c);
+
                                need_reloadListen = true;
                        }
                        else if (strcmp(event->ev_type, "SUBSCRIBE_SET") == 0)
@@ -1274,12 +1282,12 @@ remoteWorkerThread_main(void *cdata)
                                        rtcfg_storeSubscribe(sub_set, sub_provider, sub_forward);
 
                                slon_appendquery(&query1,
-                                                                "lock table %s.sl_event_lock,%s.sl_config_lock;"
-                                                                "select %s.subscribeSet_int(%d, %d, %d, '%q', '%q'); ",
+                                                        "lock table %s.sl_event_lock,%s.sl_config_lock;"
+                                         "select %s.subscribeSet_int(%d, %d, %d, '%q', '%q'); ",
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
-                                                                sub_set, sub_provider, sub_receiver, sub_forward, omit_copy);
+                               sub_set, sub_provider, sub_receiver, sub_forward, omit_copy);
                                need_reloadListen = true;
                        }
                        else if (strcmp(event->ev_type, "ENABLE_SUBSCRIPTION") == 0)
@@ -1288,7 +1296,7 @@ remoteWorkerThread_main(void *cdata)
                                int                     sub_provider = (int) strtol(event->ev_data2, NULL, 10);
                                int                     sub_receiver = (int) strtol(event->ev_data3, NULL, 10);
                                char       *sub_forward = event->ev_data4;
-                               int         copy_set_retries = 0;
+                               int                     copy_set_retries = 0;
 
                                /*
                                 * Do the actual enabling of the set only if we are the
@@ -1297,12 +1305,12 @@ remoteWorkerThread_main(void *cdata)
                                if (sub_receiver == rtcfg_nodeid &&
                                        event->ev_origin == node->no_id)
                                {
-                                       ScheduleStatus                  sched_rc;
+                                       ScheduleStatus sched_rc;
                                        int                     sleeptime = 15;
 
                                        (void) slon_mkquery(&query2, "rollback transaction");
                                        check_config = true;
-                                       
+
                                        slon_appendquery(&query1,
                                                                         "lock table %s.sl_config_lock; ",
                                                                         rtcfg_namespace);
@@ -1349,7 +1357,7 @@ remoteWorkerThread_main(void *cdata)
                                                                slon_mkquery(&query1, "start transaction;"
                                                                                         "set transaction isolation level read committed;");
                                                                slon_appendquery(&query1,
-                                                                                                 "lock table %s.sl_config_lock; ",
+                                                                                       "lock table %s.sl_config_lock; ",
                                                                                                 rtcfg_namespace);
 
                                                                if (query_execute(node, local_dbconn, &query1) < 0)
@@ -1358,16 +1366,16 @@ remoteWorkerThread_main(void *cdata)
                                                                continue;
                                                        }
                                                }
-                                       
 
-                                               /* 
+
+                                               /*
                                                 * if we have failed more than once we need to restart
                                                 * our transaction or we can end up with odd results
-                                                * in our subscription tables, and in 8.4+ LOCK
-                                                * TABLE requires you to be in a txn.
+                                                * in our subscription tables, and in 8.4+ LOCK TABLE
+                                                * requires you to be in a txn.
                                                 */
-                                               if(copy_set_retries != 0)
-                                                 {
+                                               if (copy_set_retries != 0)
+                                               {
                                                        slon_mkquery(&query1, "start transaction;"
                                                                                 "set transaction isolation level read committed;");
                                                        slon_appendquery(&query1,
@@ -1375,8 +1383,8 @@ remoteWorkerThread_main(void *cdata)
                                                                                         rtcfg_namespace);
 
                                                        if (query_execute(node, local_dbconn, &query1) < 0)
-                                                         slon_retry();
-                                                 }
+                                                               slon_retry();
+                                               }
 
                                                /*
                                                 * If the copy succeeds, exit the loop and let the
@@ -1426,7 +1434,7 @@ remoteWorkerThread_main(void *cdata)
                                         */
                                        slon_appendquery(&query1,
                                                                         "lock table %s.sl_config_lock;"
-                                                                        "select %s.enableSubscription(%d, %d, %d); ",
+                                                               "select %s.enableSubscription(%d, %d, %d); ",
                                                                         rtcfg_namespace,
                                                                         rtcfg_namespace,
                                                                         sub_set, sub_provider, sub_receiver);
@@ -1466,7 +1474,7 @@ remoteWorkerThread_main(void *cdata)
                                                                 "select %s.updateReloid(%d, '%q', %d); ",
                                                                 rtcfg_namespace,
                                                                 rtcfg_namespace,
-                                                                reset_config_setid, reset_configonly_on_node);
+                                                          reset_config_setid, reset_configonly_on_node);
                        }
                        else
                        {
@@ -1480,10 +1488,10 @@ remoteWorkerThread_main(void *cdata)
                         */
                        if (event_ok)
                        {
-                                       query_append_event(&query1, event);
-                                       slon_appendquery(&query1, "commit transaction;");
-                                       if (archive_close(node) < 0)
-                                                       slon_retry();
+                               query_append_event(&query1, event);
+                               slon_appendquery(&query1, "commit transaction;");
+                               if (archive_close(node) < 0)
+                                       slon_retry();
                        }
                        else
                        {
@@ -1536,8 +1544,8 @@ remoteWorkerThread_main(void *cdata)
  * ----------
  */
 static void
-adjust_provider_info(SlonNode *node, WorkerGroupData *wd, int cleanup,
-               int event_provider)
+adjust_provider_info(SlonNode * node, WorkerGroupData * wd, int cleanup,
+                                        int event_provider)
 {
        ProviderInfo *provider;
        ProviderInfo *provnext;
@@ -1564,7 +1572,7 @@ adjust_provider_info(SlonNode *node, WorkerGroupData *wd, int cleanup,
                 * We create a lock here and keep it until we made our final decision
                 * about what to do with the helper thread.
                 */
-               
+
                while ((pset = provider->set_head) != NULL)
                {
                        DLLIST_REMOVE(provider->set_head, provider->set_tail,
@@ -1627,6 +1635,7 @@ adjust_provider_info(SlonNode *node, WorkerGroupData *wd, int cleanup,
                                         */
                                        DLLIST_ADD_TAIL(wd->provider_head, wd->provider_tail,
                                                                        provider);
+
                                        /*
                                         * Copy the runtime configurations conninfo into the
                                         * provider info.
@@ -1683,7 +1692,7 @@ adjust_provider_info(SlonNode *node, WorkerGroupData *wd, int cleanup,
                         */
                        slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
                                         "helper thread for provider %d terminated\n",
-                                        node->no_id, provider->no_id);         
+                                        node->no_id, provider->no_id);
 
                        /*
                         * Disconnect from the database.
@@ -1769,9 +1778,10 @@ adjust_provider_info(SlonNode *node, WorkerGroupData *wd, int cleanup,
                         */
                        DLLIST_ADD_TAIL(wd->provider_head, wd->provider_tail,
                                                        provider);
+
                        /*
-                        * Copy the runtime configurations conninfo into the
-                        * provider info.
+                        * Copy the runtime configurations conninfo into the provider
+                        * info.
                         */
                        rtcfg_node = rtcfg_findNode(provider->no_id);
                        if (rtcfg_node != NULL)
@@ -1882,7 +1892,7 @@ remoteWorker_event(int event_provider,
         * anyway.
         */
        len = offsetof(SlonWorkMsg_event, raw_data)
-               +(len_timestamp = strlen(ev_timestamp) + 1)
+               + (len_timestamp = strlen(ev_timestamp) + 1)
                + (len_snapshot = strlen(ev_snapshot) + 1)
                + (len_mintxid = strlen(ev_mintxid) + 1)
                + (len_maxtxid = strlen(ev_maxtxid) + 1)
@@ -2115,9 +2125,9 @@ remoteWorker_confirm(int no_id,
                                        if ((SlonWorkMsg *) oldmsg != node->message_head)
                                        {
                                                DLLIST_REMOVE(node->message_head,
-                                                                         node->message_tail, (SlonWorkMsg *) oldmsg);
+                                                                node->message_tail, (SlonWorkMsg *) oldmsg);
                                                DLLIST_ADD_HEAD(node->message_head,
-                                                               node->message_tail, (SlonWorkMsg *) oldmsg);
+                                                                node->message_tail, (SlonWorkMsg *) oldmsg);
                                        }
                                }
                                pthread_mutex_unlock(&(node->message_lock));
@@ -2157,7 +2167,7 @@ remoteWorker_confirm(int no_id,
  * ----------
  */
 static int
-query_execute(SlonNode *node, PGconn *dbconn, SlonDString *dsp)
+query_execute(SlonNode * node, PGconn *dbconn, SlonDString * dsp)
 
 {
        PGresult   *res;
@@ -2185,11 +2195,11 @@ query_execute(SlonNode *node, PGconn *dbconn, SlonDString *dsp)
  * query_append_event
  *
  * Add queries to a dstring that insert a duplicate of an event record
- * as well as the confirmation for it.  
+ * as well as the confirmation for it.
  * ----------
  */
 static void
-query_append_event(SlonDString *dsp, SlonWorkMsg_event *event)
+query_append_event(SlonDString * dsp, SlonWorkMsg_event * event)
 {
        char            seqbuf[64];
 
@@ -2253,8 +2263,8 @@ query_append_event(SlonDString *dsp, SlonWorkMsg_event *event)
  * ----------
  */
 static void
-store_confirm_forward(SlonNode *node, SlonConn *conn,
-                                         SlonWorkMsg_confirm *confirm)
+store_confirm_forward(SlonNode * node, SlonConn * conn,
+                                         SlonWorkMsg_confirm * confirm)
 {
        SlonDString query;
        PGresult   *res;
@@ -2381,8 +2391,8 @@ get_last_forwarded_confirm(int origin, int receiver)
  * ----------
  */
 static int
-copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
-                SlonWorkMsg_event *event)
+copy_set(SlonNode * node, SlonConn * local_conn, int set_id,
+                SlonWorkMsg_event * event)
 {
        SlonSet    *set;
        SlonConn   *pro_conn;
@@ -2409,28 +2419,37 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
        SlonDString ssy_action_list;
        char            seqbuf[64];
        char       *copydata = NULL;
-       bool omit_copy = false;
-       char *v_omit_copy = event->ev_data5;
+       bool            omit_copy = false;
+       char       *v_omit_copy = event->ev_data5;
        struct timeval tv_start;
        struct timeval tv_start2;
        struct timeval tv_now;
 
        gettimeofday(&tv_start, NULL);
 
-       if (strcmp(v_omit_copy, "f") == 0) {
+       if (strcmp(v_omit_copy, "f") == 0)
+       {
                omit_copy = false;
-       } else {
-               if (strcmp(v_omit_copy, "t") == 0) {
+       }
+       else
+       {
+               if (strcmp(v_omit_copy, "t") == 0)
+               {
                        omit_copy = true;
-               } else {
+               }
+               else
+               {
                        slon_log(SLON_ERROR, "copy_set %d - omit_copy not in (t,f)- [%s]\n", set_id, v_omit_copy);
                }
        }
        slon_log(SLON_INFO, "copy_set %d - omit=%s - bool=%d\n", set_id, v_omit_copy, omit_copy);
 
-       if (omit_copy) {
+       if (omit_copy)
+       {
                slon_log(SLON_INFO, "omit is TRUE\n");
-       } else {
+       }
+       else
+       {
                slon_log(SLON_INFO, "omit is FALSE\n");
        }
 
@@ -2447,24 +2466,26 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                        break;
                }
        }
-       if (sub_provider < 0) {
+       if (sub_provider < 0)
+       {
                rtcfg_unlock();
                slon_log(SLON_ERROR, "remoteWorkerThread_%d: provider node %d for set %d"
-                        "not found in runtime configuration\n",
-                        node->no_id,
-                        sub_provider,
-                        set_id);
+                                "not found in runtime configuration\n",
+                                node->no_id,
+                                sub_provider,
+                                set_id);
                slon_retry();
                return -1;
-               
+
        }
-       if (set_origin < 0) {
+       if (set_origin < 0)
+       {
                rtcfg_unlock();
                slon_log(SLON_ERROR, "remoteWorkerThread_%d: origin node %d for set %d "
-                        "not found in runtime configuration\n",
-                        node->no_id, 
-                        set_origin,
-                        set_id);
+                                "not found in runtime configuration\n",
+                                node->no_id,
+                                set_origin,
+                                set_id);
                slon_retry();
                return -1;
        }
@@ -2552,12 +2573,13 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
         */
        if (sub_provider == set_origin)
        {
-               int provider_version=PQserverVersion(pro_dbconn);
+               int                     provider_version = PQserverVersion(pro_dbconn);
+
                (void) slon_mkquery(&query1,
                                                        "start transaction; "
-                                                       "set transaction isolation level serializable read only %s; "
+                               "set transaction isolation level serializable read only %s; "
                                                        "select \"pg_catalog\".txid_snapshot_xmin(\"pg_catalog\".txid_current_snapshot()) <= '%s'; ",
-                                                       provider_version>=90100 ? "deferrable" : ""
+                                                       provider_version >= 90100 ? "deferrable" : ""
                                                        ,event->ev_maxtxid_c);
                res1 = PQexec(pro_dbconn, dstring_data(&query1));
                if (PQresultStatus(res1) != PGRES_TUPLES_OK)
@@ -2594,11 +2616,12 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
        }
        else
        {
-               int provider_version=PQserverVersion(pro_dbconn);
+               int                     provider_version = PQserverVersion(pro_dbconn);
+
                (void) slon_mkquery(&query1,
                                                        "start transaction; "
-                                                       "set transaction isolation level serializable read only %s; ",
-                                                       provider_version >= 90100 ? "deferrable" : "" );
+                          "set transaction isolation level serializable read only %s; ",
+                                                       provider_version >= 90100 ? "deferrable" : "");
                if (query_execute(node, pro_dbconn, &query1) < 0)
                {
                        slon_disconnectdb(pro_conn);
@@ -2765,9 +2788,9 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
 
                (void) slon_mkquery(&query1,
                                                        "lock table %s.sl_config_lock;"
-                                                       "select %s.setAddSequence_int(%d, %s, '%q', '%q')",
-                                                       rtcfg_namespace, 
-                                                       rtcfg_namespace, 
+                                                 "select %s.setAddSequence_int(%d, %s, '%q', '%q')",
+                                                       rtcfg_namespace,
+                                                       rtcfg_namespace,
                                                        set_id, seq_id,
                                                        seq_fqname, seq_comment);
                if (query_execute(node, loc_dbconn, &query1) < 0)
@@ -2846,10 +2869,10 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                 */
                (void) slon_mkquery(&query1,
                                                        "lock table %s.sl_config_lock;"
-                                                       "select %s.setAddTable_int(%d, %d, '%q', '%q', '%q'); ",
+                                        "select %s.setAddTable_int(%d, %d, '%q', '%q', '%q'); ",
                                                        rtcfg_namespace,
                                                        rtcfg_namespace,
-                                                       set_id, tab_id, tab_fqname, tab_idxname, tab_comment);
+                                          set_id, tab_id, tab_fqname, tab_idxname, tab_comment);
                if (query_execute(node, loc_dbconn, &query1) < 0)
                {
                        PQclear(res1);
@@ -2866,71 +2889,54 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                /*
                 * Begin a COPY from stdin for the table on the local DB
                 */
-               if (omit_copy) {
+               if (omit_copy)
+               {
                        slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
                                         "COPY of table %s suppressed due to OMIT COPY option\n",
                                         node->no_id, tab_fqname);
-               } else {
-               slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
-                                "Begin COPY of table %s\n",
-                                node->no_id, tab_fqname);
+               }
+               else
+               {
+                       slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
+                                        "Begin COPY of table %s\n",
+                                        node->no_id, tab_fqname);
 
-               (void) slon_mkquery(&query2, "select %s.copyFields(%d);",
-                                                       rtcfg_namespace, tab_id);
+                       (void) slon_mkquery(&query2, "select %s.copyFields(%d);",
+                                                               rtcfg_namespace, tab_id);
 
-               res3 = PQexec(pro_dbconn, dstring_data(&query2));
+                       res3 = PQexec(pro_dbconn, dstring_data(&query2));
 
-               if (PQresultStatus(res3) != PGRES_TUPLES_OK)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s\n",
-                                        node->no_id, dstring_data(&query2),
-                                        PQresultErrorMessage(res3));
-                       PQclear(res3);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
+                       if (PQresultStatus(res3) != PGRES_TUPLES_OK)
+                       {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s\n",
+                                                node->no_id, dstring_data(&query2),
+                                                PQresultErrorMessage(res3));
+                               PQclear(res3);
+                               PQclear(res1);
+                               slon_disconnectdb(pro_conn);
+                               dstring_free(&query1);
+                               dstring_free(&query2);
+                               dstring_free(&query3);
+                               dstring_free(&lsquery);
+                               dstring_free(&indexregenquery);
+                               archive_terminate(node);
+                               return -1;
+                       }
 
-               (void) slon_mkquery(&query1,
-                                                       "select %s.prepareTableForCopy(%d); "
-                                                       "copy %s %s from stdin; ",
-                                                       rtcfg_namespace,
-                                                       tab_id, tab_fqname,
-                                                       PQgetvalue(res3, 0, 0)
-                       );
-               res2 = PQexec(loc_dbconn, dstring_data(&query1));
-               if (PQresultStatus(res2) != PGRES_COPY_IN)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s %s\n",
-                                        node->no_id, dstring_data(&query1),
-                                        PQresultErrorMessage(res2),
-                                        PQerrorMessage(loc_dbconn));
-                       PQclear(res3);
-                       PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-               if (archive_dir)
-               {
                        (void) slon_mkquery(&query1,
-                       "delete from %s;\ncopy %s %s from stdin;", tab_fqname, tab_fqname,
-                                                               PQgetvalue(res3, 0, 0));
-                       rc = archive_append_ds(node, &query1);
-                       if (rc < 0)
+                                                               "select %s.prepareTableForCopy(%d); "
+                                                               "copy %s %s from stdin; ",
+                                                               rtcfg_namespace,
+                                                               tab_id, tab_fqname,
+                                                               PQgetvalue(res3, 0, 0)
+                               );
+                       res2 = PQexec(loc_dbconn, dstring_data(&query1));
+                       if (PQresultStatus(res2) != PGRES_COPY_IN)
                        {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s %s\n",
+                                                node->no_id, dstring_data(&query1),
+                                                PQresultErrorMessage(res2),
+                                                PQerrorMessage(loc_dbconn));
                                PQclear(res3);
                                PQclear(res2);
                                PQclear(res1);
@@ -2943,52 +2949,41 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                                archive_terminate(node);
                                return -1;
                        }
-               }
+                       if (archive_dir)
+                       {
+                               (void) slon_mkquery(&query1,
+                                                                       "delete from %s;\ncopy %s %s from stdin;", tab_fqname, tab_fqname,
+                                                                       PQgetvalue(res3, 0, 0));
+                               rc = archive_append_ds(node, &query1);
+                               if (rc < 0)
+                               {
+                                       PQclear(res3);
+                                       PQclear(res2);
+                                       PQclear(res1);
+                                       slon_disconnectdb(pro_conn);
+                                       dstring_free(&query1);
+                                       dstring_free(&query2);
+                                       dstring_free(&query3);
+                                       dstring_free(&lsquery);
+                                       dstring_free(&indexregenquery);
+                                       archive_terminate(node);
+                                       return -1;
+                               }
+                       }
 
-               /*
-                * Begin a COPY to stdout for the table on the provider DB
-                */
-               (void) slon_mkquery(&query1,
+                       /*
+                        * Begin a COPY to stdout for the table on the provider DB
+                        */
+                       (void) slon_mkquery(&query1,
                           "copy %s %s to stdout; ", tab_fqname, PQgetvalue(res3, 0, 0));
-               PQclear(res3);
-               res3 = PQexec(pro_dbconn, dstring_data(&query1));
-               if (PQresultStatus(res3) != PGRES_COPY_OUT)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s %s\n",
-                                        node->no_id, dstring_data(&query1),
-                                        PQresultErrorMessage(res2),
-                                        PQerrorMessage(pro_dbconn));
-                       PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
                        PQclear(res3);
-                       PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-
-               /*
-                * Copy the data over
-                */
-               while ((rc = PQgetCopyData(pro_dbconn, &copydata, 0)) > 0)
-               {
-                       int                     len = strlen(copydata);
-
-                       copysize += (int64) len;
-                       if (PQputCopyData(loc_dbconn, copydata, len) != 1)
+                       res3 = PQexec(pro_dbconn, dstring_data(&query1));
+                       if (PQresultStatus(res3) != PGRES_COPY_OUT)
                        {
-                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
-                                                "PQputCopyData() - %s",
-                                                node->no_id, PQerrorMessage(loc_dbconn));
-#ifdef SLON_MEMDEBUG
-                               memset(copydata, 88, len);
-#endif
-                               PQfreemem(copydata);
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: \"%s\" %s %s\n",
+                                                node->no_id, dstring_data(&query1),
+                                                PQresultErrorMessage(res2),
+                                                PQerrorMessage(pro_dbconn));
                                PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
                                PQclear(res3);
                                PQclear(res2);
@@ -3002,16 +2997,25 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                                archive_terminate(node);
                                return -1;
                        }
-                       if (archive_dir)
+
+                       /*
+                        * Copy the data over
+                        */
+                       while ((rc = PQgetCopyData(pro_dbconn, &copydata, 0)) > 0)
                        {
-                               rc = archive_append_data(node, copydata, len);
-                               if (rc < 0)
+                               int                     len = strlen(copydata);
+
+                               copysize += (int64) len;
+                               if (PQputCopyData(loc_dbconn, copydata, len) != 1)
                                {
+                                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+                                                        "PQputCopyData() - %s",
+                                                        node->no_id, PQerrorMessage(loc_dbconn));
 #ifdef SLON_MEMDEBUG
                                        memset(copydata, 88, len);
 #endif
                                        PQfreemem(copydata);
-                                       PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation");
+                                       PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
                                        PQclear(res3);
                                        PQclear(res2);
                                        PQclear(res1);
@@ -3023,103 +3027,109 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                                        dstring_free(&indexregenquery);
                                        archive_terminate(node);
                                        return -1;
+                               }
+                               if (archive_dir)
+                               {
+                                       rc = archive_append_data(node, copydata, len);
+                                       if (rc < 0)
+                                       {
+#ifdef SLON_MEMDEBUG
+                                               memset(copydata, 88, len);
+#endif
+                                               PQfreemem(copydata);
+                                               PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation");
+                                               PQclear(res3);
+                                               PQclear(res2);
+                                               PQclear(res1);
+                                               slon_disconnectdb(pro_conn);
+                                               dstring_free(&query1);
+                                               dstring_free(&query2);
+                                               dstring_free(&query3);
+                                               dstring_free(&lsquery);
+                                               dstring_free(&indexregenquery);
+                                               archive_terminate(node);
+                                               return -1;
 
+                                       }
                                }
-                       }
 #ifdef SLON_MEMDEBUG
-                       memset(copydata, 88, len);
+                               memset(copydata, 88, len);
 #endif
-                       PQfreemem(copydata);
-               }
-               if (rc != -1)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
-                                        "PGgetCopyData() %s",
-                                        node->no_id, PQerrorMessage(pro_dbconn));
-                       PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
-                       PQclear(res3);
-                       PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
+                               PQfreemem(copydata);
+                       }
+                       if (rc != -1)
+                       {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+                                                "PGgetCopyData() %s",
+                                                node->no_id, PQerrorMessage(pro_dbconn));
+                               PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
+                               PQclear(res3);
+                               PQclear(res2);
+                               PQclear(res1);
+                               slon_disconnectdb(pro_conn);
+                               dstring_free(&query1);
+                               dstring_free(&query2);
+                               dstring_free(&query3);
+                               dstring_free(&lsquery);
+                               dstring_free(&indexregenquery);
+                               archive_terminate(node);
+                               return -1;
+                       }
 
-               /*
-                * Check that the COPY to stdout on the provider node finished
-                * successful.
-                */
-               PQclear(res3);
-               res3 = PQgetResult(pro_dbconn);
-               if (PQresultStatus(res3) != PGRES_COMMAND_OK)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
-                                        "copy to stdout on provider - %s %s",
-                                        node->no_id, PQresStatus(PQresultStatus(res3)),
-                                        PQresultErrorMessage(res3));
-                       PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
+                       /*
+                        * Check that the COPY to stdout on the provider node finished
+                        * successful.
+                        */
+                       PQclear(res3);
+                       res3 = PQgetResult(pro_dbconn);
+                       if (PQresultStatus(res3) != PGRES_COMMAND_OK)
+                       {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+                                                "copy to stdout on provider - %s %s",
+                                                node->no_id, PQresStatus(PQresultStatus(res3)),
+                                                PQresultErrorMessage(res3));
+                               PQputCopyEnd(loc_dbconn, "Slony-I: copy set operation failed");
+                               PQclear(res3);
+                               PQclear(res2);
+                               PQclear(res1);
+                               slon_disconnectdb(pro_conn);
+                               dstring_free(&query1);
+                               dstring_free(&query2);
+                               dstring_free(&query3);
+                               dstring_free(&lsquery);
+                               dstring_free(&indexregenquery);
+                               archive_terminate(node);
+                               return -1;
+                       }
                        PQclear(res3);
-                       PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-               PQclear(res3);
 
-               /*
-                * End the COPY from stdin on the local node with success
-                */
-               if (PQputCopyEnd(loc_dbconn, NULL) != 1)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
-                                        "PGputCopyEnd() %s",
-                                        node->no_id, PQerrorMessage(loc_dbconn));
-                       PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-               PQclear(res2);
-               res2 = PQgetResult(loc_dbconn);
-               if (PQresultStatus(res2) != PGRES_COMMAND_OK)
-               {
-                       slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
-                                        "copy from stdin on local node - %s %s",
-                                        node->no_id, PQresStatus(PQresultStatus(res2)),
-                                        PQresultErrorMessage(res2));
+                       /*
+                        * End the COPY from stdin on the local node with success
+                        */
+                       if (PQputCopyEnd(loc_dbconn, NULL) != 1)
+                       {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+                                                "PGputCopyEnd() %s",
+                                                node->no_id, PQerrorMessage(loc_dbconn));
+                               PQclear(res2);
+                               PQclear(res1);
+                               slon_disconnectdb(pro_conn);
+                               dstring_free(&query1);
+                               dstring_free(&query2);
+                               dstring_free(&query3);
+                               dstring_free(&lsquery);
+                               dstring_free(&indexregenquery);
+                               archive_terminate(node);
+                               return -1;
+                       }
                        PQclear(res2);
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-               if (archive_dir)
-               {
-                       rc = archive_append_str(node, "\\.");
-                       if (rc < 0)
+                       res2 = PQgetResult(loc_dbconn);
+                       if (PQresultStatus(res2) != PGRES_COMMAND_OK)
                        {
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d: "
+                                                "copy from stdin on local node - %s %s",
+                                                node->no_id, PQresStatus(PQresultStatus(res2)),
+                                                PQresultErrorMessage(res2));
                                PQclear(res2);
                                PQclear(res1);
                                slon_disconnectdb(pro_conn);
@@ -3131,40 +3141,56 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
                                archive_terminate(node);
                                return -1;
                        }
-               }
+                       if (archive_dir)
+                       {
+                               rc = archive_append_str(node, "\\.");
+                               if (rc < 0)
+                               {
+                                       PQclear(res2);
+                                       PQclear(res1);
+                                       slon_disconnectdb(pro_conn);
+                                       dstring_free(&query1);
+                                       dstring_free(&query2);
+                                       dstring_free(&query3);
+                                       dstring_free(&lsquery);
+                                       dstring_free(&indexregenquery);
+                                       archive_terminate(node);
+                                       return -1;
+                               }
+                       }
 
-               PQclear(res2);
-               slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
-                                INT64_FORMAT " bytes copied for table %s\n",
-                                node->no_id, copysize, tab_fqname);
+                       PQclear(res2);
+                       slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
+                                        INT64_FORMAT " bytes copied for table %s\n",
+                                        node->no_id, copysize, tab_fqname);
 
-               /*
-                * Analyze the table to update statistics
-                */
-               (void) slon_mkquery(&query1, "select %s.finishTableAfterCopy(%d); "
-                                                       "analyze %s; ",
-                                                       rtcfg_namespace, tab_id,
-                                                       tab_fqname);
-               if (query_execute(node, loc_dbconn, &query1) < 0)
-               {
-                       PQclear(res1);
-                       slon_disconnectdb(pro_conn);
-                       dstring_free(&query1);
-                       dstring_free(&query2);
-                       dstring_free(&query3);
-                       dstring_free(&lsquery);
-                       dstring_free(&indexregenquery);
-                       archive_terminate(node);
-                       return -1;
-               }
-               if (archive_dir)
-               {
-                       rc = archive_append_ds(node, &query1);
-                       if (rc < 0)
+                       /*
+                        * Analyze the table to update statistics
+                        */
+                       (void) slon_mkquery(&query1, "select %s.finishTableAfterCopy(%d); "
+                                                               "analyze %s; ",
+                                                               rtcfg_namespace, tab_id,
+                                                               tab_fqname);
+                       if (query_execute(node, loc_dbconn, &query1) < 0)
                        {
+                               PQclear(res1);
+                               slon_disconnectdb(pro_conn);
+                               dstring_free(&query1);
+                               dstring_free(&query2);
+                               dstring_free(&query3);
+                               dstring_free(&lsquery);
+                               dstring_free(&indexregenquery);
+                               archive_terminate(node);
                                return -1;
                        }
-               }
+                       if (archive_dir)
+                       {
+                               rc = archive_append_ds(node, &query1);
+                               if (rc < 0)
+                               {
+                                       return -1;
+                               }
+                       }
                }
                gettimeofday(&tv_now, NULL);
                slon_log(SLON_CONFIG, "remoteWorkerThread_%d: "
@@ -3577,8 +3603,8 @@ copy_set(SlonNode *node, SlonConn *local_conn, int set_id,
  * ----------
  */
 static int
-sync_event(SlonNode *node, SlonConn *local_conn,
-                  WorkerGroupData *wd, SlonWorkMsg_event *event)
+sync_event(SlonNode * node, SlonConn * local_conn,
+                  WorkerGroupData * wd, SlonWorkMsg_event * event)
 {
        ProviderInfo *provider;
        ProviderSet *pset;
@@ -3589,7 +3615,7 @@ sync_event(SlonNode *node, SlonConn *local_conn,
        PGresult   *res1;
        int                     ntuples1;
        int                     num_sets = 0;
-       int                     num_errors=0;
+       int                     num_errors = 0;
 
        int                     i;
        int                     rc;
@@ -3604,7 +3630,7 @@ sync_event(SlonNode *node, SlonConn *local_conn,
 
        int                     actionlist_len;
        int64           min_ssy_seqno;
-       PerfMon pm;
+       PerfMon         pm;
 
        gettimeofday(&tv_start, NULL);
 
@@ -3776,9 +3802,10 @@ sync_event(SlonNode *node, SlonConn *local_conn,
                int                     rc;
                int                     need_union;
                int                     sl_log_no;
-slon_log(SLON_DEBUG2,
-                "remoteWorkerThread_%d: creating log select for provider %d\n",
-                                        node->no_id, provider->no_id);
+
+               slon_log(SLON_DEBUG2,
+                         "remoteWorkerThread_%d: creating log select for provider %d\n",
+                                node->no_id, provider->no_id);
 
                need_union = 0;
                provider_query = &(provider->helper_query);
@@ -3813,7 +3840,7 @@ slon_log(SLON_DEBUG2,
                if (PQntuples(res1) != 1)
                {
                        slon_log(SLON_ERROR,
-                                "remoteWorkerThread_%d: \"%s\" %s returned %d tuples\n",
+                                        "remoteWorkerThread_%d: \"%s\" %s returned %d tuples\n",
                                         node->no_id, dstring_data(&query),
                                         PQresStatus(rc), PQntuples(res1));
                        PQclear(res1);
@@ -3825,14 +3852,14 @@ slon_log(SLON_DEBUG2,
                provider->log_status = strtol(PQgetvalue(res1, 0, 0), NULL, 10);
                PQclear(res1);
                slon_log(SLON_DEBUG2,
-                       "remoteWorkerThread_%d_%d: current remote log_status = %d\n",
+                                "remoteWorkerThread_%d_%d: current remote log_status = %d\n",
                                 node->no_id, provider->no_id, provider->log_status);
 
                /*
-                * Add the DDL selection to the provider_query if this is the
-                * event provider. In case we are subscribed to any set(s) from
-                * the origin, this is implicitly the data provider because we
-                * only listen for events on that node.
+                * Add the DDL selection to the provider_query if this is the event
+                * provider. In case we are subscribed to any set(s) from the origin,
+                * this is implicitly the data provider because we only listen for
+                * events on that node.
                 */
                if (provider->no_id == event->event_provider)
                {
@@ -3845,15 +3872,15 @@ slon_log(SLON_DEBUG2,
                                                         "where log_origin = %d ",
                                                         rtcfg_namespace, node->no_id);
                        slon_appendquery(provider_query,
-                                "and log_txid >= \"pg_catalog\".txid_snapshot_xmax('%s') "
-                                "and log_txid < '%s' "
-                                "and \"pg_catalog\".txid_visible_in_snapshot(log_txid, '%s') ",
-                                node->last_snapshot,
-                                event->ev_maxtxid_c,
-                                event->ev_snapshot_c);
+                                  "and log_txid >= \"pg_catalog\".txid_snapshot_xmax('%s') "
+                                                        "and log_txid < '%s' "
+                         "and \"pg_catalog\".txid_visible_in_snapshot(log_txid, '%s') ",
+                                                        node->last_snapshot,
+                                                        event->ev_maxtxid_c,
+                                                        event->ev_snapshot_c);
 
                        slon_appendquery(provider_query,
-                                                       "union all "
+                                                        "union all "
                                                         "select log_origin, log_txid, "
                                                         "NULL::integer, log_actionseq, "
                                                         "NULL::text, NULL::text, log_cmdtype, "
@@ -3862,20 +3889,20 @@ slon_log(SLON_DEBUG2,
                                                         "where log_origin = %d ",
                                                         rtcfg_namespace, node->no_id);
                        slon_appendquery(provider_query,
-                                "and log_txid in (select * from "
-                                "\"pg_catalog\".txid_snapshot_xip('%s') "
-                                "except "
-                                "select * from "
-                                "\"pg_catalog\".txid_snapshot_xip('%s') )",
-                                node->last_snapshot,
-                                event->ev_snapshot_c);
+                                                        "and log_txid in (select * from "
+                                                        "\"pg_catalog\".txid_snapshot_xip('%s') "
+                                                        "except "
+                                                        "select * from "
+                                                        "\"pg_catalog\".txid_snapshot_xip('%s') )",
+                                                        node->last_snapshot,
+                                                        event->ev_snapshot_c);
 
                        need_union = 1;
                }
 
                /*
-                * Only go through the trouble of looking up the setsync and tables
-                * if we actually use this provider for data.
+                * Only go through the trouble of looking up the setsync and tables if
+                * we actually use this provider for data.
                 */
                if (provider->set_head != NULL)
                {
@@ -3885,7 +3912,7 @@ slon_log(SLON_DEBUG2,
                         */
                        (void) slon_mkquery(&query,
                                                                "select SSY.ssy_setid, SSY.ssy_seqno, "
-                                         "    \"pg_catalog\".txid_snapshot_xmax(SSY.ssy_snapshot), "
+                                 "    \"pg_catalog\".txid_snapshot_xmax(SSY.ssy_snapshot), "
                                                                "    SSY.ssy_snapshot, "
                                                                "    SSY.ssy_action_list "
                                                                "from %s.sl_setsync SSY "
@@ -3925,21 +3952,21 @@ slon_log(SLON_DEBUG2,
                                PQclear(res1);
                                if (need_union)
                                {
-                                       dstring_append(provider_query, 
-                                                       " order by log_actionseq) TO STDOUT");
+                                       dstring_append(provider_query,
+                                                                  " order by log_actionseq) TO STDOUT");
                                        dstring_terminate(provider_query);
                                }
                                else
                                {
                                        slon_mkquery(provider_query,
-                                               "COPY ( "
-                                               "select log_origin, log_txid, log_tableid, "
-                                                               "log_actionseq, log_tablenspname, "
-                                                               "log_tablerelname, log_cmdtype, "
-                                                               "log_cmdupdncols, log_cmdargs "
-                                                       "from %s.sl_log_1 "
-                                                       "where false) TO STDOUT",
-                                                       rtcfg_namespace);
+                                                                "COPY ( "
+                                                                "select log_origin, log_txid, log_tableid, "
+                                                                "log_actionseq, log_tablenspname, "
+                                                                "log_tablerelname, log_cmdtype, "
+                                                                "log_cmdupdncols, log_cmdargs "
+                                                                "from %s.sl_log_1 "
+                                                                "where false) TO STDOUT",
+                                                                rtcfg_namespace);
                                }
 
                                continue;
@@ -3966,8 +3993,8 @@ slon_log(SLON_DEBUG2,
                                 */
                                (void) slon_mkquery(&query,
                                                                        "select T.tab_id, T.tab_set, "
-                                                               "    %s.slon_quote_brute(PGN.nspname) || '.' || "
-                                                       "    %s.slon_quote_brute(PGC.relname) as tab_fqname "
+                                                       "    %s.slon_quote_brute(PGN.nspname) || '.' || "
+                                               "    %s.slon_quote_brute(PGC.relname) as tab_fqname "
                                                                        "from %s.sl_table T, "
                                                                        "    \"pg_catalog\".pg_class PGC, "
                                                                        "    \"pg_catalog\".pg_namespace PGN "
@@ -4014,14 +4041,15 @@ slon_log(SLON_DEBUG2,
                                for (sl_log_no = 1; sl_log_no <= 2; sl_log_no++)
                                {
                                        /*
-                                        * We only need to query sl_log_1 when log_status is
-                                        * 0 or during log switching (log_status 2 and 3).
+                                        * We only need to query sl_log_1 when log_status is 0 or
+                                        * during log switching (log_status 2 and 3).
                                         */
                                        if (sl_log_no == 1 && provider->log_status == 1)
                                                continue;
+
                                        /*
-                                        * Likewise we only query sl_log_2 when log_status is
-                                        * 1, 2 or 3.
+                                        * Likewise we only query sl_log_2 when log_status is 1, 2
+                                        * or 3.
                                         */
                                        if (sl_log_no == 2 && provider->log_status == 0)
                                                continue;
@@ -4033,15 +4061,14 @@ slon_log(SLON_DEBUG2,
                                        need_union = 1;
 
                                        /*
-                                        * First for the big chunk that does the index
-                                        * scan with upper and lower bounds:
+                                        * First for the big chunk that does the index scan with
+                                        * upper and lower bounds:
                                         *
-                                        * select ... from sl_log_N 
-                                        *     where log_origin = X
-                                        *     and log_tableid in (<this set's tables>)
+                                        * select ... from sl_log_N where log_origin = X and
+                                        * log_tableid in (<this set's tables>)
                                         */
                                        slon_appendquery(provider_query,
-                                                                        "select log_origin, log_txid, log_tableid, "
+                                                                "select log_origin, log_txid, log_tableid, "
                                                                         "log_actionseq, log_tablenspname, "
                                                                         "log_tablerelname, log_cmdtype, "
                                                                         "log_cmdupdncols, log_cmdargs "
@@ -4054,36 +4081,36 @@ slon_log(SLON_DEBUG2,
                                        {
                                                if (tupno2 > 0)
                                                        dstring_addchar(provider_query, ',');
-                                               dstring_append(provider_query, 
+                                               dstring_append(provider_query,
                                                                           PQgetvalue(res2, tupno2, 0));
                                        }
                                        dstring_append(provider_query, ") ");
 
                                        /*
-                                        * and log_txid >= '<maxxid_last_snapshot>'
-                                        * and log_txid < '<maxxid_this_snapshot>'
-                                        * and txit_visible_in_snapshot(log_txid, '<this_snapshot>')
+                                        * and log_txid >= '<maxxid_last_snapshot>' and log_txid <
+                                        * '<maxxid_this_snapshot>' and
+                                        * txit_visible_in_snapshot(log_txid, '<this_snapshot>')
                                         */
                                        slon_appendquery(provider_query,
-                                                "and log_txid >= '%s' "
-                                                "and log_txid < '%s' "
-                                                "and \"pg_catalog\".txid_visible_in_snapshot(log_txid, '%s') ",
-                                                ssy_maxxid,
-                                                event->ev_maxtxid_c,
-                                                event->ev_snapshot_c);
+                                                                        "and log_txid >= '%s' "
+                                                                        "and log_txid < '%s' "
+                                                                        "and \"pg_catalog\".txid_visible_in_snapshot(log_txid, '%s') ",
+                                                                        ssy_maxxid,
+                                                                        event->ev_maxtxid_c,
+                                                                        event->ev_snapshot_c);
 
                                        /*
                                         * and (<actionseq_qual_on_first_sync>)
                                         */
                                        actionlist_len = strlen(ssy_action_list);
                                        slon_log(SLON_DEBUG2, "remoteWorkerThread_%d_%d: "
-                                                       "ssy_action_list length: %d\n",
-                                                       node->no_id, provider->no_id,
-                                                       actionlist_len);
+                                                        "ssy_action_list length: %d\n",
+                                                        node->no_id, provider->no_id,
+                                                        actionlist_len);
                                        slon_log(SLON_DEBUG4, "remoteWorkerThread_%d_%d: "
-                                                       "ssy_action_list value: %s\n",
-                                                       node->no_id, provider->no_id,
-                                                       ssy_action_list);
+                                                        "ssy_action_list value: %s\n",
+                                                        node->no_id, provider->no_id,
+                                                        ssy_action_list);
                                        if (actionlist_len > 0)
                                        {
                                                dstring_init(&actionseq_subquery);
@@ -4095,19 +4122,17 @@ slon_log(SLON_DEBUG2,
                                        }
 
                                        /*
-                                        * Now do it all over again to get the log rows
-                                        * from in-progress transactions at snapshot one
-                                        * that have committed by the time of snapshot two.
-                                        * again, we do:
+                                        * Now do it all over again to get the log rows from
+                                        * in-progress transactions at snapshot one that have
+                                        * committed by the time of snapshot two. again, we do:
                                         *
-                                        * select ... from sl_log_N 
-                                        *     where log_origin = X
-                                        *     and log_tableid in (<this set's tables>)
+                                        * select ... from sl_log_N where log_origin = X and
+                                        * log_tableid in (<this set's tables>)
                                         */
 
                                        slon_appendquery(provider_query,
                                                                         "union all "
-                                                                        "select log_origin, log_txid, log_tableid, "
+                                                                "select log_origin, log_txid, log_tableid, "
                                                                         "log_actionseq, log_tablenspname, "
                                                                         "log_tablerelname, log_cmdtype, "
                                                                         "log_cmdupdncols, log_cmdargs "
@@ -4120,24 +4145,24 @@ slon_log(SLON_DEBUG2,
                                        {
                                                if (tupno2 > 0)
                                                        dstring_addchar(provider_query, ',');
-                                               dstring_append(provider_query, 
-                                                       PQgetvalue(res2, tupno2, 0));
+                                               dstring_append(provider_query,
+                                                                          PQgetvalue(res2, tupno2, 0));
                                        }
                                        dstring_append(provider_query, ") ");
 
                                        /*
                                         * and log_txid in (select
-                                        *                              txid_snapshot_xip('<last_snapshot>'))
-                                        * and txit_visible_in_snapshot(log_txid, '<this_snapshot>')
+                                        * txid_snapshot_xip('<last_snapshot>')) and
+                                        * txit_visible_in_snapshot(log_txid, '<this_snapshot>')
                                         */
                                        slon_appendquery(provider_query,
-                                                "and log_txid in (select * from "
-                                                "\"pg_catalog\".txid_snapshot_xip('%s') "
-                                                "except "
-                                                "select * from "
-                                                "\"pg_catalog\".txid_snapshot_xip('%s') )",
-                                                ssy_snapshot,
-                                                event->ev_snapshot_c);
+                                                                        "and log_txid in (select * from "
+                                                                        "\"pg_catalog\".txid_snapshot_xip('%s') "
+                                                                        "except "
+                                                                        "select * from "
+                                                                 "\"pg_catalog\".txid_snapshot_xip('%s') )",
+                                                                        ssy_snapshot,
+                                                                        event->ev_snapshot_c);
 
                                        /*
                                         * and (<actionseq_qual_on_first_sync>)
@@ -4170,18 +4195,18 @@ slon_log(SLON_DEBUG2,
                if (!need_union)
                {
                        /*
-                        * This can happen when there are no tables in any of the
-                        * sets that we subscribe from this node.
+                        * This can happen when there are no tables in any of the sets
+                        * that we subscribe from this node.
                         */
                        slon_mkquery(provider_query,
-                               "COPY ( "
-                               "select log_origin, log_txid, log_tableid, "
-                                               "log_actionseq, log_tablenspname, "
-                                               "log_tablerelname, log_cmdtype, "
-                                               "log_cmdupdncols, log_cmdargs "
-                                       "from %s.sl_log_1 "
-                                       "where false) TO STDOUT",
-                                       rtcfg_namespace);
+                                                "COPY ( "
+                                                "select log_origin, log_txid, log_tableid, "
+                                                "log_actionseq, log_tablenspname, "
+                                                "log_tablerelname, log_cmdtype, "
+                                                "log_cmdupdncols, log_cmdargs "
+                                                "from %s.sl_log_1 "
+                                                "where false) TO STDOUT",
+                                                rtcfg_namespace);
                }
        }
 
@@ -4227,8 +4252,8 @@ slon_log(SLON_DEBUG2,
        PQclear(res1);
 
        /*
-        * If we have a explain_interval, run the query through explain
-        * and output the query as well as the resulting query plan.
+        * If we have a explain_interval, run the query through explain and output
+        * the query as well as the resulting query plan.
         */
        if (explain_interval > 0)
        {
@@ -4256,7 +4281,7 @@ slon_log(SLON_DEBUG2,
                 * instead of starting the helpers we want to
                 * perform the COPY on each provider.
                 */
-               num_errors+=sync_helper((void*)provider,local_dbconn);
+               num_errors += sync_helper((void *) provider, local_dbconn);
        }
 
 
@@ -4311,7 +4336,7 @@ slon_log(SLON_DEBUG2,
                                                         (pset->prev == NULL) ? "" : ",",
                                                         pset->set_id);
                slon_appendquery(&query, ") "
-                                                "  group by SL.seql_seqid,SQ.seq_nspname, SQ.seq_relname; ");
+                               "  group by SL.seql_seqid,SQ.seq_nspname, SQ.seq_relname; ");
 
                start_monitored_event(&pm);
                res1 = PQexec(provider->conn->dbconn, dstring_data(&query));
@@ -4335,8 +4360,8 @@ slon_log(SLON_DEBUG2,
                {
                        char       *seql_seqid = PQgetvalue(res1, tupno1, 0);
                        char       *seql_last_value = PQgetvalue(res1, tupno1, 1);
-                       char       *seq_nspname = PQgetvalue(res1,tupno1,2);
-                       char       *seq_relname = PQgetvalue(res1,tupno1,3);
+                       char       *seq_nspname = PQgetvalue(res1, tupno1, 2);
+                       char       *seq_relname = PQgetvalue(res1, tupno1, 3);
 
                        (void) slon_mkquery(&query,
                                                         "select %s.sequenceSetValue(%s,%d,'%s','%s'); ",
@@ -4359,9 +4384,9 @@ slon_log(SLON_DEBUG2,
                        if (archive_dir)
                        {
                                (void) slon_mkquery(&lsquery,
-                                                       "select %s.sequenceSetValue_offline('%s','%s','%s');\n",
+                                        "select %s.sequenceSetValue_offline('%s','%s','%s');\n",
                                                                        rtcfg_namespace,
-                                                                       seq_nspname,seq_relname, seql_last_value);
+                                                                 seq_nspname, seq_relname, seql_last_value);
                                rc = archive_append_ds(node, &lsquery);
                                if (rc < 0)
                                        slon_retry();
@@ -4398,10 +4423,10 @@ slon_log(SLON_DEBUG2,
                 * ... if there could be any, that is.
                 */
                slon_appendquery(&query, ") and ssy_seqno < '%s'; ", seqbuf);
-               
+
                start_monitored_event(&pm);
                res1 = PQexec(local_dbconn, dstring_data(&query));
-               monitor_subscriber_query (&pm);
+               monitor_subscriber_query(&pm);
 
                if (PQresultStatus(res1) != PGRES_COMMAND_OK)
                {
@@ -4442,14 +4467,14 @@ slon_log(SLON_DEBUG2,
                         TIMEVAL_DIFF(&tv_start, &tv_now));
        sprintf(wd->duration_buf, "%.3f s", TIMEVAL_DIFF(&tv_start, &tv_now));
 
-       slon_log(SLON_DEBUG1, 
-                        "remoteWorkerThread_%d: SYNC " INT64_FORMAT " sync_event timing: " 
-                        " pqexec (s/count)" 
-                        "- provider %.3f/%d " 
-                        "- subscriber %.3f/%d " 
+       slon_log(SLON_DEBUG1,
+                  "remoteWorkerThread_%d: SYNC " INT64_FORMAT " sync_event timing: "
+                        " pqexec (s/count)"
+                        "- provider %.3f/%d "
+                        "- subscriber %.3f/%d "
                         "- IUD %.3f/%d\n",
-                        node->no_id, event->ev_seqno, 
-                        pm.prov_query_t, pm.prov_query_c, 
+                        node->no_id, event->ev_seqno,
+                        pm.prov_query_t, pm.prov_query_c,
                         pm.subscr_query_t, pm.prov_query_c,
                         pm.subscr_iud__t, pm.subscr_iud__c);
 
@@ -4462,11 +4487,11 @@ slon_log(SLON_DEBUG2,
  * ----------
  */
 static int
-sync_helper(void *cdata,PGconn * local_conn)
+sync_helper(void *cdata, PGconn *local_conn)
 {
        ProviderInfo *provider = (ProviderInfo *) cdata;
        SlonNode   *node = provider->wd->node;
-       WorkerGroupData * wd = provider->wd;
+       WorkerGroupData *wd = provider->wd;
        PGconn     *dbconn;
        SlonDString query;
        SlonDString copy_in;
@@ -4481,45 +4506,46 @@ sync_helper(void *cdata,PGconn * local_conn)
        int                     tupno;
        PGresult   *res = NULL;
        PGresult   *res2 = NULL;
-       char            * buffer;
+       char       *buffer;
 
-       PerfMon pm;
+       PerfMon         pm;
 
        dstring_init(&query);
 
-       
+
        /*
         * OK, we got work to do.
         */
-       dbconn = provider->conn->dbconn;        
-       
+       dbconn = provider->conn->dbconn;
+
        errors = 0;
-       
+
        init_perfmon(&pm);
+
        /*
         * Start a transaction
         */
-       
+
        (void) slon_mkquery(&query, "start transaction; "
                                                "set enable_seqscan = off; "
                                                "set enable_indexscan = on; ");
-       
+
        start_monitored_event(&pm);
-       
+
        if (query_execute(node, dbconn, &query) < 0)
        {
                errors++;
                dstring_terminate(&query);
                return errors;
        }
-       monitor_subscriber_query (&pm);
-       
+       monitor_subscriber_query(&pm);
+
        /*
         * Get the current sl_log_status value
         */
        (void) slon_mkquery(&query, "select last_value from %s.sl_log_status",
                                                rtcfg_namespace);
-       
+
        start_monitored_event(&pm);
        res2 = PQexec(dbconn, dstring_data(&query));
        monitor_provider_query(&pm);
@@ -4554,21 +4580,22 @@ sync_helper(void *cdata,PGconn * local_conn)
                         "remoteWorkerThread_%d_%d: current remote log_status = %d\n",
                         node->no_id, provider->no_id, log_status);
        dstring_terminate(&query);
+
        /*
         * See if we have to run the query through EXPLAIN first
         */
        if (explain_thistime)
        {
-               SlonDString             explain_query;
-               
+               SlonDString explain_query;
+
                /*
-                * Let Postgres EXPLAIN the query plan for the current
-                * log selection query
+                * Let Postgres EXPLAIN the query plan for the current log selection
+                * query
                 */
                dstring_init(&explain_query);
                slon_mkquery(&explain_query, "explain %s",
                                         dstring_data(&(provider->helper_query)));
-               
+
                res = PQexec(dbconn, dstring_data(&explain_query));
                if (PQresultStatus(res) != PGRES_TUPLES_OK)
                {
@@ -4581,20 +4608,20 @@ sync_helper(void *cdata,PGconn * local_conn)
                        errors++;
                        return errors;
                }
-               
-               slon_log(SLON_INFO, 
+
+               slon_log(SLON_INFO,
                                 "remoteWorkerThread_%d_%d: "
                                 "Log selection query: %s\n",
                                 node->no_id, provider->no_id,
                                 dstring_data(&explain_query));
-               slon_log(SLON_INFO, 
+               slon_log(SLON_INFO,
                                 "remoteWorkerThread_%d_%d: Query Plan:\n",
                                 node->no_id, provider->no_id);
-               
+
                ntuples = PQntuples(res);
                for (tupno = 0; tupno < ntuples; tupno++)
                {
-                       slon_log(SLON_INFO, 
+                       slon_log(SLON_INFO,
                                         "remoteWorkerThread_%d_%d: PLAN %s\n",
                                         node->no_id, provider->no_id,
                                         PQgetvalue(res, tupno, 0));
@@ -4602,21 +4629,21 @@ sync_helper(void *cdata,PGconn * local_conn)
                slon_log(SLON_INFO,
                                 "remoteWorkerThread_%d_%d: PLAN_END\n",
                                 node->no_id, provider->no_id);
-               
+
                PQclear(res);
                dstring_free(&explain_query);
        }
-       
+
        gettimeofday(&tv_start, NULL);
        first_fetch = true;
        res = NULL;
-       
+
        /*
         * execute the COPY to read the log data.
         */
        start_monitored_event(&pm);
        res = PQexec(dbconn, dstring_data(&provider->helper_query));
-       ifPQresultStatus(res) != PGRES_COPY_OUT)
+       if (PQresultStatus(res) != PGRES_COPY_OUT)
        {
                errors++;
                slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error executing COPY OUT: \"%s\" %s",
@@ -4632,50 +4659,54 @@ sync_helper(void *cdata,PGconn * local_conn)
         *
         */
        dstring_init(&copy_in);
-       slon_mkquery(&copy_in,"COPY %s.\"sl_log_%d\" ( log_origin, "            \
-                                "log_txid,log_tableid,log_actionseq,log_tablenspname, "        \
-                                "log_tablerelname, log_cmdtype, log_cmdupdncols,"              \
+       slon_mkquery(&copy_in, "COPY %s.\"sl_log_%d\" ( log_origin, " \
+                                "log_txid,log_tableid,log_actionseq,log_tablenspname, " \
+                                "log_tablerelname, log_cmdtype, log_cmdupdncols," \
                                 "log_cmdargs) FROM STDIN",
                                 rtcfg_namespace, wd->active_log_table);
-       
-       res2 = PQexec(local_conn,dstring_data(&copy_in));       \
-       if ( PQresultStatus(res2) != PGRES_COPY_IN )
+
+       res2 = PQexec(local_conn, dstring_data(&copy_in));
+       \
+               if (PQresultStatus(res2) != PGRES_COPY_IN)
        {
-               
+
                slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error executing COPY IN: \"%s\" %s",
                                 node->no_id, provider->no_id,
                                 dstring_data(&copy_in),
-                                PQresultErrorMessage(res2));   
+                                PQresultErrorMessage(res2));
                errors++;
                dstring_free(&copy_in);
                PQclear(res2);
                return errors;
-               
+
        }
        if (archive_dir)
        {
                SlonDString log_copy;
+
                dstring_init(&log_copy);
-               slon_mkquery(&log_copy,"COPY %s.\"sl_log_archive\" ( log_origin, "      \
-                                "log_txid,log_tableid,log_actionseq,log_tablenspname, "        \
-                                "log_tablerelname, log_cmdtype, log_cmdupdncols,"              \
-                                "log_cmdargs) FROM STDIN;",
-                                rtcfg_namespace);
-               archive_append_ds(node,&log_copy);
+               slon_mkquery(&log_copy, "COPY %s.\"sl_log_archive\" ( log_origin, " \
+                                        "log_txid,log_tableid,log_actionseq,log_tablenspname, " \
+                                        "log_tablerelname, log_cmdtype, log_cmdupdncols," \
+                                        "log_cmdargs) FROM STDIN;",
+                                        rtcfg_namespace);
+               archive_append_ds(node, &log_copy);
                dstring_terminate(&log_copy);
-               
+
 
        }
        dstring_free(&copy_in);
-       tupno=0;
+       tupno = 0;
        while (!errors)
        {
-               rc = PQgetCopyData(dbconn,&buffer,0);
-               if (rc < 0)  {
-                       if ( rc == -2 ) {
+               rc = PQgetCopyData(dbconn, &buffer, 0);
+               if (rc < 0)
+               {
+                       if (rc == -2)
+                       {
                                errors++;
-                               slon_log(SLON_ERROR,"remoteWorkerThread_%d_%d: error reading copy data: %s",
-                                                node->no_id, provider->no_id,PQerrorMessage(dbconn));
+                               slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error reading copy data: %s",
+                                          node->no_id, provider->no_id, PQerrorMessage(dbconn));
                        }
                        break;
                }
@@ -4684,72 +4715,72 @@ sync_helper(void *cdata,PGconn * local_conn)
                {
                        gettimeofday(&tv_now, NULL);
                        slon_log(SLON_DEBUG1,
-                                        "remoteWorkerThread_%d_%d: %.3f seconds delay for first row\n",
+                         "remoteWorkerThread_%d_%d: %.3f seconds delay for first row\n",
                                         node->no_id, provider->no_id,
                                         TIMEVAL_DIFF(&tv_start, &tv_now));
-                       
+
                        first_fetch = false;
                }
-               rc2 = PQputCopyData(local_conn,buffer,rc);      
-               if (rc2 < 0 )
+               rc2 = PQputCopyData(local_conn, buffer, rc);
+               if (rc2 < 0)
                {
                        slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error writing" \
-                                        " to sl_log: %s\n", 
-                                        node->no_id,provider->no_id,
+                                        " to sl_log: %s\n",
+                                        node->no_id, provider->no_id,
                                         PQerrorMessage(local_conn));
-                       errors++;                       
-                       if(buffer)
+                       errors++;
+                       if (buffer)
                                PQfreemem(buffer);
                        break;
                }
 
-               if(archive_dir)
-                       archive_append_data(node,buffer,rc);
-               if(buffer)
+               if (archive_dir)
+                       archive_append_data(node, buffer, rc);
+               if (buffer)
                        PQfreemem(buffer);
-               
-       }/*errors*/
+
+       }                                                       /* errors */
        rc2 = PQputCopyEnd(local_conn, NULL);
        if (rc2 < 0)
        {
                slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error ending copy"
-                                " to sl_log:%s\n", 
-                                node->no_id,provider->no_id,
+                                " to sl_log:%s\n",
+                                node->no_id, provider->no_id,
                                 PQerrorMessage(local_conn));
-               errors++;                       
+               errors++;
        }
 
-       if(archive_dir)
+       if (archive_dir)
        {
-               archive_append_str(node,"\\.");
+               archive_append_str(node, "\\.");
        }
        if (res != NULL)
        {
                PQclear(res);
                res = NULL;
        }
-       ifres2 != NULL)
+       if (res2 != NULL)
        {
                PQclear(res2);
                res2 = NULL;
        }
 
        res = PQgetResult(dbconn);
-       if ( PQresultStatus(res) < 0 )
+       if (PQresultStatus(res) < 0)
        {
                slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error at end of COPY OUT: %s",
                                 node->no_id, provider->no_id,
-                                PQresultErrorMessage(res));    
+                                PQresultErrorMessage(res));
                errors++;
        }
        PQclear(res);
 
        res = PQgetResult(local_conn);
-       if ( PQresultStatus(res) < 0 )
+       if (PQresultStatus(res) < 0)
        {
                slon_log(SLON_ERROR, "remoteWorkerThread_%d_%d: error at end of COPY IN: %s",
                                 node->no_id, provider->no_id,
-                                PQresultErrorMessage(res));    
+                                PQresultErrorMessage(res));
                errors++;
        }
        PQclear(res);
@@ -4757,34 +4788,34 @@ sync_helper(void *cdata,PGconn * local_conn)
 
        if (errors)
                slon_log(SLON_ERROR,
-                        "remoteWorkerThread_%d_%d: failed SYNC's log selection query was '%s'\n",
-                        node->no_id, provider->no_id,
-                        dstring_data(&(provider->helper_query)));
-       
+                                "remoteWorkerThread_%d_%d: failed SYNC's log selection query was '%s'\n",
+                                node->no_id, provider->no_id,
+                                dstring_data(&(provider->helper_query)));
+
        dstring_init(&query);
        (void) slon_mkquery(&query, "rollback transaction; "
                                                "set enable_seqscan = default; "
                                                "set enable_indexscan = default; ");
        if (query_execute(node, dbconn, &query) < 0)
                errors++;
-       
+
        gettimeofday(&tv_now, NULL);
        slon_log(SLON_DEBUG1,
                         "remoteWorkerThread_%d_%d: %.3f seconds until close cursor\n",
                         node->no_id, provider->no_id,
                         TIMEVAL_DIFF(&tv_start, &tv_now));
-       slon_log(SLON_DEBUG1,"remoteWorkerThread_%d_%d: rows=%d\n",
-                        node->no_id,provider->no_id,tupno);
+       slon_log(SLON_DEBUG1, "remoteWorkerThread_%d_%d: rows=%d\n",
+                        node->no_id, provider->no_id, tupno);
 
-       slon_log(SLON_DEBUG1, 
-                        "remoteWorkerThread_%d: sync_helper timing: " 
-                        " pqexec (s/count)" 
-                        "- provider %.3f/%d " 
+       slon_log(SLON_DEBUG1,
+                        "remoteWorkerThread_%d: sync_helper timing: "
+                        " pqexec (s/count)"
+                        "- provider %.3f/%d "
                         "- subscriber %.3f/%d\n",
-                        node->no_id, 
-                        pm.prov_query_t, pm.prov_query_c, 
-                        pm.subscr_query_t, pm.prov_query_c);   
-       
+                        node->no_id,
+                        pm.prov_query_t, pm.prov_query_c,
+                        pm.subscr_query_t, pm.prov_query_c);
+
        slon_log(SLON_DEBUG4,
                         "remoteWorkerThread_%d_%d: sync_helper done\n",
                         node->no_id, provider->no_id);
@@ -4821,7 +4852,7 @@ sync_helper(void *cdata,PGconn * local_conn)
  * ----------
  */
 static int
-archive_open(SlonNode *node, char *seqbuf, PGconn *dbconn)
+archive_open(SlonNode * node, char *seqbuf, PGconn *dbconn)
 {
        SlonDString query;
        PGresult   *res;
@@ -4957,7 +4988,7 @@ archive_open(SlonNode *node, char *seqbuf, PGconn *dbconn)
  * ----------
  */
 static int
-archive_close(SlonNode *node)
+archive_close(SlonNode * node)
 {
        int                     rc = 0;
 
@@ -5011,7 +5042,7 @@ archive_close(SlonNode *node)
        if (command_on_logarchive)
        {
                char            command[1024];
-               
+
                sprintf(command, "%s %s", command_on_logarchive, node->archive_name);
                slon_log(SLON_DEBUG1, "remoteWorkerThread_%d: Run Archive Command %s\n",
                                 node->no_id, command);
@@ -5026,7 +5057,7 @@ archive_close(SlonNode *node)
  * ----------
  */
 static void
-archive_terminate(SlonNode *node)
+archive_terminate(SlonNode * node)
 {
        if (node->archive_fp != NULL)
        {
@@ -5040,7 +5071,7 @@ archive_terminate(SlonNode *node)
  * ----------
  */
 static int
-archive_append_ds(SlonNode *node, SlonDString *ds)
+archive_append_ds(SlonNode * node, SlonDString * ds)
 {
        int                     rc;
 
@@ -5072,7 +5103,7 @@ archive_append_ds(SlonNode *node, SlonDString *ds)
  * ----------
  */
 static int
-archive_append_str(SlonNode *node, const char *s)
+archive_append_str(SlonNode * node, const char *s)
 {
        int                     rc;
 
@@ -5106,7 +5137,7 @@ archive_append_str(SlonNode *node, const char *s)
  * ----------
  */
 static int
-archive_append_data(SlonNode *node, const char *s, int len)
+archive_append_data(SlonNode * node, const char *s, int len)
 {
        int                     rc;
 
@@ -5153,11 +5184,11 @@ archive_append_data(SlonNode *node, const char *s, int len)
 
 typedef enum
 {
-               START_STATE,
-               COLLECTING_DIGITS,
-               BETWEEN_NUMBERS,
-               DONE
-} CompressState;
+       START_STATE,
+       COLLECTING_DIGITS,
+       BETWEEN_NUMBERS,
+       DONE
+}      CompressState;
 
 #define MINMAXINITIAL -1
 
@@ -5166,10 +5197,10 @@ typedef enum
  * ----------
  */
 void
-compress_actionseq(const char *ssy_actionlist, SlonDString *action_subquery)
+compress_actionseq(const char *ssy_actionlist, SlonDString * action_subquery)
 {
-       CompressState                   state;
-       int64                   curr_number,
+       CompressState state;
+       int64           curr_number,
                                curr_min,
                                curr_max;
        int                     curr_digit;
@@ -5453,42 +5484,54 @@ check_set_subscriber(int set_id, int node_id, PGconn *local_dbconn)
        return 1;
 }
 
-static void init_perfmon(PerfMon *perf_info) {
-  perf_info->prov_query_t = 0.0;
-  perf_info->prov_query_c = 0;
-  perf_info->subscr_query_t = 0.0;
-  perf_info->subscr_query_c = 0;
-  perf_info->subscr_iud__t = 0.0;
-  perf_info->subscr_iud__c = 0;
-  perf_info->large_tuples_t = 0;
-  perf_info->large_tuples_c = 0;
-  perf_info->num_inserts = 0;
-  perf_info->num_updates = 0;
-  perf_info->num_deletes = 0;
-  perf_info->num_truncates = 0;
-}
-static void start_monitored_event(PerfMon *perf_info) {
-  gettimeofday(&(perf_info->prev_t), NULL);
+static void
+init_perfmon(PerfMon * perf_info)
+{
+       perf_info->prov_query_t = 0.0;
+       perf_info->prov_query_c = 0;
+       perf_info->subscr_query_t = 0.0;
+       perf_info->subscr_query_c = 0;
+       perf_info->subscr_iud__t = 0.0;
+       perf_info->subscr_iud__c = 0;
+       perf_info->large_tuples_t = 0;
+       perf_info->large_tuples_c = 0;
+       perf_info->num_inserts = 0;
+       perf_info->num_updates = 0;
+       perf_info->num_deletes = 0;
+       perf_info->num_truncates = 0;
 }
-static void monitor_subscriber_query(PerfMon *perf_info) {
-  double diff;
-  gettimeofday(&(perf_info->now_t), NULL);
-  diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t)); 
-  (perf_info->subscr_query_t) += diff;
-  (perf_info->subscr_query_c) ++;
+static void
+start_monitored_event(PerfMon * perf_info)
+{
+       gettimeofday(&(perf_info->prev_t), NULL);
 }
-static void monitor_provider_query(PerfMon *perf_info) {
-  double diff;
-  gettimeofday(&(perf_info->now_t), NULL);
-  diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t)); 
-  (perf_info->prov_query_t) += diff;
-  (perf_info->prov_query_c) ++;
+static void
+monitor_subscriber_query(PerfMon * perf_info)
+{
+       double          diff;
+
+       gettimeofday(&(perf_info->now_t), NULL);
+       diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t));
+       (perf_info->subscr_query_t) += diff;
+       (perf_info->subscr_query_c)++;
 }
-static void monitor_subscriber_iud(PerfMon *perf_info) {
-  double diff;
-  gettimeofday(&(perf_info->now_t), NULL);
-  diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t)); 
-  (perf_info->subscr_iud__t) += diff;
-  (perf_info->subscr_iud__c) ++;
+static void
+monitor_provider_query(PerfMon * perf_info)
+{
+       double          diff;
+
+       gettimeofday(&(perf_info->now_t), NULL);
+       diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t));
+       (perf_info->prov_query_t) += diff;
+       (perf_info->prov_query_c)++;
 }
+static void
+monitor_subscriber_iud(PerfMon * perf_info)
+{
+       double          diff;
 
+       gettimeofday(&(perf_info->now_t), NULL);
+       diff = TIMEVAL_DIFF(&(perf_info->prev_t), &(perf_info->now_t));
+       (perf_info->subscr_iud__t) += diff;
+       (perf_info->subscr_iud__c)++;
+}
index 516a761e4ac2c75a6e71098151283c2a92b6dce3..566d5acb41a9bf1801d92b2932e98bc9abb76ef6 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -29,7 +29,7 @@
 
 
 /* ----------
- * Global data 
+ * Global data
  * ----------
  */
 pid_t          slon_pid;
@@ -54,7 +54,7 @@ SlonNode   *rtcfg_node_list_tail = NULL;
 
 
 /* ----------
- * Local data 
+ * Local data
  * ----------
  */
 static pthread_mutex_t config_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -73,14 +73,14 @@ static struct to_activate *to_activate_tail = NULL;
 
 
 /* ----------
- * Local functions 
+ * Local functions
  * ----------
  */
 static void rtcfg_startStopNodeThread(SlonNode * node);
 
 
 /* ----------
- * rtcfg_lock 
+ * rtcfg_lock
  * ----------
  */
 void
@@ -91,7 +91,7 @@ rtcfg_lock(void)
 
 
 /* ----------
- * rtcfg_unlock 
+ * rtcfg_unlock
  * ----------
  */
 void
@@ -102,7 +102,7 @@ rtcfg_unlock(void)
 
 
 /* ----------
- * rtcfg_storeNode 
+ * rtcfg_storeNode
  * ----------
  */
 void
@@ -164,7 +164,7 @@ rtcfg_storeNode(int no_id, char *no_comment)
  * Set the last_event field in the node runtime structure.
  *
  * Returns: 0 if the event_seq is <= the known value -1 if the node is
- * not known event_seq otherwise 
+ * not known event_seq otherwise
  * ----------
  */
 int64
@@ -200,7 +200,7 @@ rtcfg_setNodeLastEvent(int no_id, int64 event_seq)
 /* ----------
  * rtcfg_getNodeLastEvent
  *
- * Read the nodes last_event field 
+ * Read the nodes last_event field
  * ----------
  */
 int64
@@ -222,7 +222,7 @@ rtcfg_getNodeLastEvent(int no_id)
        return retval;
 }
 
+
 /* ----------
  * rtcfg_setNodeLastSnapshot()
  *
@@ -241,7 +241,7 @@ rtcfg_setNodeLastSnapshot(int no_id, char *snapshot)
        if ((node = rtcfg_findNode(no_id)) != NULL)
        {
                if (node->last_snapshot != NULL)
-                       free (node->last_snapshot);
+                       free(node->last_snapshot);
 
                node->last_snapshot = strdup(snapshot);
        }
@@ -257,7 +257,7 @@ rtcfg_setNodeLastSnapshot(int no_id, char *snapshot)
 /* ----------
  * rtcfg_getNodeLastSnapshot
  *
- * Read the nodes last_snapshot field 
+ * Read the nodes last_snapshot field
  * ----------
  */
 char *
@@ -279,9 +279,9 @@ rtcfg_getNodeLastSnapshot(int no_id)
        return retval;
 }
 
-/* ---------- 
- * rtcfg_enableNode 
+
+/* ----------
+ * rtcfg_enableNode
  * ----------
  */
 void
@@ -316,8 +316,8 @@ rtcfg_enableNode(int no_id)
 }
 
 
-/* ---------- 
- * slon_disableNode 
+/* ----------
+ * slon_disableNode
  * ----------
  */
 void
@@ -354,8 +354,8 @@ rtcfg_disableNode(int no_id)
 }
 
 
-/* ---------- 
- * rtcfg_findNode 
+/* ----------
+ * rtcfg_findNode
  * ----------
  */
 SlonNode *
@@ -373,8 +373,8 @@ rtcfg_findNode(int no_id)
 }
 
 
-/* ---------- 
- * rtcfg_storePath 
+/* ----------
+ * rtcfg_storePath
  * ----------
  */
 void
@@ -420,8 +420,8 @@ rtcfg_storePath(int pa_server, char *pa_conninfo, int pa_connretry)
 }
 
 
-/* ---------- 
- * rtcfg_dropPath 
+/* ----------
+ * rtcfg_dropPath
  * ----------
  */
 void
@@ -477,8 +477,8 @@ rtcfg_dropPath(int pa_server)
 }
 
 
-/* ---------- 
- * rtcfg_storeListen 
+/* ----------
+ * rtcfg_storeListen
  * ----------
  */
 void
@@ -526,8 +526,8 @@ rtcfg_reloadListen(PGconn *db)
        }
        for (i = 0, n = PQntuples(res); i < n; i++)
        {
-               int                     li_origin = (int)strtol(PQgetvalue(res, i, 0), NULL, 10);
-               int                     li_provider = (int)strtol(PQgetvalue(res, i, 1), NULL, 10);
+               int                     li_origin = (int) strtol(PQgetvalue(res, i, 0), NULL, 10);
+               int                     li_provider = (int) strtol(PQgetvalue(res, i, 1), NULL, 10);
 
                rtcfg_storeListen(li_origin, li_provider);
        }
@@ -542,8 +542,8 @@ rtcfg_reloadListen(PGconn *db)
 }
 
 
-/* ---------- 
- * rtcfg_storeListen 
+/* ----------
+ * rtcfg_storeListen
  * ----------
  */
 void
@@ -608,8 +608,8 @@ rtcfg_storeListen(int li_origin, int li_provider)
 }
 
 
-/* ---------- 
- * rtcfg_dropListen 
+/* ----------
+ * rtcfg_dropListen
  * ----------
  */
 void
@@ -667,8 +667,8 @@ rtcfg_dropListen(int li_origin, int li_provider)
 }
 
 
-/* ---------- 
- * rtcfg_storeSet 
+/* ----------
+ * rtcfg_storeSet
  * ----------
  */
 void
@@ -734,8 +734,8 @@ rtcfg_storeSet(int set_id, int set_origin, char *set_comment)
 }
 
 
-/* ---------- 
- * rtcfg_dropSet 
+/* ----------
+ * rtcfg_dropSet
  * ----------
  */
 void
@@ -772,8 +772,8 @@ rtcfg_dropSet(int set_id)
        rtcfg_unlock();
 }
 
-/* ---------- 
- * rtcfg_moveSet 
+/* ----------
+ * rtcfg_moveSet
  * ----------
  */
 void
@@ -824,8 +824,8 @@ rtcfg_moveSet(int set_id, int old_origin, int new_origin, int sub_provider)
 }
 
 
-/* ---------- 
- * rtcfg_storeSubscribe 
+/* ----------
+ * rtcfg_storeSubscribe
  * ----------
  */
 void
@@ -873,8 +873,8 @@ rtcfg_storeSubscribe(int sub_set, int sub_provider, char *sub_forward)
 }
 
 
-/* ---------- 
- * rtcfg_enableSubscription 
+/* ----------
+ * rtcfg_enableSubscription
  * ----------
  */
 void
@@ -919,8 +919,8 @@ rtcfg_enableSubscription(int sub_set, int sub_provider, char *sub_forward)
 }
 
 
-/* ---------- 
- * rtcfg_unsubscribeSet 
+/* ----------
+ * rtcfg_unsubscribeSet
  * ----------
  */
 void
@@ -964,8 +964,8 @@ rtcfg_unsubscribeSet(int sub_set)
 }
 
 
-/* ---------- 
- * rtcfg_startStopNodeThread 
+/* ----------
+ * rtcfg_startStopNodeThread
  * ----------
  */
 static void
@@ -985,7 +985,7 @@ rtcfg_startStopNodeThread(SlonNode * node)
                {
                        case SLON_TSTAT_NONE:
                                if (pthread_create(&(node->worker_thread), NULL,
-                                                                  remoteWorkerThread_main, (void *)node) < 0)
+                                                                remoteWorkerThread_main, (void *) node) < 0)
                                {
                                        slon_log(SLON_FATAL,
                                                         "startStopNodeThread: cannot create "
@@ -1039,7 +1039,7 @@ rtcfg_startStopNodeThread(SlonNode * node)
                        case SLON_TSTAT_NONE:
                                node->listen_status = SLON_TSTAT_RUNNING;
                                if (pthread_create(&(node->listen_thread), NULL,
-                                                                  remoteListenThread_main, (void *)node) < 0)
+                                                                remoteListenThread_main, (void *) node) < 0)
                                {
                                        slon_log(SLON_FATAL,
                                                         "startStopNodeThread: cannot create "
@@ -1110,8 +1110,8 @@ rtcfg_startStopNodeThread(SlonNode * node)
 }
 
 
-/* ---------- 
- * rtcfg_needActivate 
+/* ----------
+ * rtcfg_needActivate
  * ----------
  */
 void
@@ -1130,8 +1130,8 @@ rtcfg_needActivate(int no_id)
 }
 
 
-/* ---------- 
- * rtcfg_doActivate 
+/* ----------
+ * rtcfg_doActivate
  * ----------
  */
 void
@@ -1148,8 +1148,8 @@ rtcfg_doActivate(void)
 }
 
 
-/* ---------- 
- * rtcfg_joinAllRemoteThreads 
+/* ----------
+ * rtcfg_joinAllRemoteThreads
  * ----------
  */
 void
@@ -1207,8 +1207,8 @@ rtcfg_joinAllRemoteThreads(void)
 }
 
 
-/* ---------- 
- * rtcfg_seq_bump 
+/* ----------
+ * rtcfg_seq_bump
  * ----------
  */
 void
@@ -1220,8 +1220,8 @@ rtcfg_seq_bump(void)
 }
 
 
-/* ---------- 
- * rtcfg_seq_get 
+/* ----------
+ * rtcfg_seq_get
  * ----------
  */
 int64
index 61283bfb55f8fb1174f78b83251ca3c3fd4129f1..16e3644c3edce1b6d9a2058019cfcaa0dffcb542 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  * ----------------------------------------------------------------------
  */
 
 #define PF_LOCAL PF_UNIX
 #endif
 
-/* ---------- 
- * Static data 
+/* ----------
+ * Static data
  * ----------
  */
-static ScheduleStatus  sched_status = SCHED_STATUS_OK;
+static ScheduleStatus sched_status = SCHED_STATUS_OK;
 
 static int     sched_numfd = 0;
 static fd_set sched_fdset_read;
@@ -56,12 +56,13 @@ static pthread_cond_t sched_master_cond;
 
 
 /* ----------
- * Local functions 
+ * Local functions
  * ----------
  */
-static void *sched_mainloop(void* );
-static void sched_add_fdset(int fd, fd_set * fds);
-static void sched_remove_fdset(int fd, fd_set * fds);
+static void *sched_mainloop(void *);
+static void sched_add_fdset(int fd, fd_set *fds);
+static void sched_remove_fdset(int fd, fd_set *fds);
+
 /* static void sched_shutdown(); */
 
 
@@ -71,11 +72,11 @@ static void sched_remove_fdset(int fd, fd_set * fds);
  * Called from SlonMain() before starting up any worker thread.
  *
  * This will spawn the event scheduling thread that does the central select(2)
- * system call. 
+ * system call.
  * ----------
  */
 int
-sched_start_mainloop(void )
+sched_start_mainloop(void)
 {
        sched_status = SCHED_STATUS_OK;
        sched_waitqueue_head = NULL;
@@ -163,7 +164,7 @@ sched_start_mainloop(void )
  *
  * Called from main() after all working threads according to the initial
  * configuration are started. Will wait until the scheduler mainloop
- * terminates. 
+ * terminates.
  * ----------
  */
 int
@@ -187,14 +188,15 @@ sched_wait_mainloop(void)
  * Assumes that the thread holds the lock on conn->conn_lock.
  *
  * Adds the connection to the central wait queue and wakes up the scheduler
- * thread to reloop onto the select(2) call. 
+ * thread to reloop onto the select(2) call.
  * ----------
  */
 int
 sched_wait_conn(SlonConn * conn, int condition)
 {
-       ScheduleStatus                  rc;
-       int                     fds;
+       ScheduleStatus rc;
+       int                     fds;
+
        /*
         * Grab the master lock and check that we're in normal runmode
         */
@@ -256,7 +258,7 @@ sched_wait_conn(SlonConn * conn, int condition)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_wait_time
  *
  * Assumes that the thread holds the lock on conn->conn_lock.
@@ -274,7 +276,7 @@ sched_wait_time(SlonConn * conn, int condition, int msec)
         * Calculate the end-time of the desired timeout.
         */
        gettimeofday(tv, NULL);
-       tv->tv_sec += (long)(msec / 1000) +
+       tv->tv_sec += (long) (msec / 1000) +
                (((msec % 1000) * 1000) + tv->tv_usec) / 1000000;
        tv->tv_usec = (tv->tv_usec + (msec % 1000) * 1000) % 1000000;
 
@@ -285,10 +287,10 @@ sched_wait_time(SlonConn * conn, int condition, int msec)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_msleep
  *
- * Use the schedulers event loop to sleep for msec milliseconds. 
+ * Use the schedulers event loop to sleep for msec milliseconds.
  * ----------
  */
 int
@@ -313,16 +315,16 @@ sched_msleep(SlonNode * node, int msec)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_get_status
  *
- * Return the current scheduler status in a thread safe fashion 
+ * Return the current scheduler status in a thread safe fashion
  * ----------
  */
 int
 sched_get_status(void)
 {
-       ScheduleStatus                  status;
+       ScheduleStatus status;
 
        pthread_mutex_lock(&sched_master_lock);
        status = sched_status;
@@ -331,12 +333,12 @@ sched_get_status(void)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_wakeup_node
  *
  * Wakeup the threads (listen and worker) of one or all remote nodes to cause
  * them rechecking the current runtime status or adjust their configuration
- * to changes. 
+ * to changes.
  * ----------
  */
 int
@@ -384,14 +386,14 @@ sched_wakeup_node(int no_id)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_mainloop
  *
- * The thread handling the master scheduling. 
+ * The thread handling the master scheduling.
  * ----------
  */
 static void *
-sched_mainloop(void * dummy)
+sched_mainloop(void *dummy)
 {
        fd_set          rfds;
        fd_set          wfds;
@@ -579,11 +581,12 @@ sched_mainloop(void * dummy)
                conn = sched_waitqueue_head;
                while (rc > 0 && conn)
                {
-                       int fd_check = PQsocket(conn->dbconn);
+                       int                     fd_check = PQsocket(conn->dbconn);
+
                        if (conn->condition & SCHED_WAIT_SOCK_READ)
                        {
 
-                               
+
                                if (fd_check >= 0 && FD_ISSET(fd_check, &rfds))
                                {
                                        next = conn->next;
@@ -680,17 +683,17 @@ sched_mainloop(void * dummy)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_add_fdset
  *
  * Add a file descriptor to one of the global scheduler sets and adjust
- * sched_numfd accordingly. 
+ * sched_numfd accordingly.
  * ----------
  */
 static void
-sched_add_fdset(int fd, fd_set * fds)
+sched_add_fdset(int fd, fd_set *fds)
 {
-       if( fd >= 0 && fds != NULL )
+       if (fd >= 0 && fds != NULL)
        {
                FD_SET(fd, fds);
                if (fd >= sched_numfd)
@@ -699,17 +702,17 @@ sched_add_fdset(int fd, fd_set * fds)
 }
 
 
-/* ---------- 
+/* ----------
  * sched_add_fdset
  *
  * Remove a file descriptor from one of the global scheduler sets and adjust
- * sched_numfd accordingly. 
+ * sched_numfd accordingly.
  * ----------
  */
 static void
-sched_remove_fdset(int fd, fd_set * fds)
+sched_remove_fdset(int fd, fd_set *fds)
 {
-       if(fd >= 0)
+       if (fd >= 0)
        {
                FD_CLR(fd, fds);
                if (sched_numfd == (fd + 1))
@@ -725,5 +728,3 @@ sched_remove_fdset(int fd, fd_set * fds)
                }
        }
 }
-
-
index 5edb243d7f401115c6268d316d5f615931c9e7e4..78b46e7dbfab0f5a8df89cbd247d0e804a60c87c 100644 (file)
 #define                SLON_WATCHDOG_RESTART           1
 #define                SLON_WATCHDOG_RETRY                     2
 #define                SLON_WATCHDOG_SHUTDOWN          3
-static int                     watchdog_status = SLON_WATCHDOG_NORMAL;
+static int     watchdog_status = SLON_WATCHDOG_NORMAL;
 #endif
 int                    sched_wakeuppipe[2];
 
 pthread_mutex_t slon_wait_listen_lock;
 pthread_cond_t slon_wait_listen_cond;
-int            slon_listen_started=0;
+int                    slon_listen_started = 0;
 bool           monitor_threads;
 
 int                    apply_cache_size;
@@ -74,28 +74,28 @@ static pthread_t local_sync_thread;
 static pthread_t local_monitor_thread;
 
 static pthread_t main_thread;
-static char *const *main_argv;
+static char *const * main_argv;
 
 static void SlonMain(void);
 
 #ifndef WIN32
 static void SlonWatchdog(void);
 static void sighandler(int signo);
-void slon_terminate_worker(void);
+void           slon_terminate_worker(void);
 #endif
-typedef void (*sighandler_t)(int);
-static sighandler_t install_signal_handler(int signum, sighandler_t  handler);
+typedef void (*sighandler_t) (int);
+static sighandler_t install_signal_handler(int signum, sighandler_t handler);
 
 int                    slon_log_level;
-char       *pid_file;
-char       *archive_dir = NULL;
-static int                     child_status;
+char      *pid_file;
+char      *archive_dir = NULL;
+static int     child_status;
 
 /**
  * A variable to indicate that the
  * worker has been restarted by the watchdog.
  */
-int worker_restarted=0;
+int                    worker_restarted = 0;
 
 /* ----------
  * Usage
@@ -104,34 +104,34 @@ int worker_restarted=0;
 void
 Usage(char *const argv[])
 {
-    fprintf(stderr, "usage: %s [options] clustername conninfo\n", argv[0]);
-    fprintf(stderr, "\n");
-    fprintf(stderr, "Options:\n");
-
-    fprintf(stderr, "    -h                    print usage message and exit\n");
-    fprintf(stderr, "    -v                    print version and exit\n");
-    fprintf(stderr, "    -d <debuglevel>       verbosity of logging (1..4)\n");
-    fprintf(stderr, "    -s <milliseconds>     SYNC check interval (default 10000)\n");
-    fprintf(stderr, "    -t <milliseconds>     SYNC interval timeout (default 60000)\n");
-    fprintf(stderr, "    -o <milliseconds>     desired subscriber SYNC processing time\n");
-    fprintf(stderr, "    -g <num>              maximum SYNC group size (default 6)\n");
-    fprintf(stderr, "    -c <num>              how often to vacuum in cleanup cycles\n");
-    fprintf(stderr, "    -p <filename>         slon pid file\n");
-    fprintf(stderr, "    -f <filename>         slon configuration file\n");
-    fprintf(stderr, "    -a <directory>        directory to store SYNC archive files\n");
-    fprintf(stderr, "    -x <command>          program to run after writing archive file\n");
-    fprintf(stderr, "    -q <num>              Terminate when this node reaches # of SYNCs\n");
-    fprintf(stderr, "    -r <num>              # of syncs for -q option\n");
-    fprintf(stderr, "    -l <interval>         this node should lag providers by this interval\n");
+       fprintf(stderr, "usage: %s [options] clustername conninfo\n", argv[0]);
+       fprintf(stderr, "\n");
+       fprintf(stderr, "Options:\n");
+
+       fprintf(stderr, "    -h                    print usage message and exit\n");
+       fprintf(stderr, "    -v                    print version and exit\n");
+       fprintf(stderr, "    -d <debuglevel>       verbosity of logging (1..4)\n");
+       fprintf(stderr, "    -s <milliseconds>     SYNC check interval (default 10000)\n");
+       fprintf(stderr, "    -t <milliseconds>     SYNC interval timeout (default 60000)\n");
+       fprintf(stderr, "    -o <milliseconds>     desired subscriber SYNC processing time\n");
+       fprintf(stderr, "    -g <num>              maximum SYNC group size (default 6)\n");
+       fprintf(stderr, "    -c <num>              how often to vacuum in cleanup cycles\n");
+       fprintf(stderr, "    -p <filename>         slon pid file\n");
+       fprintf(stderr, "    -f <filename>         slon configuration file\n");
+       fprintf(stderr, "    -a <directory>        directory to store SYNC archive files\n");
+       fprintf(stderr, "    -x <command>          program to run after writing archive file\n");
+       fprintf(stderr, "    -q <num>              Terminate when this node reaches # of SYNCs\n");
+       fprintf(stderr, "    -r <num>              # of syncs for -q option\n");
+       fprintf(stderr, "    -l <interval>         this node should lag providers by this interval\n");
 #ifdef WIN32
-    fprintf(stderr, "\nWindows service registration:\n");
-    fprintf(stderr, " slon -regservice [servicename]\n");
-    fprintf(stderr, " slon -unregservice [servicename]\n");
-    fprintf(stderr, " slon -listengines [servicename]\n");
-    fprintf(stderr, " slon -addengine [servicename] <configfile>\n");
-    fprintf(stderr, " slon -delengine [servicename] <configfile>\n");
+       fprintf(stderr, "\nWindows service registration:\n");
+       fprintf(stderr, " slon -regservice [servicename]\n");
+       fprintf(stderr, " slon -unregservice [servicename]\n");
+       fprintf(stderr, " slon -listengines [servicename]\n");
+       fprintf(stderr, " slon -addengine [servicename] <configfile>\n");
+       fprintf(stderr, " slon -delengine [servicename] <configfile>\n");
 #endif
-    exit(1);
+       exit(1);
 }
 
 
@@ -142,246 +142,246 @@ Usage(char *const argv[])
 int
 main(int argc, char *const argv[])
 {
-    char       *cp1;
-    char       *cp2;
-    int                        c;
-    int                        errors = 0;
-    extern int optind;
-    extern char *optarg;
+       char       *cp1;
+       char       *cp2;
+       int                     c;
+       int                     errors = 0;
+       extern int      optind;
+       extern char *optarg;
 
 
 #ifdef WIN32
-    WSADATA            wsaData;
-    int                        err;
+       WSADATA         wsaData;
+       int                     err;
 #endif
 
 
 #ifdef WIN32
-    if (argc >= 2 && !strcmp(argv[1], "-service"))
-    {
-        win32_servicestart();
-        exit(0);
-    }
-    if (argc >= 2 && !strcmp(argv[1], "-subservice"))
-    {
-        win32_isservice = 1;
-        argc--;
-        argv++;
-    }
-    if (argc >= 2 && argc <= 4 && (
-                                   !strcmp(argv[1], "-regservice") ||
-                                   !strcmp(argv[1], "-unregservice") ||
-                                   !strcmp(argv[1], "-addengine") ||
-                                   !strcmp(argv[1], "-delengine") ||
-                                   !strcmp(argv[1], "-listengines")))
-    {
-        win32_serviceconfig(argc, argv);
-    }
+       if (argc >= 2 && !strcmp(argv[1], "-service"))
+       {
+               win32_servicestart();
+               exit(0);
+       }
+       if (argc >= 2 && !strcmp(argv[1], "-subservice"))
+       {
+               win32_isservice = 1;
+               argc--;
+               argv++;
+       }
+       if (argc >= 2 && argc <= 4 && (
+                                                                  !strcmp(argv[1], "-regservice") ||
+                                                                  !strcmp(argv[1], "-unregservice") ||
+                                                                  !strcmp(argv[1], "-addengine") ||
+                                                                  !strcmp(argv[1], "-delengine") ||
+                                                                  !strcmp(argv[1], "-listengines")))
+       {
+               win32_serviceconfig(argc, argv);
+       }
 #endif
 
-    InitializeConfOptions();
-
-    while ((c = getopt(argc, argv, "f:a:d:s:t:g:c:p:o:q:r:l:x:hv?")) != EOF)
-    {
-        switch (c)
-        {
-            case '?':
-                Usage(argv);
-            case 'q':
-                set_config_option("quit_sync_provider", optarg);
-                break;
-
-            case 'r':
-                set_config_option("quit_sync_finalsync", optarg);
-                break;
-
-            case 'f':
-                ProcessConfigFile(optarg);
-                break;
-
-            case 'a':
-                set_config_option("archive_dir", optarg);
-                break;
-
-            case 'd':
-                set_config_option("log_level", optarg);
-                break;
-
-            case 's':
-                set_config_option("sync_interval", optarg);
-                break;
-
-            case 't':
-                set_config_option("sync_interval_timeout", optarg);
-                break;
-
-            case 'g':
-                set_config_option("sync_group_maxsize", optarg);
-                break;
-
-            case 'c':
-                set_config_option("vac_frequency", optarg);
-                break;
-
-            case 'p':
-                set_config_option("pid_file", optarg);
-                break;
-
-            case 'o':
-                set_config_option("desired_sync_time", optarg);
-                break;
-
-            case 'l':
-                set_config_option("lag_interval", optarg);
-                break;
-
-            case 'h':
-                errors++;
-                break;
-
-            case 'v':
-                printf("slon version %s\n", SLONY_I_VERSION_STRING);
-                exit(0);
-                break;
-
-            case 'x':
-                set_config_option("command_on_logarchive", optarg);
-                break;
-
-            default:
-                fprintf(stderr, "unknown option '%c'\n", c);
-                errors++;
-                break;
-        }
-    }
-
-    /*
-     * Make sure the sync interval timeout isn't too small.
-     */
-    if (sync_interval_timeout != 0 && sync_interval_timeout <= sync_interval)
-        sync_interval_timeout = sync_interval * 2;
-
-    /*
-     * Remember the cluster name and build the properly quoted namespace
-     * identifier
-     */
-    slon_pid = getpid();
+       InitializeConfOptions();
+
+       while ((c = getopt(argc, argv, "f:a:d:s:t:g:c:p:o:q:r:l:x:hv?")) != EOF)
+       {
+               switch (c)
+               {
+                       case '?':
+                               Usage(argv);
+                       case 'q':
+                               set_config_option("quit_sync_provider", optarg);
+                               break;
+
+                       case 'r':
+                               set_config_option("quit_sync_finalsync", optarg);
+                               break;
+
+                       case 'f':
+                               ProcessConfigFile(optarg);
+                               break;
+
+                       case 'a':
+                               set_config_option("archive_dir", optarg);
+                               break;
+
+                       case 'd':
+                               set_config_option("log_level", optarg);
+                               break;
+
+                       case 's':
+                               set_config_option("sync_interval", optarg);
+                               break;
+
+                       case 't':
+                               set_config_option("sync_interval_timeout", optarg);
+                               break;
+
+                       case 'g':
+                               set_config_option("sync_group_maxsize", optarg);
+                               break;
+
+                       case 'c':
+                               set_config_option("vac_frequency", optarg);
+                               break;
+
+                       case 'p':
+                               set_config_option("pid_file", optarg);
+                               break;
+
+                       case 'o':
+                               set_config_option("desired_sync_time", optarg);
+                               break;
+
+                       case 'l':
+                               set_config_option("lag_interval", optarg);
+                               break;
+
+                       case 'h':
+                               errors++;
+                               break;
+
+                       case 'v':
+                               printf("slon version %s\n", SLONY_I_VERSION_STRING);
+                               exit(0);
+                               break;
+
+                       case 'x':
+                               set_config_option("command_on_logarchive", optarg);
+                               break;
+
+                       default:
+                               fprintf(stderr, "unknown option '%c'\n", c);
+                               errors++;
+                               break;
+               }
+       }
+
+       /*
+        * Make sure the sync interval timeout isn't too small.
+        */
+       if (sync_interval_timeout != 0 && sync_interval_timeout <= sync_interval)
+               sync_interval_timeout = sync_interval * 2;
+
+       /*
+        * Remember the cluster name and build the properly quoted namespace
+        * identifier
+        */
+       slon_pid = getpid();
 #ifndef WIN32
-    if (pthread_mutex_init(&slon_watchdog_lock, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "slon: pthread_mutex_init() - %s\n",
-                 strerror(errno));
-        exit(-1);
-    }
-    slon_watchdog_pid = slon_pid;
-    slon_worker_pid = -1;
+       if (pthread_mutex_init(&slon_watchdog_lock, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "slon: pthread_mutex_init() - %s\n",
+                                strerror(errno));
+               exit(-1);
+       }
+       slon_watchdog_pid = slon_pid;
+       slon_worker_pid = -1;
 #endif
-    main_argv = argv;
-
-    if ((char *)argv[optind])
-    {
-        set_config_option("cluster_name", (char *)argv[optind]);
-        set_config_option("conn_info", (char *)argv[++optind]);
-    }
-
-    if (rtcfg_cluster_name != NULL)
-    {
-        rtcfg_namespace = malloc(strlen(rtcfg_cluster_name) * 2 + 4);
-        cp2 = rtcfg_namespace;
-        *cp2++ = '"';
-        *cp2++ = '_';
-        for (cp1 = (char *)rtcfg_cluster_name; *cp1; cp1++)
-        {
-            if (*cp1 == '"')
-                *cp2++ = '"';
-            *cp2++ = *cp1;
-        }
-        *cp2++ = '"';
-        *cp2 = '\0';
-    }
-    else
-    {
-        errors++;
-    }
-
-    slon_log(SLON_CONFIG, "main: slon version %s starting up\n",
-             SLONY_I_VERSION_STRING);
-
-    /*
-     * Remember the connection information for the local node.
-     */
-    if (rtcfg_conninfo == NULL)
-    {
-        errors++;
-    }
-
-    if (errors != 0)
-    {
-        Usage(argv);
-    }
+       main_argv = argv;
+
+       if ((char *) argv[optind])
+       {
+               set_config_option("cluster_name", (char *) argv[optind]);
+               set_config_option("conn_info", (char *) argv[++optind]);
+       }
+
+       if (rtcfg_cluster_name != NULL)
+       {
+               rtcfg_namespace = malloc(strlen(rtcfg_cluster_name) * 2 + 4);
+               cp2 = rtcfg_namespace;
+               *cp2++ = '"';
+               *cp2++ = '_';
+               for (cp1 = (char *) rtcfg_cluster_name; *cp1; cp1++)
+               {
+                       if (*cp1 == '"')
+                               *cp2++ = '"';
+                       *cp2++ = *cp1;
+               }
+               *cp2++ = '"';
+               *cp2 = '\0';
+       }
+       else
+       {
+               errors++;
+       }
+
+       slon_log(SLON_CONFIG, "main: slon version %s starting up\n",
+                        SLONY_I_VERSION_STRING);
+
+       /*
+        * Remember the connection information for the local node.
+        */
+       if (rtcfg_conninfo == NULL)
+       {
+               errors++;
+       }
+
+       if (errors != 0)
+       {
+               Usage(argv);
+       }
 
 #ifdef WIN32
 
-    /*
-     * Startup the network subsystem, in case our libpq doesn't
-     */
-    err = WSAStartup(MAKEWORD(1, 1), &wsaData);
-    if (err != 0)
-    {
-        slon_log(SLON_FATAL, "main: Cannot start the network subsystem - %d\n", err);
-        exit(-1);
-    }
+       /*
+        * Startup the network subsystem, in case our libpq doesn't
+        */
+       err = WSAStartup(MAKEWORD(1, 1), &wsaData);
+       if (err != 0)
+       {
+               slon_log(SLON_FATAL, "main: Cannot start the network subsystem - %d\n", err);
+               exit(-1);
+       }
 #endif
 
-    if (pid_file)
-    {
-        FILE       *pidfile;
-
-        pidfile = fopen(pid_file, "w");
-        if (pidfile)
-        {
-            fprintf(pidfile, "%d\n", slon_pid);
-            fclose(pidfile);
-        }
-        else
-        {
-            slon_log(SLON_FATAL, "Cannot open pid_file \"%s\"\n", pid_file);
-            exit(-1);
-        }
-    }
-
-    /*
-     * Create the pipe used to kick the workers scheduler thread
-     */
-    if (pgpipe(sched_wakeuppipe) < 0)
-    {
-        slon_log(SLON_FATAL, "slon: sched_wakeuppipe create failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-
-    if (!PQisthreadsafe())
-    {
-        slon_log(SLON_FATAL,"slon: libpq was not compiled with thread safety enabled (normally: --enable-thread-safety).  slon is a multithreaded application requiring thread-safe libpq\n");
-        slon_exit(-1);
-    }
-
-    if (!PQisthreadsafe())
-    {
-        slon_log(SLON_FATAL,"slon: libpq was not compiled with --enable-thread-safety. Slony-I requires a thread enabled libpq\n");
-        slon_exit(-1);
-    }
-
-    /*
-     * There is no watchdog process on win32. We delegate restarting and other
-     * such tasks to the Service Control Manager. And win32 doesn't support
-     * signals, so we don't need to catch them...
-     */
+       if (pid_file)
+       {
+               FILE       *pidfile;
+
+               pidfile = fopen(pid_file, "w");
+               if (pidfile)
+               {
+                       fprintf(pidfile, "%d\n", slon_pid);
+                       fclose(pidfile);
+               }
+               else
+               {
+                       slon_log(SLON_FATAL, "Cannot open pid_file \"%s\"\n", pid_file);
+                       exit(-1);
+               }
+       }
+
+       /*
+        * Create the pipe used to kick the workers scheduler thread
+        */
+       if (pgpipe(sched_wakeuppipe) < 0)
+       {
+               slon_log(SLON_FATAL, "slon: sched_wakeuppipe create failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+
+       if (!PQisthreadsafe())
+       {
+               slon_log(SLON_FATAL, "slon: libpq was not compiled with thread safety enabled (normally: --enable-thread-safety).  slon is a multithreaded application requiring thread-safe libpq\n");
+               slon_exit(-1);
+       }
+
+       if (!PQisthreadsafe())
+       {
+               slon_log(SLON_FATAL, "slon: libpq was not compiled with --enable-thread-safety. Slony-I requires a thread enabled libpq\n");
+               slon_exit(-1);
+       }
+
+       /*
+        * There is no watchdog process on win32. We delegate restarting and other
+        * such tasks to the Service Control Manager. And win32 doesn't support
+        * signals, so we don't need to catch them...
+        */
 #ifndef WIN32
-    SlonWatchdog();
+       SlonWatchdog();
 #else
-    SlonMain();
+       SlonMain();
 #endif
-    exit(0);
+       exit(0);
 }
 
 
@@ -392,412 +392,419 @@ main(int argc, char *const argv[])
 static void
 SlonMain(void)
 {
-    PGresult   *res;
-    SlonDString query;
-    int                        i,
-                n;
-    PGconn     *startup_conn;
+       PGresult   *res;
+       SlonDString query;
+       int                     i,
+                               n;
+       PGconn     *startup_conn;
 
-    slon_pid = getpid();
+       slon_pid = getpid();
 #ifndef WIN32
-    slon_worker_pid = slon_pid;
+       slon_worker_pid = slon_pid;
 #endif
 
-    if (pthread_mutex_init(&slon_wait_listen_lock, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "main: pthread_mutex_init() failed - %s\n",
-                 strerror(errno));
-        slon_abort();
-    }
-    if (pthread_cond_init(&slon_wait_listen_cond, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "main: pthread_cond_init() failed - %s\n",
-                 strerror(errno));
-        slon_abort();
-    }
-
-
-    /*
-     * Dump out current configuration - all elements of the various arrays...
-     */
-    dump_configuration();
-    /*
-     * Connect to the local database to read the initial configuration
-     */
-    startup_conn = PQconnectdb(rtcfg_conninfo);
-    if (startup_conn == NULL)
-    {
-        slon_log(SLON_FATAL, "main: PQconnectdb() failed - sleep 10s\n");
-        sleep (10);
-        slon_retry();
-        exit(-1);
-    }
-    if (PQstatus(startup_conn) != CONNECTION_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot connect to local database - %s - sleep 10s\n",
-                 PQerrorMessage(startup_conn));
-        PQfinish(startup_conn);
-        sleep(10);
-        slon_retry();
-        exit(-1);
-    }
-
-    /*
-     * Get our local node ID
-     */
-    rtcfg_nodeid = db_getLocalNodeId(startup_conn);
-    if (rtcfg_nodeid < 0)
-    {
-        slon_log(SLON_FATAL, "main: Node is not initialized properly - sleep 10s\n");
-        sleep(10);
-        slon_retry();
-        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_abort();
-    }
-    slon_log(SLON_CONFIG, "main: local node id = %d\n", rtcfg_nodeid);
-
-    dstring_init(&query);
-    slon_mkquery(&query, "select %s.slon_node_health_check();", rtcfg_namespace);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "could not call slon_node_health_check() - %",
-                 PQresultErrorMessage(res));
-        slon_abort();
-    } else {
-        if (PQntuples(res) != 1)
-        {
-                slon_log(SLON_FATAL,
-                         "query '%s' returned %d rows (expected 1)\n",
-                         query, PQntuples(res));
-                slon_abort();
-        } else {
-                if (*(PQgetvalue(res, 0, 0)) == 'f') {
-                        slon_log(SLON_FATAL,
-                                 "slon_node_health_check() returned false - fatal health problem!\n%s\nREPAIR CONFIG may be helpful to rectify this problem\n",
-                                 PQresultErrorMessage(res));
-                        slon_abort();
-                }
-        }
-    }
-    PQclear(res);
-    dstring_free(&query);
+       if (pthread_mutex_init(&slon_wait_listen_lock, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "main: pthread_mutex_init() failed - %s\n",
+                                strerror(errno));
+               slon_abort();
+       }
+       if (pthread_cond_init(&slon_wait_listen_cond, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "main: pthread_cond_init() failed - %s\n",
+                                strerror(errno));
+               slon_abort();
+       }
+
+
+       /*
+        * Dump out current configuration - all elements of the various arrays...
+        */
+       dump_configuration();
+
+       /*
+        * Connect to the local database to read the initial configuration
+        */
+       startup_conn = PQconnectdb(rtcfg_conninfo);
+       if (startup_conn == NULL)
+       {
+               slon_log(SLON_FATAL, "main: PQconnectdb() failed - sleep 10s\n");
+               sleep(10);
+               slon_retry();
+               exit(-1);
+       }
+       if (PQstatus(startup_conn) != CONNECTION_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot connect to local database - %s - sleep 10s\n",
+                                PQerrorMessage(startup_conn));
+               PQfinish(startup_conn);
+               sleep(10);
+               slon_retry();
+               exit(-1);
+       }
+
+       /*
+        * Get our local node ID
+        */
+       rtcfg_nodeid = db_getLocalNodeId(startup_conn);
+       if (rtcfg_nodeid < 0)
+       {
+               slon_log(SLON_FATAL, "main: Node is not initialized properly - sleep 10s\n");
+               sleep(10);
+               slon_retry();
+               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_abort();
+       }
+       slon_log(SLON_CONFIG, "main: local node id = %d\n", rtcfg_nodeid);
+
+       dstring_init(&query);
+       slon_mkquery(&query, "select %s.slon_node_health_check();", rtcfg_namespace);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "could not call slon_node_health_check() - %",
+                                PQresultErrorMessage(res));
+               slon_abort();
+       }
+       else
+       {
+               if (PQntuples(res) != 1)
+               {
+                       slon_log(SLON_FATAL,
+                                        "query '%s' returned %d rows (expected 1)\n",
+                                        query, PQntuples(res));
+                       slon_abort();
+               }
+               else
+               {
+                       if (*(PQgetvalue(res, 0, 0)) == 'f')
+                       {
+                               slon_log(SLON_FATAL,
+                                                "slon_node_health_check() returned false - fatal health problem!\n%s\nREPAIR CONFIG may be helpful to rectify this problem\n",
+                                                PQresultErrorMessage(res));
+                               slon_abort();
+                       }
+               }
+       }
+       PQclear(res);
+       dstring_free(&query);
 
 #ifndef WIN32
-    if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "main: SIGHUP signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_abort();
-    }
-    if (signal(SIGINT, SIG_IGN) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "main: SIGINT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_abort();
-    }
-    if (signal(SIGTERM, SIG_IGN) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "main: SIGTERM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_abort();
-    }
-    if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "main: SIGCHLD signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_abort();
-    }
-    if (signal(SIGQUIT, SIG_IGN) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "main: SIGQUIT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_abort();
-    }
+       if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "main: SIGHUP signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_abort();
+       }
+       if (signal(SIGINT, SIG_IGN) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "main: SIGINT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_abort();
+       }
+       if (signal(SIGTERM, SIG_IGN) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "main: SIGTERM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_abort();
+       }
+       if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "main: SIGCHLD signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_abort();
+       }
+       if (signal(SIGQUIT, SIG_IGN) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "main: SIGQUIT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_abort();
+       }
 #endif
 
-    slon_log(SLON_INFO, "main: main process started\n");
-
-    /*
-     * Start the event scheduling system
-     */
-    slon_log(SLON_CONFIG, "main: launching sched_start_mainloop\n");
-    if (sched_start_mainloop() < 0)
-        slon_retry();
-
-    slon_log(SLON_CONFIG, "main: loading current cluster configuration\n");
-
-    /*
-     * Begin a transaction
-     */
-    res = PQexec(startup_conn,
-                 "start transaction; "
-                 "set transaction isolation level serializable;");
-    if (PQresultStatus(res) != PGRES_COMMAND_OK)
-    {
-        slon_log(SLON_FATAL, "Cannot start transaction - %s - sleep 10s\n",
-                 PQresultErrorMessage(res));
-        sleep (10);
-        PQclear(res);
-        slon_retry();
-    }
-    PQclear(res);
-
-    /*
-     * Read configuration table sl_node
-     */
-    dstring_init(&query);
-    slon_mkquery(&query,
-                 "select no_id, no_active, no_comment, "
-                 "    (select coalesce(max(con_seqno),0) from %s.sl_confirm "
-                 "        where con_origin = no_id and con_received = %d) "
-                 "        as last_event, "
+       slon_log(SLON_INFO, "main: main process started\n");
+
+       /*
+        * Start the event scheduling system
+        */
+       slon_log(SLON_CONFIG, "main: launching sched_start_mainloop\n");
+       if (sched_start_mainloop() < 0)
+               slon_retry();
+
+       slon_log(SLON_CONFIG, "main: loading current cluster configuration\n");
+
+       /*
+        * Begin a transaction
+        */
+       res = PQexec(startup_conn,
+                                "start transaction; "
+                                "set transaction isolation level serializable;");
+       if (PQresultStatus(res) != PGRES_COMMAND_OK)
+       {
+               slon_log(SLON_FATAL, "Cannot start transaction - %s - sleep 10s\n",
+                                PQresultErrorMessage(res));
+               sleep(10);
+               PQclear(res);
+               slon_retry();
+       }
+       PQclear(res);
+
+       /*
+        * Read configuration table sl_node
+        */
+       dstring_init(&query);
+       slon_mkquery(&query,
+                                "select no_id, no_active, no_comment, "
+                                "    (select coalesce(max(con_seqno),0) from %s.sl_confirm "
+                                "        where con_origin = no_id and con_received = %d) "
+                                "        as last_event, "
                                 "    (select ev_snapshot from %s.sl_event "
                                 "        where ev_origin = no_id "
                                 "        and ev_seqno = (select max(ev_seqno) "
                                 "                    from %s.sl_event "
                                 "                    where ev_origin = no_id "
-                                "                    and ev_type = 'SYNC')) as last_snapshot "
-                 "from %s.sl_node "
-                 "order by no_id; ",
-                 rtcfg_namespace, rtcfg_nodeid, 
+                          "                    and ev_type = 'SYNC')) as last_snapshot "
+                                "from %s.sl_node "
+                                "order by no_id; ",
+                                rtcfg_namespace, rtcfg_nodeid,
                                 rtcfg_namespace, rtcfg_namespace,
                                 rtcfg_namespace);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot get node list - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        dstring_free(&query);
-        slon_retry();
-    }
-    for (i = 0, n = PQntuples(res); i < n; i++)
-    {
-        int                    no_id = (int)strtol(PQgetvalue(res, i, 0), NULL, 10);
-        int                    no_active = (*PQgetvalue(res, i, 1) == 't') ? 1 : 0;
-        char       *no_comment = PQgetvalue(res, i, 2);
-        int64          last_event;
-
-        if (no_id == rtcfg_nodeid)
-        {
-            /*
-             * Complete our own local node entry
-             */
-            rtcfg_nodeactive = no_active;
-            rtcfg_nodecomment = strdup(no_comment);
-        }
-        else
-        {
-            /*
-             * Add a remote node
-             */
-            slon_scanint64(PQgetvalue(res, i, 3), &last_event);
-            rtcfg_storeNode(no_id, no_comment);
-            rtcfg_setNodeLastEvent(no_id, last_event);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot get node list - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               dstring_free(&query);
+               slon_retry();
+       }
+       for (i = 0, n = PQntuples(res); i < n; i++)
+       {
+               int                     no_id = (int) strtol(PQgetvalue(res, i, 0), NULL, 10);
+               int                     no_active = (*PQgetvalue(res, i, 1) == 't') ? 1 : 0;
+               char       *no_comment = PQgetvalue(res, i, 2);
+               int64           last_event;
+
+               if (no_id == rtcfg_nodeid)
+               {
+                       /*
+                        * Complete our own local node entry
+                        */
+                       rtcfg_nodeactive = no_active;
+                       rtcfg_nodecomment = strdup(no_comment);
+               }
+               else
+               {
+                       /*
+                        * Add a remote node
+                        */
+                       slon_scanint64(PQgetvalue(res, i, 3), &last_event);
+                       rtcfg_storeNode(no_id, no_comment);
+                       rtcfg_setNodeLastEvent(no_id, last_event);
                        rtcfg_setNodeLastSnapshot(no_id, PQgetvalue(res, i, 4));
 
-            /*
-             * If it is active, remember for activation just before we start
-             * processing events.
-             */
-            if (no_active)
-                rtcfg_needActivate(no_id);
-        }
-    }
-    PQclear(res);
-
-    /*
-     * Read configuration table sl_path - the interesting pieces
-     */
-    slon_mkquery(&query,
-                 "select pa_server, pa_conninfo, pa_connretry "
-                 "from %s.sl_path where pa_client = %d"
+                       /*
+                        * If it is active, remember for activation just before we start
+                        * processing events.
+                        */
+                       if (no_active)
+                               rtcfg_needActivate(no_id);
+               }
+       }
+       PQclear(res);
+
+       /*
+        * Read configuration table sl_path - the interesting pieces
+        */
+       slon_mkquery(&query,
+                                "select pa_server, pa_conninfo, pa_connretry "
+                                "from %s.sl_path where pa_client = %d"
                                 " and pa_conninfo<>'<event pending>'",
-                 rtcfg_namespace, rtcfg_nodeid);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot get path config - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        dstring_free(&query);
-        slon_retry();
-    }
-    for (i = 0, n = PQntuples(res); i < n; i++)
-    {
-        int                    pa_server = (int)strtol(PQgetvalue(res, i, 0), NULL, 10);
-        char       *pa_conninfo = PQgetvalue(res, i, 1);
-        int                    pa_connretry = (int)strtol(PQgetvalue(res, i, 2), NULL, 10);
-
-        rtcfg_storePath(pa_server, pa_conninfo, pa_connretry);
-    }
-    PQclear(res);
-
-    /*
-     * Load the initial listen configuration
-     */
-    rtcfg_reloadListen(startup_conn);
-
-    /*
-     * Read configuration table sl_set
-     */
-    slon_mkquery(&query,
-                 "select set_id, set_origin, set_comment "
-                 "from %s.sl_set",
-                 rtcfg_namespace);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot get set config - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        dstring_free(&query);
-        slon_retry();
-    }
-    for (i = 0, n = PQntuples(res); i < n; i++)
-    {
-        int                    set_id = (int)strtol(PQgetvalue(res, i, 0), NULL, 10);
-        int                    set_origin = (int)strtol(PQgetvalue(res, i, 1), NULL, 10);
-        char       *set_comment = PQgetvalue(res, i, 2);
-
-        rtcfg_storeSet(set_id, set_origin, set_comment);
-    }
-    PQclear(res);
-
-    /*
-     * Read configuration table sl_subscribe - only subscriptions for local
-     * node
-     */
-    slon_mkquery(&query,
-                 "select sub_set, sub_provider, sub_forward, sub_active "
-                 "from %s.sl_subscribe "
-                 "where sub_receiver = %d",
-                 rtcfg_namespace, rtcfg_nodeid);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot get subscription config - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        dstring_free(&query);
-        slon_retry();
-    }
-    for (i = 0, n = PQntuples(res); i < n; i++)
-    {
-        int                    sub_set = (int)strtol(PQgetvalue(res, i, 0), NULL, 10);
-        int                    sub_provider = (int)strtol(PQgetvalue(res, i, 1), NULL, 10);
-        char       *sub_forward = PQgetvalue(res, i, 2);
-        char       *sub_active = PQgetvalue(res, i, 3);
-
-        rtcfg_storeSubscribe(sub_set, sub_provider, sub_forward);
-        if (*sub_active == 't')
-            rtcfg_enableSubscription(sub_set, sub_provider, sub_forward);
-    }
-    PQclear(res);
-
-    /*
-     * Remember the last known local event sequence
-     */
-    slon_mkquery(&query,
-                 "select coalesce(max(ev_seqno), -1) from %s.sl_event "
-                 "where ev_origin = '%d'",
-                 rtcfg_namespace, rtcfg_nodeid);
-    res = PQexec(startup_conn, dstring_data(&query));
-    if (PQresultStatus(res) != PGRES_TUPLES_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot get last local eventid - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        dstring_free(&query);
-        slon_retry();
-    }
-    if (PQntuples(res) == 0)
-        strcpy(rtcfg_lastevent, "-1");
-    else if (PQgetisnull(res, 0, 0))
-        strcpy(rtcfg_lastevent, "-1");
-    else
-        strcpy(rtcfg_lastevent, PQgetvalue(res, 0, 0));
-    PQclear(res);
-    dstring_free(&query);
-    slon_log(SLON_CONFIG,
-             "main: last local event sequence = %s\n",
-             rtcfg_lastevent);
-
-    /*
-     * Rollback the transaction we used to get the config snapshot
-     */
-    res = PQexec(startup_conn, "rollback transaction;");
-    if (PQresultStatus(res) != PGRES_COMMAND_OK)
-    {
-        slon_log(SLON_FATAL, "main: Cannot rollback transaction - %s\n",
-                 PQresultErrorMessage(res));
-        PQclear(res);
-        slon_retry();
-    }
-    PQclear(res);
-
-    /*
-     * Done with the startup, don't need the local connection any more.
-     */
-    PQfinish(startup_conn);
-
-    slon_log(SLON_CONFIG, "main: configuration complete - starting threads\n");
-
-    /*
-     * Create the local event thread that monitors the local node for
-     * administrative events to adjust the configuration at runtime. We wait
-     * here until the local listen thread has checked that there is no other
-     * slon daemon running.
-     */
-    pthread_mutex_lock(&slon_wait_listen_lock);
-    if (pthread_create(&local_event_thread, NULL, localListenThread_main, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "main: cannot create localListenThread - %s\n",
-                 strerror(errno));
-        slon_retry();
-    }
-    pthread_cond_wait(&slon_wait_listen_cond, &slon_wait_listen_lock);
-    if(!slon_listen_started)
-    {
-        /**
-         * The local listen thread did not start up properly.
-         */
-        slon_log(SLON_FATAL,"main: localListenThread did not start\n");
-        slon_abort();
-    }
-    pthread_mutex_unlock(&slon_wait_listen_lock);
-
-    /*
-     * Enable all nodes that are active
-     */
-    rtcfg_doActivate();
-
-    /*
-     * Create the local cleanup thread that will remove old events and log
-     * data.
-     */
-    if (pthread_create(&local_cleanup_thread, NULL, cleanupThread_main, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "main: cannot create cleanupThread - %s\n",
-                 strerror(errno));
-        slon_retry();
-    }
-
-    /*
-     * Create the local sync thread that will generate SYNC events if we had
-     * local database updates.
-     */
-    if (pthread_create(&local_sync_thread, NULL, syncThread_main, NULL) < 0)
-    {
-        slon_log(SLON_FATAL, "main: cannot create syncThread - %s\n",
-                 strerror(errno));
-        slon_retry();
-    }
-
-    /*
-     * Create the local monitor thread that will process monitoring requests
-     */
-       if (monitor_threads) {
+                                rtcfg_namespace, rtcfg_nodeid);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot get path config - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               dstring_free(&query);
+               slon_retry();
+       }
+       for (i = 0, n = PQntuples(res); i < n; i++)
+       {
+               int                     pa_server = (int) strtol(PQgetvalue(res, i, 0), NULL, 10);
+               char       *pa_conninfo = PQgetvalue(res, i, 1);
+               int                     pa_connretry = (int) strtol(PQgetvalue(res, i, 2), NULL, 10);
+
+               rtcfg_storePath(pa_server, pa_conninfo, pa_connretry);
+       }
+       PQclear(res);
+
+       /*
+        * Load the initial listen configuration
+        */
+       rtcfg_reloadListen(startup_conn);
+
+       /*
+        * Read configuration table sl_set
+        */
+       slon_mkquery(&query,
+                                "select set_id, set_origin, set_comment "
+                                "from %s.sl_set",
+                                rtcfg_namespace);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot get set config - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               dstring_free(&query);
+               slon_retry();
+       }
+       for (i = 0, n = PQntuples(res); i < n; i++)
+       {
+               int                     set_id = (int) strtol(PQgetvalue(res, i, 0), NULL, 10);
+               int                     set_origin = (int) strtol(PQgetvalue(res, i, 1), NULL, 10);
+               char       *set_comment = PQgetvalue(res, i, 2);
+
+               rtcfg_storeSet(set_id, set_origin, set_comment);
+       }
+       PQclear(res);
+
+       /*
+        * Read configuration table sl_subscribe - only subscriptions for local
+        * node
+        */
+       slon_mkquery(&query,
+                                "select sub_set, sub_provider, sub_forward, sub_active "
+                                "from %s.sl_subscribe "
+                                "where sub_receiver = %d",
+                                rtcfg_namespace, rtcfg_nodeid);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot get subscription config - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               dstring_free(&query);
+               slon_retry();
+       }
+       for (i = 0, n = PQntuples(res); i < n; i++)
+       {
+               int                     sub_set = (int) strtol(PQgetvalue(res, i, 0), NULL, 10);
+               int                     sub_provider = (int) strtol(PQgetvalue(res, i, 1), NULL, 10);
+               char       *sub_forward = PQgetvalue(res, i, 2);
+               char       *sub_active = PQgetvalue(res, i, 3);
+
+               rtcfg_storeSubscribe(sub_set, sub_provider, sub_forward);
+               if (*sub_active == 't')
+                       rtcfg_enableSubscription(sub_set, sub_provider, sub_forward);
+       }
+       PQclear(res);
+
+       /*
+        * Remember the last known local event sequence
+        */
+       slon_mkquery(&query,
+                                "select coalesce(max(ev_seqno), -1) from %s.sl_event "
+                                "where ev_origin = '%d'",
+                                rtcfg_namespace, rtcfg_nodeid);
+       res = PQexec(startup_conn, dstring_data(&query));
+       if (PQresultStatus(res) != PGRES_TUPLES_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot get last local eventid - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               dstring_free(&query);
+               slon_retry();
+       }
+       if (PQntuples(res) == 0)
+               strcpy(rtcfg_lastevent, "-1");
+       else if (PQgetisnull(res, 0, 0))
+               strcpy(rtcfg_lastevent, "-1");
+       else
+               strcpy(rtcfg_lastevent, PQgetvalue(res, 0, 0));
+       PQclear(res);
+       dstring_free(&query);
+       slon_log(SLON_CONFIG,
+                        "main: last local event sequence = %s\n",
+                        rtcfg_lastevent);
+
+       /*
+        * Rollback the transaction we used to get the config snapshot
+        */
+       res = PQexec(startup_conn, "rollback transaction;");
+       if (PQresultStatus(res) != PGRES_COMMAND_OK)
+       {
+               slon_log(SLON_FATAL, "main: Cannot rollback transaction - %s\n",
+                                PQresultErrorMessage(res));
+               PQclear(res);
+               slon_retry();
+       }
+       PQclear(res);
+
+       /*
+        * Done with the startup, don't need the local connection any more.
+        */
+       PQfinish(startup_conn);
+
+       slon_log(SLON_CONFIG, "main: configuration complete - starting threads\n");
+
+       /*
+        * Create the local event thread that monitors the local node for
+        * administrative events to adjust the configuration at runtime. We wait
+        * here until the local listen thread has checked that there is no other
+        * slon daemon running.
+        */
+       pthread_mutex_lock(&slon_wait_listen_lock);
+       if (pthread_create(&local_event_thread, NULL, localListenThread_main, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "main: cannot create localListenThread - %s\n",
+                                strerror(errno));
+               slon_retry();
+       }
+       pthread_cond_wait(&slon_wait_listen_cond, &slon_wait_listen_lock);
+       if (!slon_listen_started)
+       {
+               /**
+                * The local listen thread did not start up properly.
+                */
+               slon_log(SLON_FATAL, "main: localListenThread did not start\n");
+               slon_abort();
+       }
+       pthread_mutex_unlock(&slon_wait_listen_lock);
+
+       /*
+        * Enable all nodes that are active
+        */
+       rtcfg_doActivate();
+
+       /*
+        * Create the local cleanup thread that will remove old events and log
+        * data.
+        */
+       if (pthread_create(&local_cleanup_thread, NULL, cleanupThread_main, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "main: cannot create cleanupThread - %s\n",
+                                strerror(errno));
+               slon_retry();
+       }
+
+       /*
+        * Create the local sync thread that will generate SYNC events if we had
+        * local database updates.
+        */
+       if (pthread_create(&local_sync_thread, NULL, syncThread_main, NULL) < 0)
+       {
+               slon_log(SLON_FATAL, "main: cannot create syncThread - %s\n",
+                                strerror(errno));
+               slon_retry();
+       }
+
+       /*
+        * Create the local monitor thread that will process monitoring requests
+        */
+       if (monitor_threads)
+       {
                if (pthread_create(&local_monitor_thread, NULL, monitorThread_main, NULL) < 0)
                {
                        slon_log(SLON_FATAL, "main: cannot create monitorThread - %s\n",
@@ -805,47 +812,48 @@ SlonMain(void)
                        slon_retry();
                }
        }
-    /*
-     * Wait until the scheduler has shut down all remote connections
-     */
-    slon_log(SLON_INFO, "main: running scheduler mainloop\n");
-    if (sched_wait_mainloop() < 0)
-    {
-        slon_log(SLON_FATAL, "main: scheduler returned with error\n");
-        slon_retry();
-    }
-    slon_log(SLON_INFO, "main: scheduler mainloop returned\n");
-
-    /*
-     * Wait for all remote threads to finish
-     */
-    main_thread = pthread_self();
-
-    slon_log(SLON_CONFIG, "main: wait for remote threads\n");
-    rtcfg_joinAllRemoteThreads();
-
-    /*
-     * Wait for the local threads to finish
-     */
-    if (pthread_join(local_event_thread, NULL) < 0)
-        slon_log(SLON_ERROR, "main: cannot join localListenThread - %s\n",
-                 strerror(errno));
-
-    if (pthread_join(local_cleanup_thread, NULL) < 0)
-        slon_log(SLON_ERROR, "main: cannot join cleanupThread - %s\n",
-                 strerror(errno));
-
-    if (pthread_join(local_sync_thread, NULL) < 0)
-        slon_log(SLON_ERROR, "main: cannot join syncThread - %s\n",
-                 strerror(errno));
-
-    if (pthread_join(local_monitor_thread, NULL) < 0)
-        slon_log(SLON_ERROR, "main: cannot join monitorThread - %s\n",
-                 strerror(errno));
-
-    slon_log(SLON_CONFIG, "main: done\n");
-
-    exit(0);
+
+       /*
+        * Wait until the scheduler has shut down all remote connections
+        */
+       slon_log(SLON_INFO, "main: running scheduler mainloop\n");
+       if (sched_wait_mainloop() < 0)
+       {
+               slon_log(SLON_FATAL, "main: scheduler returned with error\n");
+               slon_retry();
+       }
+       slon_log(SLON_INFO, "main: scheduler mainloop returned\n");
+
+       /*
+        * Wait for all remote threads to finish
+        */
+       main_thread = pthread_self();
+
+       slon_log(SLON_CONFIG, "main: wait for remote threads\n");
+       rtcfg_joinAllRemoteThreads();
+
+       /*
+        * Wait for the local threads to finish
+        */
+       if (pthread_join(local_event_thread, NULL) < 0)
+               slon_log(SLON_ERROR, "main: cannot join localListenThread - %s\n",
+                                strerror(errno));
+
+       if (pthread_join(local_cleanup_thread, NULL) < 0)
+               slon_log(SLON_ERROR, "main: cannot join cleanupThread - %s\n",
+                                strerror(errno));
+
+       if (pthread_join(local_sync_thread, NULL) < 0)
+               slon_log(SLON_ERROR, "main: cannot join syncThread - %s\n",
+                                strerror(errno));
+
+       if (pthread_join(local_monitor_thread, NULL) < 0)
+               slon_log(SLON_ERROR, "main: cannot join monitorThread - %s\n",
+                                strerror(errno));
+
+       slon_log(SLON_CONFIG, "main: done\n");
+
+       exit(0);
 }
 
 #ifndef WIN32
@@ -856,170 +864,172 @@ SlonMain(void)
 static void
 SlonWatchdog(void)
 {
-    pid_t              pid;
-    int shutdown=0;
-    int return_code=-99;
-    char * termination_reason="unknown";
-    slon_log(SLON_INFO, "slon: watchdog process started\n");
-
-
-
-    slon_log(SLON_CONFIG, "slon: watchdog ready - pid = %d\n", slon_watchdog_pid);
-
-    slon_worker_pid = fork();
-    if (slon_worker_pid == 0)
-    {
-        SlonMain();
-        exit(-1);
-    }
-    else if (slon_worker_pid < 0)
-    {
-        slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
-                 errno,strerror(errno));
-        slon_exit(-1);
-
-    }
-        /*
-     * Install signal handlers
-     */
-
-    if (install_signal_handler(SIGHUP, sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGHUP signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-
-    if (install_signal_handler(SIGUSR1,sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGUSR1 signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-    if (install_signal_handler(SIGALRM,sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGALRM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-    if (install_signal_handler(SIGINT,sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGINT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-    if (install_signal_handler(SIGTERM,sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGTERM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-
-
-    if (install_signal_handler(SIGQUIT,sighandler) == SIG_ERR)
-    {
-        slon_log(SLON_FATAL, "slon: SIGQUIT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
-        slon_exit(-1);
-    }
-
-    slon_log(SLON_CONFIG, "slon: worker process created - pid = %d\n",
-             slon_worker_pid);
-    while(!shutdown)
-    {
-        while ((pid = wait(&child_status)) != slon_worker_pid)
-        {
-            if (pid < 0 && errno == EINTR)
-                continue;
-
-            slon_log(SLON_CONFIG, "slon: child terminated status: %d; pid: %d, current worker pid: %d errno: %d\n", child_status, pid, slon_worker_pid,errno);
-
-            if(pid < 0 )
-            {
-                /**
-                 * if errno is not EINTR and pid<0 we have
-                 * a problem.
-                 * looping on wait() isn't a good idea.
-                 */
-                slon_log(SLON_FATAL,"slon: wait returned an error pid:%d errno:%d\n",
-                         pid,errno);
-                exit(-1);
-            }
-        }
-        if( WIFSIGNALED(child_status) )
-        {
-            return_code=WTERMSIG(child_status);
-            termination_reason="signal";
-        }
-        else if ( WIFEXITED(child_status) )
-        {
-            return_code=WEXITSTATUS(child_status);
-            termination_reason="exit code";
-        }
-        slon_log(SLON_CONFIG, "slon: child terminated %s: %d; pid: %d, current worker pid: %d\n", termination_reason,return_code, pid, slon_worker_pid);
-
-
-        switch (watchdog_status)
-        {
-            case SLON_WATCHDOG_RESTART:
-                slon_log(SLON_CONFIG,"slon: restart of worker in 20 seconds\n");
-                sleep(20);
-                slon_worker_pid = fork();
-                if(slon_worker_pid==0)
-                {
-                    worker_restarted=1;
-                    SlonMain();
-                    exit(-1);
-                }
-                else if (slon_worker_pid < 0)
-                {
-                    slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
-                             errno,strerror(errno));
-                    slon_exit(-1);
-
-                }
-                watchdog_status=SLON_WATCHDOG_NORMAL;
-                continue;
-
-            case SLON_WATCHDOG_NORMAL:
-            case SLON_WATCHDOG_RETRY:
-                watchdog_status = SLON_WATCHDOG_RETRY;
-                if (child_status != 0)
-                {
-                    slon_log(SLON_CONFIG, "slon: restart of worker in 10 seconds\n");
-                    (void) sleep(10);
-                }
-                else
-                {
-                    slon_log(SLON_CONFIG, "slon: restart of worker\n");
-                }
-                if (watchdog_status == SLON_WATCHDOG_RETRY)
-                {
-                    slon_worker_pid=fork();
-                    if(slon_worker_pid == 0)
-                    {
-                        worker_restarted=1;
-                        SlonMain();
-                        exit(-1);
-                    }
-                    else if (slon_worker_pid < 0)
-                    {
-                        slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
-                                 errno,strerror(errno));
-                        slon_exit(-1);
-
-                    }
-                    watchdog_status=SLON_WATCHDOG_NORMAL;
-                    continue;
-                }
-                break;
-
-            default:
-              shutdown=1;
-                break;
-        } /*switch*/
-    }/*while*/
-
-    slon_log(SLON_INFO, "slon: done\n");
-
-    /*
-     * That's it.
-     */
-    slon_exit(0);
+       pid_t           pid;
+       int                     shutdown = 0;
+       int                     return_code = -99;
+       char       *termination_reason = "unknown";
+
+       slon_log(SLON_INFO, "slon: watchdog process started\n");
+
+
+
+       slon_log(SLON_CONFIG, "slon: watchdog ready - pid = %d\n", slon_watchdog_pid);
+
+       slon_worker_pid = fork();
+       if (slon_worker_pid == 0)
+       {
+               SlonMain();
+               exit(-1);
+       }
+       else if (slon_worker_pid < 0)
+       {
+               slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
+                                errno, strerror(errno));
+               slon_exit(-1);
+
+       }
+
+       /*
+        * Install signal handlers
+        */
+
+       if (install_signal_handler(SIGHUP, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGHUP signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+
+       if (install_signal_handler(SIGUSR1, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGUSR1 signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+       if (install_signal_handler(SIGALRM, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGALRM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+       if (install_signal_handler(SIGINT, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGINT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+       if (install_signal_handler(SIGTERM, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGTERM signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+
+
+       if (install_signal_handler(SIGQUIT, sighandler) == SIG_ERR)
+       {
+               slon_log(SLON_FATAL, "slon: SIGQUIT signal handler setup failed -(%d) %s\n", errno, strerror(errno));
+               slon_exit(-1);
+       }
+
+       slon_log(SLON_CONFIG, "slon: worker process created - pid = %d\n",
+                        slon_worker_pid);
+       while (!shutdown)
+       {
+               while ((pid = wait(&child_status)) != slon_worker_pid)
+               {
+                       if (pid < 0 && errno == EINTR)
+                               continue;
+
+                       slon_log(SLON_CONFIG, "slon: child terminated status: %d; pid: %d, current worker pid: %d errno: %d\n", child_status, pid, slon_worker_pid, errno);
+
+                       if (pid < 0)
+                       {
+                               /**
+                                * if errno is not EINTR and pid<0 we have
+                                * a problem.
+                                * looping on wait() isn't a good idea.
+                                */
+                               slon_log(SLON_FATAL, "slon: wait returned an error pid:%d errno:%d\n",
+                                                pid, errno);
+                               exit(-1);
+                       }
+               }
+               if (WIFSIGNALED(child_status))
+               {
+                       return_code = WTERMSIG(child_status);
+                       termination_reason = "signal";
+               }
+               else if (WIFEXITED(child_status))
+               {
+                       return_code = WEXITSTATUS(child_status);
+                       termination_reason = "exit code";
+               }
+               slon_log(SLON_CONFIG, "slon: child terminated %s: %d; pid: %d, current worker pid: %d\n", termination_reason, return_code, pid, slon_worker_pid);
+
+
+               switch (watchdog_status)
+               {
+                       case SLON_WATCHDOG_RESTART:
+                               slon_log(SLON_CONFIG, "slon: restart of worker in 20 seconds\n");
+                               sleep(20);
+                               slon_worker_pid = fork();
+                               if (slon_worker_pid == 0)
+                               {
+                                       worker_restarted = 1;
+                                       SlonMain();
+                                       exit(-1);
+                               }
+                               else if (slon_worker_pid < 0)
+                               {
+                                       slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
+                                                        errno, strerror(errno));
+                                       slon_exit(-1);
+
+                               }
+                               watchdog_status = SLON_WATCHDOG_NORMAL;
+                               continue;
+
+                       case SLON_WATCHDOG_NORMAL:
+                       case SLON_WATCHDOG_RETRY:
+                               watchdog_status = SLON_WATCHDOG_RETRY;
+                               if (child_status != 0)
+                               {
+                                       slon_log(SLON_CONFIG, "slon: restart of worker in 10 seconds\n");
+                                       (void) sleep(10);
+                               }
+                               else
+                               {
+                                       slon_log(SLON_CONFIG, "slon: restart of worker\n");
+                               }
+                               if (watchdog_status == SLON_WATCHDOG_RETRY)
+                               {
+                                       slon_worker_pid = fork();
+                                       if (slon_worker_pid == 0)
+                                       {
+                                               worker_restarted = 1;
+                                               SlonMain();
+                                               exit(-1);
+                                       }
+                                       else if (slon_worker_pid < 0)
+                                       {
+                                               slon_log(SLON_FATAL, "slon: failed to fork child: %d %s\n",
+                                                                errno, strerror(errno));
+                                               slon_exit(-1);
+
+                                       }
+                                       watchdog_status = SLON_WATCHDOG_NORMAL;
+                                       continue;
+                               }
+                               break;
+
+                       default:
+                               shutdown = 1;
+                               break;
+               }                                               /* switch */
+       }                                                       /* while */
+
+       slon_log(SLON_INFO, "slon: done\n");
+
+       /*
+        * That's it.
+        */
+       slon_exit(0);
 }
 
 
@@ -1030,36 +1040,36 @@ SlonWatchdog(void)
 static void
 sighandler(int signo)
 {
-    switch (signo)
-    {
-        case SIGALRM:
-            kill(slon_worker_pid, SIGKILL);
-            break;
-
-        case SIGCHLD:
-            break;
-
-        case SIGHUP:
-            watchdog_status = SLON_WATCHDOG_RESTART;
-            slon_terminate_worker();
-            break;
-
-        case SIGUSR1:
-            watchdog_status = SLON_WATCHDOG_RETRY;
-            slon_terminate_worker();
-            break;
-
-        case SIGINT:
-        case SIGTERM:
-            watchdog_status = SLON_WATCHDOG_SHUTDOWN;
-            slon_terminate_worker();
-            break;
-
-        case SIGQUIT:
-            kill(slon_worker_pid, SIGKILL);
-            slon_exit(-1);
-            break;
-    }
+       switch (signo)
+       {
+               case SIGALRM:
+                       kill(slon_worker_pid, SIGKILL);
+                       break;
+
+               case SIGCHLD:
+                       break;
+
+               case SIGHUP:
+                       watchdog_status = SLON_WATCHDOG_RESTART;
+                       slon_terminate_worker();
+                       break;
+
+               case SIGUSR1:
+                       watchdog_status = SLON_WATCHDOG_RETRY;
+                       slon_terminate_worker();
+                       break;
+
+               case SIGINT:
+               case SIGTERM:
+                       watchdog_status = SLON_WATCHDOG_SHUTDOWN;
+                       slon_terminate_worker();
+                       break;
+
+               case SIGQUIT:
+                       kill(slon_worker_pid, SIGKILL);
+                       slon_exit(-1);
+                       break;
+       }
 }
 
 
@@ -1070,7 +1080,7 @@ sighandler(int signo)
 void
 slon_terminate_worker()
 {
-    (void) kill(slon_worker_pid, SIGKILL);
+       (void) kill(slon_worker_pid, SIGKILL);
 
 }
 #endif
@@ -1082,40 +1092,42 @@ static void
 slon_exit(int code)
 {
 #ifdef WIN32
-    /* Cleanup winsock */
-    WSACleanup();
+       /* Cleanup winsock */
+       WSACleanup();
 #endif
 
-    if (pid_file)
-    {
-        slon_log(SLON_INFO, "slon: remove pid file\n");
-        (void) unlink(pid_file);
-    }
+       if (pid_file)
+       {
+               slon_log(SLON_INFO, "slon: remove pid file\n");
+               (void) unlink(pid_file);
+       }
 
-    slon_log(SLON_INFO, "slon: exit(%d)\n", code);
+       slon_log(SLON_INFO, "slon: exit(%d)\n", code);
 
-    exit(code);
+       exit(code);
 }
 
-static sighandler_t install_signal_handler(int signo,  sighandler_t handler)
+static sighandler_t
+install_signal_handler(int signo, sighandler_t handler)
 {
 
-  
+
 #ifndef WIN32
        struct sigaction act;
+
        act.sa_handler = handler;
        (void) sigemptyset(&act.sa_mask);
        act.sa_flags = SA_NODEFER;
 
 
 
-    if(sigaction(signo, &act, NULL) < 0)
-    {
-        return SIG_ERR;
-    }
-    return handler;
+       if (sigaction(signo, &act, NULL) < 0)
+       {
+               return SIG_ERR;
+       }
+       return handler;
 #else
-    return signal(signo,handler);
+       return signal(signo, handler);
 #endif
 }
 
index 9ee900653e9be361cf8e4b9675fedcc44207bccb..c9f88319aa569990161861fda1947ec6650fb59a 100644 (file)
@@ -12,7 +12,7 @@
 
 #ifndef SLON_H_INCLUDED
 #define SLON_H_INCLUDED
-#ifdef MSVC 
+#ifdef MSVC
 #include "config_msvc.h"
 #else
 #include "config.h"
 
 typedef enum
 {
-    SLON_TSTAT_NONE,
-    SLON_TSTAT_RUNNING,
-    SLON_TSTAT_SHUTDOWN,
-    SLON_TSTAT_RESTART,
-    SLON_TSTAT_DONE
+       SLON_TSTAT_NONE,
+       SLON_TSTAT_RUNNING,
+       SLON_TSTAT_SHUTDOWN,
+       SLON_TSTAT_RESTART,
+       SLON_TSTAT_DONE
 }      SlonThreadStatus;
 
 
@@ -93,14 +93,14 @@ typedef struct SlonWorkMsg_s SlonWorkMsg;
  */
 struct SlonState_s
 {
-               char *actor;
-               pid_t pid;
-               int node;
-               pid_t conn_pid;
-               char *activity;
-               time_t start_time;
-               int64 event;
-               char *event_type;
+       char       *actor;
+       pid_t           pid;
+       int                     node;
+       pid_t           conn_pid;
+       char       *activity;
+       time_t          start_time;
+       int64           event;
+       char       *event_type;
 };
 
 /* ----------
@@ -109,39 +109,39 @@ struct SlonState_s
  */
 struct SlonNode_s
 {
-    int                        no_id;                  /* node ID */
-    int                        no_active;              /* it's active state */
-    char       *no_comment;            /* comment field */
+       int                     no_id;                  /* node ID */
+       int                     no_active;              /* it's active state */
+       char       *no_comment;         /* comment field */
 #if 0
-    pthread_mutex_t node_lock; /* mutex for node */
+       pthread_mutex_t node_lock;      /* mutex for node */
 #endif
 
-    char       *pa_conninfo;   /* path to the node */
-    int                        pa_connretry;   /* connection retry interval */
+       char       *pa_conninfo;        /* path to the node */
+       int                     pa_connretry;   /* connection retry interval */
 
-    int64              last_event;             /* last event we have received */
+       int64           last_event;             /* last event we have received */
        char       *last_snapshot;      /* snapshot of last sync event */
 
-    SlonThreadStatus listen_status;            /* status of the listen thread */
-    pthread_t  listen_thread;  /* thread id of listen thread */
-    SlonListen *listen_head;   /* list of origins we listen for */
-    SlonListen *listen_tail;
-
-    SlonThreadStatus worker_status;            /* status of the worker thread */
-    pthread_t  worker_thread;  /* thread id of worker thread */
-    pthread_mutex_t message_lock;              /* mutex for the message queue */
-    pthread_cond_t message_cond;       /* condition variable for queue */
-    SlonWorkMsg *message_head;
-    SlonWorkMsg *message_tail;
-
-    char       *archive_name;
-    char       *archive_temp;
-    char       *archive_counter;
-    char       *archive_timestamp;
-    FILE       *archive_fp;
-
-    SlonNode   *prev;
-    SlonNode   *next;
+       SlonThreadStatus listen_status;         /* status of the listen thread */
+       pthread_t       listen_thread;  /* thread id of listen thread */
+       SlonListen *listen_head;        /* list of origins we listen for */
+       SlonListen *listen_tail;
+
+       SlonThreadStatus worker_status;         /* status of the worker thread */
+       pthread_t       worker_thread;  /* thread id of worker thread */
+       pthread_mutex_t message_lock;           /* mutex for the message queue */
+       pthread_cond_t message_cond;    /* condition variable for queue */
+       SlonWorkMsg *message_head;
+       SlonWorkMsg *message_tail;
+
+       char       *archive_name;
+       char       *archive_temp;
+       char       *archive_counter;
+       char       *archive_timestamp;
+       FILE       *archive_fp;
+
+       SlonNode   *prev;
+       SlonNode   *next;
 };
 
 /* ----------
@@ -150,10 +150,10 @@ struct SlonNode_s
  */
 struct SlonListen_s
 {
-    int                        li_origin;              /* origin of events */
+       int                     li_origin;              /* origin of events */
 
-    SlonListen *prev;
-    SlonListen *next;
+       SlonListen *prev;
+       SlonListen *next;
 };
 
 /* ----------
@@ -162,17 +162,17 @@ struct SlonListen_s
  */
 struct SlonSet_s
 {
-    int                        set_id;                 /* set ID */
-    int                        set_origin;             /* set origin */
-    char       *set_comment;   /* set comment */
+       int                     set_id;                 /* set ID */
+       int                     set_origin;             /* set origin */
+       char       *set_comment;        /* set comment */
 
-    int                        sub_provider;   /* from where this node receives */
-    /* data (if subscribed) */
-    int                        sub_forward;    /* if we need to forward data */
-    int                        sub_active;             /* if the subscription is active */
+       int                     sub_provider;   /* from where this node receives */
+       /* data (if subscribed) */
+       int                     sub_forward;    /* if we need to forward data */
+       int                     sub_active;             /* if the subscription is active */
 
-    SlonSet    *prev;
-    SlonSet    *next;
+       SlonSet    *prev;
+       SlonSet    *next;
 };
 
 /* ----------
@@ -181,19 +181,19 @@ struct SlonSet_s
  */
 struct SlonConn_s
 {
-    char       *symname;               /* Symbolic name of connection */
-    struct SlonNode_s *node;   /* remote node this belongs to */
-    PGconn     *dbconn;                        /* database connection */
-    pthread_mutex_t conn_lock; /* mutex for conn */
-    pthread_cond_t conn_cond;  /* condition variable for conn */
-
-    int                        condition;              /* what are we waiting for? */
-    struct timeval timeout;            /* timeofday for timeout */
-    int        pg_version;             /* PostgreSQL version */
-       int conn_pid;       /* PID of connection */
-
-    SlonConn   *prev;
-    SlonConn   *next;
+       char       *symname;            /* Symbolic name of connection */
+       struct SlonNode_s *node;        /* remote node this belongs to */
+       PGconn     *dbconn;                     /* database connection */
+       pthread_mutex_t conn_lock;      /* mutex for conn */
+       pthread_cond_t conn_cond;       /* condition variable for conn */
+
+       int                     condition;              /* what are we waiting for? */
+       struct timeval timeout;         /* timeofday for timeout */
+       int                     pg_version;             /* PostgreSQL version */
+       int                     conn_pid;               /* PID of connection */
+
+       SlonConn   *prev;
+       SlonConn   *next;
 };
 
 /* ----------
@@ -205,73 +205,73 @@ struct SlonConn_s
 
 typedef struct
 {
-    size_t             n_alloc;
-    size_t             n_used;
-    char       *data;
+       size_t          n_alloc;
+       size_t          n_used;
+       char       *data;
 }      SlonDString;
 
 #define                dstring_init(__ds) \
 do { \
-    (__ds)->n_alloc = SLON_DSTRING_SIZE_INIT; \
-    (__ds)->n_used = 0; \
-    (__ds)->data = malloc(SLON_DSTRING_SIZE_INIT); \
-    if ((__ds)->data == NULL) { \
-        slon_log(SLON_FATAL, "dstring_init: malloc() - %s", \
-                strerror(errno)); \
-        slon_abort(); \
-    } \
+       (__ds)->n_alloc = SLON_DSTRING_SIZE_INIT; \
+       (__ds)->n_used = 0; \
+       (__ds)->data = malloc(SLON_DSTRING_SIZE_INIT); \
+       if ((__ds)->data == NULL) { \
+               slon_log(SLON_FATAL, "dstring_init: malloc() - %s", \
+                               strerror(errno)); \
+               slon_abort(); \
+       } \
 } while (0)
 #define                dstring_reset(__ds) \
 do { \
-    (__ds)->n_used = 0; \
-    (__ds)->data[0] = '\0'; \
+       (__ds)->n_used = 0; \
+       (__ds)->data[0] = '\0'; \
 } while (0)
 #define                dstring_free(__ds) \
 do { \
-    free((__ds)->data); \
-    (__ds)->n_used = 0; \
-    (__ds)->data = NULL; \
+       free((__ds)->data); \
+       (__ds)->n_used = 0; \
+       (__ds)->data = NULL; \
 } while (0)
 #define                dstring_nappend(__ds,__s,__n) \
 do { \
-    if ((__ds)->n_used + (__n) >= (__ds)->n_alloc)     \
-    { \
-        while ((__ds)->n_used + (__n) >= (__ds)->n_alloc) \
-            (__ds)->n_alloc *= SLON_DSTRING_SIZE_INC; \
-        (__ds)->data = realloc((__ds)->data, (__ds)->n_alloc); \
-        if ((__ds)->data == NULL) \
-        { \
-            slon_log(SLON_FATAL, "dstring_nappend: realloc() - %s", \
-                    strerror(errno)); \
-            slon_abort(); \
-        } \
-    } \
-    memcpy(&((__ds)->data[(__ds)->n_used]), (__s), (__n)); \
-    (__ds)->n_used += (__n); \
+       if ((__ds)->n_used + (__n) >= (__ds)->n_alloc)  \
+       { \
+               while ((__ds)->n_used + (__n) >= (__ds)->n_alloc) \
+                       (__ds)->n_alloc *= SLON_DSTRING_SIZE_INC; \
+               (__ds)->data = realloc((__ds)->data, (__ds)->n_alloc); \
+               if ((__ds)->data == NULL) \
+               { \
+                       slon_log(SLON_FATAL, "dstring_nappend: realloc() - %s", \
+                                       strerror(errno)); \
+                       slon_abort(); \
+               } \
+       } \
+       memcpy(&((__ds)->data[(__ds)->n_used]), (__s), (__n)); \
+       (__ds)->n_used += (__n); \
 } while (0)
 #define                dstring_append(___ds,___s) \
 do { \
-    register int ___n = strlen((___s)); \
-    dstring_nappend((___ds),(___s),___n); \
+       register int ___n = strlen((___s)); \
+       dstring_nappend((___ds),(___s),___n); \
 } while (0)
 #define                dstring_addchar(__ds,__c) \
 do { \
-    if ((__ds)->n_used + 1 >= (__ds)->n_alloc) \
-    { \
-        (__ds)->n_alloc *= SLON_DSTRING_SIZE_INC; \
-        (__ds)->data = realloc((__ds)->data, (__ds)->n_alloc); \
-        if ((__ds)->data == NULL) \
-        { \
-            slon_log(SLON_FATAL, "dstring_addchar: realloc() - %s", \
-                    strerror(errno)); \
-            slon_abort(); \
-        } \
-    } \
-    (__ds)->data[(__ds)->n_used++] = (__c); \
+       if ((__ds)->n_used + 1 >= (__ds)->n_alloc)      \
+       { \
+               (__ds)->n_alloc *= SLON_DSTRING_SIZE_INC; \
+               (__ds)->data = realloc((__ds)->data, (__ds)->n_alloc); \
+               if ((__ds)->data == NULL) \
+               { \
+                       slon_log(SLON_FATAL, "dstring_addchar: realloc() - %s", \
+                                       strerror(errno)); \
+                       slon_abort(); \
+               } \
+       } \
+       (__ds)->data[(__ds)->n_used++] = (__c); \
 } while (0)
 #define                dstring_terminate(__ds) \
 do { \
-    (__ds)->data[(__ds)->n_used] = '\0'; \
+       (__ds)->data[(__ds)->n_used] = '\0'; \
 } while (0)
 #define                dstring_data(__ds)      ((__ds)->data)
 
@@ -282,43 +282,43 @@ do { \
  */
 #define DLLIST_ADD_TAIL(_pf,_pl,_obj) \
 do { \
-    if ((_pl) == NULL) { \
-        (_obj)->prev = (_obj)->next = NULL; \
-        (_pf) = (_pl) = (_obj); \
-    } else { \
-        (_obj)->prev = (_pl); \
-        (_obj)->next = NULL; \
-        (_pl)->next = (_obj); \
-        (_pl) = (_obj); \
-    } \
+       if ((_pl) == NULL) { \
+               (_obj)->prev = (_obj)->next = NULL; \
+               (_pf) = (_pl) = (_obj); \
+       } else { \
+               (_obj)->prev = (_pl); \
+               (_obj)->next = NULL; \
+               (_pl)->next = (_obj); \
+               (_pl) = (_obj); \
+       } \
 } while (0)
 
 #define DLLIST_ADD_HEAD(_pf,_pl,_obj) \
 do { \
-    if ((_pf) == NULL) { \
-        (_obj)->prev = (_obj)->next = NULL; \
-        (_pf) = (_pl) = (_obj); \
-    } else { \
-        (_obj)->prev = NULL; \
-        (_obj)->next = (_pf); \
-        (_pf)->prev = (_obj); \
-        (_pf) = (_obj); \
-    } \
+       if ((_pf) == NULL) { \
+               (_obj)->prev = (_obj)->next = NULL; \
+               (_pf) = (_pl) = (_obj); \
+       } else { \
+               (_obj)->prev = NULL; \
+               (_obj)->next = (_pf); \
+               (_pf)->prev = (_obj); \
+               (_pf) = (_obj); \
+       } \
 } while (0)
 
 #define DLLIST_REMOVE(_pf,_pl,_obj) \
 do { \
-    if ((_obj)->prev == NULL) { \
-        (_pf) = (_obj)->next; \
-    } else { \
-        (_obj)->prev->next = (_obj)->next; \
-    } \
-    if ((_obj)->next == NULL) { \
-        (_pl) = (_obj)->prev; \
-    } else { \
-        (_obj)->next->prev = (_obj)->prev; \
-    } \
-    (_obj)->prev = (_obj)->next = NULL; \
+       if ((_obj)->prev == NULL) { \
+               (_pf) = (_obj)->next; \
+       } else { \
+               (_obj)->prev->next = (_obj)->next; \
+       } \
+       if ((_obj)->next == NULL) { \
+               (_pl) = (_obj)->prev; \
+       } else { \
+               (_obj)->next->prev = (_obj)->prev; \
+       } \
+       (_obj)->prev = (_obj)->next = NULL; \
 } while (0)
 
 
@@ -330,9 +330,9 @@ do { \
  * ----------
  */
 #define TIMEVAL_DIFF(_t1,_t2) \
-    (((_t1)->tv_usec <= (_t2)->tv_usec) ? \
-        (double)((_t2)->tv_sec - (_t1)->tv_sec) + (double)((_t2)->tv_usec - (_t1)->tv_usec) / 1000000.0 : \
-        (double)((_t2)->tv_sec - (_t1)->tv_sec - 1) + (double)((_t2)->tv_usec + 1000000 - (_t1)->tv_usec) / 1000000.0)
+       (((_t1)->tv_usec <= (_t2)->tv_usec) ? \
+               (double)((_t2)->tv_sec - (_t1)->tv_sec) + (double)((_t2)->tv_usec - (_t1)->tv_usec) / 1000000.0 : \
+               (double)((_t2)->tv_sec - (_t1)->tv_sec - 1) + (double)((_t2)->tv_usec + 1000000 - (_t1)->tv_usec) / 1000000.0)
 
 
 /* ----------
@@ -341,12 +341,12 @@ do { \
  */
 typedef enum
 {
-        SCHED_STATUS_OK,
-        SCHED_STATUS_SHUTDOWN,
-        SCHED_STATUS_DONE,
-        SCHED_STATUS_CANCEL,
-        SCHED_STATUS_ERROR
-} ScheduleStatus;
+       SCHED_STATUS_OK,
+       SCHED_STATUS_SHUTDOWN,
+       SCHED_STATUS_DONE,
+       SCHED_STATUS_CANCEL,
+       SCHED_STATUS_ERROR
+}      ScheduleStatus;
 
 /* ----------
  * Scheduler wait conditions
@@ -390,54 +390,54 @@ extern SlonSet *rtcfg_set_list_tail;
 #ifndef WIN32
 #define slon_abort() \
 do { \
-    pthread_mutex_lock(&slon_watchdog_lock); \
-    if (slon_watchdog_pid >= 0) { \
-        slon_log(SLON_DEBUG2, "slon_abort() from pid=%d\n", slon_pid); \
-        (void) kill(slon_watchdog_pid, SIGTERM);                       \
-        slon_watchdog_pid = -1; \
-    } \
-    pthread_mutex_unlock(&slon_watchdog_lock); \
-    pthread_exit(NULL); \
+       pthread_mutex_lock(&slon_watchdog_lock); \
+       if (slon_watchdog_pid >= 0) { \
+               slon_log(SLON_DEBUG2, "slon_abort() from pid=%d\n", slon_pid); \
+               (void) kill(slon_watchdog_pid, SIGTERM);                        \
+               slon_watchdog_pid = -1; \
+       } \
+       pthread_mutex_unlock(&slon_watchdog_lock); \
+       pthread_exit(NULL); \
 } while (0)
 #define slon_restart() \
 do { \
-    pthread_mutex_lock(&slon_watchdog_lock); \
-    if (slon_watchdog_pid >= 0) { \
-        slon_log(SLON_DEBUG2, "slon_restart() from pid=%d\n", slon_pid); \
-        (void) kill(slon_watchdog_pid, SIGHUP);                        \
-        slon_watchdog_pid = -1; \
-    } \
-    pthread_mutex_unlock(&slon_watchdog_lock); \
-    pthread_exit(NULL); \
+       pthread_mutex_lock(&slon_watchdog_lock); \
+       if (slon_watchdog_pid >= 0) { \
+               slon_log(SLON_DEBUG2, "slon_restart() from pid=%d\n", slon_pid); \
+               (void) kill(slon_watchdog_pid, SIGHUP);                 \
+               slon_watchdog_pid = -1; \
+       } \
+       pthread_mutex_unlock(&slon_watchdog_lock); \
+       pthread_exit(NULL); \
 } while (0)
 #define slon_retry() \
 do { \
-    pthread_mutex_lock(&slon_watchdog_lock); \
-    if (slon_watchdog_pid >= 0) { \
-        slon_log(SLON_DEBUG2, "slon_retry() from pid=%d\n", slon_pid); \
-        (void) kill(slon_watchdog_pid, SIGUSR1);                       \
-        slon_watchdog_pid = -1; \
-    } \
-    pthread_mutex_unlock(&slon_watchdog_lock); \
-    pthread_exit(NULL); \
+       pthread_mutex_lock(&slon_watchdog_lock); \
+       if (slon_watchdog_pid >= 0) { \
+               slon_log(SLON_DEBUG2, "slon_retry() from pid=%d\n", slon_pid); \
+               (void) kill(slon_watchdog_pid, SIGUSR1);                        \
+               slon_watchdog_pid = -1; \
+       } \
+       pthread_mutex_unlock(&slon_watchdog_lock); \
+       pthread_exit(NULL); \
 } while (0)
 #else                                                  /* WIN32 */
 /* On win32, we currently just bail out and let the service control manager
  * deal with possible restarts */
 #define slon_abort() \
 do { \
-    WSACleanup(); \
-    exit(1); \
+       WSACleanup(); \
+       exit(1); \
 } while (0)
 #define slon_restart() \
 do { \
-    WSACleanup(); \
-    exit(1); \
+       WSACleanup(); \
+       exit(1); \
 } while (0)
 #define slon_retry() \
 do { \
-    WSACleanup(); \
-    exit(1); \
+       WSACleanup(); \
+       exit(1); \
 } while (0)
 #endif
 
@@ -446,7 +446,7 @@ extern void Usage(char *const argv[]);
 extern int     sched_wakeuppipe[];
 extern pthread_mutex_t slon_wait_listen_lock;
 extern pthread_cond_t slon_wait_listen_cond;
-extern int slon_listen_started;
+extern int     slon_listen_started;
 
 /* ----------
  * Functions in runtime_config.c
@@ -465,7 +465,7 @@ extern void rtcfg_setNodeLastSnapshot(int no_id, char *snapshot);
 extern char *rtcfg_getNodeLastSnapshot(int no_id);
 
 extern void rtcfg_storePath(int pa_server, char *pa_conninfo,
-                int pa_connretry);
+                               int pa_connretry);
 extern void rtcfg_dropPath(int pa_server);
 
 extern void rtcfg_reloadListen(PGconn *db);
@@ -475,12 +475,12 @@ extern void rtcfg_dropListen(int li_origin, int li_provider);
 extern void rtcfg_storeSet(int set_id, int set_origin, char *set_comment);
 extern void rtcfg_dropSet(int set_id);
 extern void rtcfg_moveSet(int set_id, int old_origin, int new_origin,
-              int sub_provider);
+                         int sub_provider);
 
 extern void rtcfg_storeSubscribe(int sub_set, int sub_provider,
-                     char *sub_forward);
+                                        char *sub_forward);
 extern void rtcfg_enableSubscription(int sub_set, int sub_provider,
-                         char *sub_forward);
+                                                char *sub_forward);
 extern void rtcfg_unsubscribeSet(int sub_set);
 
 extern void rtcfg_needActivate(int no_id);
@@ -531,14 +531,14 @@ extern void *syncThread_main(void *dummy);
  * ----------
  */
 extern void *monitorThread_main(void *dummy);
-extern void monitor_state (const char *actor, int node, pid_t conn_pid, const char *activity, int64 event, const char *event_type);
+extern void monitor_state(const char *actor, int node, pid_t conn_pid, const char *activity, int64 event, const char *event_type);
 
 /* ----------
  * Globals in monitor_thread.c
  * ----------
  */
 extern int     monitor_interval;
-extern bool    monitor_threads;
+extern bool monitor_threads;
 
 
 /* ----------
@@ -569,18 +569,18 @@ extern int        explain_interval;
  */
 extern void *remoteWorkerThread_main(void *cdata);
 extern void remoteWorker_event(int event_provider,
-                   int ev_origin, int64 ev_seqno,
-                   char *ev_timestamp,
-                   char *ev_snapshot, char *ev_mintxid, char *ev_maxtxid,
-                   char *ev_type,
-                   char *ev_data1, char *ev_data2,
-                   char *ev_data3, char *ev_data4,
-                   char *ev_data5, char *ev_data6,
-                   char *ev_data7, char *ev_data8);
+                                  int ev_origin, int64 ev_seqno,
+                                  char *ev_timestamp,
+                                  char *ev_snapshot, char *ev_mintxid, char *ev_maxtxid,
+                                  char *ev_type,
+                                  char *ev_data1, char *ev_data2,
+                                  char *ev_data3, char *ev_data4,
+                                  char *ev_data5, char *ev_data6,
+                                  char *ev_data7, char *ev_data8);
 extern void remoteWorker_wakeup(int no_id);
 extern void remoteWorker_confirm(int no_id,
-                     char *con_origin_c, char *con_received_c,
-                     char *con_seqno_c, char *con_timestamp_c);
+                                        char *con_origin_c, char *con_received_c,
+                                        char *con_seqno_c, char *con_timestamp_c);
 
 
 /* ----------
@@ -608,8 +608,8 @@ extern void slon_free_dummyconn(SlonConn * conn);
 extern int     db_getLocalNodeId(PGconn *conn);
 extern int     db_checkSchemaVersion(PGconn *conn);
 
-extern void    slon_mkquery(SlonDString * ds, char *fmt,...);
-extern void    slon_appendquery(SlonDString * ds, char *fmt,...);
+extern void slon_mkquery(SlonDString * ds, char *fmt,...);
+extern void slon_appendquery(SlonDString * ds, char *fmt,...);
 extern char *sql_on_connection;
 
 /* ----------
@@ -631,8 +631,6 @@ extern int  slon_log_level;
 #if defined(WIN32)
 #define snprintf pg_snprintf
 #endif
-
-
 #endif   /* SLON_H_INCLUDED */
 
 
index f7ccf8752c63d210c36fb7b75b9d75548fe5c8a3..64b2163f2abb1bf1230d9a9ec7b7350907ad6d10 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
 #include "slon.h"
 
 
-/* ---------- 
- * Global variables 
+/* ----------
+ * Global variables
  * ----------
  */
 int                    sync_interval;
 int                    sync_interval_timeout;
 
 
-/* ---------- 
+/* ----------
  * slon_localSyncThread
  *
  * Generate SYNC event if local database activity created new log info.
index 59035d00bee1b75c92891485aed52761615bed23..8de5699a1a4f7c9034d480e1983923257778dd8d 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -38,7 +38,7 @@
 int                    db_notice_silent = false;
 SlonikStmt *db_notice_stmt = NULL;
 
-extern int current_try_level;
+extern int     current_try_level;
 
 /*
  * Local functions
@@ -119,7 +119,7 @@ int
 db_connect(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
 {
        PGconn     *dbconn;
-       SlonDString     query;
+       SlonDString query;
        PGresult   *res;
 
        db_notice_stmt = stmt;
@@ -162,8 +162,8 @@ db_connect(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
         * ----
         */
        dstring_init(&query);
-       slon_mkquery(&query,"SET datestyle TO 'ISO'; "
-                                               "SET session_replication_role TO local; ");
+       slon_mkquery(&query, "SET datestyle TO 'ISO'; "
+                                "SET session_replication_role TO local; ");
 
 
        adminfo->dbconn = dbconn;
@@ -176,29 +176,31 @@ db_connect(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
        dstring_free(&query);
 
        dstring_init(&query);
-       slon_mkquery(&query,"select 1 from pg_catalog.pg_settings where name= 'application_name'; ");
-       res = db_exec_select (stmt, adminfo, &query);
+       slon_mkquery(&query, "select 1 from pg_catalog.pg_settings where name= 'application_name'; ");
+       res = db_exec_select(stmt, adminfo, &query);
 
        if (res == NULL)
-                       return -1;
+               return -1;
 
-       dstring_free(&query); 
+       dstring_free(&query);
 
        if (PQntuples(res) == 0)
        {
-                       /* Unable to set application_name on this version of PostgreSQL */
-                       PQclear(res);
-       } else {
-                       PQclear(res);
-                       dstring_init(&query);
-                       slon_mkquery(&query,"SET application_name TO 'slonik'; ");
-                       adminfo->dbconn = dbconn;
-                       if (db_exec_command(stmt, adminfo, &query) < 0)
-                       {
-                                       printf("Unable to set application name ?!?\n");
-                                       return -1;
-                       }
-                       dstring_free(&query); 
+               /* Unable to set application_name on this version of PostgreSQL */
+               PQclear(res);
+       }
+       else
+       {
+               PQclear(res);
+               dstring_init(&query);
+               slon_mkquery(&query, "SET application_name TO 'slonik'; ");
+               adminfo->dbconn = dbconn;
+               if (db_exec_command(stmt, adminfo, &query) < 0)
+               {
+                       printf("Unable to set application name ?!?\n");
+                       return -1;
+               }
+               dstring_free(&query);
        }
        /* ----
         * Commit the changes to the session settings.
@@ -244,7 +246,7 @@ db_exec_command(SlonikStmt * stmt, SlonikAdmInfo * adminfo, SlonDString * query)
 
        db_notice_stmt = stmt;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        res = PQexec(adminfo->dbconn, dstring_data(query));
@@ -281,7 +283,7 @@ db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo, SlonDString * quer
 
        db_notice_stmt = stmt;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        res = PQexec(adminfo->dbconn, dstring_data(query));
@@ -319,21 +321,21 @@ db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo, SlonDString * quer
  * ----------
  */
 int
-db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo, 
-               SlonDString * query, int nParams, const Oid *paramTypes,
-               const char *const *paramValues, const int *paramLengths,
-               const int *paramFormats, int resultFormat)
+db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                                       SlonDString * query, int nParams, const Oid *paramTypes,
+                                       const char *const * paramValues, const int *paramLengths,
+                                       const int *paramFormats, int resultFormat)
 {
        PGresult   *res;
 
        db_notice_stmt = stmt;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        res = PQexecParams(adminfo->dbconn, dstring_data(query),
-                       nParams, paramTypes, paramValues, paramLengths,
-                       paramFormats, resultFormat);
+                                          nParams, paramTypes, paramValues, paramLengths,
+                                          paramFormats, resultFormat);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
                fprintf(stderr, "%s:%d: %s %s - %s",
@@ -372,7 +374,7 @@ db_exec_select(SlonikStmt * stmt, SlonikAdmInfo * adminfo, SlonDString * query)
 
        db_notice_stmt = stmt;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return NULL;
 
        res = PQexec(adminfo->dbconn, dstring_data(query));
@@ -403,7 +405,7 @@ db_get_nodeid(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
        SlonDString query;
        int                     no_id;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -434,13 +436,13 @@ db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
 {
        PGresult   *res;
        SlonDString query;
-       char        versionstr[7];
-       int         major=0;
-       int         minor=0;
-       int         patch=0;
-       int         version=0;
+       char            versionstr[7];
+       int                     major = 0;
+       int                     minor = 0;
+       int                     patch = 0;
+       int                     version = 0;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -462,7 +464,7 @@ db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo)
        }
        PQclear(res);
        snprintf(versionstr, 7, "%.2d%.2d%.2d", major, minor, patch);
-       version=atoi(versionstr);
+       version = atoi(versionstr);
        return version;
 }
 
@@ -491,20 +493,21 @@ db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo, bool suppress_locking)
                return -1;
        }
        PQclear(res);
-       if(current_try_level > 0 && !suppress_locking)
+       if (current_try_level > 0 && !suppress_locking)
        {
                /**
                 * inside of a try block we obtain sl_event_lock
-                * right away.  This is because if sometime later
+                * right away.  This is because if sometime later
                 * in the try block needs sl_event_lock, it will
                 * be running in the same transaction and will then
                 * be too late to obtain the lock.
                 */
                SlonDString lock_query;
+
                dstring_init(&lock_query);
                slon_mkquery(&lock_query, "lock table \"_%s\".sl_event_lock; "
                                         ,stmt->script->clustername);
-               res = PQexec(adminfo->dbconn,dstring_data(&lock_query));
+               res = PQexec(adminfo->dbconn, dstring_data(&lock_query));
                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                        printf("%s:%d: lock table \"_%s\".sl_event_lock; - %s",
@@ -513,11 +516,11 @@ db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo, bool suppress_locking)
                                   PQresultErrorMessage(res));
                        PQclear(res);
                        adminfo->have_xact = true;
-                       db_rollback_xact(stmt,adminfo);
+                       db_rollback_xact(stmt, adminfo);
                        return -1;
                }
                PQclear(res);
-               
+
        }
 
        adminfo->have_xact = true;
@@ -597,7 +600,7 @@ db_check_namespace(SlonikStmt * stmt, SlonikAdmInfo * adminfo, char *clustername
        SlonDString query;
        int                     ntuples;
 
-       if (db_begin_xact(stmt, adminfo,false) < 0)
+       if (db_begin_xact(stmt, adminfo, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -630,7 +633,7 @@ db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo, char *clustern
        SlonDString query;
        int                     ntuples;
 
-       if (db_begin_xact(stmt, adminfo,true) < 0)
+       if (db_begin_xact(stmt, adminfo, true) < 0)
                return -1;
 
        dstring_init(&query);
@@ -662,7 +665,7 @@ db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo, char *clustern
        /*
         * Check loading of slony1_funcs module
         */
-       slon_mkquery(&query, "load '$libdir/slony1_funcs.%s'; ",SLONY_I_VERSION_STRING);
+       slon_mkquery(&query, "load '$libdir/slony1_funcs.%s'; ", SLONY_I_VERSION_STRING);
        if (db_exec_command(stmt, adminfo, &query) < 0)
        {
                printf("%s:%d: Error: the extension for the Slony-I C functions "
index 61ec8037f46481673f3c1c747e27daad7acd0086..265151573fa0b5ded0cd4b8103e8ff12a849f762 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -25,7 +25,6 @@
 #else
 #include <windows.h>
 #define sleep(x) Sleep(x*1000)
-
 #endif
 
 
@@ -40,7 +39,7 @@
 #include "config.h"
 #endif
 #include "../parsestatements/scanner.h"
-extern int STMTS[MAXSTATEMENTS];
+extern int     STMTS[MAXSTATEMENTS];
 
 #define MAXPGPATH 256
 
@@ -50,9 +49,9 @@ extern int STMTS[MAXSTATEMENTS];
 SlonikScript *parser_script = NULL;
 int                    parser_errors = 0;
 int                    current_try_level;
-int                    block_stmt_no=0;
-int last_event_node=-1;
-int auto_wait_disabled=0;
+int                    block_stmt_no = 0;
+int                    last_event_node = -1;
+int                    auto_wait_disabled = 0;
 
 static char share_path[MAXPGPATH];
 
@@ -91,71 +90,69 @@ static SlonikAdmInfo *get_adminfo(SlonikStmt * stmt, int no_id);
 static SlonikAdmInfo *get_active_adminfo(SlonikStmt * stmt, int no_id);
 static SlonikAdmInfo *get_checked_adminfo(SlonikStmt * stmt, int no_id);
 static int     slonik_repair_config(SlonikStmt_repair_config * stmt);
-static int  slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt);
+static int     slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt);
 
 static int     script_check(SlonikScript * script);
 static int     script_check_adminfo(SlonikStmt * hdr, int no_id);
-static int     script_check_stmts(SlonikScript * script,
-                                       SlonikStmt * stmt);
+static int script_check_stmts(SlonikScript * script,
+                                  SlonikStmt * stmt);
 static int     script_exec(SlonikScript * script);
-static int     script_exec_stmts(SlonikScript * script,
-                                       SlonikStmt * stmt);
-static void    script_commit_all(SlonikStmt * stmt,
-                                       SlonikScript * script);
+static int script_exec_stmts(SlonikScript * script,
+                                 SlonikStmt * stmt);
+static void script_commit_all(SlonikStmt * stmt,
+                                 SlonikScript * script);
 static void script_rollback_all(SlonikStmt * stmt,
                                        SlonikScript * script);
 static void script_disconnect_all(SlonikScript * script);
-static void replace_token(char *resout, char *lines, const char *token, 
-                                       const char *replacement);
-static int
-slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
+static void replace_token(char *resout, char *lines, const char *token,
+                         const char *replacement);
+static int slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
                                                        SlonikAdmInfo * adminfo1,
-                                                       const char * fqname);
-static int slonik_get_next_tab_id(SlonikStmt * stmt);
-static int slonik_get_next_sequence_id(SlonikStmt * stmt);
-static int find_origin(SlonikStmt * stmt,int set_id);
-static int
-slonik_set_add_single_sequence(SlonikStmt *stmt,
-                                                          SlonikAdmInfo *adminfo1,
-                                                          const char * seq_name,
+                                                       const char *fqname);
+static int     slonik_get_next_tab_id(SlonikStmt * stmt);
+static int     slonik_get_next_sequence_id(SlonikStmt * stmt);
+static int     find_origin(SlonikStmt * stmt, int set_id);
+static int slonik_set_add_single_sequence(SlonikStmt * stmt,
+                                                          SlonikAdmInfo * adminfo1,
+                                                          const char *seq_name,
                                                           int set_id,
-                                                          const char * seq_comment,
+                                                          const char *seq_comment,
                                                           int seq_id);
 
-static int
-slonik_add_dependent_sequences(SlonikStmt_set_add_table *stmt,
+static int slonik_add_dependent_sequences(SlonikStmt_set_add_table * stmt,
                                                           SlonikAdmInfo * adminfo1,
-                                                          const char * table_name);
+                                                          const char *table_name);
 static int slonik_is_slony_installed(SlonikStmt * stmt,
                                                  SlonikAdmInfo * adminfo);
 static int slonik_submitEvent(SlonikStmt * stmt,
-                                                         SlonikAdmInfo * adminfo, 
-                                                         SlonDString * query,
-                                                         SlonikScript * script,
-                                                         int suppress_wait_for);
-
-static size_t slonik_get_last_event_id(SlonikStmt* stmt,
-                                                                       SlonikScript * script,
-                                                                       const char * event_filter,
-                                                                       int64 ** events);
+                                  SlonikAdmInfo * adminfo,
+                                  SlonDString * query,
+                                  SlonikScript * script,
+                                  int suppress_wait_for);
+
+static size_t slonik_get_last_event_id(SlonikStmt * stmt,
+                                                SlonikScript * script,
+                                                const char *event_filter,
+                                                int64 **events);
 static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1,
-                                                                          SlonikStmt * stmt,
-                                                                          int ignore_node);
+                                                       SlonikStmt * stmt,
+                                                       int ignore_node);
 static int64 get_last_escaped_event_id(SlonikStmt * stmt,
-                                                               int node_id,
-                                                       int * skip_node_list);          
+                                                 int node_id,
+                                                 int *skip_node_list);
 
 
-static int
-fail_node_restart(SlonikStmt_failed_node * stmt,
+static int fail_node_restart(SlonikStmt_failed_node * stmt,
                                  failed_node_entry * node_entry,
                                  failnode_node * nodeinfo);
 
 
-static int fail_node_promote(SlonikStmt_failed_node * stmt,
-                                                        failed_node_entry * node_entry,
-                                                        failnode_node* nodeinfo
-                                                        ,int * fail_node_ids);
+static int
+fail_node_promote(SlonikStmt_failed_node * stmt,
+                                 failed_node_entry * node_entry,
+                                 failnode_node * nodeinfo
+                                 ,int *fail_node_ids);
+
 /* ----------
  * main
  * ----------
@@ -166,7 +163,7 @@ main(int argc, const char *argv[])
        extern int      optind;
        int                     opt;
 
-       while ((opt = getopt(argc, (char **)argv, "hvw")) != EOF)
+       while ((opt = getopt(argc, (char **) argv, "hvw")) != EOF)
        {
                switch (opt)
                {
@@ -179,7 +176,7 @@ main(int argc, const char *argv[])
                                exit(0);
                                break;
                        case 'w':
-                               auto_wait_disabled=1;
+                               auto_wait_disabled = 1;
                                break;
 
                        default:
@@ -193,7 +190,7 @@ main(int argc, const char *argv[])
                usage();
 
        /*
-        * We need to find a share directory like PostgreSQL. 
+        * We need to find a share directory like PostgreSQL.
         */
        strcpy(share_path, PGSHARE);
 
@@ -210,7 +207,7 @@ main(int argc, const char *argv[])
                                return -1;
                        }
                        scan_new_input_file(fp);
-                       current_file = (char *)argv[optind++];
+                       current_file = (char *) argv[optind++];
                        yylineno = 1;
                        yyparse();
                        fclose(fp);
@@ -349,17 +346,18 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                break;
 
                        case STMT_EXIT:
-                           {
-                                  SlonikStmt_exit *stmt = 
-                                                  (SlonikStmt_exit *) hdr;
-                                  if ((stmt->exitcode < 0) || (stmt->exitcode > 255)) 
-                                  {
-                                                  printf("%s:%d: Error: exitcode was %d - must be in range [0-255]\n",
-                                                                 hdr->stmt_filename, hdr->stmt_lno, stmt->exitcode);
-                                                  errors++;
-                                  }
-                           }
-                           break;
+                               {
+                                       SlonikStmt_exit *stmt =
+                                       (SlonikStmt_exit *) hdr;
+
+                                       if ((stmt->exitcode < 0) || (stmt->exitcode > 255))
+                                       {
+                                               printf("%s:%d: Error: exitcode was %d - must be in range [0-255]\n",
+                                                 hdr->stmt_filename, hdr->stmt_lno, stmt->exitcode);
+                                               errors++;
+                                       }
+                               }
+                               break;
 
                        case STMT_RESTART_NODE:
                                {
@@ -386,29 +384,30 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        }
                                }
                                break;
-               case STMT_RESUBSCRIBE_NODE:
+                       case STMT_RESUBSCRIBE_NODE:
                                {
-                                 SlonikStmt_resubscribe_node * stmt = 
-                                       (SlonikStmt_resubscribe_node*)hdr;
-                                 if (stmt->no_origin < 0 )
-                                 {
-                                         printf("%s:%d: Error: require ORIGIN node\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                       SlonikStmt_resubscribe_node *stmt =
+                                       (SlonikStmt_resubscribe_node *) hdr;
+
+                                       if (stmt->no_origin < 0)
+                                       {
+                                               printf("%s:%d: Error: require ORIGIN node\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
-                                 }
-                                 if (stmt->no_provider < 0 )
-                                 {
+                                       }
+                                       if (stmt->no_provider < 0)
+                                       {
 
-                                         printf("%s:%d: Error: require PROVIDER node\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                               printf("%s:%d: Error: require PROVIDER node\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
-                                 }
-                                 if (stmt->no_receiver  < 0 )
-                                 {
-                                         printf("%s:%d: Error: require RECEIVER node\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                       }
+                                       if (stmt->no_receiver < 0)
+                                       {
+                                               printf("%s:%d: Error: require RECEIVER node\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
-                                 }
+                                       }
                                }
                                break;
                        case STMT_ERROR:
@@ -434,8 +433,8 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
 
                                        if (stmt->ev_origin < 0)
                                        {
-                                               printf("%s:%d: Error: require EVENT NODE\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                               printf("%s:%d: Error: require EVENT NODE\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
                                        if (stmt->no_id == stmt->ev_origin)
@@ -459,23 +458,24 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
 
                                        if (stmt->ev_origin < 0)
                                        {
-                                               printf("%s:%d: Error: require EVENT NODE\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                               printf("%s:%d: Error: require EVENT NODE\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
-                                       if(stmt->no_id_list == NULL ||
-                                          stmt->no_id_list[0] == -1) 
+                                       if (stmt->no_id_list == NULL ||
+                                               stmt->no_id_list[0] == -1)
                                        {
                                                printf("%s:%d: Error: A node id must be provided",
-                                                           hdr->stmt_filename, hdr->stmt_lno);
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
-                                       else 
+                                       else
                                        {
-                                               int cnt;
-                                               for(cnt=0;stmt->no_id_list[cnt]!=-1;cnt++)
+                                               int                     cnt;
+
+                                               for (cnt = 0; stmt->no_id_list[cnt] != -1; cnt++)
                                                {
-                                                       if(stmt->no_id_list[cnt]==stmt->ev_origin)
+                                                       if (stmt->no_id_list[cnt] == stmt->ev_origin)
                                                        {
                                                                printf("%s:%d: Error: "
                                                                           "Node ID (%d) and event node cannot be identical\n",
@@ -484,7 +484,7 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                                                errors++;
                                                        }
                                                }
-                                               
+
                                        }
                                        if (script_check_adminfo(hdr, stmt->ev_origin) < 0)
                                                errors++;
@@ -495,27 +495,27 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                {
                                        SlonikStmt_failed_node *stmt =
                                        (SlonikStmt_failed_node *) hdr;
-                                       failed_node_entry* node=NULL;
+                                       failed_node_entry *node = NULL;
 
-                                       if(stmt->nodes == NULL)
+                                       if (stmt->nodes == NULL)
                                        {
-                                               printf("%s:%d: Error: require at least one failed node\n", 
-                                                                  hdr->stmt_filename, hdr->stmt_lno);
+                                               printf("%s:%d: Error: require at least one failed node\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
-                                       for(node=stmt->nodes; node != NULL;
-                                               node=node->next)
+                                       for (node = stmt->nodes; node != NULL;
+                                                node = node->next)
                                        {
                                                if (node->backup_node < 0)
                                                {
-                                                       printf("%s:%d: Error: require BACKUP NODE\n", 
+                                                       printf("%s:%d: Error: require BACKUP NODE\n",
                                                                   hdr->stmt_filename, hdr->stmt_lno);
                                                        errors++;
                                                }
                                                if (node->backup_node == node->no_id)
                                                {
                                                        printf("%s:%d: Error: "
-                                                                  "Node ID and backup node cannot be identical\n",
+                                                        "Node ID and backup node cannot be identical\n",
                                                                   hdr->stmt_filename, hdr->stmt_lno);
                                                        errors++;
                                                }
@@ -523,7 +523,7 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                                        errors++;
                                        }
                                        /**
-                                        * todo: verify that one backup node isn't also 
+                                        * todo: verify that one backup node isn't also
                                         * a failing node.
                                         */
                                }
@@ -639,6 +639,7 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                {
                                        SlonikStmt_create_set *stmt =
                                        (SlonikStmt_create_set *) hdr;
+
                                        if (stmt->set_id < 0)
                                        {
                                                printf("%s:%d: Error: "
@@ -711,14 +712,14 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                                           hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
-                                       if(stmt->set_origin > 0)
+                                       if (stmt->set_origin > 0)
                                        {
                                                if (script_check_adminfo(hdr, stmt->set_origin) < 0)
-                                                       errors++;                               
+                                                       errors++;
                                        }
-                               
+
                                        if (stmt->tab_fqname == NULL &&
-                                               stmt->tables == NULL )
+                                               stmt->tables == NULL)
                                        {
                                                printf("%s:%d: Error: "
                                                           "'fully qualfied name' or 'tables' must be specified\n",
@@ -728,27 +729,27 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        if (stmt->tab_fqname != NULL &&
                                                stmt->tables != NULL)
                                        {
-                                         printf("%s:%d: Error: "
-                                                        "'fully qualified name' and 'tables' can not both"
-                                                        " be specified",hdr->stmt_filename,
-                                                        hdr->stmt_lno);
-                                         errors++;
+                                               printf("%s:%d: Error: "
+                                                  "'fully qualified name' and 'tables' can not both"
+                                                          " be specified", hdr->stmt_filename,
+                                                          hdr->stmt_lno);
+                                               errors++;
                                        }
-                                       if ( stmt->tables != NULL && 
-                                                stmt->use_key != NULL)
+                                       if (stmt->tables != NULL &&
+                                               stmt->use_key != NULL)
                                        {
 
                                                printf("%s:%d: ERROR: "
                                                           "'key' can not be used with the 'tables' "
-                                                          "option.",hdr->stmt_filename,
+                                                          "option.", hdr->stmt_filename,
                                                           hdr->stmt_lno);
                                                errors++;
                                        }
 
                                        if (stmt->tab_comment == NULL && stmt->tab_fqname != NULL)
                                                stmt->tab_comment = strdup(stmt->tab_fqname);
-                                       else if (stmt->tab_comment==NULL)
-                                               stmt->tab_comment=strdup("replicated table");
+                                       else if (stmt->tab_comment == NULL)
+                                               stmt->tab_comment = strdup("replicated table");
                                }
                                break;
 
@@ -769,34 +770,34 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                                errors++;
                                        }
                                        if (stmt->set_origin >= 0)
-                                       {                                       
+                                       {
                                                if (script_check_adminfo(hdr, stmt->set_origin) < 0)
                                                        errors++;
                                        }
-                                       
+
                                        if (stmt->seq_fqname == NULL &&
-                                               stmt->sequences == NULL )
+                                               stmt->sequences == NULL)
                                        {
                                                printf("%s:%d: Error: "
-                                                          "sequence FQ-name or sequences must be specified\n",
+                                                "sequence FQ-name or sequences must be specified\n",
                                                           hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
                                        if (stmt->seq_fqname != NULL &&
                                                stmt->sequences != NULL)
                                        {
-                                         printf("%s:%d: Error: "
-                                                        "'fully qualified name' and 'sequences' can not both"
-                                                        " be specified",hdr->stmt_filename,
-                                                        hdr->stmt_lno);
-                                         errors++;
+                                               printf("%s:%d: Error: "
+                                               "'fully qualified name' and 'sequences' can not both"
+                                                          " be specified", hdr->stmt_filename,
+                                                          hdr->stmt_lno);
+                                               errors++;
                                        }
 
                                        if (stmt->seq_comment == NULL &&
                                                stmt->seq_fqname != NULL)
                                                stmt->seq_comment = strdup(stmt->seq_fqname);
                                        else if (stmt->seq_comment == NULL)
-                                               stmt->seq_comment=strdup("replicated sequence");
+                                               stmt->seq_comment = strdup("replicated sequence");
                                }
                                break;
 
@@ -1010,8 +1011,8 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                                           "set id must be specified\n",
                                                           hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
-                                       }                                       
-                                   if (stmt->set_origin < 0)
+                                       }
+                                       if (stmt->set_origin < 0)
                                        {
                                                printf("%s:%d: Error: "
                                                           "origin must be specified\n",
@@ -1094,8 +1095,8 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
 
                                        if (stmt->ev_origin < 0)
                                        {
-                                               printf("%s:%d: Error: require EVENT NODE\n", 
-                                                      hdr->stmt_filename, hdr->stmt_lno);
+                                               printf("%s:%d: Error: require EVENT NODE\n",
+                                                          hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
                                        if (stmt->ddl_fname == NULL)
@@ -1108,7 +1109,7 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        if ((stmt->only_on_node > 0) && (stmt->only_on_nodes != NULL))
                                        {
                                                printf("%s:%d: Error: "
-                                                          "cannot specify singular node as well as node list\n",
+                                               "cannot specify singular node as well as node list\n",
                                                           hdr->stmt_filename, hdr->stmt_lno);
                                                errors++;
                                        }
@@ -1210,7 +1211,7 @@ script_check_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        {
                                                printf("%s:%d: Error: "
                                                           " sleep time (%d) must be positive\n",
-                                                      hdr->stmt_filename, hdr->stmt_lno, stmt->num_secs);
+                                                 hdr->stmt_filename, hdr->stmt_lno, stmt->num_secs);
                                                errors++;
                                        }
 
@@ -1256,23 +1257,23 @@ static int
 script_exec_stmts(SlonikScript * script, SlonikStmt * hdr)
 {
        int                     errors = 0;
-       int64 events;
-       size_t event_length;
-       int idx=0;
-       SlonikAdmInfo * curAdmInfo;
-
-       event_length=slonik_get_last_event_id(hdr,script,"ev_type <> 'SYNC' ",
-                                                                                 &events);
-       forcurAdmInfo = script->adminfo_list;
-               curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
+       int64      *events;
+       size_t          event_length;
+       int                     idx = 0;
+       SlonikAdmInfo *curAdmInfo;
+
+       event_length = slonik_get_last_event_id(hdr, script, "ev_type <> 'SYNC' ",
+                                                                                       &events);
+       for (curAdmInfo = script->adminfo_list;
+                curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
        {
-               curAdmInfo->last_event=events[idx];
+               curAdmInfo->last_event = events[idx];
                idx++;
-               if(idx > event_length)
+               if (idx > event_length)
                        break;
-       }       
+       }
        free(events);
-       block_stmt_no=0;
+       block_stmt_no = 0;
        while (hdr && errors == 0)
        {
                hdr->script = script;
@@ -1285,13 +1286,13 @@ script_exec_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        SlonikStmt_try *stmt =
                                        (SlonikStmt_try *) hdr;
                                        int                     rc;
-                                       int saved_stmt_no;
+                                       int                     saved_stmt_no;
 
                                        current_try_level++;
-                                       saved_stmt_no=block_stmt_no;
+                                       saved_stmt_no = block_stmt_no;
                                        rc = script_exec_stmts(script, stmt->try_block);
                                        current_try_level--;
-                                       block_stmt_no=saved_stmt_no;
+                                       block_stmt_no = saved_stmt_no;
 
                                        if (rc < 0)
                                        {
@@ -1345,17 +1346,17 @@ script_exec_stmts(SlonikScript * script, SlonikStmt * hdr)
                                {
                                        SlonikStmt_date *stmt =
                                        (SlonikStmt_date *) hdr;
-                                       char outstr[200];
-                                       
-                                       struct tm *local;
-                                       time_t t;
-                                       
+                                       char            outstr[200];
+
+                                       struct tm  *local;
+                                       time_t          t;
+
                                        t = time(NULL);
                                        local = localtime(&t);
                                        strftime(outstr, sizeof(outstr), stmt->fmt, local);
                                        printf("%s:%d: %s\n",
-                                              stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
-                                              outstr);
+                                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
+                                                  outstr);
                                        block_stmt_no--;
                                }
                                break;
@@ -1391,7 +1392,7 @@ script_exec_stmts(SlonikScript * script, SlonikStmt * hdr)
                                        (SlonikStmt_init_cluster *) hdr;
 
                                        if (slonik_init_cluster(stmt) < 0)
-                                       errors++;
+                                               errors++;
                                }
                                break;
 
@@ -1406,9 +1407,10 @@ script_exec_stmts(SlonikScript * script, SlonikStmt * hdr)
                                break;
                        case STMT_RESUBSCRIBE_NODE:
                                {
-                                       SlonikStmt_resubscribe_node * stmt  =
-                                               (SlonikStmt_resubscribe_node*) hdr;
-                                       if(slonik_resubscribe_node(stmt) < 0)
+                                       SlonikStmt_resubscribe_node *stmt =
+                                       (SlonikStmt_resubscribe_node *) hdr;
+
+                                       if (slonik_resubscribe_node(stmt) < 0)
                                                errors++;
                                }
                                break;
@@ -1741,7 +1743,7 @@ script_commit_all(SlonikStmt * stmt, SlonikScript * script)
        {
                if (adminfo->dbconn != NULL && adminfo->have_xact)
                {
-                 db_commit_xact(stmt, adminfo);
+                       db_commit_xact(stmt, adminfo);
                }
                else
                {
@@ -1805,7 +1807,7 @@ static SlonikAdmInfo *
 get_active_adminfo(SlonikStmt * stmt, int no_id)
 {
        SlonikAdmInfo *adminfo;
-       int version;
+       int                     version;
 
        if ((adminfo = get_adminfo(stmt, no_id)) == NULL)
        {
@@ -1891,7 +1893,7 @@ load_sql_script(SlonikStmt * stmt, SlonikAdmInfo * adminfo, char *fname,...)
        FILE       *stmtp;
 
 
-       if (db_begin_xact(stmt, adminfo,true) < 0)
+       if (db_begin_xact(stmt, adminfo, true) < 0)
                return -1;
 
        va_start(ap, fname);
@@ -1986,37 +1988,37 @@ load_slony_base(SlonikStmt * stmt, int no_id)
        if (adminfo->pg_version < 80300)        /* before 8.3 */
        {
                printf("%s:%d: unsupported PostgreSQL "
-                       "version %d.%d (versions < 8.3 are not supported by Slony-I >= 2.0)\n",
-                       stmt->stmt_filename, stmt->stmt_lno,
-                       (adminfo->pg_version/10000), ((adminfo->pg_version%10000)/100));
-                       return -1;
+                          "version %d.%d (versions < 8.3 are not supported by Slony-I >= 2.0)\n",
+                          stmt->stmt_filename, stmt->stmt_lno,
+               (adminfo->pg_version / 10000), ((adminfo->pg_version % 10000) / 100));
+               return -1;
        }
-       else if ((adminfo->pg_version >= 80300) && (adminfo->pg_version < 80400)) /* 8.3 */
+       else if ((adminfo->pg_version >= 80300) && (adminfo->pg_version < 80400))       /* 8.3 */
        {
                use_major = 8;
                use_minor = 3;
        }
-       else if ((adminfo->pg_version >= 80400) && (adminfo->pg_version < 80500)) /* 8.4 */
+       else if ((adminfo->pg_version >= 80400) && (adminfo->pg_version < 80500))       /* 8.4 */
        {
                use_major = 8;
-               use_minor = 4;   
-       }               
-       else if ((adminfo->pg_version >= 90000) && (adminfo->pg_version < 90200)) /* 9.x */
+               use_minor = 4;
+       }
+       else if ((adminfo->pg_version >= 90000) && (adminfo->pg_version < 90200))       /* 9.x */
        {
                /**
                 * 9.0 and 9.1 are so far just like 8.4
                 **/
-               use_major=8;
-               use_minor=4;
+               use_major = 8;
+               use_minor = 4;
        }
        else    /* above 9.1 ??? */
        {
                use_major = 8;
                use_minor = 4;
                printf("%s:%d: Possible unsupported PostgreSQL "
-                       "version (%d) %d.%d, defaulting to 8.4 support\n",
-                        stmt->stmt_filename, stmt->stmt_lno, adminfo->pg_version,
-                       (adminfo->pg_version/10000), ((adminfo->pg_version%10000)/100));
+                          "version (%d) %d.%d, defaulting to 8.4 support\n",
+                          stmt->stmt_filename, stmt->stmt_lno, adminfo->pg_version,
+               (adminfo->pg_version / 10000), ((adminfo->pg_version % 10000) / 100));
        }
 
        dstring_init(&query);
@@ -2033,17 +2035,17 @@ load_slony_base(SlonikStmt * stmt, int no_id)
        /* Load schema, DB version specific */
        db_notice_silent = true;
        if (load_sql_script(stmt, adminfo,
-                           "%s/slony1_base.%s.sql", share_path,SLONY_I_VERSION_STRING) < 0
+                        "%s/slony1_base.%s.sql", share_path, SLONY_I_VERSION_STRING) < 0
                || load_sql_script(stmt, adminfo,
-                                  "%s/slony1_base.v%d%d.%s.sql", share_path, 
-                                  use_major, use_minor,
-                                  SLONY_I_VERSION_STRING) < 0
+                                                  "%s/slony1_base.v%d%d.%s.sql", share_path,
+                                                  use_major, use_minor,
+                                                  SLONY_I_VERSION_STRING) < 0
                || load_sql_script(stmt, adminfo,
-                                  "%s/slony1_funcs.%s.sql", share_path,
-                                  SLONY_I_VERSION_STRING) < 0
+                                                  "%s/slony1_funcs.%s.sql", share_path,
+                                                  SLONY_I_VERSION_STRING) < 0
                || load_sql_script(stmt, adminfo,
-                  "%s/slony1_funcs.v%d%d.%s.sql", share_path, use_major, 
-                                  use_minor,SLONY_I_VERSION_STRING) < 0)
+                                          "%s/slony1_funcs.v%d%d.%s.sql", share_path, use_major,
+                                                  use_minor, SLONY_I_VERSION_STRING) < 0)
        {
                db_notice_silent = false;
                dstring_free(&query);
@@ -2061,7 +2063,7 @@ static int
 load_slony_functions(SlonikStmt * stmt, int no_id)
 {
        SlonikAdmInfo *adminfo;
-       
+
 
        int                     use_major = 0;
        int                     use_minor = 0;
@@ -2070,27 +2072,27 @@ load_slony_functions(SlonikStmt * stmt, int no_id)
                return -1;
 
 
-        /* determine what schema version we should load */
+       /* determine what schema version we should load */
 
-        if (adminfo->pg_version < 80300)        /* before 8.3 */
-        {
-                printf("%s:%d: unsupported PostgreSQL "
-                        "version %d.%d\n",
-                        stmt->stmt_filename, stmt->stmt_lno,
-                        (adminfo->pg_version/10000), ((adminfo->pg_version%10000)/100));
-                       return -1;
-        }
-        else if ((adminfo->pg_version >= 80300) && adminfo->pg_version < 80400) /* 8.0 */
-        {
-                use_major = 8;
-                use_minor = 3;
-        }
-       else if ((adminfo->pg_version >= 80400) && (adminfo->pg_version < 80500)) /* 8.4 */
+       if (adminfo->pg_version < 80300)        /* before 8.3 */
+       {
+               printf("%s:%d: unsupported PostgreSQL "
+                          "version %d.%d\n",
+                          stmt->stmt_filename, stmt->stmt_lno,
+               (adminfo->pg_version / 10000), ((adminfo->pg_version % 10000) / 100));
+               return -1;
+       }
+       else if ((adminfo->pg_version >= 80300) && adminfo->pg_version < 80400)         /* 8.0 */
+       {
+               use_major = 8;
+               use_minor = 3;
+       }
+       else if ((adminfo->pg_version >= 80400) && (adminfo->pg_version < 80500))       /* 8.4 */
        {
                use_major = 8;
                use_minor = 4;
        }
-       else if ((adminfo->pg_version >= 90000) && (adminfo->pg_version < 90200)) /* 9.0, 9.1 */
+       else if ((adminfo->pg_version >= 90000) && (adminfo->pg_version < 90200))       /* 9.0, 9.1 */
        {
                /**
                 * 9.0 and 9.1 are so far just like 8.4
@@ -2098,24 +2100,24 @@ load_slony_functions(SlonikStmt * stmt, int no_id)
                use_major = 8;
                use_minor = 4;
        }
-       else    /* above 8.4 */
+       else    /* above 8.4 */
        {
                use_major = 8;
                use_minor = 4;
                printf("%s:%d: Possible unsupported PostgreSQL "
                           "version (%d) %d.%d, defaulting to 8.4 support\n",
-                      stmt->stmt_filename, stmt->stmt_lno, adminfo->pg_version,
-                      (adminfo->pg_version/10000), ((adminfo->pg_version%10000)/100));
+                          stmt->stmt_filename, stmt->stmt_lno, adminfo->pg_version,
+               (adminfo->pg_version / 10000), ((adminfo->pg_version % 10000) / 100));
        }
 
        /* Load schema, DB version specific */
        db_notice_silent = true;
        if (load_sql_script(stmt, adminfo,
-                                               "%s/slony1_funcs.%s.sql", 
-                           share_path,SLONY_I_VERSION_STRING) < 0
+                                               "%s/slony1_funcs.%s.sql",
+                                               share_path, SLONY_I_VERSION_STRING) < 0
                || load_sql_script(stmt, adminfo,
-                  "%s/slony1_funcs.v%d%d.%s.sql", share_path, use_major, 
-                                  use_minor,SLONY_I_VERSION_STRING) < 0)
+                                          "%s/slony1_funcs.v%d%d.%s.sql", share_path, use_major,
+                                                  use_minor, SLONY_I_VERSION_STRING) < 0)
        {
                db_notice_silent = false;
                return -1;
@@ -2198,7 +2200,7 @@ slonik_init_cluster(SlonikStmt_init_cluster * stmt)
        if (adminfo == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo,true) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo, true) < 0)
                return -1;
 
        rc = load_slony_base((SlonikStmt *) stmt, stmt->no_id);
@@ -2239,30 +2241,30 @@ slonik_store_node(SlonikStmt_store_node * stmt)
        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(!auto_wait_disabled)
+       if (!auto_wait_disabled)
        {
-               rc=slonik_wait_config_caughtup(adminfo2,&stmt->hdr,stmt->no_id);
-               if(rc < 0 )
-                 return rc;
+               rc = slonik_wait_config_caughtup(adminfo2, &stmt->hdr, stmt->no_id);
+               if (rc < 0)
+                       return rc;
        }
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo2,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo2, false) < 0)
                return -1;
 
        dstring_init(&query);
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,true) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, true) < 0)
        {
                dstring_free(&query);
                return -1;
        }
-       
+
        /* Load the slony base tables */
        rc = load_slony_base((SlonikStmt *) stmt, stmt->no_id);
        if (rc < 0)
@@ -2285,14 +2287,14 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                dstring_free(&query);
                return -1;
        }
-       
+
        /*
         * Duplicate the content of sl_node
         */
        slon_mkquery(&query,
-                    "select no_id, no_active, no_comment "
-                    "from \"_%s\".sl_node; ",
-                    stmt->hdr.script->clustername);
+                                "select no_id, no_active, no_comment "
+                                "from \"_%s\".sl_node; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2305,17 +2307,17 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *no_id = PQgetvalue(res, tupno, 0);
                char       *no_active = PQgetvalue(res, tupno, 1);
                char       *no_comment = PQgetvalue(res, tupno, 2);
-               
+
                slon_mkquery(&query,
-                            "select \"_%s\".storeNode_int(%s, '%q'); ",
-                            stmt->hdr.script->clustername, no_id, no_comment);
+                                        "select \"_%s\".storeNode_int(%s, '%q'); ",
+                                        stmt->hdr.script->clustername, no_id, no_comment);
                if (*no_active == 't')
                {
                        slon_appendquery(&query,
-                                        "select \"_%s\".enableNode_int(%s); ",
-                                        stmt->hdr.script->clustername, no_id);
+                                                        "select \"_%s\".enableNode_int(%s); ",
+                                                        stmt->hdr.script->clustername, no_id);
                }
-               
+
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
                {
                        dstring_free(&query);
@@ -2324,14 +2326,14 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /*
         * Duplicate the content of sl_path
         */
        slon_mkquery(&query,
-                    "select pa_server, pa_client, pa_conninfo, pa_connretry "
-                    "from \"_%s\".sl_path; ",
-                    stmt->hdr.script->clustername);
+                                "select pa_server, pa_client, pa_conninfo, pa_connretry "
+                                "from \"_%s\".sl_path; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2347,11 +2349,11 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *pa_connretry = PQgetvalue(res, tupno, 3);
 
                slon_mkquery(&query,
-                                "lock table \"_%s\".sl_config_lock;"
-                            "select \"_%s\".storePath_int(%s, %s, '%q', %s); ",
-                            stmt->hdr.script->clustername,
-                            stmt->hdr.script->clustername,
-                            pa_server, pa_client, pa_conninfo, pa_connretry);
+                                        "lock table \"_%s\".sl_config_lock;"
+                                        "select \"_%s\".storePath_int(%s, %s, '%q', %s); ",
+                                        stmt->hdr.script->clustername,
+                                        stmt->hdr.script->clustername,
+                                        pa_server, pa_client, pa_conninfo, pa_connretry);
 
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
                {
@@ -2361,14 +2363,14 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /*
         * Duplicate the content of sl_listen
         */
        slon_mkquery(&query,
-                    "select li_origin, li_provider, li_receiver "
-                    "from \"_%s\".sl_listen; ",
-                    stmt->hdr.script->clustername);
+                                "select li_origin, li_provider, li_receiver "
+                                "from \"_%s\".sl_listen; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2381,12 +2383,12 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *li_origin = PQgetvalue(res, tupno, 0);
                char       *li_provider = PQgetvalue(res, tupno, 1);
                char       *li_receiver = PQgetvalue(res, tupno, 2);
-               
+
                slon_mkquery(&query,
-                            "select \"_%s\".storeListen_int(%s, %s, %s); ",
-                            stmt->hdr.script->clustername,
-                            li_origin, li_provider, li_receiver);
-               
+                                        "select \"_%s\".storeListen_int(%s, %s, %s); ",
+                                        stmt->hdr.script->clustername,
+                                        li_origin, li_provider, li_receiver);
+
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
                {
                        dstring_free(&query);
@@ -2395,14 +2397,14 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /*
         * Duplicate the content of sl_set
         */
        slon_mkquery(&query,
-                    "select set_id, set_origin, set_comment "
-                    "from \"_%s\".sl_set; ",
-                    stmt->hdr.script->clustername);
+                                "select set_id, set_origin, set_comment "
+                                "from \"_%s\".sl_set; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2417,9 +2419,9 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *set_comment = PQgetvalue(res, tupno, 2);
 
                slon_mkquery(&query,
-                            "select \"_%s\".storeSet_int(%s, %s, '%q'); ",
-                            stmt->hdr.script->clustername,
-                            set_id, set_origin, set_comment);
+                                        "select \"_%s\".storeSet_int(%s, %s, '%q'); ",
+                                        stmt->hdr.script->clustername,
+                                        set_id, set_origin, set_comment);
 
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
                {
@@ -2429,15 +2431,15 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /*
         * Duplicate the content of sl_subscribe
         */
        slon_mkquery(&query,
-                    "select sub_set, sub_provider, sub_receiver, "
-                    "  sub_forward, sub_active "
-                    "from \"_%s\".sl_subscribe; ",
-                                        stmt->hdr.script->clustername);
+                                "select sub_set, sub_provider, sub_receiver, "
+                                "      sub_forward, sub_active "
+                                "from \"_%s\".sl_subscribe; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2452,21 +2454,21 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *sub_receiver = PQgetvalue(res, tupno, 2);
                char       *sub_forward = PQgetvalue(res, tupno, 3);
                char       *sub_active = PQgetvalue(res, tupno, 4);
-                       
+
                slon_mkquery(&query,
-                                "lock table \"_%s\".sl_config_lock;"
-                            "select \"_%s\".subscribeSet_int(%s, %s, %s, '%q', 'f'); ",
-                            stmt->hdr.script->clustername,
-                            stmt->hdr.script->clustername,
-                            sub_set, sub_provider, sub_receiver, sub_forward);
+                                        "lock table \"_%s\".sl_config_lock;"
+                                 "select \"_%s\".subscribeSet_int(%s, %s, %s, '%q', 'f'); ",
+                                        stmt->hdr.script->clustername,
+                                        stmt->hdr.script->clustername,
+                                        sub_set, sub_provider, sub_receiver, sub_forward);
                if (*sub_active == 't')
                {
                        slon_appendquery(&query,
-                                        "select \"_%s\".enableSubscription_int(%s, %s, %s); ",
-                                        stmt->hdr.script->clustername,
-                                        sub_set, sub_provider, sub_receiver);
+                                          "select \"_%s\".enableSubscription_int(%s, %s, %s); ",
+                                                        stmt->hdr.script->clustername,
+                                                        sub_set, sub_provider, sub_receiver);
                }
-               
+
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
                {
                        dstring_free(&query);
@@ -2475,16 +2477,16 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /*
         * Set our own event seqno in case the node id was used before and our
         * confirms.
         */
        slon_mkquery(&query,
-                    "select ev_origin, max(ev_seqno) "
-                    "    from \"_%s\".sl_event "
-                    "    group by ev_origin; ",
-                    stmt->hdr.script->clustername);
+                                "select ev_origin, max(ev_seqno) "
+                                "    from \"_%s\".sl_event "
+                                "    group by ev_origin; ",
+                                stmt->hdr.script->clustername);
        res = db_exec_select((SlonikStmt *) stmt, adminfo2, &query);
        if (res == NULL)
        {
@@ -2497,22 +2499,22 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                char       *ev_origin_c = PQgetvalue(res, tupno, 0);
                char       *ev_seqno_c = PQgetvalue(res, tupno, 1);
 
-               if (stmt->no_id == (int)strtol(ev_origin_c, NULL, 10))
+               if (stmt->no_id == (int) strtol(ev_origin_c, NULL, 10))
                {
                        slon_mkquery(&query,
-                                    "select \"pg_catalog\".setval('\"_%s\".sl_event_seq', "
-                                    "'%s'::int8 + 1); ",
-                                    stmt->hdr.script->clustername, ev_seqno_c);
+                                         "select \"pg_catalog\".setval('\"_%s\".sl_event_seq', "
+                                                "'%s'::int8 + 1); ",
+                                                stmt->hdr.script->clustername, ev_seqno_c);
                }
                else
                {
                        slon_appendquery(&query,
-                                        "insert into \"_%s\".sl_confirm "
-                                        "    (con_origin, con_received, con_seqno, con_timestamp) "
-                                        "    values "
-                                        "    (%s, %d, '%s', CURRENT_TIMESTAMP); ",
-                                        stmt->hdr.script->clustername,
-                                        ev_origin_c, stmt->no_id, ev_seqno_c);
+                                                        "insert into \"_%s\".sl_confirm "
+                                 "    (con_origin, con_received, con_seqno, con_timestamp) "
+                                                        "    values "
+                                                        "    (%s, %d, '%s', CURRENT_TIMESTAMP); ",
+                                                        stmt->hdr.script->clustername,
+                                                        ev_origin_c, stmt->no_id, ev_seqno_c);
                }
 
                if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
@@ -2523,7 +2525,7 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                }
        }
        PQclear(res);
-       
+
        /* On the existing node, call storeNode() and enableNode() */
        slon_mkquery(&query,
                                 "select \"_%s\".storeNode(%d, '%q'); "
@@ -2531,7 +2533,7 @@ slonik_store_node(SlonikStmt_store_node * stmt)
                                 stmt->hdr.script->clustername, stmt->no_id, stmt->no_comment,
                                 stmt->hdr.script->clustername, stmt->no_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo2, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -2548,43 +2550,45 @@ slonik_drop_node(SlonikStmt_drop_node * stmt)
        SlonikAdmInfo *adminfo1;
        SlonikAdmInfo *adminfo2;
        SlonDString query;
-       SlonikAdmInfo * curAdmInfo;
-       int rc;
-       int no_id_idx;
+       SlonikAdmInfo *curAdmInfo;
+       int                     rc;
+       int                     no_id_idx;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->ev_origin);
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
-       for(no_id_idx=0; stmt->no_id_list[no_id_idx]!=-1;no_id_idx++)
+       for (no_id_idx = 0; stmt->no_id_list[no_id_idx] != -1; no_id_idx++)
        {
-               int64 ev_id;
-               if(!auto_wait_disabled)
+               int64           ev_id;
+
+               if (!auto_wait_disabled)
                {
-                       for(curAdmInfo = stmt->hdr.script->adminfo_list;
-                               curAdmInfo!=NULL; curAdmInfo=curAdmInfo->next)
+                       for (curAdmInfo = stmt->hdr.script->adminfo_list;
+                                curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
                        {
-                               int skip=0;
-                               int list_idx;
-                               SlonikAdmInfo * fake_admin_info=NULL;
+                               int                     skip = 0;
+                               int                     list_idx;
+                               SlonikAdmInfo *fake_admin_info = NULL;
+
                                /**
                                 * If we have admin info for any of the nodes being dropped
                                 * we disable 'wait for' on that node.
                                 */
-                               for(list_idx=0; stmt->no_id_list[list_idx] != -1; list_idx++)
+                               for (list_idx = 0; stmt->no_id_list[list_idx] != -1; list_idx++)
                                {
 
-                                       
-                                       if(curAdmInfo->no_id==stmt->no_id_list[list_idx])
+
+                                       if (curAdmInfo->no_id == stmt->no_id_list[list_idx])
                                        {
-                                               skip=1;
+                                               skip = 1;
                                                break;
                                        }
                                }
-                               if(skip)
+                               if (skip)
                                        continue;
                                /**
                                 * find the last event (including SYNC events)
@@ -2597,63 +2601,64 @@ slonik_drop_node(SlonikStmt_drop_node * stmt)
                                 * origin before a FAILOVER. Some behind node still
                                 * might need to get caught up from its provider.
                                 */
-                               ev_id=get_last_escaped_event_id((SlonikStmt*)stmt,
-                                                                                               stmt->no_id_list[no_id_idx],
-                                                                                               stmt->no_id_list);
-                               if(ev_id > 0)
+                               ev_id = get_last_escaped_event_id((SlonikStmt *) stmt,
+                                                                                                 stmt->no_id_list[no_id_idx],
+                                                                                                 stmt->no_id_list);
+                               if (ev_id > 0)
                                {
-                                       SlonikStmt_wait_event wait_event;               
-                                       wait_event.hdr=*(SlonikStmt*)stmt;
-                                       wait_event.wait_origin=stmt->no_id_list[no_id_idx];
-                                       wait_event.wait_on=stmt->ev_origin;
-                                       wait_event.wait_confirmed=stmt->ev_origin;
-                                       wait_event.wait_timeout=0;
-                                       wait_event.ignore_nodes=0;
-                                       
-                                       adminfo2 = get_adminfo(&stmt->hdr,stmt->no_id_list[no_id_idx]);
-                                       if(adminfo2 == NULL) 
+                                       SlonikStmt_wait_event wait_event;
+
+                                       wait_event.hdr = *(SlonikStmt *) stmt;
+                                       wait_event.wait_origin = stmt->no_id_list[no_id_idx];
+                                       wait_event.wait_on = stmt->ev_origin;
+                                       wait_event.wait_confirmed = stmt->ev_origin;
+                                       wait_event.wait_timeout = 0;
+                                       wait_event.ignore_nodes = 0;
+
+                                       adminfo2 = get_adminfo(&stmt->hdr, stmt->no_id_list[no_id_idx]);
+                                       if (adminfo2 == NULL)
                                        {
-                                               fake_admin_info=malloc(sizeof(SlonikAdmInfo));
-                                               memset(fake_admin_info,0,sizeof(SlonikAdmInfo));
-                                               fake_admin_info->next=stmt->hdr.script->adminfo_list->next;
-                                               stmt->hdr.script->adminfo_list->next=fake_admin_info;
-                                               
+                                               fake_admin_info = malloc(sizeof(SlonikAdmInfo));
+                                               memset(fake_admin_info, 0, sizeof(SlonikAdmInfo));
+                                               fake_admin_info->next = stmt->hdr.script->adminfo_list->next;
+                                               stmt->hdr.script->adminfo_list->next = fake_admin_info;
+
                                        }
-                                       adminfo2->last_event=ev_id;
+                                       adminfo2->last_event = ev_id;
                                        printf("debug: waiting for %d,%ld on %d\n",
-                                                  wait_event.wait_origin,ev_id,wait_event.wait_on);
-                                       rc=slonik_wait_event(&wait_event);
-                                       if(rc < 0 )
+                                                  wait_event.wait_origin, ev_id, wait_event.wait_on);
+                                       rc = slonik_wait_event(&wait_event);
+                                       if (rc < 0)
                                        {
                                                return rc;
                                        }
-                                       if(fake_admin_info != NULL)
+                                       if (fake_admin_info != NULL)
                                        {
-                                               stmt->hdr.script->adminfo_list->next=fake_admin_info->next;
-                                               free(fake_admin_info);                                  
+                                               stmt->hdr.script->adminfo_list->next = fake_admin_info->next;
+                                               free(fake_admin_info);
                                        }
-                                       
+
                                }
-                               if(slonik_is_slony_installed((SlonikStmt*)stmt,curAdmInfo) > 0 )
+                               if (slonik_is_slony_installed((SlonikStmt *) stmt, curAdmInfo) > 0)
                                {
-                                       rc=slonik_wait_config_caughtup(curAdmInfo,(SlonikStmt*)stmt,
-                                                                                                  -1);
-                                       if(rc < 0)
+                                       rc = slonik_wait_config_caughtup(curAdmInfo, (SlonikStmt *) stmt,
+                                                                                                        -1);
+                                       if (rc < 0)
                                                return rc;
-                               }                                                       
+                               }
                        }
-                       
+
                }
 
        }
-       
+
 
        dstring_init(&query);
-       
-       for(no_id_idx=0; stmt->no_id_list[no_id_idx]!=-1;no_id_idx++)
+
+       for (no_id_idx = 0; stmt->no_id_list[no_id_idx] != -1; no_id_idx++)
        {
                slon_mkquery(&query,
-                                        "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
+                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
                                         "select \"_%s\".dropNode(%d); ",
                                         stmt->hdr.script->clustername,
                                         stmt->hdr.script->clustername,
@@ -2664,7 +2669,7 @@ slonik_drop_node(SlonikStmt_drop_node * stmt)
                 * above ignoring the node being dropped.
                 */
                if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                          stmt->hdr.script,true) < 0)
+                                                          stmt->hdr.script, true) < 0)
                {
                        dstring_free(&query);
                        return -1;
@@ -2673,12 +2678,13 @@ slonik_drop_node(SlonikStmt_drop_node * stmt)
                 * if we have a conninfo for the node being dropped
                 * we want to clear out the last seqid.
                 */
-               adminfo2 = get_adminfo(&stmt->hdr,stmt->no_id_list[no_id_idx]);
-               if(adminfo2 != NULL) {
-                       adminfo2->last_event=-1;
+               adminfo2 = get_adminfo(&stmt->hdr, stmt->no_id_list[no_id_idx]);
+               if (adminfo2 != NULL)
+               {
+                       adminfo2->last_event = -1;
                }
        }
-               dstring_free(&query);   
+       dstring_free(&query);
        return 0;
 }
 
@@ -2691,25 +2697,25 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
        SlonDString query;
        SlonDString failed_node_list;
 
-       int                     i;                              
-       int                     num_origins=0;
-       int                     cur_origin_idx=0;       
-       char       **failnodebuf;
-       int                **set_list=0;
+       int                     i;
+       int                     num_origins = 0;
+       int                     cur_origin_idx = 0;
+       char      **failnodebuf;
+       int               **set_list = 0;
        PGresult   *res1;
        PGresult   *res2;
        PGresult   *res3;
-       int64           * max_seqno_total = 0;
+       int64      *max_seqno_total = 0;
        failnode_node **max_node_total = NULL;
-       failed_node_entry * node_entry = stmt->nodes;
-       int fail_node_ids = NULL;
+       failed_node_entry *node_entry = stmt->nodes;
+       int                *fail_node_ids = NULL;
 
        int                     rc = 0;
 
 
        /**
-        *  The failover procedure (at a high level) is as follows
-        *  
+        *      The failover procedure (at a high level) is as follows
+        *
         * 1. Get a list of failover candidates for each failed node.
         * 2. validate that we have conninfo to all of them
         * 3. blank there paths to the failed nodes
@@ -2718,73 +2724,74 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
         * 6. execute FAILOVER on the highest canidate
         * 7. MOVE SET to the backup node.
         */
-       
+
 
        dstring_init(&failed_node_list);
-       for(node_entry=stmt->nodes; node_entry != NULL;
-               node_entry=node_entry->next) 
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next)
        {
-               if ( node_entry==stmt->nodes)
-                       slon_appendquery(&failed_node_list,"%d",node_entry->no_id);
+               if (node_entry == stmt->nodes)
+                       slon_appendquery(&failed_node_list, "%d", node_entry->no_id);
                else
-                       slon_appendquery(&failed_node_list,",%d",node_entry->no_id);
+                       slon_appendquery(&failed_node_list, ",%d", node_entry->no_id);
                num_origins++;
        }
        dstring_terminate(&failed_node_list);
-       
 
-       
+
+
        /**
         * peform some memory allocations
         */
        dstring_init(&query);
-       failnodebuf = (char**) malloc ( sizeof(char*) * num_origins);
-       set_list = (int**) malloc ( sizeof(int*) * num_origins);
-       max_seqno_total = (int64*) malloc ( sizeof(int64) * num_origins);
-       max_node_total = (failnode_node **) malloc ( sizeof(failnode_node*) *
-                                                                                                num_origins);
-       fail_node_ids = (int*) malloc(sizeof(int) * num_origins+1);
-       memset(failnodebuf,0,sizeof(char*) * num_origins);
-       memset(max_node_total,0, sizeof(failnode_node*) * num_origins);
-       memset(max_seqno_total,0, sizeof(int64) * num_origins); 
-       memset(fail_node_ids , -1, sizeof(int) * (num_origins+1) );
-       memset(set_list, 0, sizeof(int*) * num_origins);
-
-
-   
+       failnodebuf = (char **) malloc(sizeof(char *) * num_origins);
+       set_list = (int **) malloc(sizeof(int *) * num_origins);
+       max_seqno_total = (int64 *) malloc(sizeof(int64) * num_origins);
+       max_node_total = (failnode_node **) malloc(sizeof(failnode_node *) *
+                                                                                          num_origins);
+       fail_node_ids = (int *) malloc(sizeof(int) * num_origins + 1);
+       memset(failnodebuf, 0, sizeof(char *) * num_origins);
+       memset(max_node_total, 0, sizeof(failnode_node *) * num_origins);
+       memset(max_seqno_total, 0, sizeof(int64) * num_origins);
+       memset(fail_node_ids, -1, sizeof(int) * (num_origins + 1));
+       memset(set_list, 0, sizeof(int *) * num_origins);
+
+
+
        /**
         * get the list of failover candidates for each of the
         * failed nodes.
         */
-       cur_origin_idx=0;
-       for(node_entry=stmt->nodes; node_entry != NULL;
-               node_entry=node_entry->next,cur_origin_idx++)
+       cur_origin_idx = 0;
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next, cur_origin_idx++)
        {
                failnode_node *nodeinfo;
-               bool has_candidate=false;
+               bool            has_candidate = false;
+
                adminfo1 = get_active_adminfo((SlonikStmt *) stmt, node_entry->backup_node);
                if (adminfo1 == NULL)
                {
                        printf("%s:%d no admin conninfo for node %d\n",
                                   stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
                                   node_entry->backup_node);
-                       rc=-1;
+                       rc = -1;
                        goto cleanup;
                }
-               if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+               if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                {
                        printf("%s:%d can not connect to node %d\n",
                                   stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
                                   node_entry->backup_node);
-                       rc=-1;
+                       rc = -1;
                        goto cleanup;
                }
 
-               fail_node_ids[cur_origin_idx]=node_entry->no_id;
+               fail_node_ids[cur_origin_idx] = node_entry->no_id;
 
                /*
-                * On the backup node select a list of all failover candidate
-                * nodes except for the failed nodes.
+                * On the backup node select a list of all failover candidate nodes
+                * except for the failed nodes.
                 */
                slon_mkquery(&query,
                                         "select distinct no_id, backup_id from "
@@ -2797,20 +2804,20 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                                         stmt->hdr.script->clustername,
                                         stmt->hdr.script->clustername,
                                         node_entry->no_id,
-                                        dstring_data(&failed_node_list), 
+                                        dstring_data(&failed_node_list),
                                         dstring_data(&failed_node_list));
                res1 = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
                if (res1 == NULL)
                {
-                       rc=-1;
+                       rc = -1;
                        goto cleanup;
                }
                node_entry->num_nodes = PQntuples(res1);
-               
-               
+
+
                /*
-                * Get a list of all sets that are subscribed more than once 
-                * directly from the origin
+                * Get a list of all sets that are subscribed more than once directly
+                * from the origin
                 */
                slon_mkquery(&query,
                                         "select S.set_id, count(S.set_id) "
@@ -2821,46 +2828,46 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                                         "    group by set_id ",
                                         stmt->hdr.script->clustername,
 
-                                                        stmt->hdr.script->clustername,
+                                        stmt->hdr.script->clustername,
                                         node_entry->no_id);
                res2 = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
                if (res2 == NULL)
                {
                        PQclear(res1);
-                       rc=-1;
+                       rc = -1;
                        goto cleanup;
                }
                node_entry->num_sets = PQntuples(res2);
-               
+
                /*
                 * Allocate and initialize memory to hold some config info
                 */
-               failnodebuf[cur_origin_idx] = malloc( sizeof(failnode_node) 
-                                                                                 * (node_entry->num_nodes
-                                                                                                +node_entry->num_sets
-                                                                                                *node_entry->num_nodes));
-               memset(failnodebuf[cur_origin_idx],0,sizeof(failnode_node) 
+               failnodebuf[cur_origin_idx] = malloc(sizeof(failnode_node)
+                                                                                        * (node_entry->num_nodes
+                                                                                               node_entry->num_sets
+                                                                                               node_entry->num_nodes));
+               memset(failnodebuf[cur_origin_idx], 0, sizeof(failnode_node)
                           * (node_entry->num_nodes + (node_entry->num_sets
-                                                                                  * node_entry->num_nodes) ));
+                                                                                  * node_entry->num_nodes)));
                set_list[cur_origin_idx] = malloc(sizeof(int) * node_entry->num_sets);
-               memset( set_list[cur_origin_idx] , 0 , 
-                               sizeof(int) * node_entry->num_sets);
+               memset(set_list[cur_origin_idx], 0,
+                          sizeof(int) * node_entry->num_sets);
                nodeinfo = (failnode_node *) failnodebuf[cur_origin_idx];
-       
-               for(i = 0 ; i < PQntuples(res2); i++)
+
+               for (i = 0; i < PQntuples(res2); i++)
                {
-                       set_list[cur_origin_idx][i] = (int) strtol(PQgetvalue(res2,i,0),
-                                                                                                          NULL,10);
+                       set_list[cur_origin_idx][i] = (int) strtol(PQgetvalue(res2, i, 0),
+                                                                                                          NULL, 10);
                }
 
                /*
                 * Connect to all these nodes and determine if there is a node daemon
                 * running on that node.
                 */
-               has_candidate=true;
+               has_candidate = true;
                for (i = 0; i < node_entry->num_nodes; i++)
                {
-                       nodeinfo[i].no_id = (int)strtol(PQgetvalue(res1, i, 0), NULL, 10);
+                       nodeinfo[i].no_id = (int) strtol(PQgetvalue(res1, i, 0), NULL, 10);
                        nodeinfo[i].adminfo = get_active_adminfo((SlonikStmt *) stmt,
                                                                                                         nodeinfo[i].no_id);
                        if (nodeinfo[i].adminfo == NULL)
@@ -2869,21 +2876,21 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                                           stmt->hdr.stmt_filename, stmt->hdr.stmt_lno
                                           ,nodeinfo[i].no_id);
                                PQclear(res1);
-                               rc=-1;
+                               rc = -1;
                                goto cleanup;
                        }
-                       if (PQgetvalue(res1,i,0) != NULL) 
+                       if (PQgetvalue(res1, i, 0) != NULL)
                        {
-                               nodeinfo[i].failover_candidate=true;
+                               nodeinfo[i].failover_candidate = true;
                        }
                        else
-                         nodeinfo[i].failover_candidate=false;
+                               nodeinfo[i].failover_candidate = false;
 
                        slon_mkquery(&query,
                                                 "lock table \"_%s\".sl_config_lock; "
                                                 "select nl_backendpid from \"_%s\".sl_nodelock "
-                                                "    where nl_nodeid = \"_%s\".getLocalNodeId('_%s') and "
-                                                "       exists (select 1 from pg_catalog.pg_stat_activity "
+                                  "    where nl_nodeid = \"_%s\".getLocalNodeId('_%s') and "
+                                 "       exists (select 1 from pg_catalog.pg_stat_activity "
                                                 "                 where procpid = nl_backendpid);",
                                                 stmt->hdr.script->clustername,
                                                 stmt->hdr.script->clustername,
@@ -2894,7 +2901,7 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                        {
                                PQclear(res1);
                                PQclear(res2);
-                               rc=-1;
+                               rc = -1;
                                goto cleanup;
                        }
                        if (PQntuples(res3) == 0)
@@ -2905,26 +2912,27 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                        else
                        {
                                nodeinfo[i].has_slon = true;
-                               nodeinfo[i].slon_pid = (int)strtol(PQgetvalue(res3, 0, 0), NULL, 10);
+                               nodeinfo[i].slon_pid = (int) strtol(PQgetvalue(res3, 0, 0), NULL, 10);
                        }
                        PQclear(res3);
                }
-               PQclear(res1);          
+               PQclear(res1);
                PQclear(res2);
-               if ( ! has_candidate )
+               if (!has_candidate)
                {
                        printf("%s:%d error no failover candidates for %d\n",
-                                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno
                                   ,node_entry->no_id);
                        PQclear(res1);
-                       rc=-1;
+                       rc = -1;
                        goto cleanup;
                }
+
                /*
-                * Execute the preFailover() procedure on all failover candidate 
-                * nodes to stop them from receiving new messages from the failed node.
+                * Execute the preFailover() procedure on all failover candidate nodes
+                * to stop them from receiving new messages from the failed node.
                 */
-       
+
                for (i = 0; i < node_entry->num_nodes; i++)
                {
                        printf("executing preFailover(%d,%d) on %d\n",
@@ -2936,51 +2944,53 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                                                 "select \"_%s\".preFailover(%d,%s); ",
                                                 stmt->hdr.script->clustername,
                                                 stmt->hdr.script->clustername,
-                                                node_entry->no_id, nodeinfo[i].failover_candidate ? "true" : "false" );
+                                                node_entry->no_id, nodeinfo[i].failover_candidate ? "true" : "false");
                        if (db_exec_command((SlonikStmt *) stmt, nodeinfo[i].adminfo, &query) < 0)
                        {
-                               rc=-1;
+                               rc = -1;
                                goto cleanup;
                        }
                        if (db_commit_xact((SlonikStmt *) stmt, nodeinfo[i].adminfo) < 0)
                        {
-                               rc=-1;
+                               rc = -1;
                                goto cleanup;
                        }
-               }               
-                       
+               }
+
        }
 
        /*
         * Wait until all slon replication engines that were running have
         * restarted.
         */
-       cur_origin_idx=0;
-       for(node_entry=stmt->nodes; node_entry != NULL; 
-               node_entry=node_entry->next,cur_origin_idx++) 
+       cur_origin_idx = 0;
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next, cur_origin_idx++)
        {
                failnode_node *nodeinfo = (failnode_node *) failnodebuf[cur_origin_idx];
-               rc=fail_node_restart(stmt,node_entry,nodeinfo);
-               if ( rc < 0 ) 
-               {                       
+
+               rc = fail_node_restart(stmt, node_entry, nodeinfo);
+               if (rc < 0)
+               {
                        goto cleanup;
                }
-       
+
        }
-       
+
        /**
         * promote the most ahead node to be the new (temporary) origin
         * for each of the failed nodes.
         */
-       cur_origin_idx=0;
-       for(node_entry=stmt->nodes; node_entry != NULL;
-               node_entry=node_entry->next, cur_origin_idx++)
-       {
-               
-               failnode_node * nodeinfo = (failnode_node *) failnodebuf[cur_origin_idx];          
-               rc = fail_node_promote(stmt,node_entry,nodeinfo,
-                       fail_node_ids);
-               if ( rc < 0 ) 
+       cur_origin_idx = 0;
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next, cur_origin_idx++)
+       {
+
+               failnode_node *nodeinfo = (failnode_node *) failnodebuf[cur_origin_idx];
+
+               rc = fail_node_promote(stmt, node_entry, nodeinfo,
+                                                          fail_node_ids);
+               if (rc < 0)
                {
                        goto cleanup;
                }
@@ -2990,59 +3000,60 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
        /**
         * MOVE SET to move the sets to the desired origin.
         */
-       cur_origin_idx=0;
-       for(node_entry=stmt->nodes; node_entry != NULL;
-               node_entry=node_entry->next, cur_origin_idx++)
+       cur_origin_idx = 0;
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next, cur_origin_idx++)
        {
                SlonikStmt_lock_set lock_set;
                SlonikStmt_move_set move_set;
-               SlonikStmt_wait_event wait_event; 
-               if( node_entry->temp_backup_node == node_entry->backup_node)
+               SlonikStmt_wait_event wait_event;
+
+               if (node_entry->temp_backup_node == node_entry->backup_node)
                        continue;
-               lock_set.hdr=stmt->hdr;
-               lock_set.set_origin=node_entry->temp_backup_node;
-               for(i = 0 ; i < node_entry->num_sets; i++)
+               lock_set.hdr = stmt->hdr;
+               lock_set.set_origin = node_entry->temp_backup_node;
+               for (i = 0; i < node_entry->num_sets; i++)
                {
-                       lock_set.set_id=set_list[cur_origin_idx][i];
-                       if(slonik_lock_set(&lock_set) < 0)
+                       lock_set.set_id = set_list[cur_origin_idx][i];
+                       if (slonik_lock_set(&lock_set) < 0)
                        {
                                printf("%s:%d error locking set %d on %d for MOVE SET\n",
                                           stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
-                                          lock_set.set_id,     lock_set.set_origin);
+                                          lock_set.set_id, lock_set.set_origin);
                                continue;
                        }
-                       move_set.hdr=stmt->hdr;
-                       move_set.old_origin=node_entry->temp_backup_node;
-                       move_set.new_origin=node_entry->backup_node;
-                       move_set.set_id=set_list[cur_origin_idx][i];
-                       if(slonik_move_set(&move_set) < 0)
+                       move_set.hdr = stmt->hdr;
+                       move_set.old_origin = node_entry->temp_backup_node;
+                       move_set.new_origin = node_entry->backup_node;
+                       move_set.set_id = set_list[cur_origin_idx][i];
+                       if (slonik_move_set(&move_set) < 0)
                        {
                                printf("%s:%d error moving set %d on %d\n",
                                           stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
-                                          lock_set.set_id,     lock_set.set_origin);
+                                          lock_set.set_id, lock_set.set_origin);
                                continue;
                        }
                        /**
                         * now wait until the MOVE_SET completes.
                         * FAILOVER is not finished until backup_node is the
-                        * origin.  
+                        * origin.
                         */
-                       wait_event.hdr=*(SlonikStmt*)stmt;
-                       wait_event.wait_origin=node_entry->temp_backup_node;
-                       wait_event.wait_on=node_entry->temp_backup_node;
-                       wait_event.wait_confirmed=node_entry->backup_node;
-                       wait_event.wait_timeout=0;
-                       wait_event.ignore_nodes=fail_node_ids;          
-                       adminfo1 = get_active_adminfo((SlonikStmt *) stmt, 
+                       wait_event.hdr = *(SlonikStmt *) stmt;
+                       wait_event.wait_origin = node_entry->temp_backup_node;
+                       wait_event.wait_on = node_entry->temp_backup_node;
+                       wait_event.wait_confirmed = node_entry->backup_node;
+                       wait_event.wait_timeout = 0;
+                       wait_event.ignore_nodes = fail_node_ids;
+                       adminfo1 = get_active_adminfo((SlonikStmt *) stmt,
                                                                                  node_entry->temp_backup_node);
-                       if (db_commit_xact((SlonikStmt *) stmt, 
+                       if (db_commit_xact((SlonikStmt *) stmt,
                                                           adminfo1) < 0)
                        {
                                rc = -1;
                                goto cleanup;
                        }
                        rc = slonik_wait_event(&wait_event);
-                       if(rc < 0)  
+                       if (rc < 0)
                        {
                                /**
                                 * pretty serious? how do we recover?
@@ -3050,27 +3061,27 @@ slonik_failed_node(SlonikStmt_failed_node * stmt)
                                printf("%s:%d error waiting for event\n",
                                           stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
                        }
-               
+
                }
        }
 
-       
-       
+
+
 cleanup:
-       cur_origin_idx=0;
-       for(node_entry=stmt->nodes; node_entry != NULL;
-               node_entry=node_entry->next, cur_origin_idx++)
+       cur_origin_idx = 0;
+       for (node_entry = stmt->nodes; node_entry != NULL;
+                node_entry = node_entry->next, cur_origin_idx++)
        {
-               if(failnodebuf[cur_origin_idx])
+               if (failnodebuf[cur_origin_idx])
                        free(failnodebuf[cur_origin_idx]);
-               if(set_list[cur_origin_idx])
-                       free(set_list[cur_origin_idx]);                  
+               if (set_list[cur_origin_idx])
+                       free(set_list[cur_origin_idx]);
        }
        free(failnodebuf);
        free(set_list);
        free(max_seqno_total);
        free(max_node_total);
-       free(fail_node_ids);    
+       free(fail_node_ids);
        dstring_free(&query);
        return rc;
 }
@@ -3085,10 +3096,10 @@ fail_node_restart(SlonikStmt_failed_node * stmt,
                                  failed_node_entry * node_entry,
                                  failnode_node * nodeinfo)
 {
-       int n = 0;
-       int i=0;
+       int                     n = 0;
+       int                     i = 0;
        SlonDString query;
-       PGresult res1;
+       PGresult   *res1;
 
        dstring_init(&query);
 
@@ -3103,19 +3114,19 @@ fail_node_restart(SlonikStmt_failed_node * stmt,
                                n++;
                                continue;
                        }
-                       
+
                        slon_mkquery(&query,
                                                 "select nl_backendpid from \"_%s\".sl_nodelock "
                                                 "    where nl_backendpid <> %d "
                                                 "    and nl_nodeid = \"_%s\".getLocalNodeId('_%s');",
                                                 stmt->hdr.script->clustername,
-                                                nodeinfo[i].slon_pid, 
+                                                nodeinfo[i].slon_pid,
                                                 stmt->hdr.script->clustername,
                                                 stmt->hdr.script->clustername
                                );
                        res1 = db_exec_select((SlonikStmt *) stmt, nodeinfo[i].adminfo, &query);
                        if (res1 == NULL)
-                       {                               
+                       {
                                dstring_free(&query);
                                return -1;
                        }
@@ -3124,7 +3135,7 @@ fail_node_restart(SlonikStmt_failed_node * stmt,
                                nodeinfo[i].has_slon = false;
                                n++;
                        }
-                       
+
                        PQclear(res1);
                        if (db_rollback_xact((SlonikStmt *) stmt, nodeinfo[i].adminfo) < 0)
                        {
@@ -3143,35 +3154,37 @@ fail_node_restart(SlonikStmt_failed_node * stmt,
  * This function will promote the most-ahead failover candidate
  * to be the new (at least temporary) set origin.
  */
-int fail_node_promote(SlonikStmt_failed_node * stmt,
-                                         failed_node_entry * node_entry,
-                                         failnode_node * nodeinfo,
-                                         int * fail_node_ids)
+int
+fail_node_promote(SlonikStmt_failed_node * stmt,
+                                 failed_node_entry * node_entry,
+                                 failnode_node * nodeinfo,
+                                 int *fail_node_ids)
 {
-       int64 max_seqno=0;
-       int max_node_idx=0;
-       int backup_idx=0;
+       int64           max_seqno = 0;
+       int                     max_node_idx = 0;
+       int                     backup_idx = 0;
        char            ev_seqno_c[64];
        SlonDString query;
-       int rc=0;
-       int i;
-       PGresult res1;
+       int                     rc = 0;
+       int                     i;
+       PGresult   *res1;
        SlonikAdmInfo *adminfo1;
 
        dstring_init(&query);
 
        /*
-        * For every node determine the one with the event
-        *, preferring the backup node.
+        * For every node determine the one with the event , preferring the backup
+        * node.
         */
        for (i = 0; i < node_entry->num_nodes; i++)
        {
-               
+
                int64           ev_seqno;
-               if ( ! nodeinfo[i].failover_candidate )
+
+               if (!nodeinfo[i].failover_candidate)
                        continue;
                if (nodeinfo[i].no_id == node_entry->backup_node)
-                       backup_idx=i;
+                       backup_idx = i;
                slon_mkquery(&query,
                                         "select max(ev_seqno) "
                                         "      from \"_%s\".sl_event "
@@ -3186,121 +3199,125 @@ int fail_node_promote(SlonikStmt_failed_node * stmt,
                        return -1;
                }
                slon_scanint64(PQgetvalue(res1, 0, 0), &ev_seqno);
-               
+
                nodeinfo[i].max_seqno = ev_seqno;
                if (nodeinfo[i].max_seqno > max_seqno)
                {
-                       max_seqno=nodeinfo[i].max_seqno;
-                       max_node_idx=i;
+                       max_seqno = nodeinfo[i].max_seqno;
+                       max_node_idx = i;
                }
                PQclear(res1);
-               
-       }                       
-       if (nodeinfo[max_node_idx].no_id!=node_entry->backup_node)
+
+       }
+       if (nodeinfo[max_node_idx].no_id != node_entry->backup_node)
        {
-               if (nodeinfo[max_node_idx].max_seqno == 
+               if (nodeinfo[max_node_idx].max_seqno ==
                        nodeinfo[backup_idx].max_seqno)
-                       max_node_idx=backup_idx;
+                       max_node_idx = backup_idx;
        }
        adminfo1 = nodeinfo[max_node_idx].adminfo;
+
        /*
         * Now execute all FAILED_NODE events on the most ahead candidate
         */
        sprintf(ev_seqno_c, INT64_FORMAT, max_seqno);
-               slon_mkquery(&query,
-                                        "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
-                                        "select \"_%s\".failedNode2(%d,%d,'%s'); ",
-                                        stmt->hdr.script->clustername,
-                                        stmt->hdr.script->clustername,
-                                        stmt->hdr.script->clustername,
-                                        node_entry->no_id,nodeinfo[max_node_idx].no_id
-                                        , ev_seqno_c);
-               printf("NOTICE: executing \"_%s\".failedNode2 on node %d\n",
-                          stmt->hdr.script->clustername,
-                          nodeinfo[max_node_idx].no_id);
-               node_entry->temp_backup_node=nodeinfo[max_node_idx].no_id;
-               
-               if (db_exec_evcommand((SlonikStmt *) stmt,
-                                                         adminfo1,
-                                                         &query) < 0)
+       slon_mkquery(&query,
+                                "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
+                                "select \"_%s\".failedNode2(%d,%d,'%s'); ",
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                node_entry->no_id, nodeinfo[max_node_idx].no_id
+                                ,ev_seqno_c);
+       printf("NOTICE: executing \"_%s\".failedNode2 on node %d\n",
+                  stmt->hdr.script->clustername,
+                  nodeinfo[max_node_idx].no_id);
+       node_entry->temp_backup_node = nodeinfo[max_node_idx].no_id;
+
+       if (db_exec_evcommand((SlonikStmt *) stmt,
+                                                 adminfo1,
+                                                 &query) < 0)
+       {
+               rc = -1;
+               goto cleanup;
+       }
+       /**
+        * now wait for the FAILOVER_NODE event to be confirmed
+        * by all nodes
+        */
+
+       /*
+        * commit all open transactions despite of all possible errors
+        */
+       for (i = 0; i < node_entry->num_nodes; i++)
+       {
+               if (db_commit_xact((SlonikStmt *) stmt,
+                                                  nodeinfo[i].adminfo) < 0)
                {
                        rc = -1;
                        goto cleanup;
                }
+       }
+       SlonikStmt_wait_event wait_event;
+
+       wait_event.hdr = *(SlonikStmt *) stmt;
+       wait_event.wait_origin = nodeinfo[max_node_idx].no_id;
+       wait_event.wait_on = nodeinfo[max_node_idx].no_id;;
+       wait_event.wait_confirmed = -1;
+       wait_event.wait_timeout = 0;
+       wait_event.ignore_nodes = fail_node_ids;
+
+       if (db_commit_xact((SlonikStmt *) stmt,
+                                          adminfo1) < 0)
+       {
+               rc = -1;
+               goto cleanup;
+       }
+       rc = slonik_wait_event(&wait_event);
+       if (rc < 0)
+       {
                /**
-                * now wait for the FAILOVER_NODE event to be confirmed
-                * by all nodes
-                */
-               /*
-                * commit all open transactions despite of all possible errors
+                * pretty serious? how do we recover?
                 */
-               for (i = 0; i < node_entry->num_nodes; i++)
-               {
-                       if (db_commit_xact((SlonikStmt *) stmt, 
-                                                          nodeinfo[i].adminfo) < 0)
-                       {
-                               rc = -1;                        
-                               goto cleanup;
-                       }
-               }
-               SlonikStmt_wait_event wait_event; 
-               wait_event.hdr=*(SlonikStmt*)stmt;
-               wait_event.wait_origin=nodeinfo[max_node_idx].no_id;
-               wait_event.wait_on=nodeinfo[max_node_idx].no_id;;
-               wait_event.wait_confirmed=-1;
-               wait_event.wait_timeout=0;
-               wait_event.ignore_nodes=fail_node_ids;
-               
-               if (db_commit_xact((SlonikStmt *) stmt, 
-                                                  adminfo1) < 0)
-               {
+               printf("%s:%d error waiting for event\n",
+                          stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
+       }
+
+       /**
+        * now failedNod3e on the temp backup node.
+        */
+       slon_mkquery(&query,
+                                "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
+                                "select \"_%s\".failedNode3(%d,%d,'%s'); ",
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                node_entry->no_id, nodeinfo[max_node_idx].no_id
+                                ,ev_seqno_c);
+       printf("NOTICE: executing \"_%s\".failedNode3 on node %d\n",
+                  stmt->hdr.script->clustername,
+                  nodeinfo[max_node_idx].no_id);
+
+       if (db_exec_evcommand((SlonikStmt *) stmt,
+                                                 adminfo1,
+                                                 &query) < 0)
+       {
+               rc = -1;
+               goto cleanup;
+       }
+
+       /*
+        * commit all open transactions despite of all possible errors
+        */
+       for (i = 0; i < node_entry->num_nodes; i++)
+       {
+               if (db_commit_xact((SlonikStmt *) stmt,
+                                                  nodeinfo[i].adminfo) < 0)
                        rc = -1;
-                       goto cleanup;
-               }
-               rc = slonik_wait_event(&wait_event);
-               if(rc < 0)  
-               {
-                       /**
-                        * pretty serious? how do we recover?
-                        */
-                       printf("%s:%d error waiting for event\n",
-                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
-               }
-               
-               /**
-                * now failedNod3e on the temp backup node.
-                */
-               slon_mkquery(&query,
-                                        "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
-                                        "select \"_%s\".failedNode3(%d,%d,'%s'); ",
-                                        stmt->hdr.script->clustername,
-                                        stmt->hdr.script->clustername,
-                                        stmt->hdr.script->clustername,
-                                        node_entry->no_id,nodeinfo[max_node_idx].no_id
-                                        ,ev_seqno_c);
-               printf("NOTICE: executing \"_%s\".failedNode3 on node %d\n",
-                          stmt->hdr.script->clustername,
-                          nodeinfo[max_node_idx].no_id);
-               
-               if (db_exec_evcommand((SlonikStmt *) stmt,
-                                                         adminfo1,
-                                                         &query) < 0)
-               {
-                       rc = -1;                        
-                       goto cleanup;
-               }
-               /*
-                * commit all open transactions despite of all possible errors
-                */
-               for (i = 0; i < node_entry->num_nodes; i++)
-               {
-                       if (db_commit_xact((SlonikStmt *) stmt, 
-                                                          nodeinfo[i].adminfo) < 0)
-                               rc = -1;
-               }
+       }
 cleanup:
-               dstring_free(&query);
-               return rc;
+       dstring_free(&query);
+       return rc;
 }
 
 
@@ -3314,7 +3331,7 @@ slonik_uninstall_node(SlonikStmt_uninstall_node * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3353,13 +3370,14 @@ slonik_uninstall_node(SlonikStmt_uninstall_node * stmt)
                dstring_free(&query);
                return -1;
        }
-       
+
        /**
         * if we have a conninfo for the node being uninstalled
         * we want to clear out the last seqid.
         */
-       if(adminfo1 != NULL) {
-         adminfo1->last_event=-1;
+       if (adminfo1 != NULL)
+       {
+               adminfo1->last_event = -1;
        }
 
        db_disconnect((SlonikStmt *) stmt, adminfo1);
@@ -3374,39 +3392,39 @@ slonik_clone_prepare(SlonikStmt_clone_prepare * stmt)
 {
        SlonikAdmInfo *adminfo1;
        SlonDString query;
-       int rc;
+       int                     rc;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->no_provider);
        if (adminfo1 == NULL)
                return -1;
 
-       if(!auto_wait_disabled)
+       if (!auto_wait_disabled)
        {
-               rc=slonik_wait_config_caughtup(adminfo1,&stmt->hdr,-1);
-               if(rc < 0 )
-                 return rc;
+               rc = slonik_wait_config_caughtup(adminfo1, &stmt->hdr, -1);
+               if (rc < 0)
+                       return rc;
        }
 
        dstring_init(&query);
-       
+
        if (stmt->no_comment == NULL)
                slon_mkquery(&query,
-                                "lock table \"_%s\".sl_config_lock; "
-                                "select \"_%s\".cloneNodePrepare(%d, %d, 'Node %d'); ",
-                                stmt->hdr.script->clustername,
-                                stmt->hdr.script->clustername,
-                                stmt->no_id, stmt->no_provider,
-                                stmt->no_id);
+                                        "lock table \"_%s\".sl_config_lock; "
+                                        "select \"_%s\".cloneNodePrepare(%d, %d, 'Node %d'); ",
+                                        stmt->hdr.script->clustername,
+                                        stmt->hdr.script->clustername,
+                                        stmt->no_id, stmt->no_provider,
+                                        stmt->no_id);
        else
                slon_mkquery(&query,
-                                "lock table \"_%s\".sl_config_lock; "
-                                "select \"_%s\".cloneNodePrepare(%d, %d, '%q'); ",
-                                stmt->hdr.script->clustername,
-                                stmt->hdr.script->clustername,
-                                stmt->no_id, stmt->no_provider,
-                                stmt->no_comment);
+                                        "lock table \"_%s\".sl_config_lock; "
+                                        "select \"_%s\".cloneNodePrepare(%d, %d, '%q'); ",
+                                        stmt->hdr.script->clustername,
+                                        stmt->hdr.script->clustername,
+                                        stmt->no_id, stmt->no_provider,
+                                        stmt->no_comment);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3454,7 +3472,7 @@ slonik_store_path(SlonikStmt_store_path * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3468,7 +3486,7 @@ slonik_store_path(SlonikStmt_store_path * stmt)
                                 stmt->pa_server, stmt->pa_client,
                                 stmt->pa_conninfo, stmt->pa_connretry);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,1) < 0)
+                                                  stmt->hdr.script, 1) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3489,7 +3507,7 @@ slonik_drop_path(SlonikStmt_drop_path * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3502,7 +3520,7 @@ slonik_drop_path(SlonikStmt_drop_path * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->pa_server, stmt->pa_client);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3523,7 +3541,7 @@ slonik_store_listen(SlonikStmt_store_listen * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3537,7 +3555,7 @@ slonik_store_listen(SlonikStmt_store_listen * stmt)
                                 stmt->li_origin, stmt->li_provider,
                                 stmt->li_receiver);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3558,7 +3576,7 @@ slonik_drop_listen(SlonikStmt_drop_listen * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3572,7 +3590,7 @@ slonik_drop_listen(SlonikStmt_drop_listen * stmt)
                                 stmt->li_origin, stmt->li_provider,
                                 stmt->li_receiver);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3590,18 +3608,18 @@ slonik_create_set(SlonikStmt_create_set * stmt)
        SlonikAdmInfo *adminfo1;
        SlonDString query;
        const char *comment;
-       SlonikAdmInfo * curAdmInfo;
-       int64 drop_set_events;
-       int64 cached_events;
-       size_t event_size;
-       int adm_idx;
-       int rc;
+       SlonikAdmInfo *curAdmInfo;
+       int64      *drop_set_events;
+       int64      *cached_events;
+       size_t          event_size;
+       int                     adm_idx;
+       int                     rc;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->set_origin);
        if (adminfo1 == NULL)
                return -1;
 
-       if( ! auto_wait_disabled)
+       if (!auto_wait_disabled)
        {
                /**
                 * loop through each node and make sure there are no
@@ -3612,7 +3630,7 @@ slonik_create_set(SlonikStmt_create_set * stmt)
                 * caughtup to that.
                 *
                 */
-               event_size = slonik_get_last_event_id((SlonikStmt*)stmt,
+               event_size = slonik_get_last_event_id((SlonikStmt *) stmt,
                                                                                          stmt->hdr.script,
                                                                                          "ev_type='DROP_SET'",
                                                                                          &drop_set_events);
@@ -3621,35 +3639,35 @@ slonik_create_set(SlonikStmt_create_set * stmt)
                 * copy the 'real' last event to storage
                 * and update the AdmInfo structure with the last 'DROP SET' id.
                 */
-               cached_events=malloc(sizeof(int64)*event_size);         
-               adm_idx=0;
-               for(curAdmInfo = stmt->hdr.script->adminfo_list;
-                       curAdmInfo!=NULL; curAdmInfo=curAdmInfo->next)
+               cached_events = malloc(sizeof(int64) * event_size);
+               adm_idx = 0;
+               for (curAdmInfo = stmt->hdr.script->adminfo_list;
+                        curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
                {
-                       cached_events[adm_idx]=curAdmInfo->last_event;
-                       curAdmInfo->last_event=drop_set_events[adm_idx];
+                       cached_events[adm_idx] = curAdmInfo->last_event;
+                       curAdmInfo->last_event = drop_set_events[adm_idx];
                        adm_idx++;
                }
-               rc=slonik_wait_config_caughtup(adminfo1,&stmt->hdr,-1);
-               if (rc < 0) 
-                 return rc;
+               rc = slonik_wait_config_caughtup(adminfo1, &stmt->hdr, -1);
+               if (rc < 0)
+                       return rc;
                /***
                 * reset the last_event values in the AdmInfo to
                 * the values we saved above.
                 */
-               adm_idx=0;
-               for(curAdmInfo = stmt->hdr.script->adminfo_list;
-                       curAdmInfo!=NULL; curAdmInfo=curAdmInfo->next)
+               adm_idx = 0;
+               for (curAdmInfo = stmt->hdr.script->adminfo_list;
+                        curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
                {
-                       curAdmInfo->last_event=cached_events[adm_idx];
+                       curAdmInfo->last_event = cached_events[adm_idx];
                        adm_idx++;
                }
                free(cached_events);
                free(drop_set_events);
-               
+
        }
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        if (stmt->set_comment == NULL)
@@ -3667,7 +3685,7 @@ slonik_create_set(SlonikStmt_create_set * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->set_id, comment);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3688,7 +3706,7 @@ slonik_drop_set(SlonikStmt_drop_set * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -3701,7 +3719,7 @@ slonik_drop_set(SlonikStmt_drop_set * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->set_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3717,8 +3735,8 @@ slonik_merge_set(SlonikStmt_merge_set * stmt)
 {
        SlonikAdmInfo *adminfo1;
        SlonDString query;
-       PGresult *res;
-       bool in_progress=1;
+       PGresult   *res;
+       bool            in_progress = 1;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->set_origin);
        if (adminfo1 == NULL)
@@ -3736,65 +3754,65 @@ slonik_merge_set(SlonikStmt_merge_set * stmt)
         * but we don't)
         */
 
-       
+
 
        dstring_init(&query);
 
-       slon_mkquery(&query,"select \"_%s\".isSubscriptionInProgress(%d)"
+       slon_mkquery(&query, "select \"_%s\".isSubscriptionInProgress(%d)"
                                 " or \"_%s\".isSubscriptionInProgress(%d)"
                                 ,stmt->hdr.script->clustername,
                                 stmt->add_id, stmt->hdr.script->clustername,
                                 stmt->set_id);
 
-       while(in_progress)
+       while (in_progress)
        {
-               char *result;
+               char       *result;
 
-               if(current_try_level > 0)
+               if (current_try_level > 0)
                {
-                       if(current_try_level == 1 && block_stmt_no==1)
+                       if (current_try_level == 1 && block_stmt_no == 1)
                        {
                                /**
-                                * on the first command of the try block we can 
-                                * still a abort the txn and restart it later, 
+                                * on the first command of the try block we can
+                                * still a abort the txn and restart it later,
                                 * after the wait for has been complete.
-                                */                     
+                                */
                        }
                        else
                        {
                                printf("%s:%d Error: a subscription is in progress. "
                                           "slonik can not wait for it to finish inside of a "
-                                          "try block",stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
+                                  "try block", stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
                                return -1;
                        }
                }
 
-               if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+               if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                        return -1;
 
-               res = db_exec_select((SlonikStmt*) stmt,adminfo1,&query);
+               res = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
                if (res == NULL)
                {
                        dstring_free(&query);
                        return -1;
-                       
+
                }
-               result = PQgetvalue(res,0,0);
-               if(result != NULL && (*result=='t' ||
-                                                         *result=='T'))
+               result = PQgetvalue(res, 0, 0);
+               if (result != NULL && (*result == 't' ||
+                                                          *result == 'T'))
                {
                        printf("%s:%d subscription in progress before mergeSet. waiting\n",
-                               stmt->hdr.stmt_filename,stmt->hdr.stmt_lno);
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
                        fflush(stdout);
                        db_rollback_xact((SlonikStmt *) stmt, adminfo1);
                        sleep(5);
                }
                else
-                       in_progress=false;
-               if(result != NULL)
+                       in_progress = false;
+               if (result != NULL)
                        PQclear(res);
        }
-       
+
        slon_mkquery(&query,
                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
                                 "select \"_%s\".mergeSet(%d, %d); ",
@@ -3803,7 +3821,7 @@ slonik_merge_set(SlonikStmt_merge_set * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->set_id, stmt->add_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -3818,21 +3836,21 @@ int
 slonik_set_add_table(SlonikStmt_set_add_table * stmt)
 {
        SlonikAdmInfo *adminfo1;
-       int origin=stmt->set_origin;
+       int                     origin = stmt->set_origin;
        SlonDString query;
-       PGresult result;
-       int idx;
-       char table_name;
-       int rc;
+       PGresult   *result;
+       int                     idx;
+       char       *table_name;
+       int                     rc;
 
-       if(stmt->set_origin < 0)
+       if (stmt->set_origin < 0)
        {
-               origin=find_origin((SlonikStmt*)stmt,stmt->set_id);
-               if(origin < 0 )
+               origin = find_origin((SlonikStmt *) stmt, stmt->set_id);
+               if (origin < 0)
                {
 
                        printf("%s:%d:Error: unable to determine the origin for set %d",
-                                  stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,stmt->set_id);
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno, stmt->set_id);
                        return -1;
                }
        }
@@ -3847,8 +3865,8 @@ slonik_set_add_table(SlonikStmt_set_add_table * stmt)
         * the 'set add table' will take place in.
         *
         * Once that transaction is opened and has a lock
-        * on sl_config_lock the slon for the node  won't be 
-        * able to process many event types from other nodes.  
+        * on sl_config_lock the slon for the node      won't be
+        * able to process many event types from other nodes.
         * So if the origin is behind it will not be able to catch up
         * until the transaction completes.
         *
@@ -3858,15 +3876,15 @@ slonik_set_add_table(SlonikStmt_set_add_table * stmt)
         * origin is caught up before opening the
         * transaction.
         **/
-       if(db_begin_xact((SlonikStmt*)stmt,adminfo1,false) < 0)
-               return -1;
-       dstring_init(&query);   
-       slon_mkquery(&query,"lock table \"_%s\".sl_event_lock;"
-                                       "select \"_%s\".createEvent('_%s', 'SYNC'); ",
-                                       stmt->hdr.script->clustername,
-                                       stmt->hdr.script->clustername,
-                                       stmt->hdr.script->clustername);
-       slonik_submitEvent((SlonikStmt*)stmt,adminfo1,&query,stmt->hdr.script,0);
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
+               return -1;
+       dstring_init(&query);
+       slon_mkquery(&query, "lock table \"_%s\".sl_event_lock;"
+                                "select \"_%s\".createEvent('_%s', 'SYNC'); ",
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername);
+       slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query, stmt->hdr.script, 0);
        dstring_terminate(&query);
        if (db_commit_xact((SlonikStmt *) stmt, adminfo1) < 0)
        {
@@ -3877,11 +3895,11 @@ slonik_set_add_table(SlonikStmt_set_add_table * stmt)
 
 
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        /**
-        * obtain a lock on sl_event_lock.  
+        * obtain a lock on sl_event_lock.
         * it must be obtained before calling setAddTable()
         * and it must be obtained before querying the catalog.
         */
@@ -3890,45 +3908,45 @@ slonik_set_add_table(SlonikStmt_set_add_table * stmt)
                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;",
                                 stmt->hdr.script->clustername,
                                 stmt->hdr.script->clustername
-                       );
-       if( db_exec_command((SlonikStmt*)stmt,adminfo1,&query) < 0)
+               );
+       if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
        {
                printf("%s:%d:Error: unable to lock sl_event_lock\n",
-                          stmt->hdr.stmt_filename,stmt->hdr.stmt_lno);
+                          stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
                dstring_terminate(&query);
                return -1;
 
        }
        dstring_reset(&query);
-       if(stmt->tab_fqname==NULL && 
-          stmt->tables != NULL)
+       if (stmt->tab_fqname == NULL &&
+               stmt->tables != NULL)
        {
                /**
                 * query the catalog to get a list of tables.
                 */
-               slon_mkquery(&query,"select table_schema || '.' || table_name "
+               slon_mkquery(&query, "select table_schema || '.' || table_name "
                                         "from information_schema.tables where "
                                         "table_schema || '.'||table_name ~ E'%s' "
-                                        " and table_type='BASE TABLE' order by 1",stmt->tables);
-               result = db_exec_select((SlonikStmt*)stmt,adminfo1,&query);
-               if(result == NULL) 
+                                        " and table_type='BASE TABLE' order by 1", stmt->tables);
+               result = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
+               if (result == NULL)
                {
                        printf("%s:%d:Error unable to search for a list of tables. "
                                   "Perhaps your regular expression '%s' is invalid.",
-                                  stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
                                   stmt->tables);
                        dstring_terminate(&query);
                        return -1;
 
                }
-               rc=0;
-               for(idx = 0; idx < PQntuples(result); idx++)
+               rc = 0;
+               for (idx = 0; idx < PQntuples(result); idx++)
                {
 
-                       table_name=PQgetvalue(result,idx,0);
-                       rc=slonik_set_add_single_table(stmt,adminfo1,
-                                                                               table_name);
-                       if(rc < 0)
+                       table_name = PQgetvalue(result, idx, 0);
+                       rc = slonik_set_add_single_table(stmt, adminfo1,
+                                                                                        table_name);
+                       if (rc < 0)
                        {
                                PQclear(result);
                                dstring_terminate(&query);
@@ -3938,35 +3956,35 @@ slonik_set_add_table(SlonikStmt_set_add_table * stmt)
                PQclear(result);
        }
        else
-               rc=slonik_set_add_single_table(stmt,adminfo1,stmt->tab_fqname);
+               rc = slonik_set_add_single_table(stmt, adminfo1, stmt->tab_fqname);
        dstring_terminate(&query);
        return rc;
 }
 int
 slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
                                                        SlonikAdmInfo * adminfo1,
-                                                       const char * fqname)
+                                                       const char *fqname)
 {
        SlonDString query;
        char       *idxname;
        PGresult   *res;
-       int tab_id=-1;
-       int rc=0;
+       int                     tab_id = -1;
+       int                     rc = 0;
 
-       dstring_init(&query);
+       dstring_init(&query);
        if (stmt->use_key == NULL)
        {
                slon_mkquery(&query,
-                            "select \"_%s\".determineIdxnameUnique('%q', NULL); ",
-                            stmt->hdr.script->clustername, fqname);
+                                        "select \"_%s\".determineIdxnameUnique('%q', NULL); ",
+                                        stmt->hdr.script->clustername, fqname);
 
        }
        else
        {
                slon_mkquery(&query,
-                            "select \"_%s\".determineIdxnameUnique('%q', '%q'); ",
-                            stmt->hdr.script->clustername,
-                            fqname, stmt->use_key);
+                                        "select \"_%s\".determineIdxnameUnique('%q', '%q'); ",
+                                        stmt->hdr.script->clustername,
+                                        fqname, stmt->use_key);
        }
 
        db_notice_silent = true;
@@ -3979,10 +3997,10 @@ slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
        }
        idxname = PQgetvalue(res, 0, 0);
 
-       if(stmt->tab_id < 0)
+       if (stmt->tab_id < 0)
        {
-               tab_id=slonik_get_next_tab_id((SlonikStmt*)stmt);
-               if(tab_id < 0)
+               tab_id = slonik_get_next_tab_id((SlonikStmt *) stmt);
+               if (tab_id < 0)
                {
                        PQclear(res);
                        dstring_free(&query);
@@ -3990,8 +4008,8 @@ slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
                }
        }
        else
-               tab_id=stmt->tab_id;
-       
+               tab_id = stmt->tab_id;
+
        slon_mkquery(&query,
                                 "lock table \"_%s\".sl_config_lock;"
                                 "select \"_%s\".setAddTable(%d, %d, '%q', '%q', '%q'); ",
@@ -4000,14 +4018,14 @@ slonik_set_add_single_table(SlonikStmt_set_add_table * stmt,
                                 stmt->set_id, tab_id,
                                 fqname, idxname, stmt->tab_comment);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                PQclear(res);
                dstring_free(&query);
                return -1;
        }
-       if(stmt->add_sequences)
-               rc = slonik_add_dependent_sequences(stmt,adminfo1,fqname);
+       if (stmt->add_sequences)
+               rc = slonik_add_dependent_sequences(stmt, adminfo1, fqname);
 
        dstring_free(&query);
        PQclear(res);
@@ -4019,25 +4037,25 @@ int
 slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
 {
        SlonikAdmInfo *adminfo1;
-       int origin=stmt->set_origin;
-       int rc;
-       const char * sequence_name;
+       int                     origin = stmt->set_origin;
+       int                     rc;
+       const char *sequence_name;
        SlonDString query;
-       int idx;
-       PGresult result;
+       int                     idx;
+       PGresult   *result;
 
 
-       if(stmt->set_origin < 0)
+       if (stmt->set_origin < 0)
        {
-               origin=find_origin((SlonikStmt*)stmt,stmt->set_id);
-               if(origin < 0 )
+               origin = find_origin((SlonikStmt *) stmt, stmt->set_id);
+               if (origin < 0)
                {
                        printf("%s:%d:Error: unable to determine the origin for set %d",
-                                  stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,stmt->set_id);
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno, stmt->set_id);
                        return -1;
                }
        }
-       
+
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, origin);
        if (adminfo1 == NULL)
                return -1;
@@ -4048,8 +4066,8 @@ slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
         * the 'set add table' will take place in.
         *
         * Once that transaction is opened and has a lock
-        * on sl_config_lock the slon for the node  won't be 
-        * able to process many event types from other nodes.  
+        * on sl_config_lock the slon for the node      won't be
+        * able to process many event types from other nodes.
         * So if the origin is behind it will not be able to catch up
         * until the transaction completes.
         *
@@ -4059,15 +4077,15 @@ slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
         * origin is caught up before opening the
         * transaction.
         **/
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
        dstring_init(&query);
-       slon_mkquery(&query,"lock table \"_%s\".sl_event_lock;"
-                                       "select \"_%s\".createEvent('_%s', 'SYNC'); ",
-                                       stmt->hdr.script->clustername,
-                                       stmt->hdr.script->clustername,
-                                       stmt->hdr.script->clustername);
-       slonik_submitEvent((SlonikStmt*)stmt,adminfo1,&query,stmt->hdr.script,0);
+       slon_mkquery(&query, "lock table \"_%s\".sl_event_lock;"
+                                "select \"_%s\".createEvent('_%s', 'SYNC'); ",
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername,
+                                stmt->hdr.script->clustername);
+       slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query, stmt->hdr.script, 0);
        dstring_terminate(&query);
        if (db_commit_xact((SlonikStmt *) stmt, adminfo1) < 0)
        {
@@ -4077,11 +4095,11 @@ slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
 
 
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        /**
-        * obtain a lock on sl_event_lock.  
+        * obtain a lock on sl_event_lock.
         * it must be obtained before calling setAddSequence()
         * and it must be obtained before querying the catalog.
         */
@@ -4090,49 +4108,49 @@ slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;",
                                 stmt->hdr.script->clustername,
                                 stmt->hdr.script->clustername
-                       );
-       if( db_exec_command((SlonikStmt*)stmt,adminfo1,&query) < 0)
+               );
+       if (db_exec_command((SlonikStmt *) stmt, adminfo1, &query) < 0)
        {
                printf("%s:%d:Error: unable to lock sl_event_lock\n",
-                          stmt->hdr.stmt_filename,stmt->hdr.stmt_lno);
+                          stmt->hdr.stmt_filename, stmt->hdr.stmt_lno);
                dstring_terminate(&query);
                return -1;
 
        }
        dstring_reset(&query);
 
-       if(stmt->seq_fqname==NULL &&
-          stmt->sequences != NULL)
+       if (stmt->seq_fqname == NULL &&
+               stmt->sequences != NULL)
        {
                /**
                 * query the catalog to get a list of tables.
                 */
-               slon_mkquery(&query,"select sequence_schema || '.' || sequence_name "
+               slon_mkquery(&query, "select sequence_schema || '.' || sequence_name "
                                         "from information_schema.sequences where "
                                         "sequence_schema || '.'||sequence_name ~ '%s' "
-                                        "order by 1",stmt->sequences);
-               result = db_exec_select((SlonikStmt*)stmt,adminfo1,&query);
-               if(result == NULL) 
+                                        "order by 1", stmt->sequences);
+               result = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
+               if (result == NULL)
                {
                        printf("%s:%d:Error unable to search for a list of sequences. "
                                   "Perhaps your regular expression '%s' is invalid.",
-                                  stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
                                   stmt->sequences);
                        dstring_terminate(&query);
                        return -1;
 
                }
-               rc=0;
-               for(idx = 0; idx < PQntuples(result); idx++)
+               rc = 0;
+               for (idx = 0; idx < PQntuples(result); idx++)
                {
 
-                       sequence_name=PQgetvalue(result,idx,0);
-                       rc=slonik_set_add_single_sequence((SlonikStmt*)stmt,adminfo1,
-                                                                                         sequence_name,
-                                                                                         stmt->set_id,
-                                                                                         stmt->seq_comment,-1);
-                                                                                         
-                       if(rc < 0)
+                       sequence_name = PQgetvalue(result, idx, 0);
+                       rc = slonik_set_add_single_sequence((SlonikStmt *) stmt, adminfo1,
+                                                                                               sequence_name,
+                                                                                               stmt->set_id,
+                                                                                               stmt->seq_comment, -1);
+
+                       if (rc < 0)
                        {
                                PQclear(result);
                                dstring_terminate(&query);
@@ -4143,33 +4161,34 @@ slonik_set_add_sequence(SlonikStmt_set_add_sequence * stmt)
 
        }
        else
-         rc=slonik_set_add_single_sequence((SlonikStmt*)stmt,adminfo1,
-                                                                                 stmt->seq_fqname,
-                                                                                 stmt->set_id,stmt->seq_comment,
-                                                                                 stmt->seq_id);
+               rc = slonik_set_add_single_sequence((SlonikStmt *) stmt, adminfo1,
+                                                                                       stmt->seq_fqname,
+                                                                                       stmt->set_id, stmt->seq_comment,
+                                                                                       stmt->seq_id);
 
        dstring_terminate(&query);
        return rc;
 }
 int
-slonik_set_add_single_sequence(SlonikStmt *stmt,
-                                                          SlonikAdmInfo *adminfo1,
-                                                          const char * seq_name,
+slonik_set_add_single_sequence(SlonikStmt * stmt,
+                                                          SlonikAdmInfo * adminfo1,
+                                                          const char *seq_name,
                                                           int set_id,
-                                                          const char * seq_comment,
+                                                          const char *seq_comment,
                                                           int seq_id)
 {
-       SlonDString query;      
+       SlonDString query;
+
        /*
         * call setAddSequence()
         */
 
        db_notice_silent = true;
-       
-       if(seq_id < 0)
+
+       if (seq_id < 0)
        {
-         seq_id = slonik_get_next_sequence_id((SlonikStmt*)stmt);
-               if(seq_id < 0)
+               seq_id = slonik_get_next_sequence_id((SlonikStmt *) stmt);
+               if (seq_id < 0)
                        return -1;
        }
 
@@ -4182,7 +4201,7 @@ slonik_set_add_single_sequence(SlonikStmt *stmt,
                                 set_id, seq_id, seq_name,
                                 seq_comment);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->script,auto_wait_disabled) < 0)
+                                                  stmt->script, auto_wait_disabled) < 0)
        {
                db_notice_silent = false;
                dstring_free(&query);
@@ -4204,7 +4223,7 @@ slonik_set_drop_table(SlonikStmt_set_drop_table * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4217,7 +4236,7 @@ slonik_set_drop_table(SlonikStmt_set_drop_table * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->tab_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -4237,7 +4256,7 @@ slonik_set_drop_sequence(SlonikStmt_set_drop_sequence * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4253,7 +4272,7 @@ slonik_set_drop_sequence(SlonikStmt_set_drop_sequence * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->seq_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                db_notice_silent = false;
                dstring_free(&query);
@@ -4275,7 +4294,7 @@ slonik_set_move_table(SlonikStmt_set_move_table * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4288,7 +4307,7 @@ slonik_set_move_table(SlonikStmt_set_move_table * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->tab_id, stmt->new_set_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -4308,7 +4327,7 @@ slonik_set_move_sequence(SlonikStmt_set_move_sequence * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4321,7 +4340,7 @@ slonik_set_move_sequence(SlonikStmt_set_move_sequence * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->seq_id, stmt->new_set_id);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -4336,16 +4355,16 @@ slonik_subscribe_set(SlonikStmt_subscribe_set * stmt)
        SlonikAdmInfo *adminfo1;
        SlonikAdmInfo *adminfo2;
        SlonDString query;
-       PGresult    *res1;
-       int reshape=0;
-       int origin_id;
-       int rc;
+       PGresult   *res1;
+       int                     reshape = 0;
+       int                     origin_id;
+       int                     rc;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->sub_provider);
        if (adminfo1 == NULL)
                return -1;
 
-       
+
        dstring_init(&query);
 
        /**
@@ -4360,37 +4379,38 @@ slonik_subscribe_set(SlonikStmt_subscribe_set * stmt)
         * the provider node is caught up with all other nodes wrt config data.
         *
         * this is because we don't want to pick the origin based on
-        * stale data. 
+        * stale data.
         *
         * @note an alternative might be to contact all adminconninfo
         * nodes looking for the set origin and then submit the
-        * set origin to that.  This avoids the wait for and is probably
+        * set origin to that.  This avoids the wait for and is probably
         * what we should do.
-        */ 
+        */
        if (!auto_wait_disabled)
        {
-               rc=slonik_wait_config_caughtup(adminfo1,&stmt->hdr,-1);
-               if (rc < 0) 
+               rc = slonik_wait_config_caughtup(adminfo1, &stmt->hdr, -1);
+               if (rc < 0)
                        return rc;
        }
 
-       slon_mkquery(&query,"select count(*) FROM \"_%s\".sl_subscribe " \
+       slon_mkquery(&query, "select count(*) FROM \"_%s\".sl_subscribe " \
                                 "where sub_set=%d AND sub_receiver=%d " \
                                 " and sub_active=true and sub_provider<>%d",
                                 stmt->hdr.script->clustername,
-                                stmt->sub_setid,stmt->sub_receiver,
+                                stmt->sub_setid, stmt->sub_receiver,
                                 stmt->sub_provider);
-       
-       res1 = db_exec_select(&stmt->hdr,adminfo1,&query);
-       if(res1 == NULL) {
+
+       res1 = db_exec_select(&stmt->hdr, adminfo1, &query);
+       if (res1 == NULL)
+       {
                dstring_free(&query);
                return -1;
        }
-       if(PQntuples(res1) > 0)
+       if (PQntuples(res1) > 0)
        {
                if (strtol(PQgetvalue(res1, 0, 0), NULL, 10) > 0)
                {
-                       reshape=1;
+                       reshape = 1;
                }
        }
        PQclear(res1);
@@ -4398,31 +4418,31 @@ slonik_subscribe_set(SlonikStmt_subscribe_set * stmt)
 
        slon_mkquery(&query,
                                 "select set_origin from \"_%s\".sl_set where" \
-                                " set_id=%d",stmt->hdr.script->clustername,
+                                " set_id=%d", stmt->hdr.script->clustername,
                                 stmt->sub_setid);
-       res1 = db_exec_select((SlonikStmt*)stmt,adminfo1,&query);
-       if(res1==NULL || PQntuples(res1) <= 0 ) 
+       res1 = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
+       if (res1 == NULL || PQntuples(res1) <= 0)
        {
                printf("%s:%d error: can not determine set origin for set %d\n",
-                          stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,stmt->sub_setid);
-               if(res1 != NULL)
+                          stmt->hdr.stmt_filename, stmt->hdr.stmt_lno, stmt->sub_setid);
+               if (res1 != NULL)
                        PQclear(res1);
                dstring_free(&query);
                return -1;
 
        }
-       origin_id = atoi(PQgetvalue(res1,0,0));
-       if(origin_id <= 0 ) 
+       origin_id = atoi(PQgetvalue(res1, 0, 0));
+       if (origin_id <= 0)
        {
                PQclear(res1);
                dstring_free(&query);
                return -1;
-               
+
        }
        PQclear(res1);
        dstring_reset(&query);
        adminfo2 = get_active_adminfo((SlonikStmt *) stmt, origin_id);
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo2,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo2, false) < 0)
                return -1;
        slon_mkquery(&query,
                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
@@ -4435,16 +4455,16 @@ slonik_subscribe_set(SlonikStmt_subscribe_set * stmt)
                                 (stmt->sub_forward) ? "t" : "f",
                                 (stmt->omit_copy) ? "t" : "f");
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo2, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
        }
        dstring_reset(&query);
-       if(reshape)
+       if (reshape)
        {
                adminfo2 = get_active_adminfo((SlonikStmt *) stmt, stmt->sub_receiver);
-               if(adminfo2 == NULL) 
+               if (adminfo2 == NULL)
                {
                        printf("can not find conninfo for receiver node %d\n",
                                   stmt->sub_receiver);
@@ -4457,12 +4477,12 @@ slonik_subscribe_set(SlonikStmt_subscribe_set * stmt)
                                         stmt->hdr.script->clustername,
                                         stmt->sub_setid,
                                         stmt->sub_provider,
-                                        stmt->sub_receiver);   
+                                        stmt->sub_receiver);
                if (db_exec_command((SlonikStmt *) stmt, adminfo2, &query) < 0)
                {
-                       printf("error reshaping subscriber\n");         
+                       printf("error reshaping subscriber\n");
                }
-               
+
                dstring_free(&query);
        }
        return 0;
@@ -4479,7 +4499,7 @@ slonik_unsubscribe_set(SlonikStmt_unsubscribe_set * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4492,7 +4512,7 @@ slonik_unsubscribe_set(SlonikStmt_unsubscribe_set * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->sub_setid, stmt->sub_receiver);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -4553,8 +4573,8 @@ slonik_lock_set(SlonikStmt_lock_set * stmt)
        }
 
        slon_mkquery(&query,
-                    "select pg_catalog.txid_snapshot_xmin(pg_catalog.txid_current_snapshot()) >= '%s'; ",
-                    maxxid_lock);
+                                "select pg_catalog.txid_snapshot_xmin(pg_catalog.txid_current_snapshot()) >= '%s'; ",
+                                maxxid_lock);
 
        while (true)
        {
@@ -4597,7 +4617,7 @@ slonik_unlock_set(SlonikStmt_unlock_set * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4630,7 +4650,7 @@ slonik_move_set(SlonikStmt_move_set * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -4643,7 +4663,7 @@ slonik_move_set(SlonikStmt_move_set * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->set_id, stmt->new_origin);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -4658,18 +4678,20 @@ int
 slonik_ddl_script(SlonikStmt_ddl_script * stmt)
 {
        SlonikAdmInfo *adminfo1;
-       SlonDString query, equery;
+       SlonDString query,
+                               equery;
        SlonDString script;
        PGresult   *res1;
        int                     rc;
-       int                     num_statements = -1, stmtno;
+       int                     num_statements = -1,
+                               stmtno;
        char            buf[4096];
        char            rex1[256];
        char            rex2[256];
        char            rex3[256];
        char            rex4[256];
 
-#define PARMCOUNT 1  
+#define PARMCOUNT 1
 
        const char *params[PARMCOUNT];
 
@@ -4677,7 +4699,7 @@ slonik_ddl_script(SlonikStmt_ddl_script * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&script);
@@ -4687,7 +4709,7 @@ slonik_ddl_script(SlonikStmt_ddl_script * stmt)
        while (fgets(rex1, 256, stmt->ddl_fd) != NULL)
        {
                rc = strlen(rex1);
-               rex1[rc] = '\0';
+               rex1[rc] = '\0';
                replace_token(rex3, rex1, "@CLUSTERNAME@", stmt->hdr.script->clustername);
                replace_token(rex4, rex3, "@MODULEVERSION@", SLONY_I_VERSION_STRING);
                replace_token(buf, rex4, "@NAMESPACE@", rex2);
@@ -4696,78 +4718,101 @@ slonik_ddl_script(SlonikStmt_ddl_script * stmt)
        }
        dstring_terminate(&script);
 
-       /* This prepares the statement that will be run over and over for each DDL statement */
+       /*
+        * This prepares the statement that will be run over and over for each DDL
+        * statement
+        */
        dstring_init(&equery);
-       if ((stmt->only_on_nodes == NULL) && (stmt->only_on_node < 0)) {
-                       slon_mkquery(&equery,
-                                                "select \"_%s\".ddlCapture($1, NULL::text);",
-                                                stmt->hdr.script->clustername);
-       } else {
-               if (stmt->only_on_node > 0) {
+       if ((stmt->only_on_nodes == NULL) && (stmt->only_on_node < 0))
+       {
+               slon_mkquery(&equery,
+                                        "select \"_%s\".ddlCapture($1, NULL::text);",
+                                        stmt->hdr.script->clustername);
+       }
+       else
+       {
+               if (stmt->only_on_node > 0)
+               {
                        slon_mkquery(&equery,
                                                 "select \"_%s\".ddlCapture($1, '%d');",
                                                 stmt->hdr.script->clustername, stmt->only_on_node);
-               } else {  /* stmt->only_on_nodes is populated */
+               }
+               else
+               {                                               /* stmt->only_on_nodes is populated */
                        slon_mkquery(&equery,
                                                 "select \"_%s\".ddlCapture($1, '%s');",
                                                 stmt->hdr.script->clustername, stmt->only_on_nodes);
                }
        }
-       /* Split the script into a series of SQL statements - each needs to
-          be submitted separately */
-       num_statements = scan_for_statements (dstring_data(&script));
+
+       /*
+        * Split the script into a series of SQL statements - each needs to be
+        * submitted separately
+        */
+       num_statements = scan_for_statements(dstring_data(&script));
 
        /* OOPS!  Something went wrong !!! */
-       if ((num_statements < 0) || (num_statements >= MAXSTATEMENTS)) {
+       if ((num_statements < 0) || (num_statements >= MAXSTATEMENTS))
+       {
                printf("DDL - number of statements invalid - %d not between 0 and %d\n", num_statements, MAXSTATEMENTS);
                return -1;
-       } 
+       }
        dstring_init(&query);
-       for (stmtno=0; stmtno < num_statements;  stmtno++) {
-               int startpos, endpos;
-               char *dest;
+       for (stmtno = 0; stmtno < num_statements; stmtno++)
+       {
+               int                     startpos,
+                                       endpos;
+               char       *dest;
+
                if (stmtno == 0)
                        startpos = 0;
                else
-                       startpos = STMTS[stmtno-1];
+                       startpos = STMTS[stmtno - 1];
                endpos = STMTS[stmtno];
-               dest = (char *) malloc (endpos - startpos + 1);
-               if (dest == 0) {
+               dest = (char *) malloc(endpos - startpos + 1);
+               if (dest == 0)
+               {
                        printf("DDL Failure - could not allocate %d bytes of memory\n", endpos - startpos + 1);
                        return -1;
                }
-               strncpy(dest, dstring_data(&script) + startpos, endpos-startpos);
-               dest[STMTS[stmtno]-startpos] = 0;
+               strncpy(dest, dstring_data(&script) + startpos, endpos - startpos);
+               dest[STMTS[stmtno] - startpos] = 0;
                slon_mkquery(&query, "%s", dest);
                free(dest);
 
-               params[PARMCOUNT-1] = dstring_data(&query);
+               params[PARMCOUNT - 1] = dstring_data(&query);
 
                res1 = PQexecParams(adminfo1->dbconn, dstring_data(&equery), 1, NULL, params, NULL, NULL, 0);
                if (PQresultStatus(res1) != PGRES_TUPLES_OK)
                {
-                               fprintf(stderr, "%s [%s] - %s",
-                                               PQresStatus(PQresultStatus(res1)),
-                                               dstring_data(&query), PQresultErrorMessage(res1));
-                               PQclear(res1);
-                               return -1;
+                       fprintf(stderr, "%s [%s] - %s",
+                                       PQresStatus(PQresultStatus(res1)),
+                                       dstring_data(&query), PQresultErrorMessage(res1));
+                       PQclear(res1);
+                       return -1;
                }
                PQclear(res1);
        }
 
-    /*
+       /*
         * Finally call ddlScript_complete()
         */
-       if ((stmt->only_on_nodes == NULL) && (stmt->only_on_node < 0)) {
-                       slon_mkquery(&query,
-                                                "select \"_%s\".ddlScript_complete(NULL::text);",
-                                                stmt->hdr.script->clustername);
-       } else {
-               if (stmt->only_on_node > 0) {
+       if ((stmt->only_on_nodes == NULL) && (stmt->only_on_node < 0))
+       {
+               slon_mkquery(&query,
+                                        "select \"_%s\".ddlScript_complete(NULL::text);",
+                                        stmt->hdr.script->clustername);
+       }
+       else
+       {
+               if (stmt->only_on_node > 0)
+               {
                        slon_mkquery(&query,
                                                 "select \"_%s\".ddlScript_complete('%d');",
                                                 stmt->hdr.script->clustername, stmt->only_on_node);
-               } else {  /* stmt->only_on_nodes is populated */
+               }
+               else
+               {                                               /* stmt->only_on_nodes is populated */
                        slon_mkquery(&query,
                                                 "select \"_%s\".ddlScript_complete('%s');",
                                                 stmt->hdr.script->clustername, stmt->only_on_nodes);
@@ -4776,14 +4821,14 @@ slonik_ddl_script(SlonikStmt_ddl_script * stmt)
        res1 = PQexec(adminfo1->dbconn, dstring_data(&query));
        if (PQresultStatus(res1) != PGRES_TUPLES_OK)
        {
-                       fprintf(stderr, "%s [%s] - %s",
-                                       PQresStatus(PQresultStatus(res1)),
-                                       dstring_data(&query), PQresultErrorMessage(res1));
-                       PQclear(res1);
-                       dstring_free(&equery);
-                       dstring_free(&script);
-                       dstring_free(&query);
-                       return -1;
+               fprintf(stderr, "%s [%s] - %s",
+                               PQresStatus(PQresultStatus(res1)),
+                               dstring_data(&query), PQresultErrorMessage(res1));
+               PQclear(res1);
+               dstring_free(&equery);
+               dstring_free(&script);
+               dstring_free(&query);
+               return -1;
        }
        PQclear(res1);
 
@@ -4805,7 +4850,7 @@ slonik_update_functions(SlonikStmt_update_functions * stmt)
        if (adminfo == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo, false) < 0)
                return -1;
 
        /*
@@ -4905,9 +4950,9 @@ slonik_wait_event(SlonikStmt_wait_event * stmt)
        time_t          now;
        int                     all_confirmed = 0;
        char            seqbuf[NAMEDATALEN];
-       int loop_count=0;
+       int                     loop_count = 0;
        SlonDString outstanding_nodes;
-       int tupindex;
+       int                     tupindex;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->wait_on);
        if (adminfo1 == NULL)
@@ -4940,9 +4985,9 @@ slonik_wait_event(SlonikStmt_wait_event * stmt)
                                if (adminfo->no_id == stmt->wait_origin)
                                {
                                        printf("%s:%d: Error: "
-                                          "script did not generate any event on node %d\n",
-                                                          stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
-                                                          stmt->wait_origin);
+                                                  "script did not generate any event on node %d\n",
+                                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
+                                                  stmt->wait_origin);
                                        return -1;
                                }
                                continue;
@@ -4951,24 +4996,25 @@ slonik_wait_event(SlonikStmt_wait_event * stmt)
                        if (stmt->wait_confirmed < 0)
                        {
                                SlonDString ignore_condition;
-                               int * node_ptr;
+                               int                *node_ptr;
+
                                sprintf(seqbuf, INT64_FORMAT, adminfo->last_event);
                                dstring_init(&ignore_condition);
-                               
-                               for(node_ptr=stmt->ignore_nodes; node_ptr != NULL &&
-                                               *node_ptr!=-1;node_ptr++)
+
+                               for (node_ptr = stmt->ignore_nodes; node_ptr != NULL &&
+                                        *node_ptr != -1; node_ptr++)
                                {
-                                       if(node_ptr!=stmt->ignore_nodes)
+                                       if (node_ptr != stmt->ignore_nodes)
                                                slon_appendquery(&ignore_condition,
-                                                                          ",%d",*node_ptr);
+                                                                                ",%d", *node_ptr);
                                        else
                                                slon_appendquery(&ignore_condition,
-                                                                          "and N.no_id not in ( %d ",*node_ptr);
+                                                                         "and N.no_id not in ( %d ", *node_ptr);
                                }
-                               if(node_ptr != stmt->ignore_nodes)
-                                       slon_appendquery(&ignore_condition,")");
+                               if (node_ptr != stmt->ignore_nodes)
+                                       slon_appendquery(&ignore_condition, ")");
                                else
-                                       slon_appendquery(&ignore_condition,"");
+                                       slon_appendquery(&ignore_condition, "");
                                dstring_terminate(&ignore_condition);
                                slon_mkquery(&query,
                                                         "select no_id, max(con_seqno) "
@@ -5012,18 +5058,19 @@ slonik_wait_event(SlonikStmt_wait_event * stmt)
                        }
                        if (PQntuples(res) > 0)
                        {
-                               all_confirmed = 0;              
+                               all_confirmed = 0;
                                dstring_reset(&outstanding_nodes);
-                               for(tupindex=0; tupindex < PQntuples(res); tupindex++)
+                               for (tupindex = 0; tupindex < PQntuples(res); tupindex++)
                                {
-                                       char * node = PQgetvalue(res,tupindex,0);
-                                       char * last_event = PQgetvalue(res,tupindex,1);
-                                       if( last_event == 0)
-                                         last_event="null";
-                                       slon_appendquery(&outstanding_nodes,"%snode %s only on event %s"
-                                                                        , tupindex==0 ? "" : ", "
-                                                                        , node,last_event);
-                                       
+                                       char       *node = PQgetvalue(res, tupindex, 0);
+                                       char       *last_event = PQgetvalue(res, tupindex, 1);
+
+                                       if (last_event == 0)
+                                               last_event = "null";
+                                       slon_appendquery(&outstanding_nodes, "%snode %s only on event %s"
+                                                                        ,tupindex == 0 ? "" : ", "
+                                                                        ,node, last_event);
+
                                }
                                dstring_terminate(&outstanding_nodes);
                        }
@@ -5049,21 +5096,21 @@ slonik_wait_event(SlonikStmt_wait_event * stmt)
                }
 
                loop_count++;
-               if(loop_count % 10 == 0 && stmt->wait_confirmed >= 0)
+               if (loop_count % 10 == 0 && stmt->wait_confirmed >= 0)
                {
                        sprintf(seqbuf, INT64_FORMAT, adminfo->last_event);
                        printf("%s:%d: waiting for event (%d,%s) to be confirmed on node %d\n"
-                                  ,stmt->hdr.stmt_filename,stmt->hdr.stmt_lno
-                                  ,stmt->wait_origin,seqbuf,
+                                  ,stmt->hdr.stmt_filename, stmt->hdr.stmt_lno
+                                  ,stmt->wait_origin, seqbuf,
                                   stmt->wait_confirmed);
                        fflush(stdout);
                }
-               else if (loop_count % 10 ==)
+               else if (loop_count % 10 == 0)
                {
                        sprintf(seqbuf, INT64_FORMAT, adminfo->last_event);
                        printf("%s:%d: waiting for event (%d,%s).  %s\n",
-                                  stmt->hdr.stmt_filename,stmt->hdr.stmt_lno,
-                                  stmt->wait_origin,seqbuf,
+                                  stmt->hdr.stmt_filename, stmt->hdr.stmt_lno,
+                                  stmt->wait_origin, seqbuf,
                                   dstring_data(&outstanding_nodes));
                        fflush(stdout);
 
@@ -5087,7 +5134,7 @@ slonik_switch_log(SlonikStmt_switch_log * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -5119,7 +5166,7 @@ slonik_sync(SlonikStmt_sync * stmt)
        if (adminfo1 == NULL)
                return -1;
 
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo1,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo1, false) < 0)
                return -1;
 
        dstring_init(&query);
@@ -5131,7 +5178,7 @@ slonik_sync(SlonikStmt_sync * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->hdr.script->clustername);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo1, &query,
-                                                  stmt->hdr.script,1) < 0)
+                                                  stmt->hdr.script, 1) < 0)
        {
                dstring_free(&query);
                return -1;
@@ -5156,7 +5203,7 @@ slonik_sleep(SlonikStmt_sleep * stmt)
  * If errorOK is true, just return "false" for bad input.
  */
 int
-slon_scanint64(char *str, int64 * result)
+slon_scanint64(char *str, int64 *result)
 {
        char       *ptr = str;
        int64           tmp = 0;
@@ -5168,7 +5215,7 @@ slon_scanint64(char *str, int64 * result)
         */
 
        /* skip leading spaces */
-       while (*ptr && isspace((unsigned char)*ptr))
+       while (*ptr && isspace((unsigned char) *ptr))
                ptr++;
 
        /* handle sign */
@@ -5193,11 +5240,11 @@ slon_scanint64(char *str, int64 * result)
                ptr++;
 
        /* require at least one digit */
-       if (!isdigit((unsigned char)*ptr))
+       if (!isdigit((unsigned char) *ptr))
                return false;
 
        /* process digits */
-       while (*ptr && isdigit((unsigned char)*ptr))
+       while (*ptr && isdigit((unsigned char) *ptr))
        {
                int64           newtmp = tmp * 10 + (*ptr++ - '0');
 
@@ -5242,7 +5289,7 @@ replace_token(char *resout, char *lines, const char *token, const char *replacem
        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] || (strncmp((const char *) lines + i, token, toklen)))
                {
                        if (lines[i] == 0x0d)           /* ||(lines[i] == 0x0a)) */
                                break;
@@ -5251,13 +5298,13 @@ replace_token(char *resout, char *lines, const char *token, const char *replacem
                        continue;
                }
                /* if we get here a change is needed - set up new line */
-               strncpy((char *)result_set + o, replacement, replen);
+               strncpy((char *) result_set + o, replacement, replen);
                o += replen - 1;
                i += toklen - 1;
        }
 
        result_set[o] = '\0';
-       memcpy(resout, result_set, o+1);
+       memcpy(resout, result_set, o + 1);
 }
 
 /**
@@ -5266,48 +5313,49 @@ replace_token(char *resout, char *lines, const char *token, const char *replacem
 *
 *
 */
-static int 
+static int
 slonik_get_next_tab_id(SlonikStmt * stmt)
 {
        SlonikAdmInfo *adminfo_def;
        SlonDString query;
-       int max_tab_id=0;
-       int tab_id=0;
-       char tab_id_str;
-       PGresultres;
-       
+       int                     max_tab_id = 0;
+       int                     tab_id = 0;
+       char       *tab_id_str;
+       PGresult   *res;
+
        dstring_init(&query);
        slon_mkquery(&query,
                                 "select max(tab_id) FROM \"_%s\".sl_table",
                                 stmt->script->clustername);
-       
+
        for (adminfo_def = stmt->script->adminfo_list;
                 adminfo_def; adminfo_def = adminfo_def->next)
-       {       
-               SlonikAdmInfo * adminfo = get_active_adminfo(stmt,
-                                                                                                        adminfo_def->no_id);
-               if( adminfo == NULL)
+       {
+               SlonikAdmInfo *adminfo = get_active_adminfo(stmt,
+                                                                                                       adminfo_def->no_id);
+
+               if (adminfo == NULL)
                {
-                       
+
                        printf("%s:%d: Error: could not connect to node %d for next table"
                                   " id",
-                                  stmt->stmt_filename,stmt->stmt_lno,
+                                  stmt->stmt_filename, stmt->stmt_lno,
                                   adminfo_def->no_id);
                        dstring_terminate(&query);
                        return -1;
                }
-               if(slonik_is_slony_installed(stmt,adminfo) > 0 )
+               if (slonik_is_slony_installed(stmt, adminfo) > 0)
                {
-                       res = db_exec_select((SlonikStmt*)stmt,adminfo,&query);
-                       if(res == NULL ) 
+                       res = db_exec_select((SlonikStmt *) stmt, adminfo, &query);
+                       if (res == NULL)
                        {
-                                       printf("%s:%d: Error:could not query node %d for next table id",
-                                                  stmt->stmt_filename,stmt->stmt_lno,
-                                                  adminfo->no_id);
-                                       if( res != NULL)
-                                                       PQclear(res);
-                                       dstring_terminate(&query);
-                                       return -1;
+                               printf("%s:%d: Error:could not query node %d for next table id",
+                                          stmt->stmt_filename, stmt->stmt_lno,
+                                          adminfo->no_id);
+                               if (res != NULL)
+                                       PQclear(res);
+                               dstring_terminate(&query);
+                               return -1;
                        }
                }
                else
@@ -5317,23 +5365,23 @@ slonik_get_next_tab_id(SlonikStmt * stmt)
                         */
                        continue;
                }
-               if(PQntuples(res) > 0)
-               {               
-                       tab_id_str = PQgetvalue(res,0,0);
-                       if(tab_id_str != NULL)
-                               tab_id=strtol(tab_id_str,NULL,10);
+               if (PQntuples(res) > 0)
+               {
+                       tab_id_str = PQgetvalue(res, 0, 0);
+                       if (tab_id_str != NULL)
+                               tab_id = strtol(tab_id_str, NULL, 10);
                        else
                        {
                                PQclear(res);
-                               continue;                               
+                               continue;
                        }
-                       if(tab_id > max_tab_id)
-                               max_tab_id=tab_id;
+                       if (tab_id > max_tab_id)
+                               max_tab_id = tab_id;
                }
                PQclear(res);
-       }/*for*/
+       }                                                       /* for */
        dstring_terminate(&query);
-       return max_tab_id+1;
+       return max_tab_id + 1;
 }
 
 
@@ -5344,47 +5392,48 @@ slonik_get_next_tab_id(SlonikStmt * stmt)
 *
 *
 */
-static int 
+static int
 slonik_get_next_sequence_id(SlonikStmt * stmt)
 {
        SlonikAdmInfo *adminfo_def;
        SlonDString query;
-       int max_seq_id=0;
-       int seq_id=0;
-       char seq_id_str;
-       PGresultres;
-       int rc;
-       
+       int                     max_seq_id = 0;
+       int                     seq_id = 0;
+       char       *seq_id_str;
+       PGresult   *res;
+       int                     rc;
+
        dstring_init(&query);
        slon_mkquery(&query,
                                 "select max(seq_id) FROM \"_%s\".sl_sequence",
                                 stmt->script->clustername);
-       
+
        for (adminfo_def = stmt->script->adminfo_list;
                 adminfo_def; adminfo_def = adminfo_def->next)
-       {       
-               SlonikAdmInfo * adminfo = get_active_adminfo(stmt,
-                                                                                                        adminfo_def->no_id);
-               if( adminfo == NULL)
+       {
+               SlonikAdmInfo *adminfo = get_active_adminfo(stmt,
+                                                                                                       adminfo_def->no_id);
+
+               if (adminfo == NULL)
                {
-                       
+
                        printf("%s:%d: Error: could not query node %d for next sequence id",
-                                  stmt->stmt_filename,stmt->stmt_lno,
+                                  stmt->stmt_filename, stmt->stmt_lno,
                                   adminfo_def->no_id);
                        dstring_terminate(&query);
                        return -1;
                }
-               if( (rc = slonik_is_slony_installed(stmt,adminfo)) > 0)
+               if ((rc = slonik_is_slony_installed(stmt, adminfo)) > 0)
                {
-                       res = db_exec_select((SlonikStmt*)stmt,adminfo,&query);
-                       if(res == NULL ) 
+                       res = db_exec_select((SlonikStmt *) stmt, adminfo, &query);
+                       if (res == NULL)
                        {
-                               
+
                                printf("%s:%d: Error: could not query node %d for next "
                                           "sequence id",
-                                          stmt->stmt_filename,stmt->stmt_lno,
+                                          stmt->stmt_filename, stmt->stmt_lno,
                                           adminfo->no_id);
-                               ifres != NULL)
+                               if (res != NULL)
                                        PQclear(res);
                                dstring_terminate(&query);
                                return -1;
@@ -5397,24 +5446,24 @@ slonik_get_next_sequence_id(SlonikStmt * stmt)
                else
                {
                        continue;
-               }               
-               if(PQntuples(res) > 0)
-               {               
-                       seq_id_str = PQgetvalue(res,0,0);
-                       if(seq_id_str != NULL)
-                               seq_id=strtol(seq_id_str,NULL,10);
+               }
+               if (PQntuples(res) > 0)
+               {
+                       seq_id_str = PQgetvalue(res, 0, 0);
+                       if (seq_id_str != NULL)
+                               seq_id = strtol(seq_id_str, NULL, 10);
                        else
                        {
                                PQclear(res);
                                continue;
                        }
-                       if(seq_id > max_seq_id)
-                               max_seq_id=seq_id;
+                       if (seq_id > max_seq_id)
+                               max_seq_id = seq_id;
                }
                PQclear(res);
        }
        dstring_terminate(&query);
-       return max_seq_id+1;
+       return max_seq_id + 1;
 }
 
 /**
@@ -5427,56 +5476,59 @@ slonik_get_next_sequence_id(SlonikStmt * stmt)
 * one that does.
 *
 */
-static int find_origin(SlonikStmt * stmt,int set_id)
+static int
+find_origin(SlonikStmt * stmt, int set_id)
 {
 
        SlonikAdmInfo *adminfo_def;
        SlonDString query;
-       PGresult * res;
-       int origin_id=-1;
-       char * origin_id_str;
+       PGresult   *res;
+       int                     origin_id = -1;
+       char       *origin_id_str;
+
        dstring_init(&query);
        slon_mkquery(&query,
                                 "select set_origin from \"_%s\".\"sl_set\" where set_id=%d",
-                                stmt->script->clustername,set_id);
-       
+                                stmt->script->clustername, set_id);
+
        for (adminfo_def = stmt->script->adminfo_list;
                 adminfo_def; adminfo_def = adminfo_def->next)
-       {       
-               SlonikAdmInfo * adminfo = get_active_adminfo(stmt,
-                                                                                                        adminfo_def->no_id);
-               if(adminfo == NULL)
+       {
+               SlonikAdmInfo *adminfo = get_active_adminfo(stmt,
+                                                                                                       adminfo_def->no_id);
+
+               if (adminfo == NULL)
                        continue;
-               res = db_exec_select((SlonikStmt*)stmt,adminfo,&query);
-               if(res == NULL ) 
+               res = db_exec_select((SlonikStmt *) stmt, adminfo, &query);
+               if (res == NULL)
                {
                        printf("%s:%d: warning: could not query node %d for origin",
-                                  stmt->stmt_filename,stmt->stmt_lno,
+                                  stmt->stmt_filename, stmt->stmt_lno,
                                   adminfo->no_id);
                        continue;
                }
-               if(PQntuples(res) > 0)
-               {               
-                       origin_id_str = PQgetvalue(res,0,0);
-                       if(origin_id_str != NULL)
+               if (PQntuples(res) > 0)
+               {
+                       origin_id_str = PQgetvalue(res, 0, 0);
+                       if (origin_id_str != NULL)
                        {
-                               origin_id=strtol(origin_id_str,NULL,10);
+                               origin_id = strtol(origin_id_str, NULL, 10);
                                PQclear(res);
                        }
                        else
                        {
                                PQclear(res);
                                continue;
-                               
+
                        }
                }
-               if(origin_id >= 0) 
+               if (origin_id >= 0)
                        break;
-       }/* for */
-       
+       }                                                       /* for */
+
        dstring_terminate(&query);
-       
-       
+
+
        return origin_id;
 }
 
@@ -5485,64 +5537,64 @@ static int find_origin(SlonikStmt * stmt,int set_id)
 * adds any sequences that table_name depends on to the replication
 * set.
 *
-* 
+*
 *
 */
 int
-slonik_add_dependent_sequences(SlonikStmt_set_add_table *stmt,
-                                                  SlonikAdmInfo * adminfo1,
-                                                  const char * table_name)
+slonik_add_dependent_sequences(SlonikStmt_set_add_table * stmt,
+                                                          SlonikAdmInfo * adminfo1,
+                                                          const char *table_name)
 {
 
        SlonDString query;
-       PGresult result;
-       int idx=0;
-       const char * seq_name;
-       char comment;
-       int rc;
-       
+       PGresult   *result;
+       int                     idx = 0;
+       const char *seq_name;
+       char       *comment;
+       int                     rc;
+
        dstring_init(&query);
        slon_mkquery(&query,
                                 "select pg_get_serial_sequence('%s',column_name) "
                                 "FROM information_schema.columns where table_schema ||"
                                 "'.' || table_name='%s'",
-                                table_name,table_name);
-       result = db_exec_select((SlonikStmt*)stmt,adminfo1,&query);
-       ifresult == NULL)
+                                table_name, table_name);
+       result = db_exec_select((SlonikStmt *) stmt, adminfo1, &query);
+       if (result == NULL)
        {
                dstring_terminate(&query);
                return -1;
        }
-       for(idx=0; idx < PQntuples(result);idx++)
+       for (idx = 0; idx < PQntuples(result); idx++)
        {
-               
-               if(!PQgetisnull(result,idx,0)  )
+
+               if (!PQgetisnull(result, idx, 0))
                {
-                       seq_name=PQgetvalue(result,idx,0);
+                       seq_name = PQgetvalue(result, idx, 0);
                        /**
                         * add the sequence to the replication set
                         */
-                       comment=malloc(strlen(table_name)+strlen("sequence for ")+1);
-                       sprintf(comment,"sequence for %s",table_name);
-                       rc=slonik_set_add_single_sequence((SlonikStmt*)stmt,adminfo1,
-                                                                                         seq_name,
-                                                                                         stmt->set_id,
-                                                                                         comment,-1);
+                       comment = malloc(strlen(table_name) + strlen("sequence for ") + 1);
+                       sprintf(comment, "sequence for %s", table_name);
+                       rc = slonik_set_add_single_sequence((SlonikStmt *) stmt, adminfo1,
+                                                                                               seq_name,
+                                                                                               stmt->set_id,
+                                                                                               comment, -1);
                        free(comment);
-                       if(rc < 0 )
+                       if (rc < 0)
                        {
                                PQclear(result);
                                dstring_terminate(&query);
                                return rc;
                        }
-                       
+
                }
-               
-       }/*for*/
+
+       }                                                       /* for */
        PQclear(result);
        dstring_terminate(&query);
        return 0;
-       
+
 }
 
 
@@ -5551,44 +5603,44 @@ slonik_add_dependent_sequences(SlonikStmt_set_add_table *stmt,
 *
 * this function will check to see if slony tables exist
 * on the node by querying the information_schema.
-* 
+*
 * returns:
-*        -1 => could not query information schema
-*         0 => slony not installed
-*         1 => slony is installed.
+*               -1 => could not query information schema
+*                0 => slony not installed
+*                1 => slony is installed.
 */
 static int
 slonik_is_slony_installed(SlonikStmt * stmt,
-                                         SlonikAdmInfo * adminfo)
+                                                 SlonikAdmInfo * adminfo)
 {
        SlonDString query;
-       PGresult res;
-       int rc=-1;
-       bool txn_open = adminfo->have_xact;
+       PGresult   *res;
+       int                     rc = -1;
+       bool            txn_open = adminfo->have_xact;
 
-       if (db_begin_xact(stmt, adminfo,true) < 0)
+       if (db_begin_xact(stmt, adminfo, true) < 0)
                return -1;
 
        dstring_init(&query);
-       slon_mkquery(&query,"select count(*) FROM information_schema"
+       slon_mkquery(&query, "select count(*) FROM information_schema"
                                 ".tables where table_schema='_%s' AND table_name"
-                                "='sl_table'",stmt->script->clustername);
-       res = db_exec_select((SlonikStmt*)stmt,adminfo,&query);
-       if ( res == NULL ||  PQntuples(res) <= 0 )
-               rc=-1;
-       else if( strncmp(PQgetvalue(res,0,0),"1",1)==0)
-               rc=1;
-       else 
-               rc=0;
-       
-       if(res != NULL)
+                                "='sl_table'", stmt->script->clustername);
+       res = db_exec_select((SlonikStmt *) stmt, adminfo, &query);
+       if (res == NULL || PQntuples(res) <= 0)
+               rc = -1;
+       else if (strncmp(PQgetvalue(res, 0, 0), "1", 1) == 0)
+               rc = 1;
+       else
+               rc = 0;
+
+       if (res != NULL)
                PQclear(res);
-       if(!txn_open)
-         db_rollback_xact(stmt, adminfo);
+       if (!txn_open)
+               db_rollback_xact(stmt, adminfo);
        dstring_terminate(&query);
        return rc;
-       
-}      
+
+}
 
 /* slonik_submitEvent(stmt, adminfo, query, script, suppress_wait_for)
  *
@@ -5596,34 +5648,36 @@ slonik_is_slony_installed(SlonikStmt * stmt,
  * logic for whether or not to do auto wait for or suppress this into
  * one place.
  */
-                                          
-static int slonik_submitEvent(SlonikStmt * stmt,
-                                                         SlonikAdmInfo * adminfo, 
-                                                         SlonDString * query,
-                                                         SlonikScript * script,
-                                                         int suppress_wait_for)
+
+static int
+slonik_submitEvent(SlonikStmt * stmt,
+                                  SlonikAdmInfo * adminfo,
+                                  SlonDString * query,
+                                  SlonikScript * script,
+                                  int suppress_wait_for)
 {
-       int rc;
-       int recreate_txn=0;
-
-       if ( last_event_node >= 0 &&
-                last_event_node != adminfo->no_id
-               && ! suppress_wait_for )
-       {               
-               SlonikStmt_wait_event wait_event;               
+       int                     rc;
+       int                     recreate_txn = 0;
+
+       if (last_event_node >= 0 &&
+               last_event_node != adminfo->no_id
+               && !suppress_wait_for)
+       {
+               SlonikStmt_wait_event wait_event;
+
                /**
                 * the last event node is not the current event node.
                 * time to wait.
                 */
-               
-               ifcurrent_try_level != 0)
+
+               if (current_try_level != 0)
                {
-                       if( current_try_level==1 && block_stmt_no == 1)
+                       if (current_try_level == 1 && block_stmt_no == 1)
                        {
-                               recreate_txn=1;
-                               db_rollback_xact(stmt,adminfo);
+                               recreate_txn = 1;
+                               db_rollback_xact(stmt, adminfo);
                        }
-                       else 
+                       else
                        {
                                printf("%s:%d Error: the event origin can not be changed "
                                           "inside of a try block",
@@ -5634,28 +5688,28 @@ static int slonik_submitEvent(SlonikStmt * stmt,
 
                /**
                 * for now we generate a 'fake' Slonik_wait_event structure
-                * 
+                *
                 */
-               wait_event.hdr=*stmt;
-               wait_event.wait_origin=last_event_node;
-               wait_event.wait_on=last_event_node;
-               wait_event.wait_confirmed=adminfo->no_id;
-               wait_event.wait_timeout=0;
-               wait_event.ignore_nodes=0;
+               wait_event.hdr = *stmt;
+               wait_event.wait_origin = last_event_node;
+               wait_event.wait_on = last_event_node;
+               wait_event.wait_confirmed = adminfo->no_id;
+               wait_event.wait_timeout = 0;
+               wait_event.ignore_nodes = 0;
                rc = slonik_wait_event(&wait_event);
                if (recreate_txn)
                {
-                       db_begin_xact(stmt,adminfo,false);
+                       db_begin_xact(stmt, adminfo, false);
                }
-               if(rc < 0) 
+               if (rc < 0)
                        return rc;
-               
+
        }
-       rc= db_exec_evcommand(stmt,adminfo,query);
-       if(! suppress_wait_for)
-               last_event_node=adminfo->no_id;
+       rc = db_exec_evcommand(stmt, adminfo, query);
+       if (!suppress_wait_for)
+               last_event_node = adminfo->no_id;
        return rc;
-  
+
 }
 
 /**
@@ -5669,76 +5723,79 @@ static int slonik_submitEvent(SlonikStmt * stmt,
  * be used as part of a wait for.
  *
  */
-static size_t slonik_get_last_event_id(SlonikStmt *stmt,
-                                                                          SlonikScript * script,
-                                                                          const char * event_filter,
-                                                                          int64 ** events)
+static size_t
+slonik_get_last_event_id(SlonikStmt * stmt,
+                                                SlonikScript * script,
+                                                const char *event_filter,
+                                                int64 **events)
 {
-       
+
        SlonDString query;
-       PGresult result;
-       char event_id;
-       SlonikAdmInfo * curAdmInfo=NULL;
-       int node_count=0;
-       int node_idx;
-       int rc;
+       PGresult   *result;
+       char       *event_id;
+       SlonikAdmInfo *curAdmInfo = NULL;
+       int                     node_count = 0;
+       int                     node_idx;
+       int                     rc;
 
        dstring_init(&query);
-       slon_mkquery(&query,"select max(ev_seqno) FROM \"_%s\".sl_event"
+       slon_mkquery(&query, "select max(ev_seqno) FROM \"_%s\".sl_event"
                                 " , \"_%s\".sl_node "
                                 " where ev_origin=\"_%s\".getLocalNodeId('_%s') "
                                 " AND %s AND sl_node.no_id="
                                 " ev_origin"
-                                , script->clustername,script->clustername,
-                                script->clustername,script->clustername,event_filter);
-       node_count=0;
-       forcurAdmInfo = script->adminfo_list;
-               curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
+                                ,script->clustername, script->clustername,
+                                script->clustername, script->clustername, event_filter);
+       node_count = 0;
+       for (curAdmInfo = script->adminfo_list;
+                curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
        {
                node_count++;
        }
-       *events = malloc(sizeof(int64)*(node_count+1));
-       node_idx=0;
-       forcurAdmInfo = script->adminfo_list;
-                curAdmInfo != NULL; curAdmInfo = curAdmInfo->next,node_idx++)
+       *events = malloc(sizeof(int64) * (node_count + 1));
+       node_idx = 0;
+       for (curAdmInfo = script->adminfo_list;
+                curAdmInfo != NULL; curAdmInfo = curAdmInfo->next, node_idx++)
        {
-               SlonikAdmInfo * activeAdmInfo = 
-                       get_active_adminfo(stmt,curAdmInfo->no_id);
-               if( activeAdmInfo == NULL)
+               SlonikAdmInfo *activeAdmInfo =
+               get_active_adminfo(stmt, curAdmInfo->no_id);
+
+               if (activeAdmInfo == NULL)
                {
                        /**
                         * warning?
                         */
-                       (*events)[node_idx]=-1;
+                       (*events)[node_idx] = -1;
                        continue;
                }
-               rc = slonik_is_slony_installed(stmt,activeAdmInfo);
-               if(rc == 1)
+               rc = slonik_is_slony_installed(stmt, activeAdmInfo);
+               if (rc == 1)
                {
-                       result = db_exec_select(stmt,activeAdmInfo,&query);
-                       if(result == NULL || PQntuples(result) != 1 ) 
+                       result = db_exec_select(stmt, activeAdmInfo, &query);
+                       if (result == NULL || PQntuples(result) != 1)
                        {
                                printf("error: unable to query event history on node %d\n",
                                           curAdmInfo->no_id);
-                               if(result != NULL)
+                               if (result != NULL)
                                        PQclear(result);
                                return -1;
                        }
-                       event_id = PQgetvalue(result,0,0);
+                       event_id = PQgetvalue(result, 0, 0);
                        db_rollback_xact(stmt, activeAdmInfo);
-                       if(event_id != NULL)
-                               (*events)[node_idx]=strtoll(event_id,NULL,10);             
+                       if (event_id != NULL)
+                               (*events)[node_idx] = strtoll(event_id, NULL, 10);
                        else
-                               (*events)[node_idx]=-1;
+                               (*events)[node_idx] = -1;
                        PQclear(result);
                }
-               else {
-                       (*events)[node_idx]=-1;
+               else
+               {
+                       (*events)[node_idx] = -1;
                }
-               
+
        }
-       
-       
+
+
        dstring_terminate(&query);
        return node_count;
 }
@@ -5750,232 +5807,237 @@ static size_t slonik_get_last_event_id(SlonikStmt *stmt,
  * adminfo1 - The node that we are waiting to be caught up
  * stmt - The statement that is currently being executed
  * ignore_node - allows 1 node to be ignored (don't wait for
- *               adminfo1 to be caught up with that node)
- *               -1 means don't ignore any nodes.
+ *                              adminfo1 to be caught up with that node)
+ *                              -1 means don't ignore any nodes.
  *
  * Returns:
- *  0 - if all went fine
+ *     0 - if all went fine
  * -1 - if a WAIT is attempted inside a slonik TRY block
- */                                                            
-static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1,
-                                                                          SlonikStmt * stmt,
-                                                                          int ignore_node)
+ */
+static int
+slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1,
+                                                       SlonikStmt * stmt,
+                                                       int ignore_node)
 {
        SlonDString event_list;
-       PGresult * result=NULL;
-       SlonikAdmInfo * curAdmInfo=NULL;
-       int first_event=1;
-       int confirm_count=0;
+       PGresult   *result = NULL;
+       SlonikAdmInfo *curAdmInfo = NULL;
+       int                     first_event = 1;
+       int                     confirm_count = 0;
        SlonDString is_caughtup_query;
        SlonDString node_list;
-       int wait_count=0;
-       int node_list_size=0;
-       int sleep_count=0;
-       int64* behind_nodes=NULL;
-       int idx;
-       int cur_array_idx;
-       int recreate_txn=0;
+       int                     wait_count = 0;
+       int                     node_list_size = 0;
+       int                     sleep_count = 0;
+       int64      *behind_nodes = NULL;
+       int                     idx;
+       int                     cur_array_idx;
+       int                     recreate_txn = 0;
 
        /**
         * an array that stores a node_id, last_event.
         * or the last event seen for each admin conninfo
         * node.
         */
-       int64 * last_event_array=NULL;
-       
+       int64      *last_event_array = NULL;
+
 
        dstring_init(&event_list);
        dstring_init(&node_list);
 
-       ifcurrent_try_level != 0)
-       {
-         if( current_try_level==1 && block_stmt_no ==1)
-         {
-                 /**
-                  * The first statement in the try block requires
-                  * a wait for.  the code below will rollback the txn.
-                  * we set a flag so we know to create a new one 
-                  * when we are done.
-                  */
-                 recreate_txn=1;
-         }
-         else 
-         {
-                 printf("%s:%d Error: WAIT operation forbidden inside a try block\n",
-                                stmt->stmt_filename, stmt->stmt_lno);
-                 return -1;
-         }
-       }
-
-       forcurAdmInfo = stmt->script->adminfo_list;
+       if (current_try_level != 0)
+       {
+               if (current_try_level == 1 && block_stmt_no == 1)
+               {
+                       /**
+                        * The first statement in the try block requires
+                        * a wait for.  the code below will rollback the txn.
+                        * we set a flag so we know to create a new one
+                        * when we are done.
+                        */
+                       recreate_txn = 1;
+               }
+               else
+               {
+                       printf("%s:%d Error: WAIT operation forbidden inside a try block\n",
+                                  stmt->stmt_filename, stmt->stmt_lno);
+                       return -1;
+               }
+       }
+
+       for (curAdmInfo = stmt->script->adminfo_list;
                 curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
        {
                node_list_size++;
        }
-       last_event_array = malloc(node_list_size * sizeof(int64)*2);
-       memset(last_event_array,0,sizeof(node_list_size * sizeof(int64)*2));
-       
-       forcurAdmInfo = stmt->script->adminfo_list;
+       last_event_array = malloc(node_list_size * sizeof(int64) * 2);
+       memset(last_event_array, 0, sizeof(node_list_size * sizeof(int64) * 2));
+
+       for (curAdmInfo = stmt->script->adminfo_list;
                 curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
        {
-               char  seqno[NAMEDATALEN];
-               if(curAdmInfo->last_event < 0 || 
-                  curAdmInfo->no_id==adminfo1->no_id ||
-                       curAdmInfo->no_id == ignore_node )
+               char            seqno[NAMEDATALEN];
+
+               if (curAdmInfo->last_event < 0 ||
+                       curAdmInfo->no_id == adminfo1->no_id ||
+                       curAdmInfo->no_id == ignore_node)
                        continue;
-               
-               sprintf(seqno,INT64_FORMAT,curAdmInfo->last_event);
-               slon_appendquery(&event_list, 
+
+               sprintf(seqno, INT64_FORMAT, curAdmInfo->last_event);
+               slon_appendquery(&event_list,
                                                 "%s (node_list.no_id=%d)"
                                                 ,first_event ? " " : " OR "
                                                 ,curAdmInfo->no_id
                                                 ,seqno
-                                                );             
-               slon_appendquery(&node_list,"%s (%d) ",
+                       );
+               slon_appendquery(&node_list, "%s (%d) ",
                                                 first_event ? " " : ",",
                                                 curAdmInfo->no_id);
-               last_event_array[wait_count*2]=curAdmInfo->no_id;
-               last_event_array[wait_count*2+1]=curAdmInfo->last_event;
-               first_event=0;
+               last_event_array[wait_count * 2] = curAdmInfo->no_id;
+               last_event_array[wait_count * 2 + 1] = curAdmInfo->last_event;
+               first_event = 0;
                wait_count++;
        }
        dstring_terminate(&node_list);
-       
+
 
        dstring_init(&is_caughtup_query);
-        /**
-         * I need a row for the case where a node is not in sl_confirm
-         * and the node is disabled or deleted.
-         */
-        slon_mkquery(&is_caughtup_query,
-                                 "select node_list.no_id,max(con_seqno),no_active FROM "
-                                 " (VALUES %s) as node_list (no_id) LEFT JOIN "
-                                 "\"_%s\".sl_confirm ON(sl_confirm.con_origin=node_list.no_id"
-                                 " AND sl_confirm.con_received=%d)"
-                                 " LEFT JOIN \"_%s\".sl_node ON (node_list.no_id=sl_node.no_id) "
-                                 "GROUP BY node_list.no_id,no_active"
-                                 ,dstring_data(&node_list)
-                                 ,stmt->script->clustername
-                                 ,adminfo1->no_id
-                                 ,stmt->script->clustername);
-        
-        while(confirm_count != wait_count)
-        {
-                result = db_exec_select(stmt,
-                                                                adminfo1,&is_caughtup_query);
-                if (result == NULL) 
-                {
-                        /**
-                         * error
-                         */
-                }
-                confirm_count = PQntuples(result);
-
-                db_rollback_xact(stmt, adminfo1);        
-                 
-                /**
-                 * find nodes that are missing.
-                 * 
-                 */
-                behind_nodes=malloc(node_list_size * sizeof(int64));
-                memset(behind_nodes,0,node_list_size*sizeof(int64));
-                confirm_count=0;
-                for(idx = 0; idx < PQntuples(result); idx++)
-                {
-                        char * n_id_c = PQgetvalue(result,idx,0);
-                        int n_id = atoi(n_id_c);
-                        char * seqno_c = PQgetvalue(result,idx,1);
-                        int64 seqno=strtoll(seqno_c,NULL,10);  
-                        char * node_active = PQgetvalue(result,idx,2);
-                        for(cur_array_idx=0;
+       /**
+        * I need a row for the case where a node is not in sl_confirm
+        * and the node is disabled or deleted.
+        */
+       slon_mkquery(&is_caughtup_query,
+                                "select node_list.no_id,max(con_seqno),no_active FROM "
+                                " (VALUES %s) as node_list (no_id) LEFT JOIN "
+                                "\"_%s\".sl_confirm ON(sl_confirm.con_origin=node_list.no_id"
+                                " AND sl_confirm.con_received=%d)"
+                        " LEFT JOIN \"_%s\".sl_node ON (node_list.no_id=sl_node.no_id) "
+                                "GROUP BY node_list.no_id,no_active"
+                                ,dstring_data(&node_list)
+                                ,stmt->script->clustername
+                                ,adminfo1->no_id
+                                ,stmt->script->clustername);
+
+       while (confirm_count != wait_count)
+       {
+               result = db_exec_select(stmt,
+                                                               adminfo1, &is_caughtup_query);
+               if (result == NULL)
+               {
+                       /**
+                        * error
+                        */
+               }
+               confirm_count = PQntuples(result);
+
+               db_rollback_xact(stmt, adminfo1);
+
+               /**
+                * find nodes that are missing.
+                *
+                */
+               behind_nodes = malloc(node_list_size * sizeof(int64));
+               memset(behind_nodes, 0, node_list_size * sizeof(int64));
+               confirm_count = 0;
+               for (idx = 0; idx < PQntuples(result); idx++)
+               {
+                       char       *n_id_c = PQgetvalue(result, idx, 0);
+                       int                     n_id = atoi(n_id_c);
+                       char       *seqno_c = PQgetvalue(result, idx, 1);
+                       int64           seqno = strtoll(seqno_c, NULL, 10);
+                       char       *node_active = PQgetvalue(result, idx, 2);
+
+                       for (cur_array_idx = 0;
                                 cur_array_idx < wait_count; cur_array_idx++)
-                        {
-                                if(last_event_array[cur_array_idx*2]==n_id)
-                                {
-                                        /*
-                                         *  found.
-                                         */
-                                        if(node_active == NULL ||  *node_active=='f')
-                                        {
-                                                /**
-                                                 * if node_active is null we assume the
-                                                 * node has been deleted since it
-                                                 * has no entry in sl_node
-                                                 */
-                                                behind_nodes[cur_array_idx]=-1;
-                                                confirm_count++;
-                                        }                                      
-                                        else if(last_event_array[cur_array_idx*2+1]>seqno)
-                                        {
-                                                behind_nodes[cur_array_idx]=seqno;
-                                        }
-                                        else
-                                        {
-                                                behind_nodes[cur_array_idx]=-1;
-                                                confirm_count++;
-                                        }
-                                        
-                                }
-                                
-                        }
-                }/*for .. PQntuples*/
-                if(confirm_count < wait_count )
-                {
-                        sleep_count++;
-                        if(sleep_count % 10 == 0)
-                        {
-                                /**
-                                 * any elements in caught_up_nodes with a value 0
-                                 * means that the cooresponding node id in
-                                 * last_event_array is not showing up in the
-                                 * query result.
-                                 */
-                                SlonDString outstanding;
-                                dstring_init(&outstanding);
-                                first_event=1;
-                                for(cur_array_idx=0; cur_array_idx < wait_count;
+                       {
+                               if (last_event_array[cur_array_idx * 2] == n_id)
+                               {
+                                       /*
+                                        * found.
+                                        */
+                                       if (node_active == NULL || *node_active == 'f')
+                                       {
+                                               /**
+                                                * if node_active is null we assume the
+                                                * node has been deleted since it
+                                                * has no entry in sl_node
+                                                */
+                                               behind_nodes[cur_array_idx] = -1;
+                                               confirm_count++;
+                                       }
+                                       else if (last_event_array[cur_array_idx * 2 + 1] > seqno)
+                                       {
+                                               behind_nodes[cur_array_idx] = seqno;
+                                       }
+                                       else
+                                       {
+                                               behind_nodes[cur_array_idx] = -1;
+                                               confirm_count++;
+                                       }
+
+                               }
+
+                       }
+               }                                               /* for .. PQntuples */
+               if (confirm_count < wait_count)
+               {
+                       sleep_count++;
+                       if (sleep_count % 10 == 0)
+                       {
+                               /**
+                                * any elements in caught_up_nodes with a value 0
+                                * means that the cooresponding node id in
+                                * last_event_array is not showing up in the
+                                * query result.
+                                */
+                               SlonDString outstanding;
+
+                               dstring_init(&outstanding);
+                               first_event = 1;
+                               for (cur_array_idx = 0; cur_array_idx < wait_count;
                                         cur_array_idx++)
-                                {                                 
-                                        if(behind_nodes[cur_array_idx] >= 0)
-                                        {
-                                                char tmpbuf[96];
-                                                sprintf(tmpbuf,        "(" INT64_FORMAT "," INT64_FORMAT
-                                                                ") only at (" INT64_FORMAT "," INT64_FORMAT
-                                                                ")"
-                                                                ,
-                                                                last_event_array[cur_array_idx*2]
-                                                                ,last_event_array[cur_array_idx*2+1],
-                                                                last_event_array[cur_array_idx*2],
-                                                                behind_nodes[cur_array_idx] );
-                                                slon_appendquery(&outstanding,"%s %s"
-                                                                                 , first_event ? "" : ",",tmpbuf);
-                                                first_event=0;
-                                        }
-                                        
-                                }
-                                dstring_terminate(&outstanding);
-                                printf("waiting for events %s to be confirmed on node %d\n",
-                                               dstring_data(&outstanding),adminfo1->no_id);
-                                fflush(stdout);
-                          
-                        }/* every 10 iterations */                              
-                        sleep(1);
-                } 
-                free(behind_nodes);
-                
-        }/*while*/
-        if(result != NULL)
-                        PQclear(result);    
-        dstring_terminate(&event_list);
-        dstring_terminate(&is_caughtup_query);  
-        free(last_event_array);
-        
-        if(recreate_txn)
-        {
-                db_begin_xact(stmt,adminfo1,false);
-        }
-
-        return 0;
+                               {
+                                       if (behind_nodes[cur_array_idx] >= 0)
+                                       {
+                                               char            tmpbuf[96];
+
+                                               sprintf(tmpbuf, "(" INT64_FORMAT "," INT64_FORMAT
+                                                               ") only at (" INT64_FORMAT "," INT64_FORMAT
+                                                               ")"
+                                                               ,
+                                                               last_event_array[cur_array_idx * 2]
+                                                               ,last_event_array[cur_array_idx * 2 + 1],
+                                                               last_event_array[cur_array_idx * 2],
+                                                               behind_nodes[cur_array_idx]);
+                                               slon_appendquery(&outstanding, "%s %s"
+                                                                                ,first_event ? "" : ",", tmpbuf);
+                                               first_event = 0;
+                                       }
+
+                               }
+                               dstring_terminate(&outstanding);
+                               printf("waiting for events %s to be confirmed on node %d\n",
+                                          dstring_data(&outstanding), adminfo1->no_id);
+                               fflush(stdout);
+
+                       }                                       /* every 10 iterations */
+                       sleep(1);
+               }
+               free(behind_nodes);
+
+       }                                                       /* while */
+       if (result != NULL)
+               PQclear(result);
+       dstring_terminate(&event_list);
+       dstring_terminate(&is_caughtup_query);
+       free(last_event_array);
+
+       if (recreate_txn)
+       {
+               db_begin_xact(stmt, adminfo1, false);
+       }
+
+       return 0;
 
 }
 
@@ -5986,65 +6048,68 @@ static int slonik_wait_config_caughtup(SlonikAdmInfo * adminfo1,
  * (otherwise you could just get the answer directly from node_id).
  *
  * skip_node_list is a -1 terminated list of node_id values for the
- *           nodes to ignore (not search).
+ *                      nodes to ignore (not search).
  */
-static int64 get_last_escaped_event_id(SlonikStmt * stmt,
-                                               int node_id,
-                                               int * skip_node_list)
+static int64
+get_last_escaped_event_id(SlonikStmt * stmt,
+                                                 int node_id,
+                                                 int *skip_node_list)
 {
        SlonDString query;
-       PGresult result;
-       char event_id;
-       SlonikAdmInfo * curAdmInfo=NULL;
-       int64 max_event_id=0;
-       int64 cur_event_id;
-       int rc;
+       PGresult   *result;
+       char       *event_id;
+       SlonikAdmInfo *curAdmInfo = NULL;
+       int64           max_event_id = 0;
+       int64           cur_event_id;
+       int                     rc;
 
        dstring_init(&query);
-       slon_mkquery(&query,"select max(ev_seqno) FROM \"_%s\".sl_event"
+       slon_mkquery(&query, "select max(ev_seqno) FROM \"_%s\".sl_event"
                                 " where ev_origin=%d "
-                                , stmt->script->clustername,node_id);
-       forcurAdmInfo = stmt->script->adminfo_list;
+                                ,stmt->script->clustername, node_id);
+       for (curAdmInfo = stmt->script->adminfo_list;
                 curAdmInfo != NULL; curAdmInfo = curAdmInfo->next)
        {
-               int node_list_idx;
-               int skip=0;
-               for(node_list_idx=0; skip_node_list[node_list_idx]!=-1;node_list_idx++)
+               int                     node_list_idx;
+               int                     skip = 0;
+
+               for (node_list_idx = 0; skip_node_list[node_list_idx] != -1; node_list_idx++)
                {
-                       if(curAdmInfo->no_id==skip_node_list[node_list_idx])
+                       if (curAdmInfo->no_id == skip_node_list[node_list_idx])
                        {
-                               skip=1;
+                               skip = 1;
                                break;
-                       }                          
+                       }
                }
-               
-               if(skip)
+
+               if (skip)
                        continue;
-               
-               SlonikAdmInfo * activeAdmInfo = 
-                       get_active_adminfo(stmt,curAdmInfo->no_id);
-               if( activeAdmInfo == NULL)
+
+               SlonikAdmInfo *activeAdmInfo =
+               get_active_adminfo(stmt, curAdmInfo->no_id);
+
+               if (activeAdmInfo == NULL)
                {
                        continue;
                }
-               rc = slonik_is_slony_installed(stmt,activeAdmInfo);
-               if(rc == 1)
+               rc = slonik_is_slony_installed(stmt, activeAdmInfo);
+               if (rc == 1)
                {
-                       result = db_exec_select(stmt,activeAdmInfo,&query);
-                       if(result != NULL || PQntuples(result) >= 1 ) 
+                       result = db_exec_select(stmt, activeAdmInfo, &query);
+                       if (result != NULL || PQntuples(result) >= 1)
                        {
-                               event_id = PQgetvalue(result,0,0);
-                               if(event_id != NULL)                     
-                                       cur_event_id=strtoll(event_id,NULL,10); 
-                               if(cur_event_id > max_event_id)
-                                       max_event_id=cur_event_id;
+                               event_id = PQgetvalue(result, 0, 0);
+                               if (event_id != NULL)
+                                       cur_event_id = strtoll(event_id, NULL, 10);
+                               if (cur_event_id > max_event_id)
+                                       max_event_id = cur_event_id;
                        }
                        PQclear(result);
-               
-               }               
+
+               }
        }
-       
-       
+
+
        dstring_terminate(&query);
        return max_event_id;
 }
@@ -6058,13 +6123,13 @@ slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt)
        SlonikAdmInfo *adminfo1;
        SlonikAdmInfo *adminfo2;
        SlonDString query;
-       int rc;
+       int                     rc;
 
        adminfo1 = get_active_adminfo((SlonikStmt *) stmt, stmt->no_provider);
        if (adminfo1 == NULL)
                return -1;
 
-       
+
        dstring_init(&query);
 
 
@@ -6073,24 +6138,24 @@ slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt)
         * the provider node is caught up with all other nodes wrt config data.
         *
         * this is because we don't want to pick the origin based on
-        * stale data. 
+        * stale data.
         *
         * @note an alternative might be to contact all adminconninfo
         * nodes looking for the set origin and then submit the
-        * set origin to that.  This avoids the wait for and is probably
+        * set origin to that.  This avoids the wait for and is probably
         * what we should do.
-        */ 
+        */
        if (!auto_wait_disabled)
        {
-               rc=slonik_wait_config_caughtup(adminfo1,&stmt->hdr,-1);
-               if (rc < 0) 
+               rc = slonik_wait_config_caughtup(adminfo1, &stmt->hdr, -1);
+               if (rc < 0)
                        return rc;
        }
 
 
 
        adminfo2 = get_active_adminfo((SlonikStmt *) stmt, stmt->no_origin);
-       if (db_begin_xact((SlonikStmt *) stmt, adminfo2,false) < 0)
+       if (db_begin_xact((SlonikStmt *) stmt, adminfo2, false) < 0)
                return -1;
        slon_mkquery(&query,
                                 "lock table \"_%s\".sl_event_lock, \"_%s\".sl_config_lock;"
@@ -6098,17 +6163,17 @@ slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->hdr.script->clustername,
                                 stmt->hdr.script->clustername,
-                                stmt->no_origin,stmt->no_provider,
+                                stmt->no_origin, stmt->no_provider,
                                 stmt->no_receiver);
        if (slonik_submitEvent((SlonikStmt *) stmt, adminfo2, &query,
-                                                  stmt->hdr.script,auto_wait_disabled) < 0)
+                                                  stmt->hdr.script, auto_wait_disabled) < 0)
        {
                dstring_free(&query);
                return -1;
        }
        dstring_reset(&query);
        adminfo2 = get_active_adminfo((SlonikStmt *) stmt, stmt->no_receiver);
-       if(adminfo2 == NULL) 
+       if (adminfo2 == NULL)
        {
                printf("can not find conninfo for receiver node %d\n",
                           stmt->no_receiver);
@@ -6121,13 +6186,13 @@ slonik_resubscribe_node(SlonikStmt_resubscribe_node * stmt)
                                 stmt->hdr.script->clustername,
                                 stmt->no_origin,
                                 stmt->no_provider,
-                                stmt->no_receiver);    
+                                stmt->no_receiver);
        if (db_exec_command((SlonikStmt *) stmt, adminfo2, &query) < 0)
        {
-               printf("error reshaping subscriber\n");         
+               printf("error reshaping subscriber\n");
        }
-       
-       dstring_free(&query);   
+
+       dstring_free(&query);
        return 0;
 }
 
index 154d5b371b10a0b30a342edf2e22355fb9227dae..d98bb37d7471fba98b082447bba8766ac18cce55 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 #ifndef SLONIK_H
@@ -199,17 +199,18 @@ struct SlonikStmt_store_node_s
 struct SlonikStmt_drop_node_s
 {
        SlonikStmt      hdr;
-       int                     * no_id_list;
+       int                *no_id_list;
        int                     ev_origin;
 };
 
-struct failed_node_entry_s {
-       int no_id;
-       int backup_node;
-       int temp_backup_node;
-       struct failed_node_entry_s * next;
-       int num_sets;
-       int num_nodes;
+struct failed_node_entry_s
+{
+       int                     no_id;
+       int                     backup_node;
+       int                     temp_backup_node;
+       struct failed_node_entry_s *next;
+       int                     num_sets;
+       int                     num_nodes;
 };
 
 typedef struct failed_node_entry_s failed_node_entry;
@@ -217,7 +218,7 @@ typedef struct failed_node_entry_s failed_node_entry;
 struct SlonikStmt_failed_node_s
 {
        SlonikStmt      hdr;
-       failed_node_entry * nodes;
+       failed_node_entry *nodes;
 };
 
 
@@ -417,8 +418,8 @@ struct SlonikStmt_ddl_script_s
        SlonikStmt      hdr;
        char       *ddl_fname;
        int                     ev_origin;
-       char       *only_on_nodes;
-       int         only_on_node;
+       char       *only_on_nodes;
+       int                     only_on_node;
        FILE       *ddl_fd;
 };
 
@@ -437,7 +438,7 @@ struct SlonikStmt_wait_event_s
        int                     wait_confirmed;
        int                     wait_on;
        int                     wait_timeout;
-       int                     *ignore_nodes;
+       int                *ignore_nodes;
 };
 
 
@@ -592,7 +593,7 @@ extern int  slonik_switch_log(SlonikStmt_switch_log * stmt);
 extern int     slonik_sync(SlonikStmt_sync * stmt);
 extern int     slonik_sleep(SlonikStmt_sleep * stmt);
 
-extern int     slon_scanint64(char *str, int64 * result);
+extern int     slon_scanint64(char *str, int64 *result);
 
 
 /*
@@ -609,24 +610,24 @@ void              db_notice_recv(void *arg, const char *msg);
 int                    db_connect(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
 int                    db_disconnect(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
 
-int                    db_exec_command(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                               SlonDString * query);
-int                    db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                               SlonDString * query);
-int                    db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                               SlonDString * query, int nParams, const Oid *paramTypes, 
-                               const char *const *paramValues, const int *paramLengths, 
-                               const int *paramFormats, int resultFormat);
-PGresult   *db_exec_select(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+int db_exec_command(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
                                SlonDString * query);
+int db_exec_evcommand(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                                 SlonDString * query);
+int db_exec_evcommand_p(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                                       SlonDString * query, int nParams, const Oid *paramTypes,
+                                       const char *const * paramValues, const int *paramLengths,
+                                       const int *paramFormats, int resultFormat);
+PGresult *db_exec_select(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                          SlonDString * query);
 int                    db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
-int                    db_check_namespace(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                               char *clustername);
-int                    db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                               char *clustername);
+int db_check_namespace(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                                  char *clustername);
+int db_check_requirements(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                                         char *clustername);
 int                    db_get_nodeid(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
-int                    db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
-                                                 bool suppress_locking);
+int db_begin_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo,
+                         bool suppress_locking);
 int                    db_commit_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
 int                    db_rollback_xact(SlonikStmt * stmt, SlonikAdmInfo * adminfo);
 
@@ -652,7 +653,8 @@ extern int  yylex(void);
 /*
  * Common option types
  */
-typedef enum {
+typedef enum
+{
        O_ADD_ID,
        O_ADD_SEQUENCES,
        O_BACKUP_NODE,
@@ -696,21 +698,21 @@ typedef enum {
 /*
  * Common given option list
  */
-typedef struct option_list {
-       option_code     opt_code;
+typedef struct option_list
+{
+       option_code opt_code;
        int                     lineno;
        int32           ival;
        char       *str;
 
        struct option_list *next;
-} option_list;
+}      option_list;
 
 
 #ifdef WIN32
 #define strtoll _strtoui64
 #define snprintf _snprintf
 #endif
-
 #endif
 /*
  * Local Variables:
index 9971a959f54daf472b2e15e9669352a02ec961e4..8b7d463ab42439052d5a85a86776f9701a34ab3e 100644 (file)
@@ -95,7 +95,7 @@ typedef char bool;
 
 #ifndef false
 #define   false 0
-#define   true  1
+#define   true 1
 #endif
 
 #endif
index 68322525c75e93a140a7fffd36dd2753f6115993..8f53fc591d2c714af6e30ff80edd775712dceea6 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
index bca049f632148b08e5cb5afc7f2c022a787ebc58..93946a811b4018e34dca9f786c1decdefc0d3975 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
  * The daemonized logshipper keeps a sorted queue of archive
  * files that need processing.
  */
-typedef struct queue_elem_s {
-       char                               *archive_path;
-       struct queue_elem_s        *next;
-} queue_elem;
+typedef struct queue_elem_s
+{
+       char       *archive_path;
+       struct queue_elem_s *next;
+}      queue_elem;
 
 
 /*
  * Static data
  */
-static char                       *ipc_archive_dir = NULL;
-static key_t                   semkey;
-static key_t                   msgkey;
-static int                             semid;
-static int                             msgid;
-static int                             ipc_creator;
-static queue_elem         *archive_queue_head = NULL;
-static queue_elem         *archive_queue_tail = NULL;
+static char *ipc_archive_dir = NULL;
+static key_t semkey;
+static key_t msgkey;
+static int     semid;
+static int     msgid;
+static int     ipc_creator;
+static queue_elem *archive_queue_head = NULL;
+static queue_elem *archive_queue_tail = NULL;
 
 
 /*
  * Local functions
  */
 static int     ipc_generate_keys(char *archive_dir);
-static void    ipc_sighandler(int sig);
+static void ipc_sighandler(int sig);
 static int     ipc_add_path(char *path);
 static int     ipc_send_code(char *archive_dir, int code);
 
@@ -71,15 +72,14 @@ static int  ipc_send_code(char *archive_dir, int code);
 int
 ipc_init(char *archive_dir)
 {
-       struct sembuf   sops[2];
+       struct sembuf sops[2];
 
        if (ipc_generate_keys(archive_dir) < 0)
                return -1;
 
        /*
-        * We eventually have to start over again in case
-        * the existing daemon destroys the semaphore set
-        * after we attached and before we can lock it.
+        * We eventually have to start over again in case the existing daemon
+        * destroys the semaphore set after we attached and before we can lock it.
         */
        while (true)
        {
@@ -90,24 +90,22 @@ ipc_init(char *archive_dir)
                if (semid < 0)
                {
                        fprintf(stderr, "cannot create or attache to semaphore set\n"
-                                                       "semget(): %s\n", strerror(errno));
+                                       "semget(): %s\n", strerror(errno));
                        return -1;
                }
 
                /*
-                * We now do two initial operations with NOWAIT:
-                *              wait for #1 =0
-                *              inc sem  #1 +1
-                * We never again touch semaphore #1, so this either succeeds, meaning
-                * that we created the set and hold the current lock. Or it fails with
-                * EAGAIN, meaning we attached to an existing set. Or it fails with
-                * EIDRM, meaning the set was destroyed.
+                * We now do two initial operations with NOWAIT: wait for #1 =0 inc
+                * sem  #1 +1 We never again touch semaphore #1, so this either
+                * succeeds, meaning that we created the set and hold the current
+                * lock. Or it fails with EAGAIN, meaning we attached to an existing
+                * set. Or it fails with EIDRM, meaning the set was destroyed.
                 */
                sops[0].sem_num = 1;
-               sops[0].sem_op  = 0;
+               sops[0].sem_op = 0;
                sops[0].sem_flg = IPC_NOWAIT;
                sops[1].sem_num = 1;
-               sops[1].sem_op  = 1;
+               sops[1].sem_op = 1;
                sops[1].sem_flg = 0;
 
                if (semop(semid, sops, 2) < 0)
@@ -128,8 +126,8 @@ ipc_init(char *archive_dir)
                        if (ipc_lock() < 0)
                        {
                                /*
-                                * Since theres a gap between attaching and locking, the
-                                * set could have been destroyed. In that case, start over.
+                                * Since theres a gap between attaching and locking, the set
+                                * could have been destroyed. In that case, start over.
                                 */
                                if (errno == EIDRM)
                                        continue;
@@ -191,9 +189,9 @@ ipc_finish(bool force)
                if (!force)
                {
                        /*
-                        * We are the creator of the semaphore set, so if this isn't
-                        * a force operation, we lock it first, poll the message queue
-                        * and check that we have an empty queue.
+                        * We are the creator of the semaphore set, so if this isn't a
+                        * force operation, we lock it first, poll the message queue and
+                        * check that we have an empty queue.
                         */
                        if (ipc_lock() < 0)
                        {
@@ -204,7 +202,7 @@ ipc_finish(bool force)
 
                        if (ipc_poll(false) < 0)
                                return -1;
-                       
+
                        if (archive_queue_head != NULL)
                        {
                                if (ipc_unlock() < 0)
@@ -216,9 +214,10 @@ ipc_finish(bool force)
                                return 1;
                        }
                }
+
                /*
-                * At this point, we are either forced to stop or we have a lock
-                * and the queue is empty.
+                * At this point, we are either forced to stop or we have a lock and
+                * the queue is empty.
                 */
                if (msgctl(msgid, IPC_RMID, NULL) < 0)
                {
@@ -248,16 +247,17 @@ ipc_finish(bool force)
 int
 ipc_poll(bool blocking)
 {
-       int             rc;
-       struct {
+       int                     rc;
+       struct
+       {
                long            mtype;
                char            mtext[MSGMAX];
-       }       msg;
+       }                       msg;
 
-       while(true)
+       while (true)
        {
-               rc = msgrcv(msgid, &msg, sizeof(msg), 0, 
-                               (blocking) ? 0 : IPC_NOWAIT);
+               rc = msgrcv(msgid, &msg, sizeof(msg), 0,
+                                       (blocking) ? 0 : IPC_NOWAIT);
                if (rc < 0)
                {
                        if (errno == ENOMSG)
@@ -276,9 +276,8 @@ ipc_poll(bool blocking)
                        wait_for_resume = false;
                else if (msg.mtype == 5)
                        logfile_switch_requested = true;
-               else
-                       if (ipc_add_path(msg.mtext) < 0)
-                               return -1;
+               else if (ipc_add_path(msg.mtext) < 0)
+                       return -1;
 
                if (blocking)
                        break;
@@ -296,10 +295,10 @@ ipc_poll(bool blocking)
 static int
 ipc_add_path(char *path)
 {
-       queue_elem        **elemp;
-       queue_elem         *elem;
+       queue_elem **elemp;
+       queue_elem *elem;
 
-       if ((elem = (queue_elem *)malloc(sizeof(queue_elem))) == NULL)
+       if ((elem = (queue_elem *) malloc(sizeof(queue_elem))) == NULL)
        {
                fprintf(stderr, "out of memory in ipc_add_path()\n");
                return -1;
@@ -323,7 +322,7 @@ ipc_add_path(char *path)
                        return 0;
                }
        }
-       
+
 
        if (archive_queue_head == NULL)
        {
@@ -349,10 +348,11 @@ ipc_add_path(char *path)
 int
 ipc_send_path(char *logfname)
 {
-       struct {
+       struct
+       {
                long            mtype;
                char            mtext[MSGMAX];
-       }       msg;
+       }                       msg;
 
        if (strlen(logfname) > (MSGMAX - 1))
        {
@@ -361,8 +361,8 @@ ipc_send_path(char *logfname)
        }
 
        /*
-        * As the creator, we are also the consumer, so we simply add the
-        * file to the queue.
+        * As the creator, we are also the consumer, so we simply add the file to
+        * the queue.
         */
        if (ipc_creator)
                return ipc_add_path(logfname);
@@ -388,12 +388,13 @@ ipc_send_path(char *logfname)
 int
 ipc_recv_path(char *buf)
 {
-       queue_elem         *elem;
-       int                             rc;
-       struct {
+       queue_elem *elem;
+       int                     rc;
+       struct
+       {
                long            mtype;
                char            mtext[MSGMAX];
-       }       msg;
+       }                       msg;
 
        while (true)
        {
@@ -404,8 +405,8 @@ ipc_recv_path(char *buf)
                }
 
                /*
-                * If something requested an immediate shutdown, don't report any
-                * more logfiles back.
+                * If something requested an immediate shutdown, don't report any more
+                * logfiles back.
                 */
                if (shutdown_immed_requested)
                {
@@ -413,9 +414,9 @@ ipc_recv_path(char *buf)
                        return 0;
                }
 
-               /* 
-                * If a smart shutdown was requested, try to close the queue
-                * but don't force it.
+               /*
+                * If a smart shutdown was requested, try to close the queue but don't
+                * force it.
                 */
                if (shutdown_smart_requested)
                {
@@ -471,12 +472,11 @@ ipc_recv_path(char *buf)
                        wait_for_resume = false;
                else if (msg.mtype == 5)
                        logfile_switch_requested = true;
-               else
-                       if (ipc_add_path(msg.mtext) < 0)
-                       {
-                               ipc_finish(true);
-                               return -1;
-                       }
+               else if (ipc_add_path(msg.mtext) < 0)
+               {
+                       ipc_finish(true);
+                       return -1;
+               }
        }
 }
 
@@ -489,7 +489,7 @@ ipc_recv_path(char *buf)
 int
 ipc_send_term(char *archive_dir, bool immediate)
 {
-       int             rc;
+       int                     rc;
 
        rc = ipc_send_code(archive_dir, (immediate) ? 3 : 2);
        if (rc != 0)
@@ -531,10 +531,11 @@ ipc_send_resume(char *archive_dir)
 static int
 ipc_send_code(char *archive_dir, int code)
 {
-       struct {
-               long    mtype;
-               char    mtext[1];
-       } msg;
+       struct
+       {
+               long            mtype;
+               char            mtext[1];
+       }                       msg;
 
        if (ipc_generate_keys(archive_dir) < 0)
                return -1;
@@ -556,8 +557,8 @@ ipc_send_code(char *archive_dir, int code)
                ipc_unlock();
                return -1;
        }
-       
-       msg.mtype = (long)code;
+
+       msg.mtype = (long) code;
        if (msgsnd(msgid, &msg, 0, 0) < 0)
        {
                fprintf(stderr, "msgsnd() failed in ipc_send_code(): %s\n",
@@ -578,7 +579,7 @@ ipc_send_code(char *archive_dir, int code)
 int
 ipc_lock(void)
 {
-       struct sembuf   sops[1] = {{0, -1, 0}};
+       struct sembuf sops[1] = {{0, -1, 0}};
 
        if (semop(semid, sops, 1) < 0)
        {
@@ -598,7 +599,7 @@ ipc_lock(void)
 int
 ipc_unlock(void)
 {
-       struct sembuf   sops[1] = {{0, 1, 0}};
+       struct sembuf sops[1] = {{0, 1, 0}};
 
        if (semop(semid, sops, 1) < 0)
        {
@@ -618,7 +619,7 @@ ipc_unlock(void)
 int
 ipc_wait_for_destroy(void)
 {
-       struct sembuf   sops[1] = {{2, -1, 0}};
+       struct sembuf sops[1] = {{2, -1, 0}};
 
        if (semop(semid, sops, 1) < 0)
        {
@@ -655,14 +656,12 @@ ipc_cleanup(char *archive_dir)
                                        strerror(errno));
                        rc = -1;
                }
-               else
-                       if (!opt_quiet)
-                               fprintf(stderr, "semaphore set removed\n");
-                       rc = 1;
+               else if (!opt_quiet)
+                       fprintf(stderr, "semaphore set removed\n");
+               rc = 1;
        }
-       else
-               if (!opt_quiet)
-                       fprintf(stderr, "no semaphore set found\n");
+       else if (!opt_quiet)
+               fprintf(stderr, "no semaphore set found\n");
 
        if ((msgid = msgget(msgkey, 0)) >= 0)
        {
@@ -672,15 +671,13 @@ ipc_cleanup(char *archive_dir)
                                        strerror(errno));
                        rc = -1;
                }
-               else
-                       if (!opt_quiet)
-                               fprintf(stderr, "message queue removed\n");
+               else if (!opt_quiet)
+                       fprintf(stderr, "message queue removed\n");
                if (rc >= 0)
                        rc |= 2;
        }
-       else
-               if (!opt_quiet)
-                       fprintf(stderr, "no message queue found\n");
+       else if (!opt_quiet)
+               fprintf(stderr, "no message queue found\n");
 
        return rc;
 }
@@ -764,13 +761,12 @@ ipc_generate_keys(char *archive_dir)
 static void
 ipc_sighandler(int sig)
 {
-       struct {
-               long    mtype;
-               char    mtext[1];
-       } msg;
+       struct
+       {
+               long            mtype;
+               char            mtext[1];
+       }                       msg;
 
        msg.mtype = 3;
        msgsnd(msgid, &msg, 0, 0);
 }
-
-
index 8245f5c7f68d587c08cc0bbe7ce184963fc9a170..0b48ff19494c56de48131f7efff151dbb263d096 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
 #include "config.h"
 
 
-typedef struct archscan_entry_s {
-       char                                       *fname;
-       struct archscan_entry_s    *left;
-       struct archscan_entry_s    *right;
-} archscan_entry;
+typedef struct archscan_entry_s
+{
+       char       *fname;
+       struct archscan_entry_s *left;
+       struct archscan_entry_s *right;
+}      archscan_entry;
 
 /*
  * Global data
  */
-int         rescan_interval = 0;
+int                    rescan_interval = 0;
 int                    parse_errors = 0;
 int                    opt_quiet = 0;
 char      *destinationfname = NULL;
@@ -71,32 +72,32 @@ char           *destination_conninfo = NULL;
 char      *cluster_name = NULL;
 char      *namespace = NULL;
 
-RenameObject      *rename_list = NULL;
-ProcessingCommand  *pre_processing_commands = NULL;
-ProcessingCommand  *post_processing_commands = NULL;
-ProcessingCommand  *error_commands = NULL;
+RenameObject *rename_list = NULL;
+ProcessingCommand *pre_processing_commands = NULL;
+ProcessingCommand *post_processing_commands = NULL;
+ProcessingCommand *error_commands = NULL;
 
 /*
  * Local commandline options
  */
-static int                     opt_send_logswitch = 0;
-static int                     opt_send_resume = 0;
-static int                     opt_shutdown_smart = 0;
-static int                     opt_shutdown_immed = 0;
-static int                     opt_foreground = 0;
-static int                     opt_cleanup = 0;
-static int                     opt_nowait = 0;
+static int     opt_send_logswitch = 0;
+static int     opt_send_resume = 0;
+static int     opt_shutdown_smart = 0;
+static int     opt_shutdown_immed = 0;
+static int     opt_foreground = 0;
+static int     opt_cleanup = 0;
+static int     opt_nowait = 0;
 
 /*
  * Local data
  */
-static archscan_entry  *archscan_sort = NULL;
-static char                            current_at_counter[64];
-static bool                            process_in_transaction = false;
-static char                       *current_archive_path = NULL;
-static bool                            suppress_copy = false;
-static SlonDString             errlog_messages;
-static int                             archive_count = 0;
+static archscan_entry *archscan_sort = NULL;
+static char current_at_counter[64];
+static bool process_in_transaction = false;
+static char *current_archive_path = NULL;
+static bool suppress_copy = false;
+static SlonDString errlog_messages;
+static int     archive_count = 0;
 
 
 /*
@@ -106,13 +107,13 @@ static void usage(void);
 static int     process_archive(char *fname);
 static int     process_exec_sql(char *sql);
 static int     archscan(int optind, int argc, char **argv);
-static int     archscan_sort_in(archscan_entry **entpm, char *fname,
-                                       int optind, int argc, char **argv);
-static int     archscan_sort_out(archscan_entry *ent);
+static int archscan_sort_in(archscan_entry ** entpm, char *fname,
+                                int optind, int argc, char **argv);
+static int     archscan_sort_out(archscan_entry * ent);
 static int     get_current_at_counter(void);
 static int     idents_are_distinct(char *id1, char *id2);
 static int     process_command(char *command, char *inarchive, char *outarchive);
-static void    notice_processor(void *arg, const char *msg);
+static void notice_processor(void *arg, const char *msg);
 
 /* ----------
  * main
@@ -136,7 +137,7 @@ main(int argc, const char *argv[])
         * Parse commandline options
         *
         */
-       while ((opt = getopt(argc, (char **)argv, "hvqcflrtTws:")) != EOF)
+       while ((opt = getopt(argc, (char **) argv, "hvqcflrtTws:")) != EOF)
        {
                switch (opt)
                {
@@ -180,10 +181,10 @@ main(int argc, const char *argv[])
                        case 'w':
                                opt_nowait = 1;
                                break;
-            
-            case 's':
-                rescan_interval = atoi(optarg);
-                break;
+
+                       case 's':
+                               rescan_interval = atoi(optarg);
+                               break;
 
                        default:
                                fprintf(stderr, "unknown option '%c'\n", opt);
@@ -205,7 +206,7 @@ main(int argc, const char *argv[])
                return 2;
        }
        scan_new_input_file(fp);
-       current_file = (char *)argv[optind++];
+       current_file = (char *) argv[optind++];
        scan_push_string("start_config;");
        parse_errors += yyparse();
        if (parse_errors != 0)
@@ -234,13 +235,13 @@ main(int argc, const char *argv[])
        if (destination_conninfo != NULL && cluster_name == NULL)
        {
                fprintf(stderr, "no cluster name specified in config file "
-                                       "(required for database mode)\n");
+                               "(required for database mode)\n");
                return -1;
        }
 
        /*
-        * Configuration and usage are OK. From now on all messages
-        * go into the logfile, if one is configured.
+        * Configuration and usage are OK. From now on all messages go into the
+        * logfile, if one is configured.
         */
        if (logfile_path != NULL)
        {
@@ -259,22 +260,21 @@ main(int argc, const char *argv[])
                return -1;
 
        /*
-        * If we are the message queue creator and if we are running in
-        * database connetion mode, add archives not yet processed to the
-        * queue.
+        * If we are the message queue creator and if we are running in database
+        * connetion mode, add archives not yet processed to the queue.
         */
        if (init_rc == 1)
        {
-               if (archscan(optind, argc, (char **)argv) < 0)
+               if (archscan(optind, argc, (char **) argv) < 0)
                        return -0;
        }
-       
+
        /*
         * Put all filenames given to us onto the queue
         */
        while (optind < argc)
        {
-               if (ipc_send_path((char *)(argv[optind])) < 0)
+               if (ipc_send_path((char *) (argv[optind])) < 0)
                {
                        ipc_finish(true);
                        return -1;
@@ -287,7 +287,7 @@ main(int argc, const char *argv[])
 
        if (ipc_unlock() < 0)
                return -1;
-       
+
        /*
         * If we're not the message queue creator, we're done here.
         */
@@ -301,25 +301,25 @@ main(int argc, const char *argv[])
        {
                switch (pid = fork())
                {
-                       case -1:        fprintf(stderr, "fork() failed: %s\n",
-                                                               strerror(errno));
-                                               ipc_finish(true);
-                                               return -1;
-
-                       case 0:         /*
-                                                * This is the child
-                                                */
-                                               signal(SIGHUP, SIG_IGN);
-                                               close(0);
-                                               close(2);
-                                               dup2(1, 2);
-                                               setsid();
-                                               break;
+                       case -1:
+                               fprintf(stderr, "fork() failed: %s\n",
+                                               strerror(errno));
+                               ipc_finish(true);
+                               return -1;
+
+                       case 0:                         /* This is the child */
+                               signal(SIGHUP, SIG_IGN);
+                               close(0);
+                               close(2);
+                               dup2(1, 2);
+                               setsid();
+                               break;
 
-                       default:        if (!opt_quiet)
-                                                       printf("logshipper daemon created - pid = %d\n",
-                                                                       pid);
-                                               return 0;
+                       default:
+                               if (!opt_quiet)
+                                       printf("logshipper daemon created - pid = %d\n",
+                                                  pid);
+                               return 0;
                }
        }
 
@@ -342,19 +342,19 @@ main(int argc, const char *argv[])
                if (dbconn != NULL)
                {
                        if (PQstatus(dbconn) != CONNECTION_OK)
-                       while (PQstatus(dbconn) != CONNECTION_OK)
-                       {
-                               errlog(LOG_WARN, "bad database connection, try to recover\n");
-                               PQreset(dbconn);
-                               process_in_transaction = false;
-                               if (PQstatus(dbconn) == CONNECTION_OK)
-                                       break;
+                               while (PQstatus(dbconn) != CONNECTION_OK)
+                               {
+                                       errlog(LOG_WARN, "bad database connection, try to recover\n");
+                                       PQreset(dbconn);
+                                       process_in_transaction = false;
+                                       if (PQstatus(dbconn) == CONNECTION_OK)
+                                               break;
 
-                               ipc_poll(true);
+                                       ipc_poll(true);
 
-                               if (shutdown_immed_requested)
-                                       break;
-                       }
+                                       if (shutdown_immed_requested)
+                                               break;
+                               }
                }
 
                if (wait_for_resume)
@@ -374,42 +374,42 @@ main(int argc, const char *argv[])
                if (rc == -2)
                {
                        archscan_sort = NULL;
-            errlog(LOG_INFO, "Queue is empty.  Going to rescan in %d seconds\n", rescan_interval);
-            sleep(rescan_interval);
-                       if (archscan(optind, argc, (char **)argv) < 0)
+                       errlog(LOG_INFO, "Queue is empty.  Going to rescan in %d seconds\n", rescan_interval);
+                       sleep(rescan_interval);
+                       if (archscan(optind, argc, (char **) argv) < 0)
                        {
                                return -1;
                        }
-            errlog(LOG_INFO, "Archive dir scanned\n");
+                       errlog(LOG_INFO, "Archive dir scanned\n");
                        continue;
-               }
-               
+               }
+
                if (rc < 0)
                {
-                       errlog(LOG_ERROR,"ipc_recv_path returned an error:%d\n",rc);
+                       errlog(LOG_ERROR, "ipc_recv_path returned an error:%d\n", rc);
                        return -1;
                }
 
                current_archive_path = archive_path;
                if (process_archive(archive_path) != 0)
                {
-                       ProcessingCommand          *errcmd;
-                       SlonDString                             cmd;
+                       ProcessingCommand *errcmd;
+                       SlonDString cmd;
 
                        dstring_terminate(&errlog_messages);
                        dstring_init(&cmd);
                        for (errcmd = error_commands; errcmd != NULL; errcmd = errcmd->next)
                        {
-                               slon_mkquery(&cmd, 
-                                       "inarchive='%q'; outarchive=''; errortext='%q'; %s",
-                                       archive_path, dstring_data(&errlog_messages),
-                                       errcmd->command);
+                               slon_mkquery(&cmd,
+                                                "inarchive='%q'; outarchive=''; errortext='%q'; %s",
+                                                        archive_path, dstring_data(&errlog_messages),
+                                                        errcmd->command);
 
                                system(dstring_data(&cmd));
                        }
                        dstring_free(&cmd);
 
-                       
+
                        /*
                         * If it left a transaction in progress, roll it back.
                         */
@@ -440,9 +440,9 @@ main(int argc, const char *argv[])
                                if (PQstatus(dbconn) == CONNECTION_OK)
                                {
                                        /*
-                                        * this must have failed due to a parse error or
-                                        * something went wrong with one of the queries.
-                                        * Wait for resume command.
+                                        * this must have failed due to a parse error or something
+                                        * went wrong with one of the queries. Wait for resume
+                                        * command.
                                         */
                                        wait_for_resume = true;
                                }
@@ -450,9 +450,8 @@ main(int argc, const char *argv[])
                        else
                        {
                                /*
-                                * If we don't even have a DB connection, this
-                                * can only be a parse error or something similar.
-                                * Wait for resume command.
+                                * If we don't even have a DB connection, this can only be a
+                                * parse error or something similar. Wait for resume command.
                                 */
                                wait_for_resume = true;
                        }
@@ -460,8 +459,8 @@ main(int argc, const char *argv[])
                else
                {
                        /*
-                        * Every time we process one archive successfully, we
-                        * reset the errlog message collection.
+                        * Every time we process one archive successfully, we reset the
+                        * errlog message collection.
                         */
                        dstring_reset(&errlog_messages);
                }
@@ -475,10 +474,10 @@ main(int argc, const char *argv[])
 static int
 process_archive(char *fname)
 {
-       SlonDString     destfname;
-       char                       *cp;
-       FILE                       *fp;
-       ProcessingCommand  *cmd;
+       SlonDString destfname;
+       char       *cp;
+       FILE       *fp;
+       ProcessingCommand *cmd;
 
        errlog(LOG_INFO, "Processing archive file %s\n", fname);
 
@@ -528,8 +527,8 @@ process_archive(char *fname)
                destinationfp = fopen(destinationfname, "w");
                if (destinationfp == NULL)
                {
-                       errlog(LOG_ERROR, "cannot open %s - %s\n", 
-                                       dstring_data(&destfname), strerror(errno));
+                       errlog(LOG_ERROR, "cannot open %s - %s\n",
+                                  dstring_data(&destfname), strerror(errno));
                        fclose(fp);
                        dstring_free(&destfname);
                        return 1;
@@ -582,16 +581,16 @@ process_exec_sql(char *sql)
         */
        if (dbconn != NULL)
        {
-               PGresult           *res;
+               PGresult   *res;
 
                res = PQexec(dbconn, sql);
-               if (PQresultStatus(res) != PGRES_COMMAND_OK     &&
-                       PQresultStatus(res) != PGRES_TUPLES_OK  &&
+               if (PQresultStatus(res) != PGRES_COMMAND_OK &&
+                       PQresultStatus(res) != PGRES_TUPLES_OK &&
                        PQresultStatus(res) != PGRES_EMPTY_QUERY)
                {
                        errlog(LOG_ERROR, "%s: %sQuery was: %s\n",
-                                       PQresStatus(PQresultStatus(res)),
-                                       PQresultErrorMessage(res), sql);
+                                  PQresStatus(PQresultStatus(res)),
+                                  PQresultErrorMessage(res), sql);
                        PQclear(res);
 
                        return -1;
@@ -621,8 +620,8 @@ process_exec_sql(char *sql)
 int
 process_check_at_counter(char *at_counter)
 {
-       char    buf1[64];
-       char    buf2[64];
+       char            buf1[64];
+       char            buf2[64];
        size_t          i;
 
        if (destination_conninfo == NULL)
@@ -631,7 +630,7 @@ process_check_at_counter(char *at_counter)
        if (strlen(at_counter) > 20)
        {
                errlog(LOG_ERROR, "at_counter %s too long in process_check_at_counter\n",
-                               at_counter);
+                          at_counter);
                return -1;
        }
 
@@ -648,7 +647,7 @@ process_check_at_counter(char *at_counter)
        if (strcmp(buf2, buf1) <= 0)
        {
                errlog(LOG_WARN, "skip archive with counter %s - already applied\n",
-                               at_counter);
+                          at_counter);
                if (process_in_transaction)
                        process_end_transaction("rollback;");
                return 1;
@@ -668,15 +667,15 @@ process_simple_sql(char *sql)
 int
 process_insert(InsertStmt *stmt)
 {
-       SlonDString             ds;
-       char               *glue;
-       AttElem            *elem;
-       int                             rc;
-       char               *namespace;
-       char               *tablename;
-
-       if (lookup_rename(stmt->namespace, stmt->tablename, 
-                                       &namespace, &tablename) == 0)
+       SlonDString ds;
+       char       *glue;
+       AttElem    *elem;
+       int                     rc;
+       char       *namespace;
+       char       *tablename;
+
+       if (lookup_rename(stmt->namespace, stmt->tablename,
+                                         &namespace, &tablename) == 0)
                return 0;
 
        dstring_init(&ds);
@@ -711,15 +710,15 @@ process_insert(InsertStmt *stmt)
 int
 process_update(UpdateStmt *stmt)
 {
-       SlonDString             ds;
-       char               *glue;
-       AttElem            *elem;
-       int                             rc;
-       char               *namespace;
-       char               *tablename;
-
-       if (lookup_rename(stmt->namespace, stmt->tablename, 
-                                       &namespace, &tablename) == 0)
+       SlonDString ds;
+       char       *glue;
+       AttElem    *elem;
+       int                     rc;
+       char       *namespace;
+       char       *tablename;
+
+       if (lookup_rename(stmt->namespace, stmt->tablename,
+                                         &namespace, &tablename) == 0)
                return 0;
 
        dstring_init(&ds);
@@ -728,22 +727,22 @@ process_update(UpdateStmt *stmt)
        for (elem = stmt->changes->list_head; elem != NULL; elem = elem->next)
        {
                if (elem->attvalue == NULL)
-                       slon_appendquery(&ds, "%s %s=NULL", glue, 
-                                       elem->attname);
+                       slon_appendquery(&ds, "%s %s=NULL", glue,
+                                                        elem->attname);
                else
-                       slon_appendquery(&ds, "%s %s='%s'", glue, 
-                                       elem->attname, elem->attvalue);
+                       slon_appendquery(&ds, "%s %s='%s'", glue,
+                                                        elem->attname, elem->attvalue);
                glue = ",";
        }
        glue = " where";
        for (elem = stmt->qualification->list_head; elem != NULL; elem = elem->next)
        {
                if (elem->attvalue == NULL)
-                       slon_appendquery(&ds, "%s %s IS NULL", glue, 
-                                       elem->attname);
+                       slon_appendquery(&ds, "%s %s IS NULL", glue,
+                                                        elem->attname);
                else
-                       slon_appendquery(&ds, "%s %s='%s'", glue, 
-                                       elem->attname, elem->attvalue);
+                       slon_appendquery(&ds, "%s %s='%s'", glue,
+                                                        elem->attname, elem->attvalue);
                glue = " and";
        }
        dstring_addchar(&ds, ';');
@@ -759,31 +758,31 @@ process_update(UpdateStmt *stmt)
 int
 process_delete(DeleteStmt *stmt)
 {
-       SlonDString             ds;
-       char               *glue;
-       AttElem            *elem;
-       int                             rc;
-       char               *namespace;
-       char               *tablename;
-
-       if (lookup_rename(stmt->namespace, stmt->tablename, 
-                                       &namespace, &tablename) == 0)
+       SlonDString ds;
+       char       *glue;
+       AttElem    *elem;
+       int                     rc;
+       char       *namespace;
+       char       *tablename;
+
+       if (lookup_rename(stmt->namespace, stmt->tablename,
+                                         &namespace, &tablename) == 0)
                return 0;
 
        dstring_init(&ds);
-       slon_mkquery(&ds, "delete from %s%s.%s", 
-                       (stmt->only) ? "only " : "", namespace, tablename);
+       slon_mkquery(&ds, "delete from %s%s.%s",
+                                (stmt->only) ? "only " : "", namespace, tablename);
        if (stmt->qualification != NULL)
        {
                glue = " where";
                for (elem = stmt->qualification->list_head; elem != NULL; elem = elem->next)
                {
                        if (elem->attvalue == NULL)
-                               slon_appendquery(&ds, "%s %s IS NULL", glue, 
-                                               elem->attname);
+                               slon_appendquery(&ds, "%s %s IS NULL", glue,
+                                                                elem->attname);
                        else
-                               slon_appendquery(&ds, "%s %s='%s'", glue, 
-                                               elem->attname, elem->attvalue);
+                               slon_appendquery(&ds, "%s %s='%s'", glue,
+                                                                elem->attname, elem->attvalue);
                        glue = " and";
                }
        }
@@ -800,18 +799,18 @@ process_delete(DeleteStmt *stmt)
 int
 process_truncate(TruncateStmt *stmt)
 {
-       SlonDString             ds;
-       int                             rc;
-       char               *namespace;
-       char               *tablename;
+       SlonDString ds;
+       int                     rc;
+       char       *namespace;
+       char       *tablename;
 
-       if (lookup_rename(stmt->namespace, stmt->tablename, 
-                                       &namespace, &tablename) == 0)
+       if (lookup_rename(stmt->namespace, stmt->tablename,
+                                         &namespace, &tablename) == 0)
                return 0;
 
        dstring_init(&ds);
-       slon_mkquery(&ds, "truncate only %s.%s cascade;", 
-                                 namespace, tablename);
+       slon_mkquery(&ds, "truncate only %s.%s cascade;",
+                                namespace, tablename);
        dstring_terminate(&ds);
 
        rc = process_exec_sql(dstring_data(&ds));
@@ -823,15 +822,15 @@ process_truncate(TruncateStmt *stmt)
 int
 process_copy(CopyStmt *stmt)
 {
-       SlonDString             ds;
-       char               *glue;
-       AttElem            *elem;
-       PGresult           *res;
-       char               *namespace;
-       char               *tablename;
-
-       if (lookup_rename(stmt->namespace, stmt->tablename, 
-                                       &namespace, &tablename) == 0)
+       SlonDString ds;
+       char       *glue;
+       AttElem    *elem;
+       PGresult   *res;
+       char       *namespace;
+       char       *tablename;
+
+       if (lookup_rename(stmt->namespace, stmt->tablename,
+                                         &namespace, &tablename) == 0)
        {
                suppress_copy = true;
                scan_copy_start();
@@ -855,8 +854,8 @@ process_copy(CopyStmt *stmt)
                if (PQresultStatus(res) != PGRES_COPY_IN)
                {
                        errlog(LOG_ERROR, "%s: %sQuery was: %s\n",
-                                       PQresStatus(PQresultStatus(res)),
-                                       PQresultErrorMessage(res), dstring_data(&ds));
+                                  PQresStatus(PQresultStatus(res)),
+                                  PQresultErrorMessage(res), dstring_data(&ds));
                        PQclear(res);
                        dstring_free(&ds);
                        return -1;
@@ -889,7 +888,7 @@ process_copy(CopyStmt *stmt)
 int
 process_copydata(char *line)
 {
-       PGresult           *res;
+       PGresult   *res;
 
        if (suppress_copy)
                return 0;
@@ -938,7 +937,7 @@ process_copyend(void)
        if (dbconn != NULL)
        {
 #ifdef HAVE_PQPUTCOPYDATA
-               PGresult           *res;
+               PGresult   *res;
 
                if (PQputCopyEnd(dbconn, NULL) != 1)
                {
@@ -949,8 +948,8 @@ process_copyend(void)
                if (PQresultStatus(res) != PGRES_COMMAND_OK)
                {
                        errlog(LOG_ERROR, "%s: %s",
-                                       PQresStatus(PQresultStatus(res)),
-                                       PQresultErrorMessage(res));
+                                  PQresStatus(PQresultStatus(res)),
+                                  PQresultErrorMessage(res));
                        PQclear(res);
                        return -1;
                }
@@ -1016,7 +1015,7 @@ process_command(char *command, char *inarchive, char *outarchive)
 {
        int                     status;
        int                     errorignore = 0;
-       SlonDString     cmd;
+       SlonDString cmd;
 
        if (*command == '@')
        {
@@ -1026,7 +1025,7 @@ process_command(char *command, char *inarchive, char *outarchive)
 
        dstring_init(&cmd);
        slon_mkquery(&cmd, "inarchive='%q'; outarchive='%q'; %s",
-                       inarchive, (outarchive == NULL) ? "" : outarchive, command);
+                                inarchive, (outarchive == NULL) ? "" : outarchive, command);
        status = system(dstring_data(&cmd));
        if (status != 0)
        {
@@ -1052,16 +1051,16 @@ notice_processor(void *arg, const char *msg)
 
 
 void
-errlog(log_level level, char *fmt, ...)
+errlog(log_level level, char *fmt,...)
 {
-       static char     errbuf[256 * 1024];
+       static char errbuf[256 * 1024];
        char       *pos;
        va_list         ap;
        time_t          tnow;
        struct tm       now;
        char       *clevel[] = {
-                                       "DEBUG", "INFO", "WARN", "ERROR"
-                               };
+               "DEBUG", "INFO", "WARN", "ERROR"
+       };
 
        if (logfile_switch_requested && logfile_path != NULL)
        {
@@ -1078,8 +1077,8 @@ errlog(log_level level, char *fmt, ...)
        localtime_r(&tnow, &now);
 
        snprintf(errbuf, sizeof(errbuf), "%-5.5s %04d-%02d-%02d %02d:%02d:%02d > ",
-                       clevel[level], now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
-                       now.tm_hour, now.tm_min, now.tm_sec);
+                        clevel[level], now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
+                        now.tm_hour, now.tm_min, now.tm_sec);
        pos = errbuf + strlen(errbuf);
        va_start(ap, fmt);
        vsnprintf(pos, sizeof(errbuf) - (pos - errbuf), fmt, ap);
@@ -1097,8 +1096,10 @@ errlog(log_level level, char *fmt, ...)
 static int
 idents_are_distinct(char *id1, char *id2)
 {
-       if (id1 == NULL && id2 == NULL) return 0;
-       if (id1 == NULL || id2 == NULL) return 1;
+       if (id1 == NULL && id2 == NULL)
+               return 0;
+       if (id1 == NULL || id2 == NULL)
+               return 1;
 
        if (*id1 == '"')
        {
@@ -1113,9 +1114,9 @@ idents_are_distinct(char *id1, char *id2)
 
 
 void
-config_add_rename(RenameObject *entry)
+config_add_rename(RenameObject * entry)
 {
-       RenameObject    **ep;
+       RenameObject **ep;
 
        for (ep = &rename_list; *ep != NULL; ep = &((*ep)->next))
        {
@@ -1134,10 +1135,10 @@ config_add_rename(RenameObject *entry)
 
 
 int
-lookup_rename(char *namespace, char *name, 
-                       char **use_namespace, char **use_name)
+lookup_rename(char *namespace, char *name,
+                         char **use_namespace, char **use_name)
 {
-       RenameObject       *entry;
+       RenameObject *entry;
 
        /*
         * first we look for a table specific entry
@@ -1152,10 +1153,10 @@ lookup_rename(char *namespace, char *name,
                        continue;
 
                /*
-                * This is a match. 
+                * This is a match.
                 */
                *use_namespace = entry->new_namespace;
-               *use_name      = entry->new_name;
+               *use_name = entry->new_name;
                if (*use_namespace == NULL)
                        return 0;
                else
@@ -1174,10 +1175,10 @@ lookup_rename(char *namespace, char *name,
                        continue;
 
                /*
-                * This is a match. 
+                * This is a match.
                 */
                *use_namespace = entry->new_namespace;
-               *use_name      = name;
+               *use_name = name;
                if (*use_namespace == NULL)
                        return 0;
                else
@@ -1188,7 +1189,7 @@ lookup_rename(char *namespace, char *name,
         * No match found - just keep the item as it is
         */
        *use_namespace = namespace;
-       *use_name      = name;
+       *use_name = name;
        return 1;
 }
 
@@ -1201,22 +1202,22 @@ static void
 usage(void)
 {
        fprintf(stderr,
-               "usage: slony_logshipper [options] config_file [archive_file]\n"
-               "\n"
-               "    options:\n"
-               "      -h    display this help text and exit\n"
-               "      -v    display program version and exit\n"
-               "      -q    quiet mode\n"
-               "      -l    cause running daemon to reopen its logfile\n"
-               "      -r    cause running daemon to resume after error\n"
-               "      -t    cause running daemon to enter smart shutdown mode\n"
+                       "usage: slony_logshipper [options] config_file [archive_file]\n"
+                       "\n"
+                       "    options:\n"
+                       "      -h    display this help text and exit\n"
+                       "      -v    display program version and exit\n"
+                       "      -q    quiet mode\n"
+                       "      -l    cause running daemon to reopen its logfile\n"
+                       "      -r    cause running daemon to resume after error\n"
+                       "      -t    cause running daemon to enter smart shutdown mode\n"
                "      -T    cause running daemon to enter immediate shutdown mode\n"
-               "      -c    destroy existing semaphore set and message queue\n"
-               "            (use with caution)\n"
-               "      -f    stay in foreground (don't daemonize)\n"
-               "      -w    enter smart shutdown mode immediately\n"
-               "      -s    indicate (integer value) rescan interval\n"
-               "\n");
+                       "      -c    destroy existing semaphore set and message queue\n"
+                       "            (use with caution)\n"
+                       "      -f    stay in foreground (don't daemonize)\n"
+                       "      -w    enter smart shutdown mode immediately\n"
+                       "      -s    indicate (integer value) rescan interval\n"
+                       "\n");
        exit(1);
 }
 
@@ -1224,10 +1225,10 @@ usage(void)
 static int
 get_current_at_counter(void)
 {
-       SlonDString             ds;
-       SlonDString     query;
-       PGresult           *res;
-       char               *s;
+       SlonDString ds;
+       SlonDString query;
+       PGresult   *res;
+       char       *s;
 
        if (namespace == NULL)
        {
@@ -1254,32 +1255,34 @@ get_current_at_counter(void)
        }
 
        dstring_init(&query);
-       slon_mkquery(&query,"select 1 from pg_catalog.pg_settings where name= 'application_name'; ");
-       res = PQexec (dbconn, dstring_data(&query));
+       slon_mkquery(&query, "select 1 from pg_catalog.pg_settings where name= 'application_name'; ");
+       res = PQexec(dbconn, dstring_data(&query));
        dstring_free(&query);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
-                       return -1;
+               return -1;
 
        if (PQntuples(res) == 0)
        {
-                       PQclear(res);
-       } else {
-                       PQclear(res);
-                       dstring_init(&query);
-                       slon_mkquery(&query,"SET application_name TO 'slony_logshipper'; ");
-                       res=PQexec(dbconn, dstring_data(&query));
-                       dstring_free(&query); 
-                       PQclear(res);
+               PQclear(res);
+       }
+       else
+       {
+               PQclear(res);
+               dstring_init(&query);
+               slon_mkquery(&query, "SET application_name TO 'slony_logshipper'; ");
+               res = PQexec(dbconn, dstring_data(&query));
+               dstring_free(&query);
+               PQclear(res);
        }
 
        dstring_init(&ds);
        slon_mkquery(&ds, "select at_counter from %s.sl_archive_tracking;",
-                       namespace);
+                                namespace);
        res = PQexec(dbconn, dstring_data(&ds));
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
                errlog(LOG_ERROR, "cannot retrieve archive tracking status: %s\n",
-                               PQresultErrorMessage(res));
+                          PQresultErrorMessage(res));
                PQclear(res);
                PQfinish(dbconn);
                ipc_finish(true);
@@ -1290,9 +1293,9 @@ get_current_at_counter(void)
        s = PQgetvalue(res, 0, 0);
        if (strlen(s) > 20)
        {
-               errlog(LOG_ERROR, 
-                       "value of sl_archive_tracking.at_counter is suspicious: '%s'\n",
-                       s);
+               errlog(LOG_ERROR,
+                        "value of sl_archive_tracking.at_counter is suspicious: '%s'\n",
+                          s);
                PQclear(res);
                PQfinish(dbconn);
                ipc_finish(true);
@@ -1311,9 +1314,9 @@ get_current_at_counter(void)
 static int
 archscan(int optind, int argc, char **argv)
 {
-       DIR                        *dirp;
-       struct dirent  *dp;
-       char                    counter_done_buf[64];
+       DIR                *dirp;
+       struct dirent *dp;
+       char            counter_done_buf[64];
 
        if (destination_conninfo != NULL)
        {
@@ -1321,7 +1324,7 @@ archscan(int optind, int argc, char **argv)
                        return -1;
 
                counter_done_buf[0] = '\0';
-               while(strlen(counter_done_buf) + strlen(current_at_counter) < 20)
+               while (strlen(counter_done_buf) + strlen(current_at_counter) < 20)
                        strcat(counter_done_buf, "0");
                strcat(counter_done_buf, current_at_counter);
                strcat(counter_done_buf, ".sql");
@@ -1332,13 +1335,13 @@ archscan(int optind, int argc, char **argv)
        }
 
        /*
-        * Scan the archive directory for files that have not been
-        * processed yet according to the archive tracking.
+        * Scan the archive directory for files that have not been processed yet
+        * according to the archive tracking.
         */
        if ((dirp = opendir(archive_dir)) == NULL)
        {
-               errlog(LOG_ERROR, "cannot open directory %s: %s\n", archive_dir, 
-                                       strerror(errno));
+               errlog(LOG_ERROR, "cannot open directory %s: %s\n", archive_dir,
+                          strerror(errno));
                PQfinish(dbconn);
                ipc_finish(true);
                return -1;
@@ -1347,7 +1350,7 @@ archscan(int optind, int argc, char **argv)
        {
                if (strlen(dp->d_name) > 24 &&
                        strcmp(dp->d_name + strlen(dp->d_name) - 24,
-                                       counter_done_buf) <= 0)
+                                  counter_done_buf) <= 0)
                {
                        continue;
                }
@@ -1357,7 +1360,7 @@ archscan(int optind, int argc, char **argv)
                        strcmp(dp->d_name + strlen(dp->d_name) - 4, ".sql") == 0)
                {
                        if (archscan_sort_in(&archscan_sort, dp->d_name, optind,
-                                       argc, argv) < 0)
+                                                                argc, argv) < 0)
                        {
                                PQfinish(dbconn);
                                ipc_finish(true);
@@ -1379,15 +1382,15 @@ archscan(int optind, int argc, char **argv)
 
 
 static int
-archscan_sort_in(archscan_entry **entp, char *fname, int optind,
-               int argc, char **argv)
+archscan_sort_in(archscan_entry ** entp, char *fname, int optind,
+                                int argc, char **argv)
 {
-       archscan_entry  *ent;
-       char                    *cp1;
+       archscan_entry *ent;
+       char       *cp1;
 
        /*
-        * Ignore files that compare higher or equal to any of our
-        * command line arguments.
+        * Ignore files that compare higher or equal to any of our command line
+        * arguments.
         */
        while (optind < argc)
        {
@@ -1404,7 +1407,7 @@ archscan_sort_in(archscan_entry **entp, char *fname, int optind,
 
        if (*entp == NULL)
        {
-               ent = (archscan_entry *)malloc(sizeof(archscan_entry));
+               ent = (archscan_entry *) malloc(sizeof(archscan_entry));
                if (ent == NULL)
                {
                        errlog(LOG_ERROR, "out of memory in archscan_sort_in()\n");
@@ -1429,9 +1432,9 @@ archscan_sort_in(archscan_entry **entp, char *fname, int optind,
 
 
 static int
-archscan_sort_out(archscan_entry *ent)
+archscan_sort_out(archscan_entry * ent)
 {
-       char   *buf;
+       char       *buf;
 
        if (ent == NULL)
                return 0;
@@ -1439,7 +1442,7 @@ archscan_sort_out(archscan_entry *ent)
        if (archscan_sort_out(ent->left) < 0)
                return -1;
 
-       buf = (char *)malloc(strlen(archive_dir) + strlen(ent->fname) + 2);
+       buf = (char *) malloc(strlen(archive_dir) + strlen(ent->fname) + 2);
        if (buf == NULL)
        {
                errlog(LOG_ERROR, "out of memory in archscan_sort_out()\n");
index dbdd9cf19b980d99ce264cef776558bfc581826e..20111d19e5187362bb25f09438d75c5f7863b73a 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2009, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     
+ *
  *-------------------------------------------------------------------------
  */
 
@@ -91,69 +91,79 @@ do { \
 /*
  * Parser data structures
  */
-typedef struct AttElem_s {
-       char                       *attname;
-       char                       *attvalue;
-       struct AttElem_s  *next;
-} AttElem;
-
-typedef struct AttElemList_s {
-       AttElem                    *list_head;
-       AttElem                    *list_tail;
-} AttElemList;
-
-typedef struct InsertStmt_s {
-       char                       *namespace;
-       char                       *tablename;
-       AttElemList                *attributes;
+typedef struct AttElem_s
+{
+       char       *attname;
+       char       *attvalue;
+       struct AttElem_s *next;
+}      AttElem;
+
+typedef struct AttElemList_s
+{
+       AttElem    *list_head;
+       AttElem    *list_tail;
+}      AttElemList;
+
+typedef struct InsertStmt_s
+{
+       char       *namespace;
+       char       *tablename;
+       AttElemList *attributes;
 } InsertStmt;
 
-typedef struct UpdateStmt_s {
-       char                       *namespace;
-       char                       *tablename;
-       AttElemList                *changes;
-       AttElemList                *qualification;
+typedef struct UpdateStmt_s
+{
+       char       *namespace;
+       char       *tablename;
+       AttElemList *changes;
+       AttElemList *qualification;
 } UpdateStmt;
 
-typedef struct DeleteStmt_s {
-       char                       *namespace;
-       char                       *tablename;
-       int                                     only;
-       AttElemList                *qualification;
+typedef struct DeleteStmt_s
+{
+       char       *namespace;
+       char       *tablename;
+       int                     only;
+       AttElemList *qualification;
 } DeleteStmt;
 
-typedef struct TruncateStmt_s {
-  char                                 *namespace;
-  char                                 *tablename;
+typedef struct TruncateStmt_s
+{
+       char       *namespace;
+       char       *tablename;
 } TruncateStmt;
 
-typedef struct CopyStmt_s {
-       char                       *namespace;
-       char                       *tablename;
-       AttElemList                *attributes;
-       char                       *from;
+typedef struct CopyStmt_s
+{
+       char       *namespace;
+       char       *tablename;
+       AttElemList *attributes;
+       char       *from;
 } CopyStmt;
 
-typedef struct RenameObject_s {
-       char                       *old_namespace;
-       char                       *old_name;
-       char                       *new_namespace;
-       char                       *new_name;
+typedef struct RenameObject_s
+{
+       char       *old_namespace;
+       char       *old_name;
+       char       *new_namespace;
+       char       *new_name;
        struct RenameObject_s *next;
-} RenameObject;
+}      RenameObject;
 
-typedef struct ProcessingCommand_s {
-       char                       *command;
+typedef struct ProcessingCommand_s
+{
+       char       *command;
        struct ProcessingCommand_s *next;
-} ProcessingCommand;
+}      ProcessingCommand;
 
 
-typedef enum {
+typedef enum
+{
        LOG_DEBUG = 0,
        LOG_INFO,
        LOG_WARN,
        LOG_ERROR
-} log_level;
+}      log_level;
 
 
 #ifndef MSGMAX
@@ -164,46 +174,46 @@ typedef enum {
 /*
  * Globals in slony_logshipper.c
  */
-extern int                     parse_errors;
-extern char               *current_file;
-extern int                     opt_quiet;
-extern PGconn     *dbconn;
-extern bool                    logfile_switch_requested;
-extern bool                    wait_for_resume;
-extern bool                    shutdown_smart_requested;
-extern bool                    shutdown_immed_requested;
-
-extern char               *archive_dir;
-extern char               *destination_dir;
-extern char               *destination_conninfo;
-extern char               *logfile_path;
-extern int                     max_archives;
-extern char               *cluster_name;
-extern char               *namespace;
-
-extern RenameObject                       *rename_list;
-extern ProcessingCommand          *pre_processing_commands;
-extern ProcessingCommand          *post_processing_commands;
-extern ProcessingCommand          *error_commands;
+extern int     parse_errors;
+extern char *current_file;
+extern int     opt_quiet;
+extern PGconn *dbconn;
+extern bool logfile_switch_requested;
+extern bool wait_for_resume;
+extern bool shutdown_smart_requested;
+extern bool shutdown_immed_requested;
+
+extern char *archive_dir;
+extern char *destination_dir;
+extern char *destination_conninfo;
+extern char *logfile_path;
+extern int     max_archives;
+extern char *cluster_name;
+extern char *namespace;
+
+extern RenameObject *rename_list;
+extern ProcessingCommand *pre_processing_commands;
+extern ProcessingCommand *post_processing_commands;
+extern ProcessingCommand *error_commands;
 
 /*
  * Functions in slony_logshipper.c
  */
-extern int             process_check_at_counter(char *at_counter);
-extern int             process_simple_sql(char *sql);
-extern int             process_start_transaction(char *sql);
-extern int             process_end_transaction(char *sql);
-extern int             process_insert(InsertStmt *stmt);
-extern int             process_update(UpdateStmt *stmt);
-extern int             process_delete(DeleteStmt *stmt);
-extern int             process_truncate(TruncateStmt *stmt);
-extern int             process_copy(CopyStmt *stmt);
-extern int             process_copydata(char *line);
-extern int             process_copyend(void);
-extern void            config_add_rename(RenameObject *entry);
-extern int             lookup_rename(char *namespace, char *name,
-                                                       char **use_namespace, char **use_name);
-extern void            errlog(log_level level, char *fmt, ...);
+extern int     process_check_at_counter(char *at_counter);
+extern int     process_simple_sql(char *sql);
+extern int     process_start_transaction(char *sql);
+extern int     process_end_transaction(char *sql);
+extern int     process_insert(InsertStmt *stmt);
+extern int     process_update(UpdateStmt *stmt);
+extern int     process_delete(DeleteStmt *stmt);
+extern int     process_truncate(TruncateStmt *stmt);
+extern int     process_copy(CopyStmt *stmt);
+extern int     process_copydata(char *line);
+extern int     process_copyend(void);
+extern void config_add_rename(RenameObject * entry);
+extern int lookup_rename(char *namespace, char *name,
+                         char **use_namespace, char **use_name);
+extern void errlog(log_level level, char *fmt,...);
 
 /*
  * Functions in dbutil.c
@@ -237,12 +247,12 @@ void              ipc_set_shutdown_immed(void);
 extern int     yylineno;
 extern char *yytext;
 extern FILE *yyin;
-extern char    yychunk[];
+extern char yychunk[];
 
 extern void scan_new_input_file(FILE *in);
 extern void scan_push_string(char *str);
 extern int     scan_yyinput(void);
-extern void    scan_copy_start(void);
+extern void scan_copy_start(void);
 
 extern void parse_error(const char *str);