bdr: we now use ereport() and elog(DEBUG1) in various cases
authorChristian Kruse <cjk@defunct.ch>
Fri, 9 May 2014 11:48:25 +0000 (13:48 +0200)
committerAndres Freund <andres@anarazel.de>
Thu, 3 Jul 2014 15:55:33 +0000 (17:55 +0200)
contrib/bdr/bdr.c
contrib/bdr/bdr_apply.c
contrib/bdr/bdr_count.c
contrib/bdr/bdr_init_replica.c
contrib/bdr/bdr_output.c
contrib/bdr/bdr_seq.c

index 6dcf15622d6eda61ef1ca333044ba4aeaca91560..1f4bfa4e7d29ebfbf173de3661e373fd228c9f28 100644 (file)
@@ -150,7 +150,7 @@ bdr_send_feedback(PGconn *conn, XLogRecPtr blockpos, int64 now, bool replyReques
    replybuf[len] = replyRequested ? 1 : 0;     /* replyRequested */
    len += 1;
 
-   elog(LOG, "sending feedback (force %d, reply requested %d) to %X/%X",
+   elog(DEBUG1, "sending feedback (force %d, reply requested %d) to %X/%X",
         force, replyRequested,
         (uint32) (blockpos >> 32), (uint32) blockpos);
 
@@ -158,8 +158,9 @@ bdr_send_feedback(PGconn *conn, XLogRecPtr blockpos, int64 now, bool replyReques
 
    if (PQputCopyData(conn, replybuf, len) <= 0 || PQflush(conn))
    {
-       elog(ERROR, "could not send feedback packet: %s",
-            PQerrorMessage(conn));
+       ereport(ERROR,
+               (errmsg("could not send feedback packet: %s",
+                       PQerrorMessage(conn))));
        return false;
    }
 
@@ -313,7 +314,7 @@ bdr_connect(char *conninfo_repl,
                 errdetail("Both system identifiers are %s.", remote_sysid)));
    }
    else
-       elog(LOG, "local sysid %s, remote: %s",
+       elog(DEBUG1, "local sysid %s, remote: %s",
             local_sysid, remote_sysid);
 
    /*
@@ -399,7 +400,7 @@ bdr_create_slot(PGconn *streamConn, Name slot_name,
    /* now commit local identifier */
    CommitTransactionCommand();
    CurrentResourceOwner = bdr_saved_resowner;
-   elog(LOG, "created replication identifier %u", *replication_identifier);
+   elog(DEBUG1, "created replication identifier %u", *replication_identifier);
 
    if (snapshot)
        *snapshot = pstrdup(PQgetvalue(res, 0, 2));
@@ -490,7 +491,7 @@ bdr_establish_connection_and_slot(BdrConnectionConfig *cfg, Name out_slot_name,
 
    if (OidIsValid(*out_replication_identifier))
    {
-       elog(LOG, "found valid replication identifier %u",
+       elog(DEBUG1, "found valid replication identifier %u",
             *out_replication_identifier);
        if (out_snapshot)
            *out_snapshot = NULL;
@@ -506,7 +507,7 @@ bdr_establish_connection_and_slot(BdrConnectionConfig *cfg, Name out_slot_name,
         */
 
        /* create local replication identifier and a remote slot */
-       elog(LOG, "Creating new slot %s", NameStr(*out_slot_name));
+       elog(DEBUG1, "Creating new slot %s", NameStr(*out_slot_name));
        bdr_create_slot(streamConn, out_slot_name, remote_ident,
                        out_replication_identifier, out_snapshot);
    }
@@ -552,7 +553,7 @@ bdr_apply_main(Datum main_arg)
    CurrentResourceOwner = ResourceOwnerCreate(NULL, "bdr apply top-level resource owner");
    bdr_saved_resowner = CurrentResourceOwner;
 
-   elog(LOG, "%s initialized on %s",
+   elog(DEBUG1, "%s initialized on %s",
         MyBgworkerEntry->bgw_name, NameStr(bdr_apply_config->dbname));
 
    streamConn = bdr_establish_connection_and_slot(
@@ -576,7 +577,7 @@ bdr_apply_main(Datum main_arg)
     */
    start_from = RemoteCommitFromCachedReplicationIdentifier();
 
-   elog(LOG, "starting up replication at %u from %X/%X",
+   elog(INFO, "starting up replication at %u from %X/%X",
         replication_identifier,
         (uint32) (start_from >> 32), (uint32) start_from);
 
@@ -663,7 +664,7 @@ bdr_apply_main(Datum main_arg)
 
            if (r == -1)
            {
-               elog(LOG, "data stream ended");
+               elog(DEBUG1, "data stream ended");
                return;
            }
            else if (r == -2)
@@ -867,7 +868,7 @@ bdr_create_con_gucs(char  *name,
        if (strcmp(cur_option->keyword, "dbname") == 0)
        {
            if (cur_option->val == NULL)
-               elog(ERROR, "bdr %s: no dbname set", name);
+               ereport(ERROR, (errmsg("bdr %s: no dbname set", name)));
 
            strncpy(NameStr(opts->dbname), cur_option->val,
                    NAMEDATALEN);
@@ -913,8 +914,9 @@ bdr_create_con_gucs(char  *name,
    {
        elog(DEBUG2, "bdr %s: has init_replica=t", name);
        if (database_initcons[off] != NULL)
-           elog(ERROR, "Connections %s and %s on database %s both have bdr_init_replica enabled, cannot continue",
-               name, database_initcons[off], used_databases[off]);
+           ereport(ERROR,
+                   (errmsg("Connections %s and %s on database %s both have bdr_init_replica enabled, cannot continue",
+                           name, database_initcons[off], used_databases[off])));
        else
            database_initcons[off] = name; /* no need to pstrdup, see _PG_init */
    }
@@ -989,9 +991,10 @@ bdr_launch_apply_workers(char *dbname)
                        if (!RegisterDynamicBackgroundWorker(&apply_worker,
                                                             &bgw_handle))
                        {
-                           elog(ERROR, "bdr: Failed to register background worker"
-                                " %s, see previous log messages",
-                                NameStr(cfg->name));
+                           ereport(ERROR,
+                                   (errmsg("bdr: Failed to register background worker"
+                                           " %s, see previous log messages",
+                                           NameStr(cfg->name))));
                        }
                        apply_workers = lcons(bgw_handle, apply_workers);
                    }
@@ -1063,7 +1066,7 @@ bdr_perdb_worker_main(Datum main_arg)
    /* Do we need to init the local DB from a remote node? */
    bdr_init_replica(&bdr_perdb_worker->dbname);
 
-   elog(LOG, "Starting bdr apply workers for db %s", NameStr(bdr_perdb_worker->dbname));
+   elog(DEBUG1, "Starting bdr apply workers for db %s", NameStr(bdr_perdb_worker->dbname));
 
    /* Launch the apply workers */
    apply_workers = bdr_launch_apply_workers(NameStr(bdr_perdb_worker->dbname));
@@ -1078,7 +1081,7 @@ bdr_perdb_worker_main(Datum main_arg)
        pfree(h);
    }
 
-   elog(LOG, "BDR starting sequencer on db \"%s\"",
+   elog(DEBUG1, "BDR starting sequencer on db \"%s\"",
         NameStr(bdr_perdb_worker->dbname));
 
    /* initialize sequencer */
@@ -1350,7 +1353,8 @@ _PG_init(void)
    int         connection_config_idx;
 
    if (!process_shared_preload_libraries_in_progress)
-       elog(ERROR, "bdr can only be loaded via shared_preload_libraries");
+       ereport(ERROR,
+               (errmsg("bdr can only be loaded via shared_preload_libraries")));
 
    if (!commit_ts_enabled)
        ereport(ERROR,
@@ -1452,7 +1456,7 @@ _PG_init(void)
    if (bdr_max_workers == -1)
    {
        bdr_max_workers = list_length(connames) * 2;
-       elog(LOG, "bdr: bdr_max_workers unset, configuring for %d workers",
+       elog(DEBUG1, "bdr: bdr_max_workers unset, configuring for %d workers",
                bdr_max_workers);
    }
 
@@ -1553,7 +1557,7 @@ _PG_init(void)
 
        con->seq_slot = off;
 
-       elog(LOG, "starting bdr database worker for db %s", NameStr(con->dbname));
+       elog(DEBUG1, "starting bdr database worker for db %s", NameStr(con->dbname));
        snprintf(perdb_worker.bgw_name, BGW_MAXLEN,
                 "bdr: %s", NameStr(con->dbname));
        perdb_worker.bgw_main_arg = PointerGetDatum(con);
@@ -1669,8 +1673,8 @@ bdr_maintain_schema(void)
    else
        elog(ERROR, "cache lookup failed for schema bdr");
 
-   elog(LOG, "bdr.bdr_queued_commands OID set to %u", QueuedDDLCommandsRelid);
-   elog(LOG, "bdr.bdr_queued_drops OID set to %u", QueuedDropsRelid);
+   elog(DEBUG1, "bdr.bdr_queued_commands OID set to %u", QueuedDDLCommandsRelid);
+   elog(DEBUG1, "bdr.bdr_queued_drops OID set to %u", QueuedDropsRelid);
 
    bdr_conflict_handlers_init();
 
index b55af2cf4fc65bb79a325f00bcb0003562ce05d9..4886846afefd81a876c3e726d0749ed958cc9e65 100644 (file)
@@ -156,7 +156,7 @@ process_remote_begin(StringInfo s)
            (uint32) (origlsn >> 32), (uint32) origlsn,
            timestamptz_to_str(committime));
 
-   elog(LOG, "%s", statbuf);
+   elog(DEBUG1, "%s", statbuf);
 
    pgstat_report_activity(STATE_RUNNING, statbuf);
 
@@ -218,7 +218,7 @@ process_remote_commit(StringInfo s)
        origin_lsn = pq_getmsgint64(s);
    }
 
-   elog(LOG, "COMMIT origin(lsn, end, timestamp): %X/%X, %X/%X, %s",
+   elog(DEBUG1, "COMMIT origin(lsn, end, timestamp): %X/%X, %X/%X, %s",
         (uint32) (commit_lsn >> 32), (uint32) commit_lsn,
         (uint32) (end_lsn >> 32), (uint32) end_lsn,
         timestamptz_to_str(committime));
@@ -341,7 +341,7 @@ process_remote_insert(StringInfo s)
 #ifdef VERBOSE_INSERT
    initStringInfo(&o);
    tuple_to_stringinfo(&o, RelationGetDescr(rel), slot->tts_tuple);
-   elog(LOG, "INSERT:%s", o.data);
+   elog(DEBUG1, "INSERT:%s", o.data);
    resetStringInfo(&o);
 #endif
 
@@ -610,7 +610,7 @@ process_remote_update(StringInfo s)
        tuple_to_stringinfo(&o, RelationGetDescr(rel), oldslot->tts_tuple);
        appendStringInfo(&o, " to");
        tuple_to_stringinfo(&o, RelationGetDescr(rel), remote_tuple);
-       elog(LOG, "UPDATE:%s", o.data);
+       elog(DEBUG1, "UPDATE:%s", o.data);
        resetStringInfo(&o);
 #endif
 
@@ -643,7 +643,7 @@ process_remote_update(StringInfo s)
 #ifdef VERBOSE_UPDATE
                initStringInfo(&o);
                tuple_to_stringinfo(&o, RelationGetDescr(rel), user_tuple);
-               elog(LOG, "USER tuple:%s", o.data);
+               elog(DEBUG1, "USER tuple:%s", o.data);
                resetStringInfo(&o);
 #endif
 
@@ -662,7 +662,7 @@ process_remote_update(StringInfo s)
                            oldslot->tts_tuple);
        bdr_count_update_conflict();
 
-       ereport(ERROR,
+       ereport(LOG,
                (errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
                 errmsg("CONFLICT: could not find existing tuple for pkey %s",
                        o.data)));
@@ -741,7 +741,7 @@ process_remote_delete(StringInfo s)
 #ifdef VERBOSE_DELETE
    initStringInfo(&o);
    tuple_to_stringinfo(&o, RelationGetDescr(idxrel), slot->tts_tuple);
-   elog(LOG, "DELETE old-key:%s", o.data);
+   elog(DEBUG1, "DELETE old-key:%s", o.data);
    resetStringInfo(&o);
 #endif
 
@@ -1654,7 +1654,8 @@ UserTableUpdateOpenIndexes(EState *estate, TupleTableSlot *slot)
                                               estate);
 
        if (recheckIndexes != NIL)
-           elog(ERROR, "bdr doesn't don't support index rechecks");
+           ereport(ERROR,
+                   (errmsg("bdr doesn't support index rechecks")));
    }
 
    /* FIXME: recheck the indexes */
index dabf6f36e251782a967feaca54efc0c9d576b181..94a9a4ca14ce044d15fe4a6e4e2b2f7b481ce443 100644 (file)
@@ -300,7 +300,8 @@ pg_stat_get_bdr(PG_FUNCTION_ARGS)
    size_t      current_offset;
 
    if (!superuser())
-       elog(ERROR, "blarg");
+       ereport(ERROR,
+               (errmsg("Access to pg_stat_get_bdr() denied as non-superuser")));
 
    if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
        ereport(ERROR,
index ad5f73b885926da4d795f02b25e9179d54a91de0..1c4390664aadd3638dca8c8085f5efb21edb98c8 100644 (file)
@@ -432,7 +432,7 @@ bdr_drop_slot_and_replication_identifier(BdrConnectionConfig *cfg)
    StringInfoData query;
    char       *sqlstate;
 
-   elog(LOG, "bdr %s: Dropping slot and local ident from connection %s",
+   elog(DEBUG1, "bdr %s: Dropping slot and local ident from connection %s",
         NameStr(cfg->dbname), NameStr(cfg->name));
 
    snprintf(conninfo_repl, sizeof(conninfo_repl),
@@ -595,7 +595,7 @@ bdr_exec_init_replica(BdrConnectionConfig *cfg, char *snapshot)
        }
        envp[0] = path.data;
 
-       elog(LOG, "Creating replica with: %s --snapshot %s --source \"%s\" --target \"%s\" --tmp-directory \"%s\"",
+       elog(DEBUG1, "Creating replica with: %s --snapshot %s --source \"%s\" --target \"%s\" --tmp-directory \"%s\"",
             bdr_init_replica_script_path, snapshot, cfg->dsn,
             cfg->replica_local_dsn, tmpdir);
 
@@ -806,7 +806,7 @@ bdr_init_replica(Name dbname)
        char       *init_snapshot = NULL;
        PGconn     *init_repl_conn = NULL;
 
-       elog(LOG, "bdr %s: initializing from remote db", NameStr(*dbname));
+       elog(DEBUG1, "bdr %s: initializing from remote db", NameStr(*dbname));
 
        /*
         * We're starting from scratch or have cleaned up a previous failed
@@ -920,7 +920,7 @@ bdr_init_replica(Name dbname)
         * ask to be included in dumps. In particular, bdr.bdr_nodes will get
         * copied over.
         */
-       elog(LOG, "bdr %s: creating and restoring dump for %s",
+       elog(DEBUG1, "bdr %s: creating and restoring dump for %s",
             NameStr(*dbname), NameStr(init_replica_config->name));
        bdr_exec_init_replica(init_replica_config, init_snapshot);
        PQfinish(init_repl_conn);
@@ -932,14 +932,14 @@ bdr_init_replica(Name dbname)
    Assert(status == 'c');
 
    /* Launch the catchup worker and wait for it to finish */
-   elog(LOG, "bdr %s: launching catchup mode apply worker", NameStr(*dbname));
+   elog(DEBUG1, "bdr %s: launching catchup mode apply worker", NameStr(*dbname));
    min_remote_lsn = bdr_get_remote_lsn(nonrepl_init_conn);
    bdr_catchup_to_lsn(
        init_replica_worker->worker_data.apply_worker.connection_config_idx,
        min_remote_lsn);
    status = bdr_set_remote_status(nonrepl_init_conn, dbname, 'r', status);
 
-   elog(LOG, "bdr %s: catchup worker finished, ready for normal replication",
+   elog(INFO, "bdr %s: catchup worker finished, ready for normal replication",
         NameStr(*dbname));
    PQfinish(nonrepl_init_conn);
 }
@@ -1008,8 +1008,9 @@ bdr_catchup_to_lsn(int cfg_index,
    if (worker_shmem_idx == bdr_max_workers)
    {
        LWLockRelease(BdrWorkerCtl->lock);
-       elog(ERROR, "No free bdr worker slots, bdr_max_workers=%d too low",
-            bdr_max_workers);
+       ereport(ERROR,
+               (errmsg("No free bdr worker slots, bdr_max_workers=%d too low",
+                       bdr_max_workers)));
    }
    BdrWorkerCtl->slots[worker_shmem_idx].worker_type = BDR_WORKER_APPLY;
    catchup_worker = &BdrWorkerCtl->slots[worker_shmem_idx].worker_data.apply_worker;
index 2cf40c6d164c1cdf623a01a7513215235b0bb57b..85f112eaf3c59d49196f6c104517bba08f514396 100644 (file)
@@ -265,12 +265,12 @@ pg_decode_startup(LogicalDecodingContext * ctx, OutputPluginOptions *opt, bool i
            data->client_sizeof_datum != sizeof(Datum))
        {
            data->allow_binary_protocol = false;
-           elog(LOG, "disabling binary protocol because of sizeof differences");
+           elog(DEBUG1, "disabling binary protocol because of sizeof differences");
        }
        else if (data->client_bigendian != bdr_get_bigendian())
        {
            data->allow_binary_protocol = false;
-           elog(LOG, "disabling binary protocol because of endianess difference");
+           elog(DEBUG1, "disabling binary protocol because of endianess difference");
        }
 
        /*
@@ -315,7 +315,7 @@ pg_decode_startup(LogicalDecodingContext * ctx, OutputPluginOptions *opt, bool i
            if (data->bdr_conflict_handlers_reloid == InvalidOid)
                elog(ERROR, "cache lookup for relation bdr.bdr_conflict_handlers failed");
            else
-               elog(LOG, "bdr.bdr_conflict_handlers OID set to %u",
+               elog(DEBUG1, "bdr.bdr_conflict_handlers OID set to %u",
                     data->bdr_conflict_handlers_reloid);
        }
        else
@@ -635,9 +635,7 @@ write_tuple(BdrOutputData *data, StringInfo out, Relation rel,
 
            }
            else
-           {
                elog(ERROR, "unsupported tuple type");
-           }
        }
        else if (use_sendrecv)
        {
index b41756aa89fa5cc79710547832010df6b794cf35..84dfe081b355c2f5067df53e1ed2f9f8e3c24561 100644 (file)
@@ -655,7 +655,7 @@ again:
    if (ret != SPI_OK_INSERT)
        elog(ERROR, "expected SPI state %u, got %u", SPI_OK_INSERT, ret);
    my_processed = SPI_processed;
-   elog(LOG, "started %d votes", my_processed);
+   elog(DEBUG1, "started %d votes", my_processed);
 
    if (my_processed > 0)
        goto again;
@@ -712,7 +712,7 @@ bdr_sequencer_start_elections(void)
    if (ret != SPI_OK_INSERT_RETURNING)
        elog(ERROR, "expected SPI state %u, got %u", SPI_OK_INSERT_RETURNING, ret);
 
-   elog(LOG, "started %d elections", SPI_processed);
+   elog(DEBUG1, "started %d elections", SPI_processed);
 
    PopActiveSnapshot();
    SPI_finish();
@@ -769,7 +769,7 @@ bdr_sequencer_tally(void)
    if (ret != SPI_OK_SELECT)
        elog(ERROR, "expected SPI state %u, got %u", SPI_OK_SELECT, ret);
 
-   elog(LOG, "tallied %d elections", SPI_processed);
+   elog(DEBUG1, "tallied %d elections", SPI_processed);
 
    PopActiveSnapshot();
    SPI_finish();
@@ -894,7 +894,7 @@ bdr_sequencer_fill_sequence(Oid seqoid, char *seqschema, char *seqname)
    int i;
    bool acquired_new = false;
 
-   elog(LOG, "checking sequence %u: %s.%s",
+   elog(DEBUG1, "checking sequence %u: %s.%s",
         seqoid, seqschema, seqname);
 
    /* lock page, fill heaptup */
@@ -923,9 +923,9 @@ bdr_sequencer_fill_sequence(Oid seqoid, char *seqschema, char *seqname)
        if (curval->next_value == curval->end_value)
        {
            if (curval->end_value > 0)
-               elog(LOG, "used up old chunk");
+               elog(DEBUG1, "used up old chunk");
 
-           elog(LOG, "need new batch %i", i);
+           elog(DEBUG1, "need new batch %i", i);
            if (bdr_sequencer_fill_chunk(seqoid, seqschema, seqname, curval))
                acquired_new = true;
            else