Skip to content

Commit

Permalink
Rebase with yb::master up to commit 3d3480b
Browse files Browse the repository at this point in the history
  • Loading branch information
nocaway committed Jul 20, 2023
1 parent 065c1a2 commit 69fa310
Show file tree
Hide file tree
Showing 150 changed files with 8,391 additions and 5,972 deletions.
23 changes: 20 additions & 3 deletions src/postgres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ if(IS_GCC)
endif()

if(IS_CLANG)
if("${COMPILER_VERSION}" VERSION_GREATER_EQUAL "13.0.0" AND NOT IS_APPLE_CLANG)
if("${COMPILER_VERSION}" VERSION_GREATER_EQUAL "14.0.0")
add_pg_c_cxx_flags(-Wno-error=unused-but-set-variable)
endif()

if("${COMPILER_VERSION}" VERSION_GREATER_EQUAL "15.0.0")
if(("${COMPILER_VERSION}" VERSION_GREATER_EQUAL "15.0.0") OR
(IS_APPLE_CLANG AND "${COMPILER_VERSION}" VERSION_GREATER_EQUAL "14.0.3"))
add_pg_c_cxx_flags(-Wno-error=deprecated-non-prototype)
endif()
endif()
Expand Down Expand Up @@ -104,6 +105,22 @@ if(APPLE AND NOT "${MACOS_SDK_INCLUDE_DIR}" STREQUAL "")
" -isystem ${MACOS_SDK_INCLUDE_DIR}")
endif()

if(NOT "$ENV{YB_VALGRIND_PATH}" STREQUAL "")

string(APPEND POSTGRES_EXTRA_PREPROCESSOR_FLAGS " -DUSE_VALGRIND")

find_path(VALGRIND_INCLUDE_PATH "valgrind/valgrind.h"
"/usr/include"
"/usr/local/include"
$ENV{CPATH})

if (${VALGRIND_INCLUDE_PATH} STREQUAL "VALGRIND_INCLUDE_PATH-NOTFOUND")
message(FATAL_ERROR "Compiling with Valgrind support, but could not find Valgrind's header"
" files. If you have Valgrind installed in an atypical location, add the include directory"
" to CPATH and retry.")
endif()
endif()

set(PG_INCLUDE_DIRS "${YB_PREFIX_COMMON}/include")
set(PG_LIB_DIRS "${YB_PREFIX_COMMON}/lib")
if(APPLE AND NOT IS_APPLE_CLANG)
Expand Down Expand Up @@ -200,4 +217,4 @@ add_dependencies(postgres configure_postgres)
# ------------------------------------------------------------------------------------------------

# Libraries that we link into the postgres binary.
add_dependencies(postgres yb_pggate server_process)
add_dependencies(postgres yb_pggate server_process yb_pggate_webserver)
2 changes: 2 additions & 0 deletions src/postgres/contrib/adminpack/adminpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "utils/builtins.h"
#include "utils/datetime.h"

/* YB includes. */
#include "pg_yb_utils.h"
#include "yb/yql/pggate/ybc_pggate.h"

#ifdef WIN32
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/contrib/file_fdw/file_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/sampling.h"

/* YB includes. */
#include "pg_yb_utils.h"
#include "yb/yql/pggate/ybc_pggate.h"

PG_MODULE_MAGIC;
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/contrib/pg_cron/src/pg_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
#include "libpq/pqformat.h"
#include "utils/builtins.h"

/* YB includes. */
#include "pg_yb_utils.h"

#if (PG_VERSION_NUM < 120000)
#define table_open(r, l) heap_open(r, l)
#define table_close(r, l) heap_close(r, l)
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/contrib/pg_stat_monitor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EXTENSION = pg_stat_monitor
DATA = pg_stat_monitor--1.0.sql

PGFILEDESC = "pg_stat_monitor - execution statistics of SQL statements"
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process -lyb_pggate_webserver

LDFLAGS_SL += $(filter -lm, $(LIBS))

Expand Down
40 changes: 34 additions & 6 deletions src/postgres/contrib/pg_stat_monitor/pg_stat_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
#include "postgres.h"
#include "commands/explain.h"
#include "pg_stat_monitor.h"
#include "yb/server/pgsql_webserver_wrapper.h"

/* YB includes. */
#include "common/pg_yb_common.h"
#include "yb/yql/pggate/webserver/pgsql_webserver_wrapper.h"

PG_MODULE_MAGIC;

#define BUILD_VERSION "0.9.0"
#define PG_STAT_STATEMENTS_COLS 51 /* maximum of above */
#define PGSM_TEXT_FILE "/tmp/pg_stat_monitor_query"

#define YB_PGSM_TEXT_FILE_PREFIX "pg_stat_monitor_query"

#define PGUNSIXBIT(val) (((val) & 0x3F) + '0')

#define _snprintf(_str_dst, _str_src, _len, _max_len)\
Expand Down Expand Up @@ -199,6 +204,7 @@ void
_PG_init(void)
{
int i;
const char *yb_tmp_dir = YbGetTmpDir();

elog(DEBUG2, "pg_stat_monitor: %s()", __FUNCTION__);
/*
Expand All @@ -218,7 +224,11 @@ _PG_init(void)
for (i = 0; i < PGSM_MAX_BUCKETS; i++)
{
char file_name[1024];
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, i);
if (yb_tmp_dir)
snprintf(file_name, 1024, "%s/%s.%d", yb_tmp_dir,
YB_PGSM_TEXT_FILE_PREFIX, i);
else
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, i);
unlink(file_name);
}

Expand Down Expand Up @@ -1678,6 +1688,7 @@ get_next_wbucket(pgssSharedState *pgss)
uint64 current_usec;
uint64 bucket_id;
struct tm *lt;
const char *yb_tmp_dir = YbGetTmpDir();

gettimeofday(&tv,NULL);
current_usec = (TimestampTz) tv.tv_sec - ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
Expand All @@ -1694,7 +1705,12 @@ get_next_wbucket(pgssSharedState *pgss)
buf = pgss_qbuf[bucket_id];
hash_entry_dealloc(bucket_id);
hash_query_entry_dealloc(bucket_id);
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, (int)bucket_id);
if (yb_tmp_dir)
snprintf(file_name, 1024, "%s/%s.%d", yb_tmp_dir,
YB_PGSM_TEXT_FILE_PREFIX, (int) bucket_id);
else
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, (int)bucket_id);

unlink(file_name);

/* reset the query buffer */
Expand Down Expand Up @@ -2887,8 +2903,14 @@ dump_queries_buffer(int bucket_id, unsigned char *buf, int buf_len)
{
int fd = 0;
char file_name[1024];
const char *yb_tmp_dir = YbGetTmpDir();

if (yb_tmp_dir)
snprintf(file_name, 1024, "%s/%s.%d", yb_tmp_dir,
YB_PGSM_TEXT_FILE_PREFIX, bucket_id);
else
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, bucket_id);

snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, bucket_id);
fd = OpenTransientFile(file_name, O_RDWR | O_CREAT | O_APPEND | PG_BINARY);
if (fd < 0)
ereport(LOG,
Expand All @@ -2913,9 +2935,15 @@ read_query_buffer(int bucket_id, uint64 queryid, char *query_txt)
char file_name[1024];
unsigned char *buf = NULL;
int off = 0;
const char *yb_tmp_dir = YbGetTmpDir();

if (yb_tmp_dir)
snprintf(file_name, 1024, "%s/%s.%d", yb_tmp_dir,
YB_PGSM_TEXT_FILE_PREFIX, bucket_id);
else
snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, bucket_id);

snprintf(file_name, 1024, "%s.%d", PGSM_TEXT_FILE, bucket_id);
fd = OpenTransientFile(file_name, O_RDONLY | PG_BINARY);
fd = OpenTransientFile(file_name, O_RDONLY | PG_BINARY);
if (fd < 0)
goto exit;

Expand Down
2 changes: 1 addition & 1 deletion src/postgres/contrib/pg_stat_statements/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DATA = pg_stat_statements--1.4.sql \
pg_stat_statements--1.3--1.4.sql pg_stat_statements--1.2--1.3.sql \
pg_stat_statements--1.1--1.2.sql pg_stat_statements--1.0--1.1.sql
PGFILEDESC = "pg_stat_statements - execution statistics of SQL statements"
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process -lyb_pggate_webserver

LDFLAGS_SL += $(filter -lm, $(LIBS))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

/* Yugabyte includes */
#include "common/pg_yb_common.h"
#include "yb/server/pgsql_webserver_wrapper.h"
#include "yb/yql/pggate/webserver/pgsql_webserver_wrapper.h"

PG_MODULE_MAGIC;

Expand Down
41 changes: 38 additions & 3 deletions src/postgres/contrib/pg_trgm/trgm_regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
#include "utils/hsearch.h"
#include "utils/memutils.h"

/* YB includes. */
#include "common/pg_yb_common.h"

/*
* Uncomment (or use -DTRGM_REGEXP_DEBUG) to print debug info,
* for exploring and debugging the algorithm implementation.
Expand Down Expand Up @@ -2134,6 +2137,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
int nstates = pg_reg_getnumstates(regex);
int state;
int i;
const char *yb_tmp_dir = YbGetTmpDir();

initStringInfo(&buf);

Expand Down Expand Up @@ -2199,9 +2203,18 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)

{
/* dot -Tpng -o /tmp/source.png < /tmp/source.gv */
FILE *fp = fopen("/tmp/source.gv", "w");
FILE *fp = NULL;
char *yb_custom_path = palloc0(MAX_STRING_LEN);
if (yb_tmp_dir)
{
snprintf(yb_custom_path, MAX_STRING_LEN, "%s/source.gv", yb_tmp_dir);
fp = fopen(yb_custom_path, "w");
}
else
fp = fopen("/tmp/source.gv", "w");

fprintf(fp, "%s", buf.data);
pfree(yb_custom_path);
fclose(fp);
}

Expand All @@ -2218,6 +2231,7 @@ printTrgmNFA(TrgmNFA *trgmNFA)
HASH_SEQ_STATUS scan_status;
TrgmState *state;
TrgmState *initstate = NULL;
const char *yb_tmp_dir = YbGetTmpDir();

initStringInfo(&buf);

Expand Down Expand Up @@ -2261,9 +2275,19 @@ printTrgmNFA(TrgmNFA *trgmNFA)

{
/* dot -Tpng -o /tmp/transformed.png < /tmp/transformed.gv */
FILE *fp = fopen("/tmp/transformed.gv", "w");
char *yb_custom_path = palloc0(MAX_STRING_LEN);
FILE *fp = NULL;
if (yb_tmp_dir)
{
snprintf(yb_custom_path, MAX_STRING_LEN, "%s/transformed.gv",
yb_tmp_dir);
fp = fopen(yb_custom_path, "w");
}
else
fp = fopen("/tmp/transformed.gv", "w");

fprintf(fp, "%s", buf.data);
pfree(yb_custom_path);
fclose(fp);
}

Expand Down Expand Up @@ -2352,10 +2376,21 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)

{
/* dot -Tpng -o /tmp/packed.png < /tmp/packed.gv */
FILE *fp = fopen("/tmp/packed.gv", "w");
FILE *fp = NULL;
char *yb_custom_path = palloc0(MAX_STRING_LEN);
const char *yb_tmp_dir = YbGetTmpDir();

if (yb_tmp_dir)
{
snprintf(yb_custom_path, MAX_STRING_LEN, "%s/packed.gv", yb_tmp_dir);
fp = fopen(yb_custom_path, "w");
}
else
fp = fopen("/tmp/packed.gv", "w");

fprintf(fp, "%s", buf.data);
fclose(fp);
pfree(yb_custom_path);
}

pfree(buf.data);
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/contrib/pgaudit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OBJS = pgaudit.o $(WIN32RES)
EXTENSION = pgaudit
DATA = pgaudit--1.3.2.sql pgaudit--1.3--1.3.1.sql pgaudit--1.3.1--1.3.2.sql
PGFILEDESC = "pgAudit - An audit logging extension for PostgreSQL"
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process -lyb_pggate_webserver

LDFLAGS_SL += $(filter -lm, $(LIBS))

Expand Down
3 changes: 3 additions & 0 deletions src/postgres/contrib/pgaudit/pgaudit.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include "utils/timestamp.h"
#include "utils/varlena.h"

/* YB includes. */
#include "pg_yb_utils.h"

PG_MODULE_MAGIC;

void _PG_init(void);
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/contrib/yb_pg_metrics/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ OBJS = yb_pg_metrics.o $(WIN32RES)
EXTENSION = yb_pg_metrics
DATA =
PGFILEDESC = "yb_pg_metrics - YugaByte metrics"
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process -lyb_common
SHLIB_LINK += -L$(YB_BUILD_ROOT)/lib -lserver_process -lyb_pggate_util -lyb_pggate_webserver
subdir = contrib/yb_pg_metrics
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
Expand Down
Loading

0 comments on commit 69fa310

Please sign in to comment.