Merge pull request #4188 from sysown/v2.x-coredumper

Adding again google coredumper
pull/4184/head^2
René Cannaò 3 years ago committed by GitHub
commit 680bc0a839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
.gitignore vendored

@ -92,7 +92,7 @@ deps/pcre/pcre-*/
deps/prometheus-cpp/prometheus-cpp-*/
deps/re2/re2-*/
deps/sqlite3/sqlite-amalgamation-*/
deps/coredumper/coredumper-*/
test/.vagrant
.DS_Store

24
deps/Makefile vendored

@ -56,11 +56,14 @@ endif
PROXYSQLCLICKHOUSE := $(shell echo $(PROXYSQLCLICKHOUSE))
tmpdefault=libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre lz4 cityhash microhttpd curl ev libssl libhttpserver libinjection prometheus-cpp
ifeq ($(UNAME_S),Linux)
tmpdefault+= coredumper
endif
ifeq ($(PROXYSQLCLICKHOUSE),1)
default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre clickhouse-cpp lz4 cityhash microhttpd curl ev libssl libhttpserver libinjection prometheus-cpp
else
default: libconfig libdaemon jemalloc mariadb_client re2 sqlite3 pcre cityhash microhttpd curl ev libssl libhttpserver libinjection prometheus-cpp
tmpdefault+= clickhouse-cpp
endif
default: $(tmpdefault)
.PHONY: default
@ -137,12 +140,21 @@ libev/libev/.libs/libev.a:
ev: libev/libev/.libs/libev.a
coredumper/coredumper/src/libcoredumper.a:
cd coredumper && rm -rf coredumper-*/ || true
cd coredumper && tar -zxf coredumper-*.tar.gz
cd coredumper/coredumper && cmake . -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug
cd coredumper/coredumper && CC=${CC} CXX=${CXX} ${MAKE}
coredumper: coredumper/coredumper/src/libcoredumper.a
curl/curl/lib/.libs/libcurl.a: libssl/openssl/libssl.a
cd curl && rm -rf curl-*/ || true
cd curl && tar -zxf curl-*.tar.gz
# cd curl/curl && ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --with-ssl=$(shell pwd)/../../libssl/openssl/ && CC=${CC} CXX=${CXX} ${MAKE}
# cd curl/curl && patch configure < ../configure.patch
cd curl/curl && autoreconf -fi
ifeq ($(UNAME_S),Darwin)
cd curl/curl && patch configure < ../configure.patch
endif
cd curl/curl && CFLAGS=-fPIC ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --without-librtmp --without-libpsl --without-zstd --with-ssl=$(shell pwd)/libssl/openssl/ --enable-shared=no && CC=${CC} CXX=${CXX} ${MAKE}
curl: curl/curl/lib/.libs/libcurl.a
@ -158,9 +170,6 @@ else
cd libmicrohttpd && ln -s libmicrohttpd-0.9.75 libmicrohttpd
cd libmicrohttpd && tar -zxf libmicrohttpd-0.9.75.tar.gz
# cd libmicrohttpd/libmicrohttpd && patch src/microhttpd/connection.c < ../connection.c-snprintf-overflow.patch
endif
ifeq ($(UNAME_S),Darwin)
cd libmicrohttpd/libmicrohttpd && patch src/microhttpd/mhd_sockets.c < ../mhd_sockets.c-issue-5977.patch
endif
cd libmicrohttpd/libmicrohttpd && ./configure --enable-https && CC=${CC} CXX=${CXX} ${MAKE}
@ -364,5 +373,6 @@ cleanall:
cd libconfig && rm -rf libconfig-*/ || true
cd prometheus-cpp && rm -rf prometheus-cpp-*/ || true
cd cityhash && rm -rf cityhash-*/ || true
cd coredumper && rm -rf coredumper-*/ || true
.PHONY: cleanall

@ -0,0 +1,28 @@
Copyright (c) 2005-2007, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@ -0,0 +1 @@
coredumper-cb6cead

Binary file not shown.

@ -1,4 +1,4 @@
@@ -33462,7 +33462,7 @@
@@ -34014,7 +34014,7 @@
else $as_nop
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5
printf "%s\n" "failed" >&6; }
@ -7,7 +7,7 @@
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
@@ -33497,7 +33497,7 @@
@@ -34049,7 +34049,7 @@
else $as_nop
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5
printf "%s\n" "failed" >&6; }

@ -1,8 +0,0 @@
@@ -528,6 +528,7 @@ MHD_socket_cork_ (MHD_socket sock,
TCP_CORK always flushes socket buffer. */
if (0 > send (sock,
&dummy,
+ 0,
0))
return 0; /* even force flush failed!? */
return 1; /* success */

@ -10,6 +10,7 @@ endif
DEPS_PATH=../deps
UNAME_S := $(shell uname -s)
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
MARIADB_IDIR=$(MARIADB_PATH)/include
@ -41,8 +42,11 @@ LIBHTTPSERVER_IDIR=-I$(LIBHTTPSERVER_DIR)/src
MICROHTTPD_DIR=$(DEPS_PATH)/libmicrohttpd/libmicrohttpd
MICROHTTPD_IDIR=-I$(MICROHTTPD_DIR) -I$(MICROHTTPD_DIR)/src/include
COREDUMPER_DIR=$(DEPS_PATH)/coredumper/coredumper
COREDUMPER_IDIR=$(COREDUMPER_DIR)/include
CURL_DIR=$(DEPS_PATH)/curl/curl
CURL_IDIR=-I$(CURL_DIR)/include
CURL_IDIR=$(CURL_DIR)/include
SSL_DIR=$(DEPS_PATH)/libssl/openssl/
SSL_IDIR=$(SSL_DIR)/include
@ -57,8 +61,10 @@ PROMETHEUS_LDIR=$(PROMETHEUS_PATH)/lib
IDIR=../include
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) -I/usr/local/include -I$(CLICKHOUSE_CPP_DIR) -I$(CLICKHOUSE_CPP_DIR)/contrib/ $(MICROHTTPD_IDIR) $(LIBHTTPSERVER_IDIR) $(LIBINJECTION_IDIR) $(CURL_IDIR) -I$(EV_DIR) -I$(SSL_IDIR) -I$(PROMETHEUS_IDIR)
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) -I/usr/local/include -I$(CLICKHOUSE_CPP_DIR) -I$(CLICKHOUSE_CPP_DIR)/contrib/ $(MICROHTTPD_IDIR) $(LIBHTTPSERVER_IDIR) $(LIBINJECTION_IDIR) -I$(CURL_IDIR) -I$(EV_DIR) -I$(SSL_IDIR) -I$(PROMETHEUS_IDIR)
ifeq ($(UNAME_S),Linux)
IDIRS+= -I$(COREDUMPER_IDIR)
endif
LDIRS=-L$(JEMALLOC_PATH)/lib -L$(RE2_PATH)/obj -L$(INJECTION_PATH) -L$(PROMETHEUS_LDIR)
#LIBS=-rdynamic -Wl,-Bstatic -ljemalloc_pic -lre2 -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt $(EXTRALINK)
@ -95,8 +101,6 @@ else
WGCOV=
endif
UNAME_S := $(shell uname -s)
# determine good compiler version for stdc++17
IS_CXX17 := 0

@ -3795,7 +3795,7 @@ unique_ptr<MySQL_Thread> init_mysql_thread_struct() {
return mysql_thr;
}
struct thread_info_t {
struct mon_thread_info_t {
pthread_t pthread;
uint32_t writer_hg;
};
@ -3924,18 +3924,18 @@ void* monitor_GR_thread_HG(void *arg) {
/**
* @brief Creates a monitoring thread for each 'GroupReplication' cluster determined by writer hostgroups.
* @param writer_hgs The writer hostgroups to use when creating the threads.
* @return A vector of 'thread_info_t' holding info of the created threads.
* @return A vector of 'mon_thread_info_t' holding info of the created threads.
*/
vector<thread_info_t> create_group_replication_worker_threads(const set<uint32_t>& writer_hgs) {
vector<mon_thread_info_t> create_group_replication_worker_threads(const set<uint32_t>& writer_hgs) {
proxy_info("Activating Monitoring of %lu Group Replication clusters\n", writer_hgs.size());
vector<thread_info_t> threads_info {};
vector<mon_thread_info_t> threads_info {};
for (const uint32_t writer_hg : writer_hgs) {
threads_info.push_back({pthread_t {}, writer_hg});
}
for (thread_info_t& thread_info : threads_info) {
for (mon_thread_info_t& thread_info : threads_info) {
proxy_info("Starting Monitor thread for Group Replication writer HG %u\n", thread_info.writer_hg);
int err = pthread_create(&thread_info.pthread, NULL, monitor_GR_thread_HG, &thread_info.writer_hg);
@ -3963,7 +3963,7 @@ void* MySQL_Monitor::monitor_group_replication_2() {
unique_ptr<MySQL_Thread> mysql_thr { init_mysql_thread_struct() };
// Info of the current GR monitoring threads: handle + writer_hg
vector<thread_info_t> threads_info {};
vector<mon_thread_info_t> threads_info {};
while (GloMyMon->shutdown == false && mysql_thread___monitor_enabled == true) {
// Quick exit during shutdown/restart
@ -3988,7 +3988,7 @@ void* MySQL_Monitor::monitor_group_replication_2() {
// Wait for the threads to terminate; Threads should exit on config change
if (threads_info.empty() == false) {
for (const thread_info_t& thread_info : threads_info) {
for (const mon_thread_info_t& thread_info : threads_info) {
pthread_join(thread_info.pthread, NULL);
proxy_info("Stopped Monitor thread for Group Replication writer HG %u\n", thread_info.writer_hg);
}

@ -54,6 +54,11 @@
#include "platform.h"
#include "microhttpd.h"
#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || defined(__mips__)) && defined(__linux)
// currently only support x86-32, x86-64, ARM, and MIPS on Linux
#include "coredumper/coredumper.h"
#endif
#include <uuid/uuid.h>
using std::string;
@ -1515,6 +1520,53 @@ bool admin_handler_command_kill_connection(char *query_no_space, unsigned int qu
* return true if the command is not a valid one and needs to be executed by SQLite (that will return an error)
*/
bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_space_length, MySQL_Session *sess, ProxySQL_Admin *pa) {
#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || defined(__mips__)) && defined(__linux)
// currently only support x86-32, x86-64, ARM, and MIPS on Linux
if (!(strncasecmp("PROXYSQL COREDUMP", query_no_space, strlen("PROXYSQL COREDUMP")))) {
string filename = "core";
if (query_no_space_length > strlen("PROXYSQL COREDUMP")) {
if (query_no_space[strlen("PROXYSQL COREDUMP")] == ' ') {
filename = string(query_no_space+strlen("PROXYSQL COREDUMP "));
} else {
filename = "";
}
}
if (filename == "") {
proxy_error("Received incorrect PROXYSQL COREDUMP command: %s\n", query_no_space);
} else {
proxy_info("Received PROXYSQL COREDUMP command: %s\n", query_no_space);
// generates a core dump
WriteCoreDump(filename.c_str());
ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
string msg = "Coredump: " + filename;
SPA->send_MySQL_OK(&sess->client_myds->myprot, (char *)msg.c_str());
return false;
}
}
if (!(strncasecmp("PROXYSQL COMPRESSEDCOREDUMP", query_no_space, strlen("PROXYSQL COMPRESSEDCOREDUMP")))) {
string filename = "core";
if (query_no_space_length > strlen("PROXYSQL COMPRESSEDCOREDUMP")) {
if (query_no_space[strlen("PROXYSQL COMPRESSEDCOREDUMP")] == ' ') {
filename = string(query_no_space+strlen("PROXYSQL COMPRESSEDCOREDUMP "));
} else {
filename = "";
}
}
if (filename == "") {
proxy_error("Received incorrect PROXYSQL COMPRESSEDCOREDUMP command: %s\n", query_no_space);
} else {
proxy_info("Received PROXYSQL COMPRESSEDCOREDUMP command: %s\n", query_no_space);
// generates a compressed core dump
WriteCompressedCoreDump(filename.c_str(), SIZE_MAX, COREDUMPER_COMPRESSED, NULL);
ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa;
string msg = "Coredump: " + filename;
SPA->send_MySQL_OK(&sess->client_myds->myprot, (char *)msg.c_str());
return false;
}
}
#endif
if (!(strncasecmp("PROXYSQL CLUSTER_NODE_UUID ", query_no_space, strlen("PROXYSQL CLUSTER_NODE_UUID ")))) {
int l = strlen("PROXYSQL CLUSTER_NODE_UUID ");
if (sess->client_myds->addr.port == 0) {
@ -9569,7 +9621,7 @@ int ProxySQL_Admin::stats___save_mysql_query_digest_to_sqlite(
int num_rows = resultset ? resultset->rows_count : digest_umap->size();
int max_bulk_row_idx = num_rows/32;
max_bulk_row_idx=max_bulk_row_idx*32;
auto it = resultset ? (std::unordered_map<uint64_t, void *>::iterator)NULL : digest_umap->cbegin();
auto it = resultset ? digest_umap->cend() : digest_umap->cbegin();
int i = 0;
// If the function do not receives a resultset, it gets the values directly from the digest_umap
while (resultset ? i != resultset->rows_count : it != digest_umap->end()) {

@ -63,6 +63,10 @@ MICROHTTPD_DIR=$(DEPS_PATH)/libmicrohttpd/libmicrohttpd/src
MICROHTTPD_IDIR=$(MICROHTTPD_DIR)/include
MICROHTTPD_LDIR=$(MICROHTTPD_DIR)/microhttpd/.libs
COREDUMPER_DIR=$(DEPS_PATH)/coredumper/coredumper
COREDUMPER_IDIR=$(COREDUMPER_DIR)/include
COREDUMPER_LDIR=$(COREDUMPER_DIR)/src
CURL_DIR=$(DEPS_PATH)/curl/curl
CURL_IDIR=$(CURL_DIR)/include
CURL_LDIR=$(CURL_DIR)/lib/.libs
@ -83,6 +87,10 @@ LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIA
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDIRS+= -L$(COREDUMPER_LDIR)
endif
ifeq ($(UNAME_S),Darwin)
IDIRS+= -I/usr/local/include
LDIRS+= -L/usr/local/lib -L/opt/homebrew/lib
@ -152,11 +160,15 @@ LDFLAGS+= -fsanitize=address
endif
NOJEMALLOC := $(shell echo $(NOJEMALLOC))
STATICMYLIBS=-Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lcurl -lssl -lcrypto -lev
ifeq ($(NOJEMALLOC),1)
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lcurl -lssl -lcrypto -lev -Wl,-Bdynamic -lgnutls -lpthread -lm -lz -lrt -lprometheus-cpp-pull -lprometheus-cpp-core -luuid $(EXTRALINK)
else
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lcurl -lssl -lcrypto -lev -Wl,-Bdynamic -lgnutls -lpthread -lm -lz -lrt -lprometheus-cpp-pull -lprometheus-cpp-core -luuid $(EXTRALINK)
STATICMYLIBS+= -ljemalloc
endif
ifeq ($(UNAME_S),Linux)
STATICMYLIBS+= -lcoredumper
endif
MYLIBS=-Wl,--export-dynamic $(STATICMYLIBS) -Wl,-Bdynamic -lgnutls -lpthread -lm -lz -lrt -lprometheus-cpp-pull -lprometheus-cpp-core -luuid $(EXTRALINK)
ifeq ($(UNAME_S),Darwin)
MYLIBS=-lre2 -lmariadbclient -lpthread -lm -lz -liconv -lgnutls -lprometheus-cpp-pull -lprometheus-cpp-core -luuid
@ -177,7 +189,7 @@ endif
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
ifeq ($(UNAME_S),Darwin)
LIBPROXYSQLAR=$(LDIR)/libproxysql.a ../deps/jemalloc/jemalloc/lib/libjemalloc.a ../deps/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a ../deps/libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a ../deps/pcre/pcre/.libs/libpcre.a ../deps/pcre/pcre/.libs/libpcrecpp.a ../deps/libdaemon/libdaemon/libdaemon/.libs/libdaemon.a ../deps/libconfig/libconfig/lib/.libs/libconfig++.a ../deps/libconfig/libconfig/lib/.libs/libconfig.a ../deps/curl/curl/lib/.libs/libcurl.a ../deps/sqlite3/sqlite3/sqlite3.o ../deps/libinjection/libinjection/src/libinjection.a ../deps/libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a ../deps/libev/libev-4.24/.libs/libev.a
LIBPROXYSQLAR=$(LDIR)/libproxysql.a ../deps/jemalloc/jemalloc/lib/libjemalloc.a ../deps/libmicrohttpd/libmicrohttpd/src/microhttpd/.libs/libmicrohttpd.a ../deps/libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a ../deps/pcre/pcre/.libs/libpcre.a ../deps/pcre/pcre/.libs/libpcrecpp.a ../deps/libdaemon/libdaemon/libdaemon/.libs/libdaemon.a ../deps/libconfig/libconfig/lib/.libs/libconfig++.a ../deps/libconfig/libconfig/lib/.libs/libconfig.a ../deps/curl/curl/lib/.libs/libcurl.a ../deps/sqlite3/sqlite3/sqlite3.o ../deps/libinjection/libinjection/src/libinjection.a ../deps/libhttpserver/libhttpserver/build/src/.libs/libhttpserver.a ../deps/libev/libev/.libs/libev.a
endif
LIBPROXYSQLAR+= $(SSL_LDIR)/libssl.a $(SSL_LDIR)/libcrypto.a $(CITYHASH_DIR)/libcityhash.a

Loading…
Cancel
Save