add missing headers

pull/4044/head
Sait Talha Nisanci 2020-07-13 16:35:00 +03:00
parent dc53350652
commit 1b3f4d79fe
6 changed files with 93 additions and 61 deletions

View File

@ -54,7 +54,7 @@ utils/citus_version.o: $(CITUS_VERSION_INVALIDATE)
SHLIB_LINK += $(filter -lssl -lcrypto -lssleay32 -leay32, $(LIBS))
override LDFLAGS += $(libbacktrace_a)
override CPPFLAGS += -I$(libpq_srcdir) -I$(safestringlib_srcdir)/include -I$(libbacktrace_builddir)/include/
override CPPFLAGS += -I$(libpq_srcdir) -I$(safestringlib_srcdir)/include -I$(libbacktrace_srcdir)
SQL_DEPDIR=.deps/sql
SQL_BUILDDIR=build/sql
@ -66,6 +66,8 @@ $(libbacktrace_a): $(libbacktrace_sources)
citus.so: $(libbacktrace_a)
$(OBJS): $(libbacktrace_a)
$(generated_sql_files): $(citus_abs_srcdir)/build/%: %
@mkdir -p $(citus_abs_srcdir)/$(SQL_DEPDIR) $(citus_abs_srcdir)/$(SQL_BUILDDIR)
cd $(citus_abs_srcdir) && cpp -undef -w -P -MMD -MP -MF$(SQL_DEPDIR)/$(*F).Po -MT$@ $< > $@

View File

@ -105,9 +105,10 @@ JobExecutorType(DistributedPlan *distributedPlan)
if (!EnableRepartitionJoins)
{
ereport(ERROR, (
errmsg("the query contains a join that requires repartitioning"),
errhint("Set citus.enable_repartition_joins to on "
"to enable repartitioning")));
errmsg(
"the query contains a join that requires repartitioning"),
errhint("Set citus.enable_repartition_joins to on "
"to enable repartitioning")));
}
if (HasReplicatedDistributedTable(distributedPlan->relationIdList))
{
@ -134,6 +135,7 @@ JobExecutorType(DistributedPlan *distributedPlan)
return executorType;
}
/*
* HasReplicatedDistributedTable returns true if there is any
* table in the given list that is:

View File

@ -368,6 +368,7 @@ multi_log_hook(ErrorData *edata)
}
}
/*
* StartupCitusBackend initializes per-backend infrastructure, and is called
* the first time citus is used in a database.

View File

@ -8,7 +8,7 @@
#include "postgres.h"
#include "backtrace.h"
#include "backtrace-supported.h"
// #include "backtrace-supported.h"
#include "lib/stringinfo.h"
#include "distributed/backtrace.h"
@ -17,59 +17,78 @@
#define BACKTRACE_SKIP 2
static int BacktraceFullCallback(void *data, uintptr_t pc,
const char *filename, int lineno,
const char *function);
const char *filename, int lineno,
const char *function);
static void BacktraceErrorCallback(void *data, const char *msg, int errnum);
static void InitBackTrace(void);
static bool ShouldLogBacktrace(int elevel);
static char* GenerateBackTrace(void);
static char * GenerateBackTrace(void);
static struct backtrace_state* backTracestate;
static struct backtrace_state *backTracestate;
static void InitBackTrace(void) {
const char* filename = NULL;
void* data = NULL;
backTracestate = backtrace_create_state(filename, BACKTRACE_SUPPORTS_THREADS,
BacktraceErrorCallback, data);
}
static bool ShouldLogBacktrace(int elevel) {
return elevel >= ERROR;
static void
InitBackTrace(void)
{
const char *filename = NULL;
void *data = NULL;
backTracestate = backtrace_create_state(filename, 0,
BacktraceErrorCallback, data);
}
void Backtrace(int elevel) {
if (!ShouldLogBacktrace(elevel)) {
return;
}
errdetail("%s", GenerateBackTrace());
}
static bool
ShouldLogBacktrace(int elevel)
{
return elevel >= ERROR;
}
static char* GenerateBackTrace(void) {
if (backTracestate == NULL) {
InitBackTrace();
}
StringInfo msgWithBacktrace = makeStringInfo();
void
Backtrace(int elevel)
{
if (!ShouldLogBacktrace(elevel))
{
return;
}
errdetail("%s", GenerateBackTrace());
}
static char *
GenerateBackTrace(void)
{
if (backTracestate == NULL)
{
InitBackTrace();
}
StringInfo msgWithBacktrace = makeStringInfo();
appendStringInfoString(msgWithBacktrace, BACKTRACE_HEADER);
backtrace_full(backTracestate, BACKTRACE_SKIP, BacktraceFullCallback,
BacktraceErrorCallback, msgWithBacktrace);
BacktraceErrorCallback, msgWithBacktrace);
return msgWithBacktrace->data;
return msgWithBacktrace->data;
}
static int BacktraceFullCallback(void *data, uintptr_t pc, const char *filename, int lineno,
const char *function) {
StringInfo str = (StringInfo) data;
if (function && filename) {
appendStringInfo(str, "%s:%s:%d\n",filename, function, lineno);
}
/* returning 0 means we will continue the backtrace */
return 0;
static int
BacktraceFullCallback(void *data, uintptr_t pc, const char *filename, int lineno,
const char *function)
{
StringInfo str = (StringInfo) data;
if (function && filename)
{
appendStringInfo(str, "%s:%s:%d\n", filename, function, lineno);
}
/* returning 0 means we will continue the backtrace */
return 0;
}
static void BacktraceErrorCallback(void *data, const char *msg, int errnum) {
// currently NO-OP
static void
BacktraceErrorCallback(void *data, const char *msg, int errnum)
{
/* currently NO-OP */
}

View File

@ -14,5 +14,3 @@
void Backtrace(int elevel);
#endif

View File

@ -9,9 +9,11 @@
#ifndef LOG_UTILS_H
#define LOG_UTILS_H
#include "c.h"
#include "postgres.h"
#include "utils/guc.h"
#include "distributed/backtrace.h"
#include "utils/elog.h"
/* do not log */
#define CITUS_LOG_LEVEL_OFF 0
@ -23,29 +25,37 @@ extern char * HashLogMessage(const char *text);
#define ApplyLogRedaction(text) \
(log_min_messages <= ereport_loglevel ? HashLogMessage(text) : text)
#undef ereport_domain
#if defined(errno) && defined(__linux__)
#define pg_prevent_errno_in_scope() int __errno_location pg_attribute_unused()
#elif defined(errno) && (defined(__darwin__) || defined(__freebsd__))
#define pg_prevent_errno_in_scope() int __error pg_attribute_unused()
#else
#define pg_prevent_errno_in_scope()
#endif
#ifdef HAVE__BUILTIN_CONSTANT_P
#define ereport_domain(elevel, domain, ...) \
#define ereport_domain(elevel, domain, ...) \
do { \
pg_prevent_errno_in_scope(); \
if (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain)) { \
__VA_ARGS__, Backtrace(elevel);errfinish(0); \
}\
if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
pg_unreachable(); \
} while(0)
#else /* !HAVE__BUILTIN_CONSTANT_P */
#define ereport_domain(elevel, domain, ...) \
__VA_ARGS__, Backtrace(elevel); errfinish(0); \
} \
if (__builtin_constant_p(elevel) && (elevel) >= ERROR) { \
pg_unreachable(); } \
} while (0)
#else /* !HAVE__BUILTIN_CONSTANT_P */
#define ereport_domain(elevel, domain, ...) \
do { \
const int elevel_ = (elevel); \
pg_prevent_errno_in_scope(); \
if (errstart(elevel_, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain)) {\
__VA_ARGS__, Backtrace(elevel);errfinish(0); \
}\
if (elevel_ >= ERROR) \
pg_unreachable(); \
} while(0)
#endif /* HAVE__BUILTIN_CONSTANT_P */
if (errstart(elevel_, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain)) { \
__VA_ARGS__, Backtrace(elevel); errfinish(0); \
} \
if (elevel_ >= ERROR) { \
pg_unreachable(); } \
} while (0)
#endif /* HAVE__BUILTIN_CONSTANT_P */
#undef ereport