├── .github └── issue_template.md ├── .gitignore ├── CHANGELOG.md ├── FAQ.md ├── INSTALL.md ├── LICENSE ├── Makefile ├── README.md ├── RUNNING.md ├── binaries └── .gitignore ├── bounty.md ├── build_images.py ├── compile_examples.txt ├── deps ├── Makefile ├── cityhash │ └── cityhash.tar.gz ├── clickhouse-cpp │ └── clickhouse-cpp.tar.gz ├── curl │ ├── COPYING │ ├── curl │ └── curl-7.57.0.tar.gz ├── google-coredumper │ └── google-coredumper.tar.gz ├── jemalloc │ ├── COPYING │ ├── README │ ├── issue823.520.patch │ ├── issue823.patch │ ├── jemalloc │ ├── jemalloc-4.3.1.tar.bz2 │ └── jemalloc-5.2.0.tar.bz2 ├── json │ └── json.hpp ├── libconfig │ ├── libconfig │ ├── libconfig-1.4.9.tar.gz │ └── libconfig-1.7.2.tar.gz ├── libdaemon │ ├── LICENSE │ ├── README │ ├── libdaemon │ └── libdaemon-0.14.tar.gz ├── libev │ ├── LICENSE │ ├── libev │ └── libev-4.24.tar.gz ├── libmicrohttpd │ ├── COPYING │ ├── libmicrohttpd │ └── libmicrohttpd-0.9.55.tar.gz ├── libssl │ ├── openssl │ └── openssl-1.1.1b.tar.gz ├── lz4 │ ├── LICENSE │ ├── lz4 │ └── lz4-1.7.5.tar.gz ├── mariadb-client-library │ ├── COPYING.LIB │ ├── README │ ├── ma_alloc.c.patch │ ├── ma_charset.c.patch │ ├── ma_password.c.patch │ ├── ma_pvio.c.patch │ ├── ma_secure.c.patch │ ├── mariadb-connector-c-2.3.1-src.tar.gz │ ├── mariadb-connector-c-3.0.2-src.tar.gz │ ├── mariadb-connector-c-3.0.9-src.tar.gz │ ├── mariadb_async.c.patch │ ├── mariadb_client │ ├── mariadb_lib.c.patch │ ├── mariadb_stmt.c.patch │ ├── mysql.h.patch │ ├── net.c.patch │ ├── password.c.patch │ ├── unittest_basic-t.c.patch │ └── unittest_charset.c.patch ├── pcre │ ├── LICENCE │ ├── pcre │ └── pcre-8.39.tar.gz ├── re2 │ ├── 2018-07-01.tar.gz │ ├── LICENSE │ ├── mutex.h.patch │ ├── re2 │ └── re2.tar.gz └── sqlite3 │ ├── from_unixtime.patch │ ├── sqlite-amalgamation-3190200.tar.gz │ └── sqlite3 ├── diamond ├── ProxySQLCollector.conf └── proxysqlstat.py ├── doc ├── internal │ ├── Standard_ProxySQL_Admin.txt │ ├── Stats_API.txt │ ├── command_line_options.txt │ ├── global_variables.txt │ └── query_parser.txt └── release_notes │ ├── ProxySQL_v1.2.2.md │ ├── ProxySQL_v1.2.3.md │ ├── ProxySQL_v1.2.4.md │ ├── ProxySQL_v1.3.0.md │ ├── ProxySQL_v1.3.0g.md │ ├── ProxySQL_v1.3.2.md │ ├── ProxySQL_v1.3.3.md │ └── ProxySQL_v1.4.4.md ├── docker-compose.yml ├── docker ├── 1backend-complex-config │ ├── docker-compose.yml │ ├── mysql │ │ ├── Dockerfile │ │ ├── import_schema.sh │ │ └── schema.sql │ └── proxysql │ │ ├── Dockerfile │ │ ├── compile_and_start_proxysql.sh │ │ └── proxysql.cnf ├── images │ ├── mysql │ │ ├── mysql-empty │ │ │ └── Dockerfile │ │ └── mysql-simple-dump │ │ │ ├── Dockerfile │ │ │ ├── import_schema.sh │ │ │ └── schema.sql │ └── proxysql │ │ ├── deb-compliant │ │ ├── bionic-package │ │ │ └── ctl │ │ │ │ └── proxysql.ctl │ │ ├── ctl │ │ │ └── proxysql.ctl │ │ ├── entrypoint │ │ │ └── entrypoint.bash │ │ └── pre-systemd │ │ │ └── ctl │ │ │ └── proxysql.ctl │ │ ├── legacy │ │ ├── Makefile.legacy │ │ ├── centos5-build │ │ │ ├── proxysql.spec │ │ │ └── rpmmacros │ │ ├── centos67-build │ │ │ ├── proxysql.spec │ │ │ └── rpmmacros │ │ ├── centos7-build │ │ │ ├── proxysql.spec │ │ │ └── rpmmacros │ │ ├── debian-7.8-build │ │ │ └── proxysql.ctl │ │ ├── debian-8.2-build │ │ │ └── proxysql.ctl │ │ ├── debian-9-build │ │ │ └── proxysql.ctl │ │ ├── debian-9.4-build │ │ │ └── proxysql.ctl │ │ ├── fedora24-build │ │ │ ├── proxysql.spec │ │ │ └── rpmmacros │ │ ├── fedora27-build │ │ │ ├── proxysql.spec │ │ │ └── rpmmacros │ │ ├── proxysql │ │ │ ├── Dockerfile │ │ │ └── compile_and_start_proxysql.sh │ │ ├── ubuntu-12.04-build │ │ │ └── proxysql.ctl │ │ ├── ubuntu-14.04-build │ │ │ └── proxysql.ctl │ │ ├── ubuntu-15.10-build │ │ │ └── proxysql.ctl │ │ └── ubuntu-16.04-build │ │ │ └── proxysql.ctl │ │ ├── proxysql │ │ ├── Dockerfile │ │ ├── compile_and_start_proxysql.sh │ │ └── proxysql.cnf │ │ └── rhel-compliant │ │ ├── entrypoint │ │ └── entrypoint.bash │ │ └── rpmmacros │ │ ├── .rpmmacros │ │ └── rpmbuild │ │ └── SPECS │ │ └── proxysql.spec └── scenarios │ ├── 1backend │ └── docker-compose.yml │ ├── 5backends-replication │ ├── docker-compose.yml │ ├── master-conf.d │ │ └── my.cnf │ ├── slave1-conf.d │ │ └── my.cnf │ ├── slave2-conf.d │ │ └── my.cnf │ ├── slave3-conf.d │ │ └── my.cnf │ └── slave4-conf.d │ │ └── my.cnf │ └── repl1 │ ├── app.sh │ ├── configure.sh │ ├── configure_repl_hostgroup.sh │ ├── mysql.sh │ ├── mysql_add.cnf_ │ ├── proxy.sh │ ├── test1.py │ ├── test1_.py │ ├── vars │ └── vars2 ├── etc ├── init.d │ └── proxysql ├── logrotate.d │ └── proxysql └── proxysql.cnf ├── include ├── ClickHouse_Authentication.hpp ├── ClickHouse_Server.h ├── MySQL_Authentication.hpp ├── MySQL_Data_Stream.h ├── MySQL_HostGroups_Manager.h ├── MySQL_LDAP_Authentication.hpp ├── MySQL_Logger.hpp ├── MySQL_Monitor.hpp ├── MySQL_PreparedStatement.h ├── MySQL_Protocol.h ├── MySQL_Session.h ├── MySQL_Thread.h ├── ProxySQL_Cluster.hpp ├── ProxySQL_HTTP_Server.hpp ├── ProxySQL_Statistics.hpp ├── SQLite3_Server.h ├── SpookyV2.h ├── StatCounters.h ├── btree.h ├── btree_container.h ├── btree_map.h ├── btree_set.h ├── btree_test.h ├── c_tokenizer.h ├── configfile.hpp ├── cpp.h ├── ezOptionParser.hpp ├── fileutils.hpp ├── gen_utils.h ├── mysql_backend.h ├── mysql_connection.h ├── proxy_defines.h ├── proxysql.h ├── proxysql_admin.h ├── proxysql_atomic.h ├── proxysql_debug.h ├── proxysql_glovars.hpp ├── proxysql_gtid.h ├── proxysql_hash.h ├── proxysql_macros.h ├── proxysql_mem.h ├── proxysql_structs.h ├── query_cache.hpp ├── query_processor.h ├── safe_btree.h ├── safe_btree_map.h ├── safe_btree_set.h ├── set_parser.h ├── sqlite3db.h ├── thread.h ├── valgrind.h └── wqueue.h ├── lib ├── Chart_bundle_js.cpp ├── ClickHouse_Authentication.cpp ├── ClickHouse_Server.cpp ├── Makefile ├── MySQL_Authentication.cpp ├── MySQL_HostGroups_Manager.cpp ├── MySQL_Logger.cpp ├── MySQL_Monitor.cpp ├── MySQL_PreparedStatement.cpp ├── MySQL_Protocol.cpp ├── MySQL_Session.cpp ├── MySQL_Thread.cpp ├── ProxySQL_Admin.cpp ├── ProxySQL_Cluster.cpp ├── ProxySQL_GloVars.cpp ├── ProxySQL_HTTP_Server.cpp ├── ProxySQL_Statistics.cpp ├── Query_Cache.cpp ├── Query_Processor.cpp ├── SQLite3_Server.cpp ├── SpookyV2.cpp ├── c_tokenizer.c ├── configfile.cpp ├── debug.cpp ├── font-awesome.min.css.cpp ├── gen_utils.cpp ├── main-bundle.min.css.cpp ├── mysql_backend.cpp ├── mysql_connection.cpp ├── mysql_data_stream.cpp ├── network.cpp ├── set_parser.cpp ├── sqlite3db.cpp └── thread.cpp ├── microbench └── PR1977_bench.cpp ├── proxysql-tests.ini.example ├── proxysql_notes.txt ├── requirements.txt ├── scenarios.py ├── src ├── Makefile ├── gdb-commands.txt ├── http_server.key ├── http_server.pem ├── main.cpp ├── newreq.pem ├── proxysql.cfg └── proxysql_global.cpp ├── systemd └── system │ └── proxysql.service ├── test ├── ChangeUser │ ├── .gitignore │ ├── Makefile │ └── client1.cpp ├── PrepStmt │ ├── .gitignore │ ├── Makefile │ ├── client1.cpp │ ├── client2.cpp │ ├── client3.cpp │ ├── client4.cpp │ ├── client5.cpp │ ├── client6.cpp │ ├── client7.cpp │ ├── client8.cpp │ └── client9.cpp ├── Vagrantfile ├── __init__.py ├── admin_tables_test.py ├── admin_test.py ├── authentication_test.py ├── check_result.py ├── config_file_parsing_test.py ├── docker_fleet.py ├── encrypt │ ├── .gitignore │ ├── Makefile │ └── client1.cpp ├── fast_rand.c ├── how_to.md ├── jemalloc │ └── issue522.c ├── main ├── main.cpp ├── monot ├── monot.cpp ├── one_backend_test.py ├── polygon.hpp ├── proxysql_base_test.py ├── proxysql_ping_thread.py ├── proxysql_tests_config.py ├── regextest │ ├── .gitignore │ ├── Makefile │ └── client1.cpp ├── replication_topology_awareness_test.py ├── set_parser_test │ ├── .gitignore │ ├── Makefile │ └── setparsertest.cpp └── sysbench_test.py └── tools ├── Makefile ├── check_variables.pl ├── eventslog_reader_sample.cpp ├── proxysql_galera_checker.sh └── proxysql_galera_writer.pl /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | This is the place for paid support and community users to report a **reproducible bug** in ProxySQL, suggest enhancements or make feature requests. This also includes documentation errors and/or missing documentation. 2 | 3 | * Remember, this is the place for fixing and improving ProxySQL rather than the place to get free support. 4 | * If you do not have a paid support contract please try https://groups.google.com/forum/#!forum/proxysql. Due to the high volume of requests, we are unable to always provide timely support for community users. 5 | 6 | If you are submitting a reproducible bug report, please provide: 7 | [ ] A clear description of your issue 8 | [ ] The version of OS and ProxySQL 9 | [ ] Every step to reproduce the issue 10 | [ ] The FULL error log (not just the last few lines) 11 | [ ] If it is a crashing bug, please check here: https://github.com/sysown/proxysql/wiki/How-to-report-a-crash-bug 12 | 13 | Please use markdown to format code or SQL: https://guides.github.com/features/mastering-markdown/ 14 | 15 | Thank you! 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.oo 5 | *.oo2 6 | *.pyc 7 | 8 | # Libraries 9 | *.lib 10 | *.a 11 | 12 | # Shared objects (inc. Windows DLLs) 13 | *.dll 14 | *.so 15 | *.so.* 16 | *.dylib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | 23 | # gcov 24 | *.gcda 25 | *.gcno 26 | 27 | callgrind.out.* 28 | cachegrind.out.* 29 | 30 | oldcode/tests/connect_speed 31 | 32 | *.swp 33 | 34 | 35 | # SQLITE files 36 | *.db 37 | *.db-shm 38 | *.db-wal 39 | 40 | 41 | #pidfile and errorlog 42 | *.pid 43 | *.log 44 | *.err 45 | 46 | #binary 47 | src/proxysql 48 | src/*pem 49 | binaries/*deb 50 | binaries/*rpm 51 | tools/eventslog_reader_sample 52 | 53 | proxysql-2.0.0/ 54 | docker/images/proxysql/rhel-compliant/rpmmacros 55 | 56 | #core 57 | core 58 | 59 | #config 60 | proxysql.cnf* 61 | proxysql.db* 62 | 63 | jeprof*heap 64 | perf.data* 65 | 66 | notes.txt 67 | architecture.txt 68 | 69 | 70 | 71 | ### DEPS 72 | 73 | #jemalloc source 74 | deps/jemalloc/jemalloc-3.6.0/ 75 | deps/jemalloc/jemalloc-4.1.0/ 76 | deps/jemalloc/jemalloc-4.2.1/ 77 | deps/jemalloc/jemalloc-4.3.1/ 78 | deps/jemalloc/jemalloc-5.2.0/ 79 | 80 | #libdaemon 81 | deps/libdaemon/libdaemon-0.14/ 82 | 83 | #mariadb client library 84 | deps/mariadb-client-library/mariadb_client-2.0.0-Linux-x86/ 85 | deps/mariadb-client-library/mariadb_client-2.0.0-Linux-x86_64/ 86 | deps/mariadb-client-library/mariadb_client-2.0.0-src/ 87 | deps/mariadb-client-library/mariadb-connector-c-2.1.0-src/ 88 | deps/mariadb-client-library/mariadb-connector-c-2.3.1/ 89 | deps/mariadb-client-library/mariadb-connector-c-3.0.2-src/ 90 | deps/mariadb-client-library/mariadb-connector-c-3.0.9-src/ 91 | 92 | #glib 93 | deps/glib/glib-2.40.0/ 94 | 95 | #libevent 96 | deps/libevent/libevent-2.0.22-stable/ 97 | 98 | #memcached 99 | deps/memcached/memcached-1.4.20/ 100 | 101 | #libconfig 102 | deps/libconfig/libconfig-1.4.9/ 103 | deps/libconfig/libconfig-1.7.2/ 104 | 105 | #libmicrohttpd 106 | deps/libmicrohttpd/libmicrohttpd-0.9.55/ 107 | 108 | #clickhouse 109 | deps/clickhouse-cpp/clickhouse-cpp/ 110 | deps/cityhash/cityhash/ 111 | deps/lz4/lz4-1.7.5/ 112 | deps/lz4/lz4/ 113 | 114 | #re2 115 | deps/re2/re2/ 116 | deps/re2/re2-2018-07-01/ 117 | deps/pcre/pcre-8.39/ 118 | deps/pcre/pcre/ 119 | 120 | # curl 121 | deps/curl/curl/ 122 | deps/curl/curl-7.57.0/ 123 | 124 | deps/libev/libev-4.24/ 125 | 126 | #protobuf 127 | deps/protobuf/protobuf-2.6.1/ 128 | 129 | deps/sqlite3/sqlite-amalgamation-3150000/ 130 | deps/sqlite3/sqlite-amalgamation-3190200/ 131 | deps/sqlite3/sqlite-amalgamation-3270200/ 132 | 133 | deps/clickhouse-cpp 134 | deps/cityhash/cityhash/ 135 | deps/lz4/lz4-1.7.5/ 136 | 137 | #libev 138 | deps/libev/libev-4.24/ 139 | 140 | #libssl 141 | deps/libssl/openssl-1.1.0h/ 142 | deps/libssl/openssl-1.1.1b/ 143 | 144 | #google coredumper 145 | deps/google-coredumper/google-coredumper/ 146 | 147 | test/.vagrant 148 | .DS_Store 149 | proxysql-tests.ini 150 | 151 | #heaptrack 152 | heaptrack.* 153 | 154 | #eclipse 155 | .cproject 156 | .project 157 | .settings/ 158 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | v0.3.0-beta1 2 | ============= 3 | 4 | * using libdaemon to daemonize the ProxySQL process 5 | * added angel process that is able to monitor and restart ProxySQL 6 | * added separate error log 7 | * integrated MariaDB client library 8 | * using libevent for connecting and querying backend MySQL servers in Monitor module 9 | * added transaction awareness within the Proxy 10 | * added a per-user: 11 | * max_connection value that limits the number of connections from the same user 12 | * transaction_persistent flag that keeps transactions within the same hostgroup for a certain user 13 | * add debug build target (make debug will now build a binary with vs. make) 14 | * introduce support for packets larger than 16 MB (the maximal single packet size from MySQL binary protocol) 15 | * handling in-memory stats database locking errors gracefully by retrying (this leads to less errors when gathering stats under load) 16 | * added possibility of killing a query from a remote backend server 17 | * implemented LOAD MYSQL QUERY RULES FROM CONFIG 18 | * implemented SAVE MYSQL USERS FROM RUNTIME 19 | * implemented PROXYSQL FLUSH LOGS that makes log rotation possible 20 | * implemented some new admin interface queries 21 | * select @@version_comment limit 1 22 | * show charset 23 | * show collation 24 | * show tables from 25 | * added new admin tables 26 | * stats_mysql_processlist 27 | * stats_mysql_connection_pool 28 | * stats_mysql_query_digest 29 | * stats_mysql_query_digest_reset 30 | * added new variables for config file 31 | * connect_timeout_server_max 32 | * free_connections_pct 33 | * connect_retries_delay 34 | * max_transaction_time 35 | * max_connections 36 | * default_query_delay 37 | * default_query_timeout 38 | * sessions_sort 39 | * default_reconnect 40 | * improved logging 41 | * support for 2 different config files 42 | * proxysql.cfg 43 | * proxysql.cnf -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | How to install ProxySQL 2 | ======================= 3 | 4 | ProxySQL offers 2 types of releases: 5 | - pre-packaged versions of the __last stable version__ (periodically updated at `https://github.com/sysown/proxysql/releases`). 6 | The list of currently supported operating systems for binary packaging is: 7 | - [Ubuntu 14](https://github.com/sysown/proxysql/releases/download/v1.3.4/proxysql_1.3.4-ubuntu14_amd64.deb) 8 | - [Ubuntu 12](https://github.com/sysown/proxysql/releases/download/v1.3.4/proxysql_1.3.4-ubuntu12_amd64.deb) 9 | - [CentOS 7](https://github.com/sysown/proxysql/releases/download/v1.3.4/proxysql-1.3.4-1-centos7.x86_64.rpm) 10 | 11 | Installing from source 12 | ---------------------- 13 | Make sure you have installed the equivalent for each of these packages for your operating system: 14 | - automake 15 | - bzip2 16 | - cmake 17 | - make 18 | - g++ 19 | - gcc 20 | - git 21 | - patch 22 | - openssl 23 | - openssl-devel # Only for RHEL / CentOS based 24 | - libssl-dev # Only for Debian / Ubuntu based 25 | 26 | Shortcut commands for installing pre-requisites: 27 | ``` 28 | # RHEL / CentOS < 7: 29 | yum install automake bzip2 cmake make g++ gcc git openssl openssl-devel patch 30 | 31 | # CentOS 7.4+ / Fedora 28+: 32 | yum install automake bzip2 cmake make gcc-c++ gcc git openssl openssl-devel patch 33 | 34 | # Debian / Ubuntu Based: 35 | apt-get install automake bzip2 cmake make g++ gcc git openssl libssl-dev patch 36 | ``` 37 | 38 | On Mac OSX, Proxysql's dependencies are not fully satisfied by the tools included with the XCode/clang toolkit. The Proxysql build system needs to be told where to find non-system `curl` (and possibly `openssl`) libraries. Using the [Homebrew](https://brew.sh/) OSX package manager, dependencies can be installed and located on OSX like this: 39 | 40 | ```bash 41 | brew install automake bzip2 cmake make git gpatch openssl curl 42 | export OPENSSL_ROOT_DIR="$(brew --prefix openssl)" 43 | export CXXFLAGS="${CXXFLAGS:-} -I$(brew --prefix openssl)/include -I$(brew --prefix curl)/include" 44 | export LDFLAGS="${LDFLAGS:-} -L$(brew --prefix openssl)/lib" 45 | ``` 46 | 47 | Go to the directory where you cloned the repo (or unpacked the tarball) and run: 48 | 49 | ```bash 50 | make 51 | sudo make install 52 | ``` 53 | 54 | Compilation time should be around a couple of minutes for the first time around. The configuration file will be found at `/etc/proxysql.cnf` afterwards. 55 | 56 | Once you have installed it, please take a look at the document about [running and operating the proxy](https://github.com/sysown/proxysql/blob/master/RUNNING.md). 57 | -------------------------------------------------------------------------------- /binaries/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /bounty.md: -------------------------------------------------------------------------------- 1 | # Pull Request Bounty for Politehnica Students in Summer 2015 2 | 3 | ProxySQL is an open-source, high-performance proxy for MySQL and compatible forks. 4 | Its main values are: 5 | * high performance 6 | * high availability (since it's a proxy, whenever it's down, access to the database is down as well) 7 | * flexibility (allow the user to customize the behaviour of the proxy as much possible) 8 | 9 | How will you use these values? Make sure you take them into consideration with 10 | each coding decision that you make. 11 | 12 | # How is this going to work? 13 | 14 | The value of the prize is $150, and it will be awarded for the best pull 15 | request submitted from your own fork. The pull requests should be sumitted until 16 | Friday, July 31st 2015, midnight in Bucharest time. In order to choose something 17 | to work on, ask questions on the repo issues or ping us via e-mail asking for 18 | guidance. 19 | 20 | The pull requests will be evaluated, subjectively, by @renecannao and @aismail, 21 | by the following criteria: 22 | * choice of problem (which of the issues did you choose, how important it is) 23 | * technical solution (how well written is it, how well documented, how efficient) 24 | 25 | Any undergraduate student from Politehnica University of Bucharest, Faculty of 26 | Automatic Control and Computers is allowed to participate. 27 | 28 | We will publish the result on Monday, July 13th 2015 and will contact the 29 | winner to send the prize :) 30 | 31 | # Notes 32 | 33 | The idea of this bounty came from @aismail's presentation at Politehnica's 34 | [Open Source Summer School](https://open-source.cs.pub.ro/summer-school/2014/wiki/home) 35 | from June 30th 2015 named "How to go to Vama Veche with Open Source". -------------------------------------------------------------------------------- /build_images.py: -------------------------------------------------------------------------------- 1 | from test.docker_fleet import DockerFleet 2 | 3 | fleet = DockerFleet() 4 | fleet.build_images() -------------------------------------------------------------------------------- /compile_examples.txt: -------------------------------------------------------------------------------- 1 | ## EXAMPLES of how to compiles on Linux and FreeBSD 2 | 3 | ## On Linux 4 | 5 | ## compile using gcc 4.8 6 | time CXX=g++-4.8 CC=gcc-4.8 make 7 | 8 | ## compile using clang 3.6 and stdc++4.8 9 | CXX=clang++-3.6 CC=clang-3.6 CPPFLAGS="-I/usr/include/c++/4.8/ -I/usr/include/x86_64-linux-gnu/c++/4.8" LDFLAGS="-L/usr/lib/x86_64-linux-gnu/ -L/usr/lib/gcc/x86_64-linux-gnu/4.8" make 10 | 11 | ==== 12 | 13 | ## On FreeBSD 14 | 15 | ## compile using gcc 4.8 16 | CC=gcc48 CXX=g++48 LIBS="-Wl,-rpath=/usr/local/lib/gcc48 -liconv" CPPFLAGS=-D_GLIBCXX_USE_C99 gmake 17 | 18 | ## compile using gcc 4.9 19 | CC=gcc49 CXX=g++49 LIBS="-Wl,-rpath=/usr/local/lib/gcc49 -liconv" CPPFLAGS=-D_GLIBCXX_USE_C99 gmake 20 | 21 | ## compile using clang 3.7 22 | CC=clang37 CXX=clang++37 gmake 23 | -------------------------------------------------------------------------------- /deps/cityhash/cityhash.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/cityhash/cityhash.tar.gz -------------------------------------------------------------------------------- /deps/clickhouse-cpp/clickhouse-cpp.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/clickhouse-cpp/clickhouse-cpp.tar.gz -------------------------------------------------------------------------------- /deps/curl/COPYING: -------------------------------------------------------------------------------- 1 | COPYRIGHT AND PERMISSION NOTICE 2 | 3 | Copyright (c) 1996 - 2017, Daniel Stenberg, , and many 4 | contributors, see the THANKS file. 5 | 6 | All rights reserved. 7 | 8 | Permission to use, copy, modify, and distribute this software for any purpose 9 | with or without fee is hereby granted, provided that the above copyright 10 | notice and this permission notice appear in all copies. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN 15 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 17 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 18 | OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | Except as contained in this notice, the name of a copyright holder shall not 21 | be used in advertising or otherwise to promote the sale, use or other dealings 22 | in this Software without prior written authorization of the copyright holder. 23 | -------------------------------------------------------------------------------- /deps/curl/curl: -------------------------------------------------------------------------------- 1 | curl-7.57.0 -------------------------------------------------------------------------------- /deps/curl/curl-7.57.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/curl/curl-7.57.0.tar.gz -------------------------------------------------------------------------------- /deps/google-coredumper/google-coredumper.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/google-coredumper/google-coredumper.tar.gz -------------------------------------------------------------------------------- /deps/jemalloc/COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise specified, files in the jemalloc source distribution are 2 | subject to the following license: 3 | -------------------------------------------------------------------------------- 4 | Copyright (C) 2002-2015 Jason Evans . 5 | All rights reserved. 6 | Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | Copyright (C) 2009-2015 Facebook, Inc. All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 1. Redistributions of source code must retain the above copyright notice(s), 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /deps/jemalloc/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general purpose malloc(3) implementation that emphasizes 2 | fragmentation avoidance and scalable concurrency support. jemalloc first came 3 | into use as the FreeBSD libc allocator in 2005, and since then it has found its 4 | way into numerous applications that rely on its predictable behavior. In 2010 5 | jemalloc development efforts broadened to include developer support features 6 | such as heap profiling, Valgrind integration, and extensive monitoring/tuning 7 | hooks. Modern jemalloc releases continue to be integrated back into FreeBSD, 8 | and therefore versatility remains critical. Ongoing development efforts trend 9 | toward making jemalloc among the best allocators for a broad range of demanding 10 | applications, and eliminating/mitigating weaknesses that have practical 11 | repercussions for real world applications. 12 | 13 | The COPYING file contains copyright and licensing information. 14 | 15 | The INSTALL file contains information on how to configure, build, and install 16 | jemalloc. 17 | 18 | The ChangeLog file contains a brief summary of changes for each release. 19 | 20 | URL: http://www.canonware.com/jemalloc/ 21 | -------------------------------------------------------------------------------- /deps/jemalloc/issue823.520.patch: -------------------------------------------------------------------------------- 1 | @@ -107,8 +107,7 @@ 2 | flag_opt_junk_alloc = (1U), 3 | flag_opt_junk_free = (1U << 1), 4 | flag_opt_zero = (1U << 2), 5 | - flag_opt_utrace = (1U << 3), 6 | - flag_opt_xmalloc = (1U << 4) 7 | + flag_opt_utrace = (1U << 3) 8 | }; 9 | static uint8_t malloc_slow_flags; 10 | 11 | @@ -922,8 +921,7 @@ 12 | malloc_slow_flags |= (opt_junk_alloc ? flag_opt_junk_alloc : 0) 13 | | (opt_junk_free ? flag_opt_junk_free : 0) 14 | | (opt_zero ? flag_opt_zero : 0) 15 | - | (opt_utrace ? flag_opt_utrace : 0) 16 | - | (opt_xmalloc ? flag_opt_xmalloc : 0); 17 | + | (opt_utrace ? flag_opt_utrace : 0); 18 | 19 | malloc_slow = (malloc_slow_flags != 0); 20 | } 21 | -------------------------------------------------------------------------------- /deps/jemalloc/issue823.patch: -------------------------------------------------------------------------------- 1 | @@ -928,8 +928,7 @@ 2 | | (opt_junk_free ? flag_opt_junk_free : 0) 3 | | (opt_quarantine ? flag_opt_quarantine : 0) 4 | | (opt_zero ? flag_opt_zero : 0) 5 | - | (opt_utrace ? flag_opt_utrace : 0) 6 | - | (opt_xmalloc ? flag_opt_xmalloc : 0); 7 | + | (opt_utrace ? flag_opt_utrace : 0); 8 | 9 | if (config_valgrind) 10 | malloc_slow_flags |= (in_valgrind ? flag_in_valgrind : 0); 11 | @@ -1588,7 +1587,7 @@ 12 | assert(!tsdn_null(tsdn) || ret == NULL); 13 | 14 | if (unlikely(ret == NULL)) { 15 | - if (slow_path && config_xmalloc && unlikely(opt_xmalloc)) { 16 | + if (config_xmalloc && unlikely(opt_xmalloc)) { 17 | malloc_printf(": Error in %s(): out of " 18 | "memory\n", func); 19 | abort(); 20 | -------------------------------------------------------------------------------- /deps/jemalloc/jemalloc: -------------------------------------------------------------------------------- 1 | jemalloc-5.2.0 -------------------------------------------------------------------------------- /deps/jemalloc/jemalloc-4.3.1.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/jemalloc/jemalloc-4.3.1.tar.bz2 -------------------------------------------------------------------------------- /deps/jemalloc/jemalloc-5.2.0.tar.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/jemalloc/jemalloc-5.2.0.tar.bz2 -------------------------------------------------------------------------------- /deps/libconfig/libconfig: -------------------------------------------------------------------------------- 1 | libconfig-1.7.2 -------------------------------------------------------------------------------- /deps/libconfig/libconfig-1.4.9.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libconfig/libconfig-1.4.9.tar.gz -------------------------------------------------------------------------------- /deps/libconfig/libconfig-1.7.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libconfig/libconfig-1.7.2.tar.gz -------------------------------------------------------------------------------- /deps/libdaemon/libdaemon: -------------------------------------------------------------------------------- 1 | libdaemon-0.14 -------------------------------------------------------------------------------- /deps/libdaemon/libdaemon-0.14.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libdaemon/libdaemon-0.14.tar.gz -------------------------------------------------------------------------------- /deps/libev/LICENSE: -------------------------------------------------------------------------------- 1 | All files in libev are 2 | Copyright (c)2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | Alternatively, the contents of this package may be used under the terms 29 | of the GNU General Public License ("GPL") version 2 or any later version, 30 | in which case the provisions of the GPL are applicable instead of the 31 | above. If you wish to allow the use of your version of this package only 32 | under the terms of the GPL and not to allow others to use your version of 33 | this file under the BSD license, indicate your decision by deleting the 34 | provisions above and replace them with the notice and other provisions 35 | required by the GPL in this and the other files of this package. If you do 36 | not delete the provisions above, a recipient may use your version of this 37 | file under either the BSD or the GPL. 38 | -------------------------------------------------------------------------------- /deps/libev/libev: -------------------------------------------------------------------------------- 1 | libev-4.24 -------------------------------------------------------------------------------- /deps/libev/libev-4.24.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libev/libev-4.24.tar.gz -------------------------------------------------------------------------------- /deps/libmicrohttpd/libmicrohttpd: -------------------------------------------------------------------------------- 1 | libmicrohttpd-0.9.55 -------------------------------------------------------------------------------- /deps/libmicrohttpd/libmicrohttpd-0.9.55.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libmicrohttpd/libmicrohttpd-0.9.55.tar.gz -------------------------------------------------------------------------------- /deps/libssl/openssl: -------------------------------------------------------------------------------- 1 | openssl-1.1.1b -------------------------------------------------------------------------------- /deps/libssl/openssl-1.1.1b.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/libssl/openssl-1.1.1b.tar.gz -------------------------------------------------------------------------------- /deps/lz4/LICENSE: -------------------------------------------------------------------------------- 1 | LZ4 Library 2 | Copyright (c) 2011-2016, Yann Collet 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /deps/lz4/lz4: -------------------------------------------------------------------------------- 1 | lz4-1.7.5 -------------------------------------------------------------------------------- /deps/lz4/lz4-1.7.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/lz4/lz4-1.7.5.tar.gz -------------------------------------------------------------------------------- /deps/mariadb-client-library/README: -------------------------------------------------------------------------------- 1 | This is LGPL MariaDB client library that can be used to connect to MySQL 2 | or MariaDB. 3 | 4 | This code is based on the LGPL libmysql client library from MySQL 3.23 5 | and PHP's mysqlnd extension. 6 | 7 | This product includes PHP software, freely available from 8 | 9 | 10 | The following are the main known limitations: 11 | 12 | - double to string conversion for prepared statements 13 | doesn't work correctly 14 | - support for dynamic columns is not integrated yet 15 | - Asynchronus interface is not integrated yet 16 | 17 | If you want to be part of this development effort, you can discuss this at 18 | maria-developers@lists.launchpad.org. 19 | 20 | If you are interested in sponsoring this effort, you can contact us at 21 | sales@askmonty.org 22 | 23 | The MariaDB team 24 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/ma_alloc.c.patch: -------------------------------------------------------------------------------- 1 | @@ -85,7 +85,7 @@ 2 | if (! next) 3 | { /* Time to alloc new block */ 4 | get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)), 5 | - (mem_root->block_size & ~1) * (mem_root->block_num >> 2)); 6 | + (mem_root->block_size & ~1) * ( (mem_root->block_num >> 2) < 4 ? 4 : (mem_root->block_num >> 2) ) ); 7 | 8 | if (!(next = (MA_USED_MEM*) malloc(get_size))) 9 | { 10 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/ma_charset.c.patch: -------------------------------------------------------------------------------- 1 | @@ -679,7 +679,7 @@ 2 | { 182, 1, "utf32", "utf32_unicode_520_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, 3 | { 183, 1, "utf32", "utf32_vietnamese_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, 4 | 5 | - { 192, 1, UTF8_MB3, UTF8_MB3"_general_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, 6 | + { 192, 1, UTF8_MB3, UTF8_MB3"_unicode_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, 7 | { 193, 1, UTF8_MB3, UTF8_MB3"_icelandic_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, 8 | { 194, 1, UTF8_MB3, UTF8_MB3"_latvian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, 9 | { 195, 1, UTF8_MB3, UTF8_MB3"_romanian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, 10 | @@ -732,6 +732,7 @@ 11 | { 247, 1, UTF8_MB4, UTF8_MB4"_vietnamese_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, 12 | 13 | { 254, 1, UTF8_MB3, UTF8_MB3"_general_cs", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, 14 | + { 255, 1, UTF8_MB4, UTF8_MB4"_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, 15 | { 576, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ 16 | { 577, 1, UTF8_MB3, UTF8_MB3"_myanmar_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ 17 | { 578, 1, UTF8_MB3, UTF8_MB3"_thai_520_w2", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ 18 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/ma_password.c.patch: -------------------------------------------------------------------------------- 1 | @@ -105,6 +105,35 @@ 2 | } 3 | } 4 | 5 | +unsigned char decode_char(char x) { 6 | + if (x >= '0' && x <= '9') 7 | + return (x - 0x30); 8 | + else if (x >= 'A' && x <= 'F') 9 | + return(x - 0x37); 10 | + else if (x >= 'a' && x <= 'f') 11 | + return(x - 0x57); 12 | + else { 13 | + fprintf(stderr,"%s:%d:%s(): [ERROR in libmariadbclient]: \n", __FILE__, __LINE__, __func__); 14 | + return 0; 15 | + } 16 | +} 17 | + 18 | +void unhex_pass(unsigned char *out, const char *in) { 19 | + int i=0; 20 | + for (i=0;ioptions.ssl_ca && !mysql->options.ssl_capath) 16 | < { 17 | < ok= 1; 18 | < DBUG_RETURN(1); 19 | < } 20 | < 21 | < if (!ok) 22 | < { 23 | < uint depth; 24 | < if (!(check_cert= X509_STORE_CTX_get_current_cert(ctx))) 25 | < DBUG_RETURN(0); 26 | < depth= X509_STORE_CTX_get_error_depth(ctx); 27 | < if (depth == 0) 28 | < ok= 1; 29 | < } 30 | < 31 | < /* 32 | < my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 33 | < ER(CR_SSL_CONNECTION_ERROR), 34 | < X509_verify_cert_error_string(ctx->error)); 35 | < */ 36 | < DBUG_RETURN(ok); 37 | < } 38 | < 39 | < 40 | 352d313 41 | < int verify; 42 | 372,376d332 43 | < verify= (!mysql->options.ssl_ca && !mysql->options.ssl_capath) ? 44 | < SSL_VERIFY_NONE : SSL_VERIFY_PEER; 45 | < 46 | < SSL_CTX_set_verify(SSL_context, verify, my_verify_callback); 47 | < SSL_CTX_set_verify_depth(SSL_context, 1); 48 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb-connector-c-2.3.1-src.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/mariadb-client-library/mariadb-connector-c-2.3.1-src.tar.gz -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb-connector-c-3.0.2-src.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/mariadb-client-library/mariadb-connector-c-3.0.2-src.tar.gz -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb-connector-c-3.0.9-src.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/mariadb-client-library/mariadb-connector-c-3.0.9-src.tar.gz -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb_async.c.patch: -------------------------------------------------------------------------------- 1 | @@ -479,19 +479,20 @@ 2 | struct mysql_set_character_set_params { 3 | MYSQL *mysql; 4 | const char *csname; 5 | + uint charsetnr; 6 | }; 7 | static void 8 | mysql_set_character_set_start_internal(void *d) 9 | { 10 | MK_ASYNC_INTERNAL_BODY( 11 | mysql_set_character_set, 12 | - (parms->mysql, parms->csname), 13 | + (parms->mysql, parms->csname, parms->charsetnr), 14 | parms->mysql, 15 | int, 16 | r_int) 17 | } 18 | int STDCALL 19 | -mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname) 20 | +mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname, uint charsetnr) 21 | { 22 | MK_ASYNC_START_BODY( 23 | mysql_set_character_set, 24 | @@ -500,6 +501,7 @@ 25 | WIN_SET_NONBLOCKING(mysql) 26 | parms.mysql= mysql; 27 | parms.csname= csname; 28 | + parms.charsetnr= charsetnr; 29 | }, 30 | 1, 31 | r_int, 32 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb_client: -------------------------------------------------------------------------------- 1 | mariadb-connector-c-3.0.2-src -------------------------------------------------------------------------------- /deps/mariadb-client-library/mariadb_stmt.c.patch: -------------------------------------------------------------------------------- 1 | @@ -124,6 +124,7 @@ 2 | case MYSQL_TYPE_TIMESTAMP: 3 | case MYSQL_TYPE_TINY: 4 | case MYSQL_TYPE_TINY_BLOB: 5 | + case MYSQL_TYPE_VARCHAR: 6 | case MYSQL_TYPE_VAR_STRING: 7 | case MYSQL_TYPE_YEAR: 8 | return 1; 9 | @@ -1143,6 +1144,7 @@ 10 | break; 11 | case MYSQL_TYPE_STRING: 12 | case MYSQL_TYPE_JSON: 13 | + case MYSQL_TYPE_VARCHAR: 14 | case MYSQL_TYPE_VAR_STRING: 15 | case MYSQL_TYPE_BLOB: 16 | case MYSQL_TYPE_TINY_BLOB: 17 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/mysql.h.patch: -------------------------------------------------------------------------------- 1 | @@ -490,7 +490,7 @@ 2 | unsigned long STDCALL mysql_thread_id(MYSQL *mysql); 3 | const char * STDCALL mysql_character_set_name(MYSQL *mysql); 4 | void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs); 5 | -int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); 6 | +int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname, uint charsetnr); 7 | 8 | my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...); 9 | my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg); 10 | @@ -509,6 +509,7 @@ 11 | const char *unix_socket, 12 | unsigned long clientflag); 13 | void STDCALL mysql_close(MYSQL *sock); 14 | +void STDCALL mysql_close_no_command(MYSQL *sock); 15 | int STDCALL mysql_select_db(MYSQL *mysql, const char *db); 16 | int STDCALL mysql_query(MYSQL *mysql, const char *q); 17 | int STDCALL mysql_send_query(MYSQL *mysql, const char *q, 18 | @@ -608,7 +609,7 @@ 19 | int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); 20 | 21 | int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, 22 | - const char *csname); 23 | + const char *csname, uint charsetnr); 24 | int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, 25 | int status); 26 | int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql, 27 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/net.c.patch: -------------------------------------------------------------------------------- 1 | @@ -224,16 +224,16 @@ 2 | /* see conc-71: we need to check the socket status first: 3 | if the socket is dead we set net->error, so net_flush 4 | will report an error */ 5 | - while (net_check_socket_status(net->vio->sd)) 6 | - { 7 | +// while (net_check_socket_status(net->vio->sd)) 8 | +// { 9 | /* vio_read returns size_t. so casting to long is required to check for -1 */ 10 | - if ((long)vio_read(net->vio, (gptr)net->buff, (size_t) net->max_packet) <= 0) 11 | +/* if ((long)vio_read(net->vio, (gptr)net->buff, (size_t) net->max_packet) <= 0) 12 | { 13 | net->error= 2; 14 | DBUG_PRINT("info", ("socket disconnected")); 15 | DBUG_VOID_RETURN; 16 | } 17 | - } 18 | + } */ 19 | net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ 20 | net->write_pos=net->buff; 21 | DBUG_VOID_RETURN; 22 | -------------------------------------------------------------------------------- /deps/mariadb-client-library/password.c.patch: -------------------------------------------------------------------------------- 1 | @@ -112,17 +112,47 @@ 2 | } 3 | } 4 | 5 | +unsigned char decode_char(char x) { 6 | + if (x >= '0' && x <= '9') 7 | + return (x - 0x30); 8 | + else if (x >= 'A' && x <= 'F') 9 | + return(x - 0x37); 10 | + else if (x >= 'a' && x <= 'f') 11 | + return(x - 0x57); 12 | + else { 13 | + fprintf(stderr,"%s:%d:%s(): [ERROR in libmariadbclient]: \n", __FILE__, __LINE__, __func__); 14 | + return 0; 15 | + } 16 | +} 17 | + 18 | +void unhex_pass(unsigned char *out, const char *in) { 19 | + int i=0; 20 | + for (i=0;i void Mutex::Lock() { } 9 | > void Mutex::Unlock() { } 10 | > bool Mutex::TryLock() { return 0 == 0; } 11 | > void Mutex::ReaderLock() { } 12 | > void Mutex::ReaderUnlock() { } 13 | 125,127c125,127 14 | < void Mutex::Lock() { SAFE_PTHREAD(pthread_mutex_lock(&mutex_)); } 15 | < void Mutex::Unlock() { SAFE_PTHREAD(pthread_mutex_unlock(&mutex_)); } 16 | < bool Mutex::TryLock() { return pthread_mutex_trylock(&mutex_) == 0; } 17 | --- 18 | > void Mutex::Lock() { } 19 | > void Mutex::Unlock() { } 20 | > bool Mutex::TryLock() { return 0 == 0; } 21 | -------------------------------------------------------------------------------- /deps/re2/re2: -------------------------------------------------------------------------------- 1 | re2-2018-07-01 -------------------------------------------------------------------------------- /deps/re2/re2.tar.gz: -------------------------------------------------------------------------------- 1 | 2018-07-01.tar.gz -------------------------------------------------------------------------------- /deps/sqlite3/from_unixtime.patch: -------------------------------------------------------------------------------- 1 | --- sqlite3.c 2017-05-26 00:15:22.000000000 +0200 2 | +++ /tmp/sqlite3.c 2017-05-29 20:12:54.644378605 +0200 3 | @@ -19772,6 +19772,44 @@ 4 | } 5 | 6 | /* 7 | +** from_unixtime( TIMESTRING) 8 | +** 9 | +** Return YYYY-MM-DD HH:MM:SS 10 | +*/ 11 | +static void from_unixtimeFunc( 12 | + sqlite3_context *context, 13 | + int argc, 14 | + sqlite3_value **argv 15 | +){ 16 | + DateTime p; 17 | + int i, n; 18 | + const unsigned char *z; 19 | + int eType; 20 | + memset(&p, 0, sizeof(p)); 21 | + if( argc==0 ){ 22 | + setDateTimeToCurrent(context, &p); 23 | + return; 24 | + } 25 | + if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT 26 | + || eType==SQLITE_INTEGER ){ 27 | + setRawDateNumber(&p, sqlite3_value_double(argv[0])); 28 | + }else{ 29 | + z = sqlite3_value_text(argv[0]); 30 | + if( !z || parseDateOrTime(context, (char*)z, &p) ){ 31 | + return; 32 | + } 33 | + } 34 | + if( z==0 || parseModifier(context, (char*)"unixepoch", 9, &p) ) return; 35 | + computeJD(&p); 36 | + if( p.isError || !validJulianDay(p.iJD) ) return; 37 | + char zBuf[100]; 38 | + computeYMD_HMS(&p); 39 | + sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d", 40 | + p.Y, p.M, p.D, p.h, p.m, (int)(p.s)); 41 | + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); 42 | +} 43 | + 44 | +/* 45 | ** time( TIMESTRING, MOD, MOD, ...) 46 | ** 47 | ** Return HH:MM:SS 48 | @@ -20061,6 +20099,7 @@ 49 | DFUNCTION(date, -1, 0, 0, dateFunc ), 50 | DFUNCTION(time, -1, 0, 0, timeFunc ), 51 | DFUNCTION(datetime, -1, 0, 0, datetimeFunc ), 52 | + DFUNCTION(from_unixtime, -1, 0, 0, from_unixtimeFunc ), 53 | DFUNCTION(strftime, -1, 0, 0, strftimeFunc ), 54 | DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), 55 | DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), 56 | -------------------------------------------------------------------------------- /deps/sqlite3/sqlite-amalgamation-3190200.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/deps/sqlite3/sqlite-amalgamation-3190200.tar.gz -------------------------------------------------------------------------------- /deps/sqlite3/sqlite3: -------------------------------------------------------------------------------- 1 | sqlite-amalgamation-3190200 -------------------------------------------------------------------------------- /diamond/ProxySQLCollector.conf: -------------------------------------------------------------------------------- 1 | enabled=True 2 | db = None 3 | host = 127.0.0.1 4 | passwd = stats 5 | port = 6032 6 | user = stats 7 | 8 | -------------------------------------------------------------------------------- /doc/internal/Standard_ProxySQL_Admin.txt: -------------------------------------------------------------------------------- 1 | Standard_ProxySQL_Admin.cpp contains the code that current implements the Admin Module. 2 | 3 | Currently it is in alpha stage (a lot of implementation details will change) 4 | and is implemented as the follow: 5 | 6 | main() calls create_ProxySQL_Admin() : this create a new object 7 | Standard_ProxySQL_Admin, that then calls init() . 8 | -------------------------------------------------------------------------------- /doc/internal/Stats_API.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This API should be simple. 5 | Each module should collect statistics and stores them internally, preferibly 6 | in a table format because this is how Admin will expect the results. 7 | 8 | Each module should implement 2 functions: 9 | - stats_get_tables_list() returns an array of pointer to variables name, where 10 | the last element is NULL; 11 | - stat_get_table() returns the content of such table in the form of a 12 | SQLite3_result resultset 13 | 14 | 15 | Important note: 16 | The reads should be considered in read committed isolation level. It is not 17 | possible to read multiple tables at the same time, therefore it is possible 18 | that the relation between these tables are not consistent. Due the temporary 19 | nature of statistics information, this glitch is absolutely expected. 20 | -------------------------------------------------------------------------------- /doc/internal/command_line_options.txt: -------------------------------------------------------------------------------- 1 | Command Line Options 2 | 3 | Configuration of proxysql is performed through the processing of a config file, or a database file, or a combination of both. 4 | 5 | Config file is a read only file that proxysql does not modify. 6 | Database file is a read write file that proxysql can modify. 7 | The path of the config file can be passed to proxysql through the --config option. 8 | The path to the database file cannot be passed to proxysql directly, instead it is possible to pass its directory (called datadir) through the --datadir option. 9 | The database file is named proxysql.db inside the datadir. 10 | Both config file and datadir have default values if not specified in the command line. 11 | 12 | If a datadir is not provided in the command line, the config file is read to parse a possible datadir. 13 | 14 | If a database file is present in the datadir, its configuration is used by proxysql. 15 | 16 | If the option --initial is present, the database file is deleted. 17 | If a database file does not exist (or deleted because of --initial), the config file is parsed and a new database file is created based on its content. 18 | 19 | If the option --reload is specified, the config file is parsed and an attempt to merge its content with the database file is performed. 20 | -------------------------------------------------------------------------------- /doc/internal/query_parser.txt: -------------------------------------------------------------------------------- 1 | ProxySQL implements query parsing in the Query_Processor class. 2 | 3 | 4 virtual functions are introduced in Query_Processor class: 4 | virtual void * query_parser_init(char *query, int query_length, int flags) {return NULL;}; 5 | virtual enum MYSQL_COM_QUERY_command query_parser_command_type(void *args) {return MYSQL_COM_QUERY___UNKNOWN;} 6 | virtual char * query_parser_first_comment(void *args) { return NULL; } 7 | virtual void query_parser_free(void *args) {}; 8 | 9 | query_parser_init() 10 | query_parser_init() get as arguments a pointer to the query, its length, and flags that are specific to Query_Processor implementation or simply ignored. 11 | Because multiple implementations of the query parsing should be possible, query_parser_init() returns a generic pointer that should point to a data structure created by query_parser_init() itself. The pointer needs to be passed at the end to query_parser_free() to be freed. 12 | 13 | query_parser_free() 14 | Free the structure originally created by query_parser_init() 15 | 16 | query_parser_command_type() 17 | Accept as argument the structure created by query_parser_init() and returns the type of query processed. 18 | 19 | query_parser_first_comment() 20 | Not implemented yet. 21 | In case the filterning need to be performed based on comments in the query, query_parser_first_comment() can return such comment. 22 | -------------------------------------------------------------------------------- /doc/release_notes/ProxySQL_v1.2.3.md: -------------------------------------------------------------------------------- 1 | # ProxySQL v1.2.3 2 | 3 | Release date: 2016-09-20 4 | 5 | ## Performance improvement 6 | 7 | None 8 | 9 | 10 | ## Usability improvement 11 | 12 | * Admin: introduced new table `runtime_mysql_users` [#691](../../../../issues/691) 13 | * Compile: new packages avaiable for Fedora24 14 | * Compile: new packages avaiable for Ubuntu16 15 | * Doc: updated documentation on passwords 16 | * General: added suppot for systemd (yet not included in binaries) 17 | 18 | 19 | ## New features 20 | 21 | * Admin: introduced new variable `admin-hash_passwords` to automatically hash mysql passwords [#676](../../../../issues/676) 22 | * Query Cache: aggressive memory purging when 90% of memory limit is reached [#690](../../../../issues/690) 23 | * Query Processor: added parsing for several SQL commands 24 | 25 | 26 | ## Bug fixes 27 | 28 | * Mirroring: fixes several bugs related to errors handling 29 | * Mirroring: fixes crashing bug 30 | * Query Cache: memory used was computed incorrectly 31 | * Connection Pool: a failed `CHANGE_USER` could cause a crash [#682](../../../../issues/682) 32 | 33 | 34 | ## Contributors 35 | 36 | Thanks to contributors, in alphabetical order: 37 | * @dveeden 38 | -------------------------------------------------------------------------------- /doc/release_notes/ProxySQL_v1.2.4.md: -------------------------------------------------------------------------------- 1 | # ProxySQL v1.2.4 2 | 3 | Release date: 2016-09-29 4 | 5 | ## Performance improvement 6 | 7 | None 8 | 9 | ## Usability improvement 10 | 11 | * Admin: Report in error log if unable to read config file [#705](../../../../issues/705) 12 | * Admin: Allow GO clients to connect to Admin interface using user "stats" [#708](../../../../issues/708) 13 | * Monitor: added [diamond Collector](../../diamond/) to export to graphite or similar 14 | 15 | ## New features 16 | 17 | * Admin: introduced new variable status related to connection pool usage [#703](../../../../issues/703) 18 | * Protocol: filters SHOW WARNINGS , [#696](../../../../issues/696) 19 | 20 | ## Bug fixes 21 | 22 | * Mirroring: crashing bug on mirrorred traffic and show mysql status [#699](../../../../issues/699) 23 | * Connection Pool: SSL did not work with RDS , [#700](../../../../issues/700) 24 | * Protocol: in some case, compressed packets were being corrupted [#297](../../../../issues/297) 25 | * Monitor: rows were not deleted from monitor tables [#704](../../../../issues/704) 26 | -------------------------------------------------------------------------------- /doc/release_notes/ProxySQL_v1.3.0.md: -------------------------------------------------------------------------------- 1 | # ProxySQL v1.3.0 2 | 3 | Release date: 2016-10-19 4 | 5 | ## Performance improvement 6 | 7 | * support for millions of connections. It is also able to handle workloads with hundreds thousands client connections, but only few connections are active. For example, 100k total connections, but only 100 active connections. 8 | * use of pthread_mutex for connection pool 9 | * several performance improvements 10 | 11 | 12 | ## Usability improvement 13 | 14 | * Packaging: version number now includes commit hash 15 | * Monitor: limit the number of Monitor thread to 16 16 | 17 | 18 | ## New features 19 | 20 | * EXPERIMENTAL support for proepared statements 21 | * Connection Pool: each MySQL_Thread now has a pair thread, therefore the number of threads executed are mysql-threads x 2 . The second set of MySQL_Threads are responsible to only handle idle connections. 22 | It also introduced two new global variables and a new global status: 23 | * `mysql-session_idle_ms` (default 1000) : when a session is idle for that long, it is moved to a thread responsible to handle idle connections 24 | * `mysql-session_idle_show_processlist` (default false) : specifies if idle connections are displayed on SHOW PROCESSLIST or on any query against `stats_mysql_processlist` 25 | * `Client_Connections_non_idle` : returns the number of client connections that are not idle, therefore handled by the main MySQL_Threads and not moved to the second set of MySQL_Threads responsible to only handle idle connections 26 | * Network: add support for IPv6 [#726](../../../../issues/726) and [#460](../../../../issues/460), thanks to @ton31337 27 | * Connection Pool: support for SO_REUSEPORT, it can be only enabled on the command line with -r or --reuseport at startup 28 | * Query Processor: added new variable mysql-digests_lowercase to always set digest to lowercase [#725](../../../../issues/725) 29 | 30 | 31 | ## Bug fixes 32 | 33 | * Query Processor: rules with only digest were matching everything [#717](../../../../issues/717) 34 | * Query Processor: rules without digest where incorrectly displayed [#719](../../../../issues/719) 35 | * General: Unix Socket Domain file was not removed at shutdown [#714](../../../../issues/714) 36 | * MySQL Protocol: upgrade from mariadb-connector-c 2.1.0 to 2.3.1 due to several bugs 37 | * Connection Pool: server is not shunned if max_user_connections is reached for user [#737](../../../../issues/737) 38 | 39 | -------------------------------------------------------------------------------- /doc/release_notes/ProxySQL_v1.3.2.md: -------------------------------------------------------------------------------- 1 | ## ProxySQL v1.3.2 2 | 3 | Release date: 2016-12-29 4 | 5 | Stable release v1.3.2 , released on 2016-12-29 6 | 7 | Compared to v1.3.1, has the following bugs fixed / enhancements: 8 | 9 | * Monitor: crashing bug and memory leak in `purge_idle_connection` fixed thanks to @efirs 10 | * Query routing: query session variables, combined with `transaction_persistent==true` were incorrectly disabling query routing [#837](../../../../issues/837) 11 | * Monitor/Galera: improvement on scheduler tool `proxysql_galera_checker.sh` , thanks to @grypyrg 12 | * MySQL Protocol: support for COM_QUERY + USE as equivalent to COM_INIT_DB [#718](../../../../issues/718) 13 | * Admin: improved the speed time to populate tables `stats_mysql_query_digest` and `stats_mysql_query_digest_text` 14 | 15 | Introduced two new variables, mainly to reduce memory footprint for wokload with a lot of unique queries [#766](../../../../issues/766): 16 | * mysql-query_digests_max_digest_length : defines the maximum length of `digest_text` as reported in `stats_mysql_query_digest` 17 | * mysql-query_digests_max_query_length : defines the maximum query length processed when computing query's `digest` and `digext_text` 18 | -------------------------------------------------------------------------------- /doc/release_notes/ProxySQL_v1.3.3.md: -------------------------------------------------------------------------------- 1 | ## ProxySQL v1.3.3 2 | 3 | Release date: 2016-12-29 4 | 5 | Stable release v1.3.3 , released on 2017-01-20 6 | 7 | Compared to v1.3.2, has the following bugs fixed / enhancements: 8 | 9 | * MySQL Protocol: handle for mysql [bug 66884](https://bugs.mysql.com/bug.php?id=66884) that could cause infinite loop [#873](../../../../issues/873) 10 | * MySQL Protocol: improved SSL connection over slow network, workaround for bug CONC-225 [#883](../../../../issues/833) 11 | * Query routing: in some circumstances `transaction_persistent` could disable routing after commit #889](../../../../issues/889) 12 | * Admin: `Latency_us` was incorrectly named `Latency_ms` [#882](../../../../issues/882) 13 | * Admin: improved scalability on access to `mysql_servers` 14 | * General: improved sypport for systemd 15 | * General: init script returns codes for LSB compliance 16 | * MySQL Protocol: removed assert() for unknown commands, and replaced with an error [#859](../../../../issues/859) 17 | * MySQL Protocol: return an error for `COM_PROCESS_KILL`, deprecated command [#858](../../../../issues/858) 18 | -------------------------------------------------------------------------------- /docker/1backend-complex-config/docker-compose.yml: -------------------------------------------------------------------------------- 1 | proxysql: 2 | build: proxysql 3 | links: 4 | - backend1hostgroup0 5 | ports: 6 | # ProxySQL admin port for MySQL commands 7 | - "6032:6032" 8 | # ProxySQL main port 9 | - "6033:6033" 10 | # gdbserver 11 | - "2345:2345" 12 | volumes: 13 | - /tmp/proxysql-tests:/opt/proxysql 14 | privileged: true 15 | 16 | backend1hostgroup0: 17 | build: mysql 18 | environment: 19 | MYSQL_ROOT_PASSWORD: root 20 | expose: 21 | - "3306" 22 | ports: 23 | - "13306:3306" 24 | -------------------------------------------------------------------------------- /docker/1backend-complex-config/mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | # We are creating a custom Dockerfile for MySQL as there is no easy way to 2 | # move a file from host into the container. In our case, it's schema.sql 3 | # There is a proposed improvement to "docker cp" but it's still being 4 | # discussed (https://github.com/docker/docker/issues/5846). 5 | FROM mysql:latest 6 | ADD ./schema.sql /tmp/ 7 | ADD ./import_schema.sh /tmp/ -------------------------------------------------------------------------------- /docker/1backend-complex-config/mysql/import_schema.sh: -------------------------------------------------------------------------------- 1 | cat /tmp/schema.sql | mysql -h 127.0.0.1 -u root -proot -------------------------------------------------------------------------------- /docker/1backend-complex-config/mysql/schema.sql: -------------------------------------------------------------------------------- 1 | # Used by monitoring module for connection health 2 | CREATE USER monitor@'%' IDENTIFIED BY 'monitor'; 3 | GRANT ALL PRIVILEGES ON test.* TO 'monitor'@'%'; 4 | FLUSH PRIVILEGES; -------------------------------------------------------------------------------- /docker/1backend-complex-config/proxysql/Dockerfile: -------------------------------------------------------------------------------- 1 | # We're using Ubuntu 14:04 because ProxySQL compilation needs one of the latest 2 | # g++ compilers. Also, it's a long term release. 3 | FROM ubuntu:14.04 4 | MAINTAINER Andrei Ismail 5 | RUN apt-get update && apt-get install -y\ 6 | automake\ 7 | cmake\ 8 | make\ 9 | g++\ 10 | gcc\ 11 | gdb\ 12 | gdbserver\ 13 | git\ 14 | libmysqlclient-dev\ 15 | libssl-dev\ 16 | libtool 17 | 18 | RUN cd /opt; git clone https://github.com/akopytov/sysbench.git 19 | RUN cd /opt/sysbench; ./autogen.sh; ./configure --bindir=/usr/bin; make; make install 20 | 21 | ADD ./proxysql.cnf /etc/ 22 | RUN mkdir -p /var/lib/proxysql 23 | ADD ./compile_and_start_proxysql.sh /tmp/ 24 | RUN chmod +x /tmp/compile_and_start_proxysql.sh 25 | 26 | CMD ["/tmp/compile_and_start_proxysql.sh"] 27 | -------------------------------------------------------------------------------- /docker/1backend-complex-config/proxysql/compile_and_start_proxysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d /opt/proxysql ]; then 4 | mkdir -p /opt/proxysql 5 | cp -R /tmp/proxysql-src/* /opt/proxysql 6 | cd /opt/proxysql 7 | make clean && make > /tmp/proxysql_compile.log 8 | fi 9 | 10 | cd /opt/proxysql/src 11 | # TODO(andrei): re-enable the commented line when figuring out interactive mode 12 | # gdbserver 0.0.0.0:2345 ./proxysql --initial -f -c /etc/proxysql.cnf 13 | ./proxysql --initial -f -c /etc/proxysql.cnf -------------------------------------------------------------------------------- /docker/1backend-complex-config/proxysql/proxysql.cnf: -------------------------------------------------------------------------------- 1 | datadir="/tmp" 2 | 3 | admin_variables = 4 | { 5 | admin_credentials="admin2:admin2" 6 | mysql_ifaces="0.0.0.0:6032" 7 | refresh_interval=2000 8 | } 9 | 10 | mysql_variables = 11 | { 12 | connect_timeout_server=5000 13 | default_charset="utf8" 14 | have_compress=false 15 | monitor_history=300000 16 | monitor_connect_interval=120000 17 | monitor_connect_timeout=200 18 | monitor_ping_interval=60000 19 | monitor_ping_timeout=150 20 | monitor_username="root" 21 | monitor_password="root" 22 | monitor_query_variables="SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES" 23 | monitor_query_status="SELECT * FROM INFORMATION_SCHEMA.GLOBAL_STATUS" 24 | monitor_query_interval=30000 25 | monitor_query_timeout=150 26 | monitor_timer_cached=false 27 | ping_interval_server=2000 28 | ping_timeout_server=150 29 | default_schema="test" 30 | poll_timeout=1000 31 | poll_timeout_on_failure=150 32 | server_capabilities=47627 33 | server_version="5.1.31" 34 | commands_stats=true 35 | servers_stats=false 36 | stacksize=2097152 37 | threads=2 38 | } 39 | 40 | mysql_users = 41 | ( 42 | { 43 | username = "root" 44 | password = "root" 45 | default_hostgroup = 0 46 | }, 47 | { 48 | username = "john" 49 | password = "doe" 50 | default_hostgroup = 1 51 | } 52 | ) 53 | 54 | mysql_servers = 55 | ( 56 | { 57 | address = "127.0.0.1" 58 | port = 3306 59 | weight = 1 60 | hostgroup = 0 61 | max_connections = 5 62 | }, 63 | { 64 | address = "127.0.0.1" 65 | port = 3307 66 | weight = 2 67 | hostgroup = 0 68 | max_connections = 1 69 | }, 70 | { 71 | address = "127.0.0.1" 72 | port = 3308 73 | weight = 2 74 | hostgroup = 0 75 | max_connections = 10 76 | } 77 | ) -------------------------------------------------------------------------------- /docker/images/mysql/mysql-empty/Dockerfile: -------------------------------------------------------------------------------- 1 | # The only purpose for which this image exists is to add ProxySQL-relevant 2 | # labels to it. 3 | FROM mysql:latest 4 | 5 | LABEL vendor=proxysql\ 6 | com.proxysql.type=mysql -------------------------------------------------------------------------------- /docker/images/mysql/mysql-simple-dump/Dockerfile: -------------------------------------------------------------------------------- 1 | # We are creating a custom Dockerfile for MySQL as there is no easy way to 2 | # move a file from host into the container. In our case, it's schema.sql 3 | # There is a proposed improvement to "docker cp" but it's still being 4 | # discussed (https://github.com/docker/docker/issues/5846). 5 | FROM mysql:latest 6 | 7 | LABEL vendor=proxysql\ 8 | com.proxysql.type=mysql 9 | 10 | ADD ./schema.sql /tmp/ 11 | ADD ./import_schema.sh /tmp/ -------------------------------------------------------------------------------- /docker/images/mysql/mysql-simple-dump/import_schema.sh: -------------------------------------------------------------------------------- 1 | cat /tmp/schema.sql | mysql -h 127.0.0.1 -u root -proot -------------------------------------------------------------------------------- /docker/images/mysql/mysql-simple-dump/schema.sql: -------------------------------------------------------------------------------- 1 | DROP DATABASE IF EXISTS test; 2 | CREATE DATABASE test; 3 | 4 | # Used by monitoring module for connection health 5 | CREATE USER monitor@'%' IDENTIFIED BY 'monitor'; 6 | CREATE USER john@'%' IDENTIFIED BY 'doe'; 7 | CREATE USER danny@'%' IDENTIFIED BY 'white'; 8 | 9 | GRANT ALL PRIVILEGES ON test.* TO 'monitor'@'%'; 10 | GRANT ALL PRIVILEGES ON test.* TO 'john'@'%'; 11 | GRANT ALL PRIVILEGES ON test.* TO 'danny'@'%'; 12 | FLUSH PRIVILEGES; 13 | 14 | USE test; 15 | 16 | CREATE TABLE strings(value LONGTEXT); 17 | 18 | INSERT INTO strings(value) VALUES('a'); 19 | INSERT INTO strings(value) VALUES('ab'); 20 | INSERT INTO strings(value) VALUES('abc'); 21 | INSERT INTO strings(value) VALUES('abcd'); -------------------------------------------------------------------------------- /docker/images/proxysql/deb-compliant/bionic-package/ctl/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: PKG_VERSION_CURVER 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf /etc/ 14 | etc/logrotate.d/proxysql /etc/logrotate.d/ 15 | systemd/system/proxysql.service /lib/systemd/system/ 16 | tools/proxysql_galera_checker.sh /usr/share/proxysql/tools/ 17 | tools/proxysql_galera_writer.pl /usr/share/proxysql/tools/ 18 | Description: High performance MySQL proxy 19 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 20 | . 21 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 22 | File: postinst 23 | #!/bin/sh -e 24 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 25 | if ! id -u proxysql > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/proxysql -c "ProxySQL Server" proxysql; fi 26 | chown -R proxysql: /var/lib/proxysql 27 | chown root:proxysql /etc/proxysql.cnf 28 | chmod 640 /etc/proxysql.cnf 29 | if [ -d /run/systemd/system ]; then 30 | systemctl enable proxysql.service > /dev/null || true 31 | systemctl --system daemon-reload > /dev/null || true 32 | fi 33 | -------------------------------------------------------------------------------- /docker/images/proxysql/deb-compliant/ctl/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: PKG_VERSION_CURVER 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/logrotate.d/proxysql /etc/logrotate.d/ 15 | systemd/system/proxysql.service /lib/ 16 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 17 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 18 | Description: High performance MySQL proxy 19 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 20 | . 21 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 22 | File: postinst 23 | #!/bin/sh -e 24 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 25 | if ! id -u proxysql > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/proxysql -c "ProxySQL Server" proxysql; fi 26 | chown -R proxysql: /var/lib/proxysql 27 | chown root:proxysql /etc/proxysql.cnf 28 | chmod 640 /etc/proxysql.cnf 29 | if [ -d /run/systemd/system ]; then 30 | systemctl enable proxysql.service > /dev/null || true 31 | systemctl --system daemon-reload > /dev/null || true 32 | fi 33 | -------------------------------------------------------------------------------- /docker/images/proxysql/deb-compliant/entrypoint/entrypoint.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | # Delete package if exists 6 | rm -f "/opt/proxysql/binaries/proxysql_${CURVER}-${PKG_RELEASE}_amd64.deb" || true 7 | # Cleanup relic directories from a previously failed build 8 | rm -f /opt/proxysql/proxysql.ctl /opt/proxysql/proxysql || true 9 | # Clean and build dependancies and source 10 | cd /opt/proxysql 11 | # Patch for Ubuntu 12 12 | if [ "`grep Ubuntu /etc/issue | awk '{print $2}' | cut -d. -f1`" == "12" ]; then 13 | sed -i -e 's/c++11/c++0x/' lib/Makefile 14 | sed -i -e 's/c++11/c++0x/' src/Makefile 15 | cd /opt/proxysql/deps/re2/ 16 | mv re2.tar.gz /tmp/ 17 | wget -O re2.tar.gz https://github.com/sysown/proxysql/raw/v1.3.9/deps/re2/re2-20140304.tgz 18 | cd /opt/proxysql 19 | fi 20 | if [[ -z ${PROXYSQL_BUILD_TYPE:-} ]] ; then 21 | deps_target="build_deps" 22 | build_target="" 23 | else 24 | deps_target="build_deps_$PROXYSQL_BUILD_TYPE" 25 | build_target="$PROXYSQL_BUILD_TYPE" 26 | fi 27 | ${MAKE} cleanbuild 28 | ${MAKE} ${MAKEOPT} "${deps_target}" 29 | 30 | if [[ -z ${build_target} ]] ; then 31 | ${MAKE} ${MAKEOPT} 32 | else 33 | ${MAKE} ${MAKEOPT} "${build_target}" 34 | fi 35 | # Prepare package files and build RPM 36 | cp /root/ctl/proxysql.ctl /opt/proxysql/proxysql.ctl 37 | sed -i "s/PKG_VERSION_CURVER/${CURVER}/g" /opt/proxysql/proxysql.ctl 38 | cp /opt/proxysql/src/proxysql /opt/proxysql/ 39 | equivs-build proxysql.ctl 40 | mv "/opt/proxysql/proxysql_${CURVER}_amd64.deb" "./binaries/proxysql_${CURVER}-${PKG_RELEASE}_amd64.deb" 41 | # Cleanup current build 42 | # Unpatch Ubuntu 12 43 | if [ "`grep Ubuntu /etc/issue | awk '{print $2}' | cut -d. -f1`" == "12" ]; then 44 | sed -i -e 's/c++0x/c++11/' lib/Makefile 45 | sed -i -e 's/c++0x/c++11/' src/Makefile 46 | mv /tmp/re2.tar.gz /opt/proxysql/deps/re2/ 47 | fi 48 | rm -f /opt/proxysql/proxysql.ctl /opt/proxysql/proxysql 49 | -------------------------------------------------------------------------------- /docker/images/proxysql/deb-compliant/pre-systemd/ctl/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: PKG_VERSION_CURVER 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/logrotate.d/proxysql /etc/logrotate.d/proxysql 15 | etc/init.d/proxysql / 16 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 17 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 18 | Description: High performance MySQL proxy 19 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 20 | . 21 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 22 | File: postinst 23 | #!/bin/sh -e 24 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 25 | if ! id -u proxysql > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/proxysql -c "ProxySQL Server" proxysql; fi 26 | chown -R proxysql: /var/lib/proxysql 27 | chown root:proxysql /etc/proxysql.cnf 28 | update-rc.d proxysql defaults 29 | chmod 640 /etc/proxysql.cnf 30 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos5-build/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | mkdir /var/run/%{name} 40 | chkconfig --add %{name} 41 | 42 | %preun 43 | /etc/init.d/%{name} stop 44 | chkconfig --del %{name} 45 | 46 | %postun 47 | rm -rf /var/run/%{name} 48 | 49 | %files 50 | %defattr(-,root,root,-) 51 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 52 | %{_bindir}/* 53 | %{_sysconfdir}/init.d/%{name} 54 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 55 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 56 | 57 | %changelog 58 | * Wed Oct 19 2016 Rene Cannao 1.3.0 59 | - experimental support for Prepared Statements 60 | - enhanced scalability 61 | * Thu Sep 29 2016 Rene Cannao 1.2.4 62 | - Forth stable release of 1.2 63 | * Tue Sep 20 2016 Rene Cannao 1.2.3 64 | - Third stable release of 1.2 65 | * Fri Sep 2 2016 Rene Cannao 1.2.2 66 | - Second stable release of 1.2 67 | * Tue Aug 2 2016 Rene Cannao 1.2.1 68 | - First stable release of 1.2 69 | * Mon Mar 14 2016 Rene Cannao 1.2.0 70 | - First testing release of 1.2 71 | * Sat Mar 11 2016 Rene Cannao 1.1.2 72 | - Upgraded to release 1.1.2 73 | * Sat Oct 31 2015 Rene Cannao 1.0.1 74 | - Compiles 1.0.1 75 | * Wed Sep 9 2015 Andrei Ismail 0.2 76 | - Added support for automatic packaging on Ubuntu 14.04 and CentOS 7. 77 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos5-build/rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos67-build/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | mkdir /var/run/%{name} 40 | chkconfig --add %{name} 41 | 42 | %preun 43 | /etc/init.d/%{name} stop 44 | chkconfig --del %{name} 45 | 46 | %postun 47 | rm -rf /var/run/%{name} 48 | 49 | %files 50 | %defattr(-,root,root,-) 51 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 52 | %{_bindir}/* 53 | %{_sysconfdir}/init.d/%{name} 54 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 55 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 56 | 57 | %changelog 58 | * Wed Oct 19 2016 Rene Cannao 1.3.0 59 | - experimental support for Prepared Statements 60 | - enhanced scalability 61 | * Thu Sep 29 2016 Rene Cannao 1.2.4 62 | - Forth stable release of 1.2 63 | * Tue Sep 20 2016 Rene Cannao 1.2.3 64 | - Third stable release of 1.2 65 | * Fri Sep 2 2016 Rene Cannao 1.2.2 66 | - Second stable release of 1.2 67 | * Tue Aug 2 2016 Rene Cannao 1.2.1 68 | - First stable release of 1.2 69 | * Mon Mar 14 2016 Rene Cannao 1.2.0 70 | - First testing release of 1.2 71 | * Sat Mar 11 2016 Rene Cannao 1.1.2 72 | - Upgraded to release 1.1.2 73 | * Sat Oct 31 2015 Rene Cannao 1.0.1 74 | - Compiles 1.0.1 75 | * Wed Sep 9 2015 Andrei Ismail 0.2 76 | - Added support for automatic packaging on Ubuntu 14.04 and CentOS 7. 77 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos67-build/rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos7-build/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | mkdir /var/run/%{name} 40 | chkconfig --add %{name} 41 | 42 | %preun 43 | /etc/init.d/%{name} stop 44 | chkconfig --del %{name} 45 | 46 | %postun 47 | rm -rf /var/run/%{name} 48 | 49 | %files 50 | %defattr(-,root,root,-) 51 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 52 | %{_bindir}/* 53 | %{_sysconfdir}/init.d/%{name} 54 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 55 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 56 | 57 | %changelog 58 | * Wed Oct 19 2016 Rene Cannao 1.3.0 59 | - experimental support for Prepared Statements 60 | - enhanced scalability 61 | * Thu Sep 29 2016 Rene Cannao 1.2.4 62 | - Forth stable release of 1.2 63 | * Tue Sep 20 2016 Rene Cannao 1.2.3 64 | - Third stable release of 1.2 65 | * Fri Sep 2 2016 Rene Cannao 1.2.2 66 | - Second stable release of 1.2 67 | * Tue Aug 2 2016 Rene Cannao 1.2.1 68 | - First stable release of 1.2 69 | * Mon Mar 14 2016 Rene Cannao 1.2.0 70 | - First testing release of 1.2 71 | * Sat Mar 11 2016 Rene Cannao 1.1.2 72 | - Upgraded to release 1.1.2 73 | * Sat Oct 31 2015 Rene Cannao 1.0.1 74 | - Compiles 1.0.1 75 | * Wed Sep 9 2015 Andrei Ismail 0.2 76 | - Added support for automatic packaging on Ubuntu 14.04 and CentOS 7. 77 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/centos7-build/rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/debian-7.8-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/debian-8.2-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/debian-9-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/debian-9.4-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/fedora24-build/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | mkdir /var/run/%{name} 40 | chkconfig --add %{name} 41 | 42 | %preun 43 | /etc/init.d/%{name} stop 44 | chkconfig --del %{name} 45 | 46 | %postun 47 | rm -rf /var/run/%{name} 48 | 49 | %files 50 | %defattr(-,root,root,-) 51 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 52 | %{_bindir}/* 53 | %{_sysconfdir}/init.d/%{name} 54 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 55 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 56 | 57 | %changelog 58 | * Wed Oct 19 2016 Rene Cannao 1.3.0 59 | - experimental support for Prepared Statements 60 | - enhanced scalability 61 | * Thu Sep 29 2016 Rene Cannao 1.2.4 62 | - Forth stable release of 1.2 63 | * Tue Sep 20 2016 Rene Cannao 1.2.3 64 | - Third stable release of 1.2 65 | * Fri Sep 2 2016 Rene Cannao 1.2.2 66 | - Second stable release of 1.2 67 | * Tue Aug 2 2016 Rene Cannao 1.2.1 68 | - First stable release of 1.2 69 | * Mon Mar 14 2016 Rene Cannao 1.2.0 70 | - First testing release of 1.2 71 | * Sat Mar 11 2016 Rene Cannao 1.1.2 72 | - Upgraded to release 1.1.2 73 | * Sat Oct 31 2015 Rene Cannao 1.0.1 74 | - Compiles 1.0.1 75 | * Wed Sep 9 2015 Andrei Ismail 0.2 76 | - Added support for automatic packaging on Ubuntu 14.04 and CentOS 7. 77 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/fedora24-build/rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/fedora27-build/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | mkdir /var/run/%{name} 40 | chkconfig --add %{name} 41 | 42 | %preun 43 | /etc/init.d/%{name} stop 44 | chkconfig --del %{name} 45 | 46 | %postun 47 | rm -rf /var/run/%{name} 48 | 49 | %files 50 | %defattr(-,root,root,-) 51 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 52 | %{_bindir}/* 53 | %{_sysconfdir}/init.d/%{name} 54 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 55 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 56 | 57 | %changelog 58 | * Wed Oct 19 2016 Rene Cannao 1.3.0 59 | - experimental support for Prepared Statements 60 | - enhanced scalability 61 | * Thu Sep 29 2016 Rene Cannao 1.2.4 62 | - Forth stable release of 1.2 63 | * Tue Sep 20 2016 Rene Cannao 1.2.3 64 | - Third stable release of 1.2 65 | * Fri Sep 2 2016 Rene Cannao 1.2.2 66 | - Second stable release of 1.2 67 | * Tue Aug 2 2016 Rene Cannao 1.2.1 68 | - First stable release of 1.2 69 | * Mon Mar 14 2016 Rene Cannao 1.2.0 70 | - First testing release of 1.2 71 | * Sat Mar 11 2016 Rene Cannao 1.1.2 72 | - Upgraded to release 1.1.2 73 | * Sat Oct 31 2015 Rene Cannao 1.0.1 74 | - Compiles 1.0.1 75 | * Wed Sep 9 2015 Andrei Ismail 0.2 76 | - Added support for automatic packaging on Ubuntu 14.04 and CentOS 7. 77 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/fedora27-build/rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/proxysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Andrei Ismail 3 | 4 | LABEL vendor=proxysql\ 5 | com.proxysql.type=proxysql\ 6 | com.proxysql.os=ubuntu14\ 7 | com.proxysql.interactive=false\ 8 | com.proxysql.config=simple\ 9 | com.proxysql.purpose=testing 10 | 11 | RUN apt-get update && apt-get install -y \ 12 | automake \ 13 | cmake \ 14 | make \ 15 | g++ \ 16 | gcc \ 17 | gdb \ 18 | gdbserver \ 19 | git \ 20 | libmysqlclient-dev \ 21 | libssl-dev \ 22 | libtool \ 23 | && \ 24 | apt-get clean && \ 25 | rm -rf /var/lib/apt/lists/ 26 | 27 | RUN cd /opt; git clone https://github.com/akopytov/sysbench.git 28 | RUN cd /opt/sysbench; ./autogen.sh; ./configure --bindir=/usr/bin; make; make install 29 | 30 | ADD ./proxysql.cnf /etc/ 31 | RUN mkdir -p /var/lib/proxysql 32 | ADD ./compile_and_start_proxysql.sh /tmp/ 33 | RUN chmod +x /tmp/compile_and_start_proxysql.sh 34 | 35 | CMD ["/tmp/compile_and_start_proxysql.sh"] 36 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/proxysql/compile_and_start_proxysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d /opt/proxysql ]; then 4 | mkdir -p /opt/proxysql 5 | cp -R /tmp/proxysql-src/* /opt/proxysql 6 | cd /opt/proxysql 7 | make clean && make > /tmp/proxysql_compile.log 8 | fi 9 | 10 | cd /opt/proxysql/src 11 | # TODO(andrei): re-enable the commented line when figuring out interactive mode 12 | # gdbserver 0.0.0.0:2345 ./proxysql --initial -f -c /etc/proxysql.cnf 13 | ./proxysql --initial -f -c /etc/proxysql.cnf -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/ubuntu-12.04-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/ubuntu-14.04-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/ubuntu-15.10-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 1.2.4 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/legacy/ubuntu-16.04-build/proxysql.ctl: -------------------------------------------------------------------------------- 1 | Section: misc 2 | Priority: optional 3 | Homepage: http://www.proxysql.com 4 | Standards-Version: 3.9.2 5 | 6 | Package: proxysql 7 | Version: 2.0.0 8 | Maintainer: Rene Cannao 9 | Architecture: amd64 10 | # Changelog: CHANGELOG.md 11 | # Readme: README.md 12 | Files: proxysql /usr/bin/ 13 | etc/proxysql.cnf / 14 | etc/init.d/proxysql / 15 | tools/proxysql_galera_checker.sh /usr/share/proxysql/ 16 | tools/proxysql_galera_writer.pl /usr/share/proxysql/ 17 | Description: High performance MySQL proxy 18 | ProxySQL is a fast, reliable MySQL proxy with advanced runtime configuration management (virtually no configuration change requires a restart). 19 | . 20 | It features query routing, query caching, query rewriting (for queries generated by ORMs, for example) and is most of the time a drop-in replacement for mysqld from the point of view of the application. It can be configured and remote controlled through an SQL-compatible admin interface. 21 | File: postinst 22 | #!/bin/sh -e 23 | if [ ! -d /var/lib/proxysql ]; then mkdir /var/lib/proxysql ; fi 24 | update-rc.d proxysql defaults 25 | -------------------------------------------------------------------------------- /docker/images/proxysql/proxysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Andrei Ismail 3 | 4 | LABEL vendor=proxysql\ 5 | com.proxysql.type=proxysql\ 6 | com.proxysql.os=ubuntu14\ 7 | com.proxysql.interactive=false\ 8 | com.proxysql.config=simple\ 9 | com.proxysql.purpose=testing 10 | 11 | RUN apt-get update && apt-get install -y \ 12 | automake \ 13 | cmake \ 14 | make \ 15 | g++ \ 16 | gcc \ 17 | gdb \ 18 | gdbserver \ 19 | git \ 20 | libmysqlclient-dev \ 21 | libssl-dev \ 22 | libtool \ 23 | && \ 24 | apt-get clean && \ 25 | rm -rf /var/lib/apt/lists/ 26 | 27 | RUN cd /opt; git clone https://github.com/akopytov/sysbench.git 28 | RUN cd /opt/sysbench; ./autogen.sh; ./configure --bindir=/usr/bin; make; make install 29 | 30 | ADD ./proxysql.cnf /etc/ 31 | RUN mkdir -p /var/lib/proxysql 32 | ADD ./compile_and_start_proxysql.sh /tmp/ 33 | RUN chmod +x /tmp/compile_and_start_proxysql.sh 34 | 35 | CMD ["/tmp/compile_and_start_proxysql.sh"] 36 | -------------------------------------------------------------------------------- /docker/images/proxysql/proxysql/compile_and_start_proxysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d /opt/proxysql ]; then 4 | mkdir -p /opt/proxysql 5 | cp -R /tmp/proxysql-src/* /opt/proxysql 6 | cd /opt/proxysql 7 | make clean && make > /tmp/proxysql_compile.log 8 | fi 9 | 10 | cd /opt/proxysql/src 11 | # TODO(andrei): re-enable the commented line when figuring out interactive mode 12 | # gdbserver 0.0.0.0:2345 ./proxysql --initial -f -c /etc/proxysql.cnf 13 | ./proxysql --initial -f -c /etc/proxysql.cnf -------------------------------------------------------------------------------- /docker/images/proxysql/proxysql/proxysql.cnf: -------------------------------------------------------------------------------- 1 | datadir="/tmp" 2 | 3 | admin_variables = 4 | { 5 | admin_credentials="admin:admin" 6 | mysql_ifaces="0.0.0.0:6032" 7 | refresh_interval=2000 8 | debug=true 9 | } 10 | 11 | mysql_users = 12 | ( 13 | { 14 | username = "root" 15 | password = "root" 16 | default_hostgroup = 0 17 | }, 18 | 19 | { 20 | username = "john" 21 | password = "doe" 22 | default_hostgroup = 0 23 | } 24 | ) -------------------------------------------------------------------------------- /docker/images/proxysql/rhel-compliant/entrypoint/entrypoint.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eu 3 | 4 | echo "==> Build environment:" 5 | env 6 | 7 | echo "==> Cleaning" 8 | # Delete package if exists 9 | rm -f /opt/proxysql/binaries/proxysql-${CURVER}-1-${PKG_RELEASE}.x86_64.rpm || true 10 | # Cleanup relic directories from a previously failed build 11 | rm -fr /root/.pki /root/rpmbuild/{BUILDROOT,RPMS,SRPMS,BUILD,SOURCES,tmp} /opt/proxysql/proxysql /opt/proxysql/proxysql-${CURVER} || true 12 | 13 | # Clean and build dependancies and source 14 | echo "==> Building" 15 | cd /opt/proxysql 16 | if [[ -z ${PROXYSQL_BUILD_TYPE:-} ]] ; then 17 | deps_target="build_deps" 18 | build_target="" 19 | else 20 | deps_target="build_deps_$PROXYSQL_BUILD_TYPE" 21 | build_target="$PROXYSQL_BUILD_TYPE" 22 | fi 23 | ${MAKE} cleanbuild 24 | ${MAKE} ${MAKEOPT} "${deps_target}" 25 | 26 | if [[ -z ${build_target} ]] ; then 27 | ${MAKE} ${MAKEOPT} 28 | else 29 | ${MAKE} ${MAKEOPT} "${build_target}" 30 | fi 31 | 32 | # Prepare package files and build RPM 33 | echo "==> Packaging" 34 | mkdir -p proxysql/usr/bin proxysql/etc 35 | cp src/proxysql proxysql/usr/bin/ 36 | cp -a etc proxysql 37 | mkdir -p proxysql/usr/share/proxysql/tools 38 | cp -a tools/proxysql_galera_checker.sh tools/proxysql_galera_writer.pl proxysql/usr/share/proxysql/tools 39 | mv proxysql "proxysql-${CURVER}" 40 | tar czvf "proxysql-${CURVER}.tar.gz" proxysql-${CURVER} 41 | mkdir -p /root/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp} 42 | mv "/opt/proxysql/proxysql-${CURVER}.tar.gz" /root/rpmbuild/SOURCES 43 | cd /root/rpmbuild && rpmbuild -ba SPECS/proxysql.spec --define "version ${CURVER}" 44 | mv "/root/rpmbuild/RPMS/x86_64/proxysql-${CURVER}-1.x86_64.rpm" "/opt/proxysql/binaries/proxysql-${CURVER}-1-${PKG_RELEASE}.x86_64.rpm" 45 | # Cleanup current build 46 | rm -fr /root/.pki /root/rpmbuild/{BUILDROOT,RPMS,SRPMS,BUILD,SOURCES,tmp} /opt/proxysql/proxysql "/opt/proxysql/proxysql-${CURVER}" 47 | -------------------------------------------------------------------------------- /docker/images/proxysql/rhel-compliant/rpmmacros/.rpmmacros: -------------------------------------------------------------------------------- 1 | %_topdir %(echo $HOME)/rpmbuild 2 | %_tmppath %{_topdir}/tmp -------------------------------------------------------------------------------- /docker/images/proxysql/rhel-compliant/rpmmacros/rpmbuild/SPECS/proxysql.spec: -------------------------------------------------------------------------------- 1 | # Don't try fancy stuff like debuginfo, which is useless on binary-only 2 | # packages. Don't strip binary too 3 | # Be sure buildpolicy set to do nothing 4 | %define __spec_install_post %{nil} 5 | %define debug_package %{nil} 6 | %define __os_install_post %{_dbpath}/brp-compress 7 | 8 | Summary: A high-performance MySQL proxy 9 | Name: proxysql 10 | Version: %{version} 11 | Release: 1 12 | License: GPL+ 13 | Group: Development/Tools 14 | SOURCE0 : %{name}-%{version}.tar.gz 15 | URL: http://www.proxysql.com/ 16 | 17 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 18 | 19 | %description 20 | %{summary} 21 | 22 | %prep 23 | %setup -q 24 | 25 | %build 26 | # Empty section. 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot} 31 | 32 | # in builddir 33 | cp -a * %{buildroot} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | if [ ! -d /var/run/%{name} ]; then mkdir /var/run/%{name} ; fi 40 | if [ ! -d /var/lib/%{name} ]; then mkdir /var/lib/%{name} ; fi 41 | if ! id -u %{name} > /dev/null 2>&1; then useradd -r -U -s /bin/false -d /var/lib/%{name} -c "ProxySQL Server" %{name}; fi 42 | chown -R %{name}: /var/lib/%{name} /var/run/%{name} 43 | chown root:%{name} /etc/%{name}.cnf 44 | chmod 640 /etc/%{name}.cnf 45 | chkconfig --add %{name} 46 | #systemctl enable proxysql.service 47 | 48 | %preun 49 | /etc/init.d/%{name} stop 50 | chkconfig --del %{name} 51 | 52 | %postun 53 | rm -rf /var/run/%{name} 54 | 55 | %files 56 | %defattr(-,root,root,-) 57 | %config(noreplace) %{_sysconfdir}/%{name}.cnf 58 | %attr(640,root,%{name}) %{_sysconfdir}/%{name}.cnf 59 | %config(noreplace) %attr(640,root,%{name}) %{_sysconfdir}/logrotate.d/%{name} 60 | %{_bindir}/* 61 | %{_sysconfdir}/init.d/%{name} 62 | /usr/share/proxysql/tools/proxysql_galera_checker.sh 63 | /usr/share/proxysql/tools/proxysql_galera_writer.pl 64 | 65 | %changelog 66 | -------------------------------------------------------------------------------- /docker/scenarios/1backend/docker-compose.yml: -------------------------------------------------------------------------------- 1 | proxysql: 2 | image: proxysql:{{proxysql_image}} 3 | links: 4 | - backend1hostgroup0 5 | ports: 6 | # ProxySQL admin port for MySQL commands 7 | - "6032:6032" 8 | # ProxySQL main port 9 | - "6033:6033" 10 | # gdbserver 11 | - "2345:2345" 12 | volumes: 13 | # Sharing the data with 14 | - /tmp/proxysql-tests:/tmp/proxysql-src 15 | privileged: true 16 | 17 | # TODO(aismail): remove these hardcoded labels and add them in the template 18 | # as a variable by using docker-inspect on the image. 19 | labels: 20 | "com.proxysql.config": "simple" 21 | "com.proxysql.interactive": "false" 22 | "com.proxysql.os": "ubuntu14" 23 | "com.proxysql.purpose": "testing" 24 | "com.proxysql.type": "proxysql" 25 | "vendor": "proxysql" 26 | 27 | backend1hostgroup0: 28 | image: proxysql:mysql-simple-dump 29 | environment: 30 | MYSQL_ROOT_PASSWORD: root 31 | expose: 32 | - "3306" 33 | ports: 34 | - "13306:3306" 35 | # TODO(aismail): remove these hardcoded labels and add them in the template 36 | # as a variable by using docker-inspect on the image. 37 | labels: 38 | "com.proxysql.type": "mysql" 39 | "vendor": "proxysql" 40 | "com.proxysql.hostgroup": "0" -------------------------------------------------------------------------------- /docker/scenarios/5backends-replication/master-conf.d/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = 1 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 -------------------------------------------------------------------------------- /docker/scenarios/5backends-replication/slave1-conf.d/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = 2 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 -------------------------------------------------------------------------------- /docker/scenarios/5backends-replication/slave2-conf.d/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = 3 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 -------------------------------------------------------------------------------- /docker/scenarios/5backends-replication/slave3-conf.d/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = 4 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 -------------------------------------------------------------------------------- /docker/scenarios/5backends-replication/slave4-conf.d/my.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = 5 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 -------------------------------------------------------------------------------- /docker/scenarios/repl1/app.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | . ./vars 3 | 4 | destroy() { 5 | for i in `seq 1 ${NUMAPPS}` ; do 6 | echo -n "Destroying container app$i ... " 7 | ID=`$USESUDO docker ps -a -f name=app$i -q` 8 | if [ -z "$ID" ]; then 9 | echo "not found" 10 | else 11 | $USESUDO docker rm app$i 12 | echo "done" 13 | fi 14 | done 15 | } 16 | 17 | prepare() { 18 | for i in `seq 1 ${NUMAPPS}` ; do 19 | echo Creating and running container app$i 20 | $USESUDO docker create --hostname=app$i --name=app$i renecannao/proxysql:dev /bin/sh -c "while true; do sleep 3600; done" 21 | $USESUDO docker start app$i 22 | done 23 | } 24 | 25 | shutdown() { 26 | for i in `seq 1 ${NUMAPPS}` ; do 27 | echo -n "Stopping container app$i ... " 28 | ID=`$USESUDO docker ps -f name=app$i -q` 29 | if [ -z "$ID" ]; then 30 | echo "not found" 31 | else 32 | $USESUDO docker stop app$i 33 | echo "done" 34 | fi 35 | done 36 | } 37 | 38 | case $1 in 39 | destroy) 40 | destroy 41 | ;; 42 | prepare) 43 | prepare 44 | ;; 45 | shutdown) 46 | shutdown 47 | ;; 48 | *) 49 | echo "Invalid argument" 50 | ;; 51 | esac 52 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/configure_repl_hostgroup.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | . ./vars 3 | 4 | declare -a AIPS 5 | declare -a DIPS 6 | declare -a PIPS 7 | 8 | 9 | echo Retrieving IPs 10 | for i in `seq 1 ${NUMSERVERS}` ; do 11 | DIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' db$i` 12 | done 13 | 14 | echo Retrieving Application IPs 15 | for i in `seq 1 ${NUMAPPS}` ; do 16 | AIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' app$i` 17 | done 18 | 19 | echo Retrieving ProxySQL IPs 20 | for i in `seq 1 ${NUMPROXIES}` ; do 21 | PIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' proxy$i` 22 | done 23 | 24 | 25 | configure_ro_dbs() { 26 | export MYSQL_PWD=$ROOTPASS 27 | for i in ${DIPS[*]} ; do 28 | echo "Configuring read_only=$1 on $i" 29 | mysql -u root -h $i -P3306 -e "SET GLOBAL read_only=$1" 30 | done 31 | } 32 | 33 | 34 | dump_ro_proxies() { 35 | echo "Dumping mysql_servers table" 36 | for i in ${PIPS[*]} ; do 37 | mysql -u admin -h $i -P6032 -e "SELECT * FROM mysql_servers" 38 | done 39 | } 40 | 41 | configure_repl_hostgroup() { 42 | echo Configure Replication topology on Cluster Layer 43 | for i in ${PIPS[*]} ; do 44 | echo "Processing ProxySQL on $i" 45 | echo "Configuring monitoring users" 46 | echo "UPDATE global_variables SET variable_value='root' WHERE variable_name='mysql-monitor_username';" | mysql -u admin -h $i -P6032 47 | echo "UPDATE global_variables SET variable_value=\"$ROOTPASS\" WHERE variable_name='mysql-monitor_password';" | mysql -u admin -h $i -P6032 48 | echo "LOAD MYSQL VARIABLES TO RUNTIME" | mysql -u admin -h $i -P6032 49 | echo "SAVE MYSQL VARIABLES TO DISK" | mysql -u admin -h $i -P6032 50 | echo "Setting hostgroups" 51 | echo "DELETE FROM mysql_replication_hostgroups;" | mysql -u admin -h $i -P6032 52 | echo "INSERT INTO mysql_replication_hostgroups VALUES(0,1);" | mysql -u admin -h $i -P6032 53 | echo "LOAD MYSQL SERVERS TO RUNTIME" | mysql -u admin -h $i -P6032 54 | echo "SAVE MYSQL SERVERS TO DISK" | mysql -u admin -h $i -P6032 55 | done 56 | } 57 | 58 | 59 | export MYSQL_PWD="admin" 60 | configure_repl_hostgroup 61 | 62 | configure_ro_dbs 0 63 | export MYSQL_PWD="admin" 64 | echo "ProxySQL should reconfigure the servers" 65 | echo "All servers must be at least in hostgroup 0 , and optionally in hostgroup 1" 66 | echo "We sleep few seconds..." 67 | sleep 5 68 | dump_ro_proxies 69 | 70 | configure_ro_dbs 1 71 | export MYSQL_PWD="admin" 72 | echo "ProxySQL should reconfigure the servers" 73 | echo "All servers must be in hostgroup 1 , **NONE** in hostgroup 0" 74 | echo "We sleep few seconds..." 75 | sleep 5 76 | dump_ro_proxies 77 | 78 | 79 | 80 | 81 | 82 | #echo APP IPs: ${AIPS[*]} 83 | #echo ProxySQL IPs: ${PIPS[*]} 84 | 85 | 86 | configure_repl_hostgroup 87 | 88 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/mysql.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | . ./vars 3 | 4 | destroy() { 5 | for i in `seq 1 ${NUMSERVERS}` ; do 6 | echo -n "Destroying container db$i ... " 7 | ID=`$USESUDO docker ps -a -f name=db$i -q` 8 | if [ -z "$ID" ]; then 9 | echo "not found" 10 | else 11 | $USESUDO docker rm db$i 12 | echo "done" 13 | fi 14 | done 15 | } 16 | 17 | prepare() { 18 | for i in `seq 1 ${NUMSERVERS}` ; do 19 | echo Creating container db$i 20 | $USESUDO docker create --hostname=db$i --name=db$i -e MYSQL_ROOT_PASSWORD=${ROOTPASS} mysql:latest 21 | RANID=$(($RANDOM*32768+$RANDOM)) 22 | echo "Using random server_id $RANID" 23 | sed -e "s/XXXX/$RANID/" mysql_add.cnf_ > mysql_add.cnf 24 | $USESUDO docker cp mysql_add.cnf db$i:/etc/mysql/conf.d/ 25 | done 26 | rm mysql_add.cnf 27 | for i in `seq 1 ${NUMSERVERS}` ; do 28 | echo Starting container db$i 29 | $USESUDO docker start db$i 30 | done 31 | } 32 | 33 | shutdown() { 34 | for i in `seq 1 ${NUMSERVERS}` ; do 35 | echo -n "Stopping container db$i ... " 36 | ID=`$USESUDO docker ps -f name=db$i -q` 37 | if [ -z "$ID" ]; then 38 | echo "not found" 39 | else 40 | $USESUDO docker stop db$i 41 | echo "done" 42 | fi 43 | done 44 | } 45 | 46 | case $1 in 47 | destroy) 48 | destroy 49 | ;; 50 | prepare) 51 | prepare 52 | ;; 53 | shutdown) 54 | shutdown 55 | ;; 56 | *) 57 | echo "Invalid argument" 58 | ;; 59 | esac 60 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/mysql_add.cnf_: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | server_id = XXXX 3 | innodb_file_per_table 4 | innodb_flush_log_at_trx_commit=2 5 | query_cache_size = 0 6 | sync_binlog = 0 7 | log_bin 8 | binlog_format = MIXED 9 | gtid_mode = ON 10 | log-slave-updates 11 | enforce-gtid-consistency 12 | expire_logs_days = 3 13 | max_binlog_size = 100M 14 | bind_address = 0.0.0.0 15 | max_connections = 5000 16 | skip_name_resolve 17 | 18 | [mysqld_safe] 19 | open_files_limit = 102400 20 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/proxy.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | . ./vars 3 | 4 | 5 | destroy() { 6 | for i in `seq 1 ${NUMPROXIES}` ; do 7 | echo -n "Destroying container proxy$i ... " 8 | ID=`$USESUDO docker ps -a -f name=proxy$i -q` 9 | if [ -z "$ID" ]; then 10 | echo "not found" 11 | else 12 | $USESUDO docker rm proxy$i 13 | echo "done" 14 | fi 15 | done 16 | } 17 | 18 | prepare() { 19 | for i in `seq 1 ${NUMPROXIES}` ; do 20 | echo Creating and running container proxy$i 21 | $USESUDO docker create --hostname=proxy$i --name=proxy$i renecannao/proxysql:dev /bin/sh -c "while true; do sleep 3600; done" 22 | $USESUDO docker start proxy$i 23 | done 24 | } 25 | 26 | shutdown() { 27 | for i in `seq 1 ${NUMPROXIES}` ; do 28 | echo -n "Stopping container proxy$i ... " 29 | ID=`$USESUDO docker ps -f name=proxy$i -q` 30 | if [ -z "$ID" ]; then 31 | echo "not found" 32 | else 33 | $USESUDO docker stop proxy$i 34 | echo "done" 35 | fi 36 | done 37 | } 38 | 39 | case $1 in 40 | destroy) 41 | destroy 42 | ;; 43 | prepare) 44 | prepare 45 | ;; 46 | shutdown) 47 | shutdown 48 | ;; 49 | *) 50 | echo "Invalid argument" 51 | ;; 52 | esac 53 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/test1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import MySQLdb 3 | import os 4 | import sys 5 | import thread 6 | import time 7 | import signal 8 | import threading 9 | 10 | qcounter = 0 11 | qcounter_lock = threading.Lock() 12 | qOK = 0 13 | qOK_lock = threading.Lock() 14 | qERR = 0 15 | qERR_lock = threading.Lock() 16 | 17 | 18 | 19 | # config 20 | mysqluser = os.getenv('MYSQL_USER') 21 | mysqlpass = os.getenv('MYSQL_PASS') 22 | app_ips = os.getenv('APP_IPS') 23 | database_ips = os.getenv('DATABASE_IPS') 24 | proxy_ips = os.getenv('PROXY_IPS') 25 | 26 | app_list = [] 27 | database_list = [] 28 | proxy_list = [] 29 | 30 | def sigterm_handler(_signo, _stack_frame): 31 | # Raises SystemExit(0): 32 | sys.exit(0) 33 | 34 | 35 | 36 | def print_exception(e): 37 | line_number = sys.exc_info()[2].tb_lineno 38 | print "Line: " + str(line_number) 39 | print e 40 | 41 | def thread_client_conn(app_ip): 42 | conn = None 43 | try: 44 | conn = MySQLdb.connect(host=app_ip, port=6033, user=mysqluser, passwd=mysqlpass) 45 | #conn = MySQLdb.connect(host="172.17.0.139", port=6033, user=mysqluser, passwd=mysqlpass) 46 | 47 | cur = conn.cursor() 48 | while True: 49 | # for x in range(0, 100): 50 | global qcounter 51 | global qOK 52 | global qERR 53 | qcounter_lock.acquire() 54 | qcounter += 1 55 | x = qcounter 56 | qcounter_lock.release() 57 | time.sleep(1) 58 | query = "SELECT " + str(x) 59 | try: 60 | cur.execute(query) 61 | res = cur.fetchone() 62 | # print res[0] 63 | qOK_lock.acquire() 64 | qOK += 1 65 | qOK_lock.release() 66 | except Exception, e: 67 | qERR_lock.acquire() 68 | qERR += 1 69 | qERR_lock.release() 70 | #print "Query failed" 71 | except Exception, e: 72 | print "Failed to connect" 73 | print_exception(e) 74 | finally: 75 | if conn: 76 | conn.close() 77 | 78 | def main(): 79 | # signal.signal(signal.SIGTERM, sigterm_handler) 80 | if not mysqluser or not mysqlpass or not database_ips or not app_ips or not proxy_ips: 81 | sys.exit("environment incorrectly configured; aborting!") 82 | app_list = app_ips.split() 83 | database_list = database_ips.split() 84 | proxy_list = proxy_ips.split() 85 | try: 86 | threads = [threading.Thread(target=thread_client_conn) for t in range(10)] 87 | for t in threads: 88 | t.setDaemon(True) 89 | t.start() 90 | # for t in threads: 91 | # t.join() 92 | while True: 93 | time.sleep(1) 94 | finally: 95 | print "Queries result. OK: " , qOK , " ERR: " , qERR 96 | 97 | if __name__ == '__main__': 98 | main() 99 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/test1_.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import MySQLdb 3 | import os 4 | import sys 5 | import thread 6 | import time 7 | import signal 8 | import threading 9 | 10 | qcounter = 0 11 | qcounter_lock = threading.Lock() 12 | qOK = 0 13 | qOK_lock = threading.Lock() 14 | qERR = 0 15 | qERR_lock = threading.Lock() 16 | 17 | 18 | 19 | # config 20 | mysqluser = os.getenv('MYSQL_USER') 21 | mysqlpass = os.getenv('MYSQL_PASS') 22 | 23 | 24 | def sigterm_handler(_signo, _stack_frame): 25 | # Raises SystemExit(0): 26 | sys.exit(0) 27 | 28 | 29 | 30 | def print_exception(e): 31 | line_number = sys.exc_info()[2].tb_lineno 32 | print "Line: " + str(line_number) 33 | print e 34 | 35 | def thread_client_conn(): 36 | conn = None 37 | try: 38 | conn = MySQLdb.connect(host="127.0.0.1", port=6033, user=mysqluser, passwd=mysqlpass) 39 | #conn = MySQLdb.connect(host="172.17.0.139", port=6033, user=mysqluser, passwd=mysqlpass) 40 | 41 | cur = conn.cursor() 42 | while True: 43 | # for x in range(0, 100): 44 | global qcounter 45 | global qOK 46 | global qERR 47 | qcounter_lock.acquire() 48 | qcounter += 1 49 | x = qcounter 50 | qcounter_lock.release() 51 | time.sleep(1) 52 | query = "SELECT " + str(x) 53 | try: 54 | cur.execute(query) 55 | res = cur.fetchone() 56 | # print res[0] 57 | qOK_lock.acquire() 58 | qOK += 1 59 | qOK_lock.release() 60 | except Exception, e: 61 | qERR_lock.acquire() 62 | qERR += 1 63 | qERR_lock.release() 64 | #print "Query failed" 65 | except Exception, e: 66 | print "Failed to connect" 67 | print_exception(e) 68 | finally: 69 | if conn: 70 | conn.close() 71 | 72 | def main(): 73 | signal.signal(signal.SIGTERM, sigterm_handler) 74 | if not mysqluser or not mysqlpass: 75 | sys.exit("environment incorrectly configured; aborting!") 76 | try: 77 | threads = [threading.Thread(target=thread_client_conn) for t in range(10)] 78 | for t in threads: 79 | t.setDaemon(True) 80 | t.start() 81 | # for t in threads: 82 | # t.join() 83 | while True: 84 | time.sleep(1) 85 | finally: 86 | print "Queries result. OK: " , qOK , " ERR: " , qERR 87 | 88 | if __name__ == '__main__': 89 | main() 90 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/vars: -------------------------------------------------------------------------------- 1 | export ROOTPASS=rootpass 2 | export REPLPASS=replpass 3 | export NUMAPPS=2 4 | export NUMSERVERS=5 5 | export NUMPROXIES=2 6 | export USESUDO=sudo 7 | export DOCNET=`ifconfig docker0| grep "inet addr" | awk -F ':' '{print $2}' | awk '{print $1}'` 8 | -------------------------------------------------------------------------------- /docker/scenarios/repl1/vars2: -------------------------------------------------------------------------------- 1 | . ./vars 2 | 3 | declare -a AIPS 4 | declare -a DIPS 5 | declare -a PIPS 6 | 7 | 8 | for i in `seq 1 ${NUMSERVERS}` ; do 9 | DIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' db$i` 10 | done 11 | 12 | 13 | for i in `seq 1 ${NUMAPPS}` ; do 14 | AIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' app$i` 15 | done 16 | 17 | for i in `seq 1 ${NUMPROXIES}` ; do 18 | PIPS[$i]=`$USESUDO docker inspect -f '{{.NetworkSettings.IPAddress}}' proxy$i` 19 | done 20 | 21 | export APP_IPS="${AIPS[*]}" 22 | export DATABASE_IPS="${DIPS[*]}" 23 | export PROXY_IPS="${PIPS[*]}" 24 | -------------------------------------------------------------------------------- /etc/logrotate.d/proxysql: -------------------------------------------------------------------------------- 1 | /var/lib/proxysql/proxysql.log { 2 | missingok 3 | notifempty 4 | copytruncate 5 | } 6 | -------------------------------------------------------------------------------- /include/ClickHouse_Authentication.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_PROXYSQL_CLICKHOUSE_AUTHENTICATION_H 2 | #define CLASS_PROXYSQL_CLICKHOUSE_AUTHENTICATION_H 3 | 4 | #include "proxysql.h" 5 | #include "cpp.h" 6 | 7 | #define PROXYSQL_AUTH_PTHREAD_MUTEX 8 | 9 | #ifndef CH_ACCOUNT_DETAILS_T 10 | #define CH_ACCOUNT_DETAILS_T 11 | typedef struct _ch_account_details_t { 12 | char *username; 13 | char *password; 14 | void *sha1_pass; 15 | bool use_ssl; 16 | int default_hostgroup; 17 | char *default_schema; 18 | bool schema_locked; 19 | bool transaction_persistent; 20 | bool fast_forward; 21 | int max_connections; 22 | int num_connections_used; 23 | bool __frontend; // this is used only during the dump 24 | bool __backend; // this is used only during the dump 25 | bool __active; 26 | } ch_account_details_t; 27 | 28 | typedef std::map ch_umap_auth; 29 | #endif // CH_ACCOUNT_DETAILS_T 30 | 31 | #ifdef DEBUG 32 | #define DEB "_DEBUG" 33 | #else 34 | #define DEB "" 35 | #endif /* DEBUG */ 36 | #define PROXYSQL_CLICKHOUSE_AUTHENTICATION_VERSION "0.1.0702" DEB 37 | 38 | class PtrArray; 39 | 40 | #ifndef CH_CREDS_GROUPS_T 41 | #define CH_CREDS_GROUPS_T 42 | typedef struct _ch_creds_group_t { 43 | #ifdef PROXYSQL_AUTH_PTHREAD_MUTEX 44 | pthread_rwlock_t lock; 45 | #else 46 | rwlock_t lock; 47 | #endif 48 | ch_umap_auth bt_map; 49 | PtrArray *cred_array; 50 | } ch_creds_group_t; 51 | #endif // CH_CREDS_GROUPS_T 52 | 53 | class ClickHouse_Authentication { 54 | private: 55 | ch_creds_group_t creds_backends; 56 | ch_creds_group_t creds_frontends; 57 | bool _reset(enum cred_username_type usertype); 58 | 59 | public: 60 | ClickHouse_Authentication(); 61 | ~ClickHouse_Authentication(); 62 | bool add(char *username, char *password, enum cred_username_type usertype, 63 | bool use_ssl, int default_hostgroup, char *default_schema, 64 | bool schema_locked, bool transaction_persistent, bool fast_forward, 65 | int max_connections); 66 | bool del(char *username, enum cred_username_type usertype, 67 | bool set_lock = true); 68 | bool reset(); 69 | void print_version(); 70 | bool exists(char *username); 71 | char *lookup(char *username, enum cred_username_type usertype, 72 | bool *use_ssl, int *default_hostgroup, char **default_schema, 73 | bool *schema_locked, bool *transaction_persistent, 74 | bool *fast_forward, int *max_connections, void **sha1_pass); 75 | int dump_all_users(ch_account_details_t ***, bool _complete = true); 76 | int increase_frontend_user_connections(char *username, int *mc = NULL); 77 | void decrease_frontend_user_connections(char *username); 78 | void set_all_inactive(enum cred_username_type usertype); 79 | void remove_inactives(enum cred_username_type usertype); 80 | bool set_SHA1(char *username, enum cred_username_type usertype, 81 | void *sha_pass); 82 | }; 83 | 84 | #endif // CLASS_PROXYSQL_CLICKHOUSE_AUTHENTICATION_H 85 | -------------------------------------------------------------------------------- /include/ClickHouse_Server.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_PROXYSQL_CLICKHOUSE_SERVER_H 2 | #define CLASS_PROXYSQL_CLICKHOUSE_SERVER_H 3 | 4 | #include "proxy_defines.h" 5 | #include "proxysql.h" 6 | #include "cpp.h" 7 | #include 8 | 9 | #include "clickhouse/client.h" 10 | 11 | class ClickHouse_Session { 12 | public: 13 | SQLite3DB *sessdb; 14 | bool transfer_started; 15 | bool schema_initialized; 16 | uint8_t sid; 17 | ClickHouse_Session(); 18 | bool init(); 19 | bool connected; 20 | ~ClickHouse_Session(); 21 | clickhouse::ClientOptions co; 22 | clickhouse::Client *client; 23 | }; 24 | 25 | class ClickHouse_Server { 26 | public: 27 | void wrlock(); 28 | void wrunlock(); 29 | private: 30 | volatile int main_shutdown; 31 | SQLite3DB *SQLite_General_DB; 32 | int main_poll_nfds; 33 | struct pollfd *main_poll_fds; 34 | int *main_callback_func; 35 | 36 | pthread_rwlock_t rwlock; 37 | 38 | 39 | struct { 40 | char *mysql_ifaces; 41 | bool read_only; 42 | #ifdef DEBUG 43 | bool debug; 44 | #endif // DEBUG 45 | char *hostname; 46 | uint16_t port; 47 | } variables; 48 | 49 | void dump_mysql_collations(); 50 | public: 51 | ClickHouse_Server(); 52 | ~ClickHouse_Server(); 53 | void print_version(); 54 | char **get_variables_list(); 55 | char *get_variable(char *name); 56 | bool set_variable(char *name, char *value); 57 | bool init(); 58 | bool has_variable(const char *name); 59 | void send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows = 0); 60 | void send_MySQL_ERR(MySQL_Protocol *myprot, char *msg); 61 | }; 62 | #endif // CLASS_PROXYSQL_CLICKHOUSE_SERVER_H 63 | -------------------------------------------------------------------------------- /include/MySQL_Authentication.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_MYSQL_AUTHENTICATION_H 2 | #define __CLASS_MYSQL_AUTHENTICATION_H 3 | 4 | #include "proxysql.h" 5 | #include "cpp.h" 6 | 7 | #define PROXYSQL_AUTH_PTHREAD_MUTEX 8 | 9 | #ifndef ACCOUNT_DETAILS_T 10 | #define ACCOUNT_DETAILS_T 11 | typedef struct _account_details_t { 12 | char *username; 13 | char *password; 14 | void *sha1_pass; 15 | bool use_ssl; 16 | int default_hostgroup; 17 | char *default_schema; 18 | bool schema_locked; 19 | bool transaction_persistent; 20 | bool fast_forward; 21 | int max_connections; 22 | int num_connections_used; 23 | bool __frontend; // this is used only during the dump 24 | bool __backend; // this is used only during the dump 25 | bool __active; 26 | char *comment; 27 | } account_details_t; 28 | 29 | typedef std::map umap_auth; 30 | #endif // ACCOUNT_DETAILS_T 31 | 32 | #ifdef DEBUG 33 | #define DEB "_DEBUG" 34 | #else 35 | #define DEB "" 36 | #endif /* DEBUG */ 37 | #define MYSQL_AUTHENTICATION_VERSION "0.2.0902" DEB 38 | 39 | 40 | class PtrArray; 41 | 42 | #ifndef CREDS_GROUPS_T 43 | #define CREDS_GROUPS_T 44 | typedef struct _creds_group_t { 45 | #ifdef PROXYSQL_AUTH_PTHREAD_MUTEX 46 | pthread_rwlock_t lock; 47 | #else 48 | rwlock_t lock; 49 | #endif 50 | umap_auth bt_map; 51 | PtrArray *cred_array; 52 | } creds_group_t; 53 | #endif // CREDS_GROUPS_T 54 | 55 | class MySQL_Authentication { 56 | private: 57 | creds_group_t creds_backends; 58 | creds_group_t creds_frontends; 59 | bool _reset(enum cred_username_type usertype); 60 | uint64_t _get_runtime_checksum(enum cred_username_type usertype); 61 | public: 62 | MySQL_Authentication(); 63 | ~MySQL_Authentication(); 64 | bool add(char *username, char *password, enum cred_username_type usertype, bool use_ssl, int default_hostgroup, char *default_schema, bool schema_locked, bool transaction_persistent, bool fast_forward, int max_connections, char *comment); 65 | bool del(char *username, enum cred_username_type usertype, bool set_lock=true); 66 | bool reset(); 67 | void print_version(); 68 | bool exists(char *username); 69 | char * lookup(char *username, enum cred_username_type usertype, bool *use_ssl, int *default_hostgroup, char **default_schema, bool *schema_locked, bool *transaction_persistent, bool *fast_forward, int *max_connections, void **sha1_pass); 70 | int dump_all_users(account_details_t ***, bool _complete=true); 71 | int increase_frontend_user_connections(char *username, int *mc=NULL); 72 | void decrease_frontend_user_connections(char *username); 73 | void set_all_inactive(enum cred_username_type usertype); 74 | void remove_inactives(enum cred_username_type usertype); 75 | bool set_SHA1(char *username, enum cred_username_type usertype, void *sha_pass); 76 | unsigned int memory_usage(); 77 | uint64_t get_runtime_checksum(); 78 | }; 79 | 80 | #endif /* __CLASS_MYSQL_AUTHENTICATION_H */ 81 | -------------------------------------------------------------------------------- /include/MySQL_Logger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_MYSQL_LOGGER_H 2 | #define __CLASS_MYSQL_LOGGER_H 3 | #include "proxysql.h" 4 | #include "cpp.h" 5 | 6 | #define PROXYSQL_LOGGER_PTHREAD_MUTEX 7 | 8 | class MySQL_Event { 9 | private: 10 | uint32_t thread_id; 11 | char *username; 12 | char *schemaname; 13 | size_t username_len; 14 | size_t schemaname_len; 15 | uint64_t start_time; 16 | uint64_t end_time; 17 | uint64_t query_digest; 18 | char *query_ptr; 19 | size_t query_len; 20 | char *server; 21 | char *client; 22 | size_t server_len; 23 | size_t client_len; 24 | //uint64_t total_length; 25 | unsigned char buf[10]; 26 | enum log_event_type et; 27 | uint64_t hid; 28 | char *extra_info; 29 | public: 30 | MySQL_Event(log_event_type _et, uint32_t _thread_id, char * _username, char * _schemaname , uint64_t _start_time , uint64_t _end_time , uint64_t _query_digest, char *_client, size_t _client_len); 31 | uint64_t write(std::fstream *f, MySQL_Session *sess); 32 | uint64_t write_query(std::fstream *f); 33 | void write_auth(std::fstream *f, MySQL_Session *sess); 34 | void set_query(const char *ptr, int len); 35 | void set_server(int _hid, const char *ptr, int len); 36 | void set_extra_info(char *); 37 | }; 38 | 39 | class MySQL_Logger { 40 | private: 41 | struct { 42 | bool enabled; 43 | char *base_filename; 44 | char *datadir; 45 | unsigned int log_file_id; 46 | unsigned int max_log_file_size; 47 | std::fstream *logfile; 48 | } events; 49 | struct { 50 | bool enabled; 51 | char *base_filename; 52 | char *datadir; 53 | unsigned int log_file_id; 54 | unsigned int max_log_file_size; 55 | std::fstream *logfile; 56 | } audit; 57 | #ifdef PROXYSQL_LOGGER_PTHREAD_MUTEX 58 | pthread_mutex_t wmutex; 59 | #else 60 | rwlock_t rwlock; 61 | #endif 62 | void wrlock(); 63 | void wrunlock(); 64 | void events_close_log_unlocked(); 65 | void events_open_log_unlocked(); 66 | void audit_close_log_unlocked(); 67 | void audit_open_log_unlocked(); 68 | unsigned int events_find_next_id(); 69 | unsigned int audit_find_next_id(); 70 | public: 71 | MySQL_Logger(); 72 | ~MySQL_Logger(); 73 | void flush_log(); 74 | void events_flush_log_unlocked(); 75 | void audit_flush_log_unlocked(); 76 | void events_set_datadir(char *); 77 | void events_set_base_filename(); 78 | void audit_set_datadir(char *); 79 | void audit_set_base_filename(); 80 | void log_request(MySQL_Session *, MySQL_Data_Stream *); 81 | void log_audit_entry(log_event_type, MySQL_Session *, MySQL_Data_Stream *, char *e = NULL); 82 | void flush(); 83 | }; 84 | 85 | 86 | #endif /* __CLASS_MYSQL_LOGGER_H */ 87 | -------------------------------------------------------------------------------- /include/ProxySQL_HTTP_Server.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_PROXYSQL_HTTP_SERVER_H 2 | #define CLASS_PROXYSQL_HTTP_SERVER_H 3 | #include "proxysql.h" 4 | #include "cpp.h" 5 | #include 6 | 7 | #define ProxySQL_HTTP_Server_Rate_Limit 100 8 | 9 | class ProxySQL_HTTP_Server { 10 | unsigned int page_sec; 11 | time_t cur_time; 12 | pthread_mutex_t check_version_mutex; 13 | time_t last_check_version; 14 | std::string * generate_header(char *); 15 | std::string * generate_canvas(char *); 16 | std::string * generate_chart(char *chart_name, char *ts, int nsets, char **dname, char **llabel, char **values); 17 | char *extract_values(SQLite3_result *result, int idx, bool relative, double mult=1); 18 | char *extract_ts(SQLite3_result *result, bool relative); 19 | public: 20 | struct { 21 | char *proxysql_latest_version; 22 | } variables; 23 | ProxySQL_HTTP_Server(); 24 | ~ProxySQL_HTTP_Server(); 25 | void init(); 26 | int handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr); 27 | void print_version(); 28 | void check_latest_version_http(); 29 | }; 30 | 31 | #endif /* CLASS_PROXYSQL_HTTP_SERVER */ 32 | -------------------------------------------------------------------------------- /include/SQLite3_Server.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_PROXYSQL_SQLITE3_SERVER_H 2 | #define CLASS_PROXYSQL_SQLITE3_SERVER_H 3 | 4 | #include "proxy_defines.h" 5 | #include "proxysql.h" 6 | #include "cpp.h" 7 | #include 8 | 9 | class SQLite3_Session { 10 | public: 11 | SQLite3DB *sessdb; 12 | SQLite3_Session(); 13 | ~SQLite3_Session(); 14 | }; 15 | 16 | class SQLite3_Server { 17 | private: 18 | volatile int main_shutdown; 19 | SQLite3DB *sessdb; 20 | int main_poll_nfds; 21 | struct pollfd *main_poll_fds; 22 | int *main_callback_func; 23 | 24 | pthread_rwlock_t rwlock; 25 | 26 | struct { 27 | char *admin_credentials; 28 | char *stats_credentials; 29 | int refresh_interval; 30 | char *mysql_ifaces; 31 | char *telnet_admin_ifaces; 32 | char *telnet_stats_ifaces; 33 | bool read_only; 34 | bool hash_passwords; 35 | char * admin_version; 36 | #ifdef DEBUG 37 | bool debug; 38 | #endif // DEBUG 39 | } variables; 40 | #ifdef TEST_AURORA 41 | std::vector *tables_defs_aurora; 42 | #endif // TEST_AURORA 43 | #ifdef TEST_GALERA 44 | std::vector *tables_defs_galera; 45 | #endif // TEST_GALERA 46 | #if defined(TEST_AURORA) || defined(TEST_GALERA) 47 | void insert_into_tables_defs(std::vector *, const char *table_name, const char *table_def); 48 | void drop_tables_defs(std::vector *tables_defs); 49 | void check_and_build_standard_tables(SQLite3DB *db, std::vector *tables_defs); 50 | #endif // TEST_AURORA || TEST_GALERA 51 | public: 52 | #ifdef TEST_AURORA 53 | unsigned int cur_aurora_writer[3]; 54 | unsigned int num_aurora_servers[3]; 55 | unsigned int max_num_aurora_servers; 56 | pthread_mutex_t aurora_mutex; 57 | void populate_aws_aurora_table(MySQL_Session *sess); 58 | #endif // TEST_AURORA 59 | #ifdef TEST_GALERA 60 | //unsigned int cur_aurora_writer[3]; 61 | unsigned int num_galera_servers[3]; 62 | unsigned int max_num_galera_servers; 63 | pthread_mutex_t galera_mutex; 64 | void populate_galera_table(MySQL_Session *sess); 65 | #endif // TEST_GALERA 66 | SQLite3_Server(); 67 | ~SQLite3_Server(); 68 | char **get_variables_list(); 69 | char *get_variable(char *name); 70 | bool set_variable(char *name, char *value); 71 | bool has_variable(const char *name); 72 | void print_version(); 73 | bool init(); 74 | void wrlock(); 75 | void wrunlock(); 76 | void send_MySQL_OK(MySQL_Protocol *myprot, char *msg, int rows=0); 77 | void send_MySQL_ERR(MySQL_Protocol *myprot, char *msg); 78 | }; 79 | #endif // CLASS_PROXYSQL_SQLITE3_SERVER_H 80 | -------------------------------------------------------------------------------- /include/StatCounters.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_STAT_COUNTERS_H 2 | #define __CLASS_STAT_COUNTERS_H 3 | #include "proxysql_atomic.h" 4 | 5 | #define PROXYSQL_STATSCOUNTERS_NOLOCK 6 | class StatCounters { 7 | private: 8 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 9 | #else 10 | bool with_lock; 11 | rwlock_t _lock; 12 | #endif 13 | int last; 14 | int keep; 15 | void cleanup() { 16 | int i; 17 | int l=last%len; 18 | if (l last ) { 61 | last=_i; cleanup(); 62 | } 63 | val[_i%len]=_v; 64 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 65 | #else 66 | if (with_lock) 67 | spin_wrunlock(&_lock); 68 | #endif 69 | } 70 | void incr(int _i) { 71 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 72 | #else 73 | if (with_lock) 74 | spin_wrlock(&_lock); 75 | #endif 76 | if ( _i > last ) { 77 | if ( _i > last + keep ) val[_i%len]=0; 78 | last=_i; cleanup(); 79 | } 80 | val[_i%len]++; 81 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 82 | #else 83 | if (with_lock) 84 | spin_wrunlock(&_lock); 85 | #endif 86 | } 87 | void decr(int _i) { 88 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 89 | #else 90 | if (with_lock) 91 | spin_wrlock(&_lock); 92 | #endif 93 | if ( _i > last ) { 94 | if ( _i > last + keep ) val[_i%len]=0; 95 | last=_i; cleanup(); 96 | } 97 | val[_i%len]--; 98 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 99 | #else 100 | if (with_lock) 101 | spin_wrunlock(&_lock); 102 | #endif 103 | } 104 | int sum(int _i, int _k) { 105 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 106 | #else 107 | if (with_lock) 108 | spin_wrlock(&_lock); 109 | #endif 110 | if ( _i > last ) { 111 | if ( _i > last + keep ) val[_i%len]=0; 112 | last=_i; cleanup(); 113 | } 114 | int i; 115 | int ret=0; 116 | for (i=0; i<_k; i++) { 117 | ret+=val[(_i-i)%len]; 118 | } 119 | #ifdef PROXYSQL_STATSCOUNTERS_NOLOCK 120 | #else 121 | if (with_lock) 122 | spin_wrunlock(&_lock); 123 | #endif 124 | return ret; 125 | } 126 | }; 127 | #endif /* __CLASS_STAT_COUNTERS_H */ 128 | 129 | -------------------------------------------------------------------------------- /include/c_tokenizer.h: -------------------------------------------------------------------------------- 1 | /* c_tokenizer.h */ 2 | // some code borrowed from http://www.cplusplus.com/faq/sequences/strings/split/ 3 | 4 | #pragma once 5 | #ifndef C_TOKENIZER_H 6 | #define C_TOKENIZER_H 7 | 8 | #define PROXYSQL_TOKENIZER_BUFFSIZE 128 9 | 10 | #ifndef FIRST_COMMENT_MAX_LENGTH 11 | #define FIRST_COMMENT_MAX_LENGTH 1024 12 | #endif /* FIRST_COMMENT_MAX_LENGTH */ 13 | 14 | typedef struct 15 | { 16 | char buffer[PROXYSQL_TOKENIZER_BUFFSIZE]; 17 | int s_length; 18 | char* s; 19 | const char* delimiters; 20 | char* current; 21 | char* next; 22 | int is_ignore_empties; 23 | } 24 | tokenizer_t; 25 | 26 | enum { TOKENIZER_EMPTIES_OK, TOKENIZER_NO_EMPTIES }; 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif /* __cplusplus */ 31 | //tokenizer_t tokenizer( const char* s, const char* delimiters, int empties ); 32 | void tokenizer( tokenizer_t *, const char* s, const char* delimiters, int empties ); 33 | const char* free_tokenizer( tokenizer_t* tokenizer ); 34 | const char* tokenize( tokenizer_t* tokenizer ); 35 | char * mysql_query_digest_and_first_comment(char *s , int len , char **first_comment, char *buf); 36 | char * mysql_query_strip_comments(char *s , int len); 37 | void c_split_2(const char *in, const char *del, char **out1, char **out2); 38 | #ifdef __cplusplus 39 | } 40 | #endif /* __cplusplus */ 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/configfile.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_PROXYSQL_CONFIGFILE_H 2 | #define __CLASS_PROXYSQL_CONFIGFILE_H 3 | 4 | #include "libconfig.h++" 5 | 6 | using namespace libconfig; 7 | 8 | 9 | class ProxySQL_ConfigFile { 10 | private: 11 | //struct stat statbuf; 12 | char *filename; 13 | public: 14 | Config *cfg; 15 | ProxySQL_ConfigFile(); 16 | bool OpenFile(const char *); 17 | void CloseFile(); 18 | bool ReadGlobals(); 19 | bool configVariable(const char *, const char *, int &, int, int, int, int); 20 | bool configVariable(const char *, const char *, int64_t &, int64_t, int64_t, int64_t, int64_t); 21 | bool configVariable(const char *, const char *, bool &, bool); 22 | bool configVariable(const char *, const char *, char **, const char *); 23 | ~ProxySQL_ConfigFile(); 24 | }; 25 | 26 | 27 | #endif /* __CLASS_PROXYSQL_CONFIGFILE_H */ 28 | -------------------------------------------------------------------------------- /include/cpp.h: -------------------------------------------------------------------------------- 1 | #include "gen_utils.h" 2 | #include "MySQL_Thread.h" 3 | #include "MySQL_Session.h" 4 | #include "mysql_backend.h" 5 | #include "MySQL_Data_Stream.h" 6 | #include "query_cache.hpp" 7 | #include "mysql_connection.h" 8 | #include "sqlite3db.h" 9 | #include "StatCounters.h" 10 | #include "MySQL_Monitor.hpp" 11 | #include "MySQL_Protocol.h" 12 | #include "MySQL_Authentication.hpp" 13 | #include "MySQL_LDAP_Authentication.hpp" 14 | #ifdef PROXYSQLCLICKHOUSE 15 | #include "ClickHouse_Authentication.hpp" 16 | #endif /* PROXYSQLCLICKHOUSE */ 17 | #include "fileutils.hpp" 18 | #include "configfile.hpp" 19 | #include "query_processor.h" 20 | #include "proxysql_admin.h" 21 | #include "SQLite3_Server.h" 22 | #ifdef PROXYSQLCLICKHOUSE 23 | #include "ClickHouse_Server.h" 24 | #endif /* PROXYSQLCLICKHOUSE */ 25 | #include "MySQL_HostGroups_Manager.h" 26 | #include "MySQL_Logger.hpp" 27 | #include "MySQL_PreparedStatement.h" 28 | #include "ProxySQL_Cluster.hpp" // cluster 29 | #include "ProxySQL_Statistics.hpp" // statistics 30 | #include "ProxySQL_HTTP_Server.hpp" // HTTP server 31 | #undef swap 32 | #undef min 33 | #undef max 34 | #include 35 | #include 36 | #include 37 | -------------------------------------------------------------------------------- /include/fileutils.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef __CLASS_FILEUTILS_H 4 | #define __CLASS_FILEUTILS_H 5 | class FileUtils { 6 | public: 7 | static bool isReadable(const char *pathname) { 8 | if (access(pathname, R_OK)==0) return true; 9 | return false; 10 | }; 11 | static bool isWritable(const char *pathname) { 12 | if (access(pathname, W_OK)==0) return true; 13 | return false; 14 | }; 15 | }; 16 | #endif /* __CLASS_FILEUTILS_H */ 17 | -------------------------------------------------------------------------------- /include/mysql_backend.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_MYSQL_BACKEND_H 2 | #define __CLASS_MYSQL_BACKEND_H 3 | #include "proxysql.h" 4 | #include "cpp.h" 5 | 6 | 7 | class MySQL_Backend 8 | { 9 | public: 10 | void * operator new(size_t); 11 | void operator delete(void *); 12 | int hostgroup_id; 13 | char gtid_uuid[64]; 14 | uint64_t gtid_trxid; 15 | MySQL_Data_Stream *server_myds; 16 | // mysql_cp_entry_t *server_mycpe; 17 | bytes_stats_t server_bytes_at_cmd; 18 | //MySQL_Hostgroup_Entry *mshge; 19 | //MySQL_Connection *myconn; 20 | MySQL_Backend(); 21 | ~MySQL_Backend(); 22 | void reset(); 23 | }; 24 | 25 | #endif /* __CLASS_MYSQL_BACKEND_H */ 26 | -------------------------------------------------------------------------------- /include/proxy_defines.h: -------------------------------------------------------------------------------- 1 | 2 | // If defined then active pthread mutex in ProxySQL_Admin else use the wrlock 3 | #define PA_PTHREAD_MUTEX 4 | 5 | #if !defined(__FreeBSD__) && !defined(__APPLE__) 6 | // If enabled, it adds support for auxiliary threads 7 | #define IDLE_THREADS 8 | #endif 9 | -------------------------------------------------------------------------------- /include/proxysql.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #ifndef EZOPTION 8 | #define EZOPTION 9 | #endif /* EZOPTION */ 10 | #endif 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #ifdef NDEBUG 19 | #undef NDEBUG 20 | #endif 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include 49 | 50 | #include 51 | 52 | #if !defined(__FreeBSD__) && !defined(__APPLE__) 53 | #define HAVE_BOOL 54 | #include "ma_global.h" 55 | //#include "my_pthread.h" 56 | #endif 57 | #include "mysql.h" 58 | #include "mariadb_com.h" 59 | 60 | #include "proxysql_mem.h" 61 | 62 | #include "proxysql_structs.h" 63 | #include "proxysql_debug.h" 64 | #include "proxysql_macros.h" 65 | 66 | #include "jemalloc.h" 67 | 68 | #ifdef DEBUG 69 | //#define VALGRIND_ENABLE_ERROR_REPORTING 70 | //#define VALGRIND_DISABLE_ERROR_REPORTING 71 | #include "valgrind.h" 72 | #else 73 | #define VALGRIND_ENABLE_ERROR_REPORTING 74 | #define VALGRIND_DISABLE_ERROR_REPORTING 75 | #endif /* DEBUG */ 76 | 77 | #include "sqlite3.h" 78 | 79 | #include "c_tokenizer.h" 80 | 81 | #ifdef DEBUG 82 | #define DEB "_DEBUG" 83 | #else 84 | #define DEB "" 85 | #endif /* DEBUG */ 86 | #define PROXYSQL_VERSION GITVERSION DEB 87 | #define PROXYSQL_CODENAME "Truls" 88 | 89 | #ifndef PROXYSQL_FUNC_DEFS 90 | #define PROXYSQL_FUNC_DEFS 91 | 92 | #ifdef __cplusplus 93 | extern "C" { 94 | #endif /* __cplusplus */ 95 | 96 | int listen_on_port(char *ip, uint16_t port, int backlog, bool reuseport=false); 97 | int listen_on_unix(char *, int); 98 | int connect_socket(char *, int); 99 | int config_file_is_readable(char *); 100 | unsigned int CPY3(unsigned char *); 101 | 102 | int pkt_ok(unsigned char *, unsigned int); 103 | int pkt_end(unsigned char *, unsigned int); 104 | int pkt_com_query(unsigned char *, unsigned int); 105 | enum MySQL_response_type mysql_response(unsigned char *, unsigned int); 106 | 107 | void proxy_error_func(const char *, ...); 108 | 109 | #ifdef DEBUG 110 | void init_debug_struct(); 111 | void init_debug_struct_from_cmdline(); 112 | void proxy_debug_func(enum debug_module, int, int, const char *, int, const char *, const char *, ...); 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif /* __cplusplus */ 118 | 119 | #endif /* PROXYSQL_FUNC_DEFS */ 120 | -------------------------------------------------------------------------------- /include/proxysql_atomic.h: -------------------------------------------------------------------------------- 1 | #ifdef PROXYSQL_USE_SPINLOCK 2 | // PROXYSQL_USE_SPINLOCK is NOT define 3 | // spinlock have been removed in 1.4.1 due to issue #977 , to compile in ARM 4 | // this file is kept for reference, and will be completely removed in future 5 | #ifndef PROXYSQL_ATOMIC 6 | #define PROXYSQL_ATOMIC 7 | /* 8 | typedef unsigned spinlock; 9 | typedef struct _rwlock_t rwlock_t; 10 | struct _rwlock_t { 11 | spinlock lock; 12 | unsigned readers; 13 | }; 14 | */ 15 | #define atomic_inc(P) __sync_add_and_fetch((P), 1) 16 | #define atomic_dec(P) __sync_add_and_fetch((P), -1) 17 | 18 | /* Compile read-write barrier */ 19 | #define barrier() asm volatile("": : :"memory") 20 | 21 | /* Pause instruction to prevent excess processor bus usage */ 22 | #define cpu_relax_pa() asm volatile("pause\n": : :"memory") 23 | #define cpu_relax_us() usleep(1) 24 | 25 | #define RELAX_TRIES 100 26 | 27 | static inline unsigned xchg_32(void *ptr, unsigned x) { 28 | __asm__ __volatile__("xchgl %0,%1" 29 | :"=r" (x) 30 | :"m" (*(volatile unsigned *)ptr), "0" (x) 31 | :"memory"); 32 | return x; 33 | } 34 | 35 | static inline void spinlock_rwlock_init(rwlock_t *l) { 36 | memset(l,0,sizeof(rwlock_t)); 37 | } 38 | 39 | static inline void spinlock_init(spinlock *l) { 40 | memset(l,0,sizeof(spinlock)); 41 | } 42 | 43 | static inline void spin_lock(spinlock *lock) { 44 | int i=RELAX_TRIES; 45 | while (1) { 46 | if (!xchg_32(lock, 1)) return; 47 | while (*lock) { if (i) { i--; cpu_relax_pa(); } else { i=RELAX_TRIES; cpu_relax_us(); } } 48 | } 49 | } 50 | 51 | static inline void spin_unlock(spinlock *lock) { 52 | barrier(); 53 | *lock = 0; 54 | } 55 | 56 | static inline void spin_wrlock(rwlock_t *l) { 57 | spin_lock(&l->lock); 58 | int i=RELAX_TRIES; 59 | while (l->readers) { if (i) { i--; cpu_relax_pa(); } else { i=RELAX_TRIES; cpu_relax_us(); } } 60 | } 61 | 62 | static inline void spin_wrunlock(rwlock_t *l) { 63 | spin_unlock(&l->lock); 64 | } 65 | 66 | static inline void spin_rdlock(rwlock_t *l) { 67 | int i=RELAX_TRIES; 68 | while (1) { 69 | atomic_inc(&l->readers); 70 | if (!l->lock) return; 71 | atomic_dec(&l->readers); 72 | while (l->lock) { if (i) { i--; cpu_relax_pa(); } else { i=RELAX_TRIES; cpu_relax_us(); } } 73 | } 74 | } 75 | 76 | static inline void spin_rdunlock(rwlock_t *l) { 77 | atomic_dec(&l->readers); 78 | } 79 | 80 | 81 | #endif /* PROXYSQL_ATOMIC */ 82 | #endif // PROXYSQL_USE_SPINLOCK 83 | -------------------------------------------------------------------------------- /include/proxysql_debug.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | #ifdef DEBUG 4 | #ifndef DEBUG_EXTERN 5 | #define DEBUG_EXTERN 6 | extern debug_level *gdbg_lvl; 7 | extern int gdbg; 8 | #endif 9 | #endif 10 | */ 11 | #ifdef DEBUG 12 | #define PROXY_TRACE() { proxy_debug(PROXY_DEBUG_GENERIC,10,"TRACE\n"); } 13 | #else 14 | #define PROXY_TRACE() 15 | #endif 16 | 17 | #ifdef DEBUG 18 | #ifdef SYS_gettid 19 | #define proxy_debug(module, verbosity, fmt, ...) \ 20 | do { if (GloVars.global.gdbg) { \ 21 | proxy_debug_func(module, verbosity, syscall(SYS_gettid), __FILE__, __LINE__, __func__ , fmt, ## __VA_ARGS__); \ 22 | } } while (0) 23 | #else 24 | #define proxy_debug(module, verbosity, fmt, ...) 25 | #endif /* SYS_gettid */ 26 | #else 27 | #define proxy_debug(module, verbosity, fmt, ...) 28 | #endif /* DEBUG */ 29 | 30 | /* 31 | #ifdef DEBUG 32 | */ 33 | #define proxy_error(fmt, ...) \ 34 | do { \ 35 | time_t __timer; \ 36 | char __buffer[30]; \ 37 | struct tm __tm_info; \ 38 | time(&__timer); \ 39 | localtime_r(&__timer, &__tm_info); \ 40 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", &__tm_info); \ 41 | proxy_error_func("%s %s:%d:%s(): [ERROR] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \ 42 | } while(0) 43 | /* 44 | #else 45 | #define proxy_error(fmt, ...) \ 46 | do { \ 47 | time_t __timer; \ 48 | char __buffer[25]; \ 49 | struct tm *__tm_info; \ 50 | time(&__timer); \ 51 | __tm_info = localtime(&__timer); \ 52 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \ 53 | proxy_error_func("%s [ERROR] " fmt , __buffer , ## __VA_ARGS__); \ 54 | } while(0) 55 | #endif 56 | */ 57 | /* 58 | #ifdef DEBUG 59 | */ 60 | #define proxy_warning(fmt, ...) \ 61 | do { \ 62 | time_t __timer; \ 63 | char __buffer[25]; \ 64 | struct tm *__tm_info; \ 65 | time(&__timer); \ 66 | __tm_info = localtime(&__timer); \ 67 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \ 68 | proxy_error_func("%s %s:%d:%s(): [WARNING] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \ 69 | } while(0) 70 | /* 71 | #else 72 | #define proxy_warning(fmt, ...) \ 73 | do { \ 74 | time_t __timer; \ 75 | char __buffer[25]; \ 76 | struct tm *__tm_info; \ 77 | time(&__timer); \ 78 | __tm_info = localtime(&__timer); \ 79 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \ 80 | proxy_error_func("%s [WARNING] " fmt , __buffer , ## __VA_ARGS__); \ 81 | } while(0) 82 | #endif 83 | */ 84 | #ifdef DEBUG 85 | #define proxy_info(fmt, ...) \ 86 | do { \ 87 | time_t __timer; \ 88 | char __buffer[25]; \ 89 | struct tm *__tm_info; \ 90 | time(&__timer); \ 91 | __tm_info = localtime(&__timer); \ 92 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \ 93 | proxy_error_func("%s %s:%d:%s(): [INFO] " fmt, __buffer, __FILE__, __LINE__, __func__ , ## __VA_ARGS__); \ 94 | } while(0) 95 | #else 96 | #define proxy_info(fmt, ...) \ 97 | do { \ 98 | time_t __timer; \ 99 | char __buffer[25]; \ 100 | struct tm *__tm_info; \ 101 | time(&__timer); \ 102 | __tm_info = localtime(&__timer); \ 103 | strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); \ 104 | proxy_error_func("%s [INFO] " fmt , __buffer , ## __VA_ARGS__); \ 105 | } while(0) 106 | #endif 107 | 108 | #ifdef DEBUG 109 | //void *debug_logger(); 110 | #endif 111 | -------------------------------------------------------------------------------- /include/proxysql_gtid.h: -------------------------------------------------------------------------------- 1 | #ifndef PROXYSQL_GTID 2 | #define PROXYSQL_GTID 3 | // highly inspired by libslave 4 | // https://github.com/vozbu/libslave/ 5 | #include 6 | #include 7 | #include 8 | 9 | typedef std::pair gtid_t; 10 | typedef std::pair gtid_interval_t; 11 | typedef std::unordered_map> gtid_set_t; 12 | 13 | /* 14 | class Gtid_Server_Info { 15 | public: 16 | gtid_set_t executed_gtid_set; 17 | char *hostname; 18 | uint16_t mysql_port; 19 | uint16_t gtid_port; 20 | bool active; 21 | Gtid_Server_Info(char *_h, uint16_t _mp, uint16_t _gp) { 22 | hostname = strdup(_h); 23 | mysql_port = _mp; 24 | gtid_port = _gp; 25 | active = true; 26 | }; 27 | ~Gtid_Server_Info() { 28 | free(hostname); 29 | }; 30 | }; 31 | */ 32 | 33 | #endif /* PROXYSQL_GTID */ 34 | -------------------------------------------------------------------------------- /include/proxysql_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | Use of generic memory structure 3 | set/get function defined by the user 4 | 5 | Ex: 6 | */ 7 | 8 | 9 | 10 | typedef _hte_ext_t hte_ext_t; 11 | 12 | union _hte_ext_t { 13 | void *ptr; 14 | int i; 15 | uint32_t u32; 16 | uint64_t u64; 17 | }; 18 | 19 | struct __leo_hash_entry_t { 20 | unsigned char *key; 21 | void *self; 22 | hte_ext_t ext0; 23 | hte_ext_t ext1; 24 | hte_ext_t ext2; 25 | hte_ext_t ext3; 26 | hte_ext_t ext4; 27 | hte_ext_t ext5; 28 | hte_ext_t ext6; 29 | hte_ext_t ext7; 30 | hte_ext_t ext8; 31 | hte_ext_t ext9; 32 | }; 33 | -------------------------------------------------------------------------------- /include/proxysql_macros.h: -------------------------------------------------------------------------------- 1 | 2 | #define strdup_null(__c) ( __c ? strdup(__c) : __c ) 3 | #define char_malloc (char *)malloc 4 | #define free_null(__c) { if(__c) { free(__c); __c=NULL; } } 5 | 6 | #define itostr(__s, __i) { __s=char_malloc(32); sprintf(__s, "%lld", __i); } 7 | 8 | // fast memory copy forward . Use this instead of memcpy for small buffers 9 | #define MEM_COPY_FWD(dst_p, src_p, bytes) \ 10 | do { \ 11 | void *__a=dst_p; \ 12 | void *__b=src_p; \ 13 | size_t __nbytes = (bytes); \ 14 | while (__nbytes > 0) { \ 15 | char __x = ((char *) __b)[0]; \ 16 | __b += 1; \ 17 | __nbytes -= 1; \ 18 | ((char *) __a)[0] = __x; \ 19 | __a += 1; \ 20 | } \ 21 | } while (0) 22 | 23 | 24 | // copy 1 byte 25 | #define CPY1(x) *((uint8_t *)(x)) 26 | 27 | // copy 2 bytes 28 | #define CPY2(x) *((uint16_t *)(x)) 29 | 30 | 31 | 32 | /* 33 | #define CPY3(x) \ 34 | do { \ 35 | uchar _cpy3buf[4]; \ 36 | memcpy(_cpy3buf, x, 3); \ 37 | _cpy3buf[3]=0; \ 38 | return *((uint32_t *)cy3buf); \ 39 | } while(0) 40 | */ 41 | 42 | // copy 4 bytes 43 | #define CPY4(x) *((uint32_t *)x) 44 | 45 | // (un)set blocking mode on a file descriptor 46 | #define ioctl_FIONBIO(fd, mode) \ 47 | { \ 48 | int ioctl_mode=mode; \ 49 | ioctl(fd, FIONBIO, (char *)&ioctl_mode); \ 50 | } 51 | 52 | // copy 4 bytes 53 | #define Copy4B(x,y) \ 54 | do { \ 55 | uint32_t *a=(uint32_t *)x; \ 56 | *a=*((uint32_t *)y); \ 57 | } while(0) 58 | 59 | #ifndef PROXYSQL_LIKELY 60 | #ifdef __GNUC__ 61 | # define likely(x) __builtin_expect(!!(x), 1) 62 | # define unlikely(x) __builtin_expect(!!(x), 0) 63 | #else 64 | # define likely(x) !!(x) 65 | # define unlikely(x) !!(x) 66 | #endif 67 | #endif /* PROXYSQL_LIKELY */ 68 | -------------------------------------------------------------------------------- /include/proxysql_mem.h: -------------------------------------------------------------------------------- 1 | #define L_SFC_MIN_ELEM_SIZE 8 2 | #define L_SFC_MID_ELEM_SIZE 128 3 | #define L_SFC_MAX_ELEM_SIZE 2048 4 | #define L_SFP_ARRAY_MID 5 5 | #define L_SFP_ARRAY_LEN 9 6 | #define L_SFC_MEM_BLOCK_SIZE 262144 7 | typedef struct _l_stack_t l_stack; 8 | typedef struct _l_super_free_chunk_t l_sfc; 9 | #ifndef L_SFP 10 | #define L_SFP 11 | typedef struct _l_super_free_pool_t l_sfp; 12 | typedef struct _LPtrArray LPtrArray; 13 | 14 | struct _l_stack_t { 15 | l_stack *n; 16 | }; 17 | 18 | struct _l_super_free_chunk_t { 19 | l_stack *stack; 20 | void **mem_blocks; 21 | size_t elem_size; 22 | size_t blocks_cnt; 23 | size_t alloc_cnt; 24 | size_t free_cnt; 25 | size_t __mem_l_free_count; 26 | 27 | }; 28 | 29 | struct _l_super_free_pool_t { 30 | l_sfc sfc[L_SFP_ARRAY_LEN]; 31 | }; 32 | 33 | #endif 34 | //extern __thread l_sfp *__thr_sfp; 35 | 36 | l_sfp * l_mem_init(); 37 | void l_mem_destroy(l_sfp *); 38 | //void * l_alloc(size_t); 39 | void * l_alloc0(size_t); 40 | void * l_realloc(void *, size_t, size_t); 41 | //void l_free(size_t, void *); 42 | void * __l_alloc(l_sfp *, size_t); 43 | void __l_free(l_sfp *, size_t, void *); 44 | 45 | #ifndef L_STACK 46 | #define L_STACK 47 | 48 | //#define l_alloc(s) __l_alloc(__thr_sfp,s) 49 | //#define l_free(s,p) __l_free(__thr_sfp,s,p) 50 | #define l_alloc(s) malloc(s) 51 | #define l_free(s,p) free(p) 52 | 53 | static inline void l_stack_push (l_stack **s, void *p) { 54 | l_stack *d=(l_stack *)p; 55 | d->n=*s; 56 | *s=d; 57 | } 58 | 59 | static inline void * l_stack_pop (l_stack **s) { 60 | l_stack *d; 61 | d=*s; 62 | if (d) { *s=d->n; d->n=NULL; } 63 | return d; 64 | } 65 | 66 | inline int mystrcasecmp(const char *a, const char *b) { 67 | char ca; 68 | char cb; 69 | do { 70 | cb = *b++; 71 | ca = *a++; 72 | 73 | if (cb >= 'a' && cb <= 'z') { 74 | cb -= 0x20; 75 | } 76 | if (ca != cb) 77 | return 1; 78 | } while (cb); 79 | 80 | return 0; 81 | } 82 | 83 | static inline char * l_strdup(const char *s) { 84 | size_t len=strlen(s)+1; 85 | char *r=(char *)l_alloc(len); 86 | memcpy(r,s,len); 87 | return r; 88 | } 89 | 90 | 91 | #endif /* L_STACK */ 92 | -------------------------------------------------------------------------------- /include/query_cache.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_QUERY_CACHE_H 2 | #define __CLASS_QUERY_CACHE_H 3 | #include "proxysql.h" 4 | #include "cpp.h" 5 | 6 | #define EXPIRE_DROPIT 0 7 | #define SHARED_QUERY_CACHE_HASH_TABLES 32 8 | #define HASH_EXPIRE_MAX 3600*24*365*10 9 | #define DEFAULT_purge_loop_time 500000 10 | #define DEFAULT_purge_total_time 10000000 11 | #define DEFAULT_purge_threshold_pct_min 3 12 | #define DEFAULT_purge_threshold_pct_max 90 13 | 14 | 15 | class KV_BtreeArray; 16 | 17 | typedef struct __QC_entry_t QC_entry_t; 18 | 19 | struct __QC_entry_t { 20 | uint64_t key; // primary key 21 | char *value; // pointer to value 22 | KV_BtreeArray *kv; // pointer to the KV_BtreeArray where the entry is stored 23 | QC_entry_t *self; // pointer to itself 24 | uint32_t klen; // length of the key : FIXME: not sure if still relevant 25 | uint32_t length; // length of the value 26 | unsigned long long create_ms; // when the entry was created, monotonic, millisecond granularity 27 | unsigned long long expire_ms; // when the entry will expire, monotonic , millisecond granularity 28 | unsigned long long access_ms; // when the entry was read last , monotonic , millisecond granularity 29 | uint32_t ref_count; // reference counter 30 | }; 31 | 32 | class KV_BtreeArray; 33 | class Query_Cache { 34 | private: 35 | KV_BtreeArray * KVs[SHARED_QUERY_CACHE_HASH_TABLES]; 36 | uint64_t get_data_size_total(); 37 | unsigned int current_used_memory_pct(); 38 | public: 39 | void * purgeHash_thread(void *); 40 | int size; 41 | int shutdown; 42 | unsigned long long QCnow_ms; 43 | pthread_t purge_thread_id; 44 | unsigned int purge_loop_time; 45 | unsigned int purge_total_time; 46 | unsigned int purge_threshold_pct_min; 47 | unsigned int purge_threshold_pct_max; 48 | uint64_t max_memory_size; 49 | Query_Cache(); 50 | ~Query_Cache(); 51 | void print_version(); 52 | bool set(uint64_t , const unsigned char *, uint32_t, unsigned char *, uint32_t, unsigned long long, unsigned long long, unsigned long long); 53 | unsigned char * get(uint64_t , const unsigned char *, const uint32_t, uint32_t *, unsigned long long, unsigned long long); 54 | uint64_t flush(); 55 | SQLite3_result * SQL3_getStats(); 56 | }; 57 | #endif /* __CLASS_QUERY_CACHE_H */ 58 | 59 | -------------------------------------------------------------------------------- /include/set_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLASS_SET_PARSER_H 2 | #define __CLASS_SET_PARSER_H 3 | #include 4 | #include 5 | #include 6 | 7 | class SetParser { 8 | private: 9 | std::string query; 10 | public: 11 | SetParser(std::string q); 12 | std::map> parse(); 13 | }; 14 | 15 | 16 | #endif /* __CLASS_SET_PARSER_H */ 17 | -------------------------------------------------------------------------------- /include/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | thread.h 3 | 4 | Header for a Java style thread class in C++. 5 | 6 | ------------------------------------------ 7 | 8 | Copyright © 2013 [Vic Hargrave - http://vichargrave.com] 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | */ 22 | 23 | #ifndef __thread_h__ 24 | #define __thread_h__ 25 | 26 | #include 27 | #include "jemalloc.h" 28 | 29 | class Thread 30 | { 31 | public: 32 | Thread(); 33 | virtual ~Thread(); 34 | 35 | int start(unsigned int ss=64, bool jemalloc_tcache=true); 36 | int join(); 37 | int detach(); 38 | pthread_t self(); 39 | 40 | virtual void* run() = 0; 41 | 42 | private: 43 | pthread_t m_tid; 44 | int m_running; 45 | int m_detached; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/wqueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | wqueue.h 3 | 4 | Worker thread queue based on the Standard C++ library list 5 | template class. 6 | 7 | ------------------------------------------ 8 | 9 | Copyright @ 2013 [Vic Hargrave - http://vichargrave.com] 10 | 11 | Licensed under the Apache License, Version 2.0 (the "License"); 12 | you may not use this file except in compliance with the License. 13 | You may obtain a copy of the License at 14 | 15 | http://www.apache.org/licenses/LICENSE-2.0 16 | 17 | Unless required by applicable law or agreed to in writing, software 18 | distributed under the License is distributed on an "AS IS" BASIS, 19 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | See the License for the specific language governing permissions and 21 | limitations under the License. 22 | */ 23 | 24 | #ifndef __wqueue_h__ 25 | #define __wqueue_h__ 26 | 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | template class wqueue 33 | { 34 | list m_queue; 35 | pthread_mutex_t m_mutex; 36 | pthread_cond_t m_condv; 37 | 38 | public: 39 | wqueue() { 40 | pthread_mutex_init(&m_mutex, NULL); 41 | pthread_cond_init(&m_condv, NULL); 42 | } 43 | ~wqueue() { 44 | pthread_mutex_destroy(&m_mutex); 45 | pthread_cond_destroy(&m_condv); 46 | } 47 | void add(T item) { 48 | pthread_mutex_lock(&m_mutex); 49 | m_queue.push_back(item); 50 | pthread_cond_signal(&m_condv); 51 | pthread_mutex_unlock(&m_mutex); 52 | } 53 | T remove() { 54 | pthread_mutex_lock(&m_mutex); 55 | while (m_queue.size() == 0) { 56 | pthread_cond_wait(&m_condv, &m_mutex); 57 | } 58 | T item = m_queue.front(); 59 | m_queue.pop_front(); 60 | pthread_mutex_unlock(&m_mutex); 61 | return item; 62 | } 63 | int size() { 64 | pthread_mutex_lock(&m_mutex); 65 | int size = m_queue.size(); 66 | pthread_mutex_unlock(&m_mutex); 67 | return size; 68 | } 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lib/mysql_backend.cpp: -------------------------------------------------------------------------------- 1 | #include "proxysql.h" 2 | #include "cpp.h" 3 | 4 | void * MySQL_Backend::operator new(size_t size) { 5 | return l_alloc(size); 6 | } 7 | 8 | void MySQL_Backend::operator delete(void *ptr) { 9 | l_free(sizeof(MySQL_Backend),ptr); 10 | } 11 | 12 | MySQL_Backend::MySQL_Backend() { 13 | hostgroup_id=-1; 14 | server_myds=NULL; 15 | server_bytes_at_cmd.bytes_recv=0; 16 | server_bytes_at_cmd.bytes_sent=0; 17 | memset(gtid_uuid,0,sizeof(gtid_uuid)); 18 | gtid_trxid=0; 19 | } 20 | 21 | MySQL_Backend::~MySQL_Backend() { 22 | } 23 | 24 | void MySQL_Backend::reset() { 25 | if (server_myds && server_myds->myconn) { 26 | MySQL_Connection *mc=server_myds->myconn; 27 | if (mysql_thread___multiplexing && (server_myds->DSS==STATE_MARIADB_GENERIC || server_myds->DSS==STATE_READY) && mc->reusable==true && mc->IsActiveTransaction()==false && mc->MultiplexDisabled()==false && mc->async_state_machine==ASYNC_IDLE) { 28 | server_myds->myconn->last_time_used=server_myds->sess->thread->curtime; 29 | server_myds->return_MySQL_Connection_To_Pool(); 30 | } else { 31 | if (server_myds->sess && server_myds->sess->session_fast_forward == false) { 32 | server_myds->destroy_MySQL_Connection_From_Pool(true); 33 | } else { 34 | server_myds->destroy_MySQL_Connection_From_Pool(false); 35 | } 36 | } 37 | }; 38 | if (server_myds) { 39 | delete server_myds; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/set_parser.cpp: -------------------------------------------------------------------------------- 1 | #include "set_parser.h" 2 | #include "re2/re2.h" 3 | #include "re2/regexp.h" 4 | #include "gen_utils.h" 5 | #include 6 | #include 7 | #include 8 | 9 | SetParser::SetParser(std::string nq) { 10 | int query_no_space_length = nq.length(); 11 | char *query_no_space=(char *)malloc(query_no_space_length+1); 12 | memcpy(query_no_space,nq.c_str(),query_no_space_length); 13 | query_no_space[query_no_space_length]='\0'; 14 | query_no_space_length=remove_spaces(query_no_space); 15 | query = string(query_no_space); 16 | free(query_no_space); 17 | } 18 | 19 | std::map> SetParser::parse() { 20 | 21 | proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Parsing query %s\n", query.c_str()); 22 | re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet); 23 | opt2->set_case_sensitive(false); 24 | opt2->set_longest_match(false); 25 | 26 | re2::RE2 re0("^\\s*SET\\s+", *opt2); 27 | re2::RE2::Replace(&query, re0, ""); 28 | 29 | std::map> result; 30 | 31 | #define NAMES "(NAMES)" 32 | #define QUOTES "(?:'|\")?" 33 | #define NAME_VALUE "((?:\\w|\\d)+)" 34 | #define SESSION "(?:|SESSION +|@@|@@session.)" 35 | #define VAR "(\\w+)" 36 | #define SPACES " *" 37 | //#define VAR_VALUE "((?:[\\w/\\d:\\+\\-]|,)+)" 38 | //#define VAR_VALUE "((?:CONCAT\\((?:(REPLACE|CONCAT)\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))" 39 | #define VAR_VALUE "(((?:CONCAT\\()*(?:((?: )*REPLACE|CONCAT)\\()+(?: )*@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\))*)|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))" 40 | 41 | const string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION VAR SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE QUOTES ") *,? *"; 42 | re2::RE2 re(pattern, *opt2); 43 | string var; 44 | string value1, value2, value3, value4, value5; 45 | re2::StringPiece input(query); 46 | while (re2::RE2::Consume(&input, re, &value1, &value2, &value3, &value4, &value5)) { 47 | std::vector op; 48 | #ifdef DEBUG 49 | proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "SET parsing: v1='%s' , v2='%s' , v3='%s' , v4='%s' , v5='%s'\n", value1.c_str(), value2.c_str(), value3.c_str(), value4.c_str(), value5.c_str()); 50 | #endif // DEBUG 51 | string key; 52 | if (value1 != "") { 53 | // NAMES 54 | key = value1; 55 | op.push_back(value2); 56 | if (value3 != "") { 57 | op.push_back(value3); 58 | } 59 | } else if (value4 != "") { 60 | // VARIABLE 61 | value5.erase(value5.find_last_not_of(" \n\r\t\,")+1); 62 | key = value4; 63 | op.push_back(value5); 64 | } 65 | 66 | std::transform(key.begin(), key.end(), key.begin(), ::tolower); 67 | result[key] = op; 68 | } 69 | return result; 70 | } 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /lib/thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | thread.cpp 3 | 4 | Definition of a Java style thread class in C++. 5 | 6 | ------------------------------------------ 7 | 8 | Copyright © 2013 [Vic Hargrave - http://vichargrave.com] 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | */ 22 | 23 | #include "thread.h" 24 | 25 | static void* runThread(void* arg) 26 | { 27 | return ((Thread*)arg)->run(); 28 | } 29 | 30 | Thread::Thread() : m_tid(0), m_running(0), m_detached(0) {} 31 | 32 | Thread::~Thread() 33 | { 34 | if (m_running == 1) { 35 | if (m_detached == 0) { 36 | pthread_detach(m_tid); 37 | } 38 | pthread_cancel(m_tid); 39 | } 40 | } 41 | 42 | int Thread::start(unsigned int ss, bool jemalloc_tcache) 43 | { 44 | pthread_attr_t attr; 45 | pthread_attr_init(&attr); 46 | pthread_attr_setstacksize (&attr, ss*1024); 47 | int result = pthread_create(&m_tid, &attr, runThread, this); 48 | if (result == 0) { 49 | m_running = 1; 50 | } 51 | if (jemalloc_tcache==false) { 52 | #ifndef NOJEM 53 | bool cache=false; 54 | mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool)); 55 | #endif /* NOJEM */ 56 | } 57 | return result; 58 | } 59 | 60 | int Thread::join() 61 | { 62 | int result = -1; 63 | if (m_running == 1) { 64 | result = pthread_join(m_tid, NULL); 65 | if (result == 0) { 66 | m_running = 0; 67 | } 68 | } 69 | return result; 70 | } 71 | 72 | int Thread::detach() 73 | { 74 | int result = -1; 75 | if (m_running == 1 && m_detached == 0) { 76 | result = pthread_detach(m_tid); 77 | if (result == 0) { 78 | m_detached = 1; 79 | } 80 | } 81 | return result; 82 | } 83 | 84 | pthread_t Thread::self() { 85 | return m_tid; 86 | } 87 | -------------------------------------------------------------------------------- /proxysql-tests.ini.example: -------------------------------------------------------------------------------- 1 | [ProxySQL] 2 | hostname=127.0.0.1 3 | username=root 4 | password=root 5 | port=6033 6 | admin_username=admin 7 | admin_password=admin 8 | admin_port=6032 9 | 10 | [Email] 11 | smtp_server=smtp.gmail.com 12 | smtp_port=587 13 | username=proxysql.tests 14 | password= 15 | from=ProxySQL Tests 16 | to=Andrei-Adnan Ismail 17 | 18 | [Ping] 19 | ping_command=SELECT @@version_comment LIMIT 1 20 | db=information_schema 21 | connect_timeout=30 22 | ping_interval=60 23 | failed_connections_before_alert=3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docker-compose==1.4.2 2 | Jinja2==2.8 3 | MySQL-python==1.2.5 4 | nose==1.3.6 5 | requests==2.6.2 -------------------------------------------------------------------------------- /src/gdb-commands.txt: -------------------------------------------------------------------------------- 1 | set pagination off 2 | target remote 0.0.0.0:2345 3 | continue 4 | quit -------------------------------------------------------------------------------- /src/http_server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDa6rriYRLPcCV+HlaS1arXoK3p9uFKbMGsV4xtHJqZ7dw39NHK 3 | W6GzgL53mNGnaIXtqwvSRRQRl/2IwwRgG38l+eidJFFs8AeBL717YnYua3E0iG2v 4 | 3fPmeul4jkjsN7sdx9sUUl0zLUFECNy/NCwfEqIHiEZG6tjRlV1UA9aZHwIDAQAB 5 | AoGABsA4VSTTNKxrq5D58HtAUnf1BQME/YuPCWaFwROhvN917A/TrF7ZBLUSqpN+ 6 | 25/AiYy9x5UzwjsiqWYCK4iNiiqf57sj9z6lP18JDwWFwCMIAK+thSQPjpDq8V+l 7 | MMBrgRju5hQawhhfwRIqbaT5lyK1mZvNJuMFu8LCzvthy2kCQQD+u528ivsN0sqf 8 | pCMaCvYaPoi99zfS7eO9tLEPyvJJlgXxmyu7IwZ0YL7K0oSBwizetCuMzGNyy+NF 9 | SIEENjgFAkEA3AGBPH4RSJ6ba2/abQ4pJPjyAaosWPa7HEVWDMw1QtrMih8ZfCP7 10 | bkmZpXdQ8JQ9aCaRMjpW+Eni+gAVOQlJ0wJBAN+nUL4K9JRVgCwcS+mAuEWgpCTO 11 | W0gqMCwO6usn0AUF4KAaEpJTFUa27q1bmpXnK8g5Pod3qNVQ6HGbUBOnmxUCQF2h 12 | 9lK8hLaXaiYLcLbBNBmcKcMznbQvLesWR00jC/fsDukp2zrORY/mmxGk+jmpnYja 13 | ASmTUrhRGdy0dFPV9CkCQCwvn7tBno1ONOPjg5z2LcT5KltMkHOgd1Qu1UxNnXAh 14 | Ohqkg9sIhfZy9aTtiQmMkowuWWzjluEHmE24qY1qyng= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /src/http_server.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIChDCCAe2gAwIBAgIJAOtQYwItW44rMA0GCSqGSIb3DQEBCwUAMFsxCzAJBgNV 3 | BAYTAk1UMRMwEQYDVQQIDApTb21lLVN0YXRlMRUwEwYDVQQKDAxQcm94eVNRTCBM 4 | TEMxIDAeBgkqhkiG9w0BCQEWEWluZm9AcHJveHlzcWwuY29tMB4XDTE3MTExOTAw 5 | NDQxM1oXDTI3MTExNzAwNDQxM1owWzELMAkGA1UEBhMCTVQxEzARBgNVBAgMClNv 6 | bWUtU3RhdGUxFTATBgNVBAoMDFByb3h5U1FMIExMQzEgMB4GCSqGSIb3DQEJARYR 7 | aW5mb0Bwcm94eXNxbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANrq 8 | uuJhEs9wJX4eVpLVqtegren24UpswaxXjG0cmpnt3Df00cpbobOAvneY0adohe2r 9 | C9JFFBGX/YjDBGAbfyX56J0kUWzwB4EvvXtidi5rcTSIba/d8+Z66XiOSOw3ux3H 10 | 2xRSXTMtQUQI3L80LB8SogeIRkbq2NGVXVQD1pkfAgMBAAGjUDBOMB0GA1UdDgQW 11 | BBTRGiA7HWP+8ntdu8+vrTd8DrzJ4zAfBgNVHSMEGDAWgBTRGiA7HWP+8ntdu8+v 12 | rTd8DrzJ4zAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4GBAEsTu6LVQFxr 13 | 3fI7KcacssUrFcsFQhW0Ld6fTJLnd18Jy4rj4wHxTiKiyvgToHtWHP5lqhjoDEZs 14 | D2ggix3sPkF+sMddkaesoOlHRHlKcTNrpPcef9J9qgQHS6nGvNcECyj9MLVlFIhC 15 | Mj5dZlLYQRGUR4Zif8FnbGRy97mcF2aM 16 | -----END CERTIFICATE----- 17 | -------------------------------------------------------------------------------- /src/newreq.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB0zCCAX2gAwIBAgIJAPN/LP8jMKjmMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV 3 | BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX 4 | aWRnaXRzIFB0eSBMdGQwHhcNMTQxMTE1MDAyOTU0WhcNMTcxMTE0MDAyOTU0WjBF 5 | MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 6 | ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKlv 7 | SvA4vKYJ0henWm+sJ0qOfC64lYpe+cFQXSPQ4n8AwL1mxQRyCFUtwdTYosU/B0di 8 | djWJsN6aXI8cyCG7rmsCAwEAAaNQME4wHQYDVR0OBBYEFPRCYy6vBwfTsft+NxWe 9 | +qKkFzPEMB8GA1UdIwQYMBaAFPRCYy6vBwfTsft+NxWe+qKkFzPEMAwGA1UdEwQF 10 | MAMBAf8wDQYJKoZIhvcNAQEFBQADQQA5i9xD5pMXisVYxgYX48ea648dMG0qLbZA 11 | t3gIE2bGaR4zoJVtuoqD4d5/2cG7yI1CVIlPpCE/sUF4LVFTsOby 12 | -----END CERTIFICATE----- 13 | -------------------------------------------------------------------------------- /src/proxysql_global.cpp: -------------------------------------------------------------------------------- 1 | #define PROXYSQL_EXTERN 2 | #include "proxysql.h" 3 | //#include "proxysql_glovars.hpp" 4 | #include "cpp.h" 5 | //ProxySQL_GlobalVariables GloVars; 6 | -------------------------------------------------------------------------------- /systemd/system/proxysql.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=High Performance Advanced Proxy for MySQL 3 | After=network.target 4 | 5 | [Service] 6 | Type=forking 7 | RuntimeDirectory=proxysql 8 | #PermissionsStartOnly=true 9 | #ExecStartPre=/usr/bin/mkdir -p /var/run/proxysql /var/run/proxysql 10 | #ExecStartPre=/usr/bin/chown -R proxysql: /var/run/proxysql/ 11 | ExecStart=/usr/bin/proxysql -c /etc/proxysql.cnf 12 | PIDFile=/var/lib/proxysql/proxysql.pid 13 | #StandardError=null # all output is in stderr 14 | SyslogIdentifier=proxysql 15 | Restart=no 16 | User=proxysql 17 | Group=proxysql 18 | PermissionsStartOnly=true 19 | UMask=0007 20 | LimitNOFILE=102400 21 | LimitCORE=1073741824 22 | ProtectHome=yes 23 | ReadOnlyPaths=/ 24 | ReadWritePaths=/var/lib/proxysql /var/run/proxysql 25 | NoNewPrivileges=true 26 | CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE 27 | RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_ALG 28 | ProtectSystem=full 29 | PrivateDevices=yes 30 | ProtectKernelTunables=true 31 | ProtectControlGroups=true 32 | 33 | [Install] 34 | WantedBy=multi-user.target 35 | -------------------------------------------------------------------------------- /test/ChangeUser/.gitignore: -------------------------------------------------------------------------------- 1 | client1 2 | client2 3 | client3 4 | client4 5 | client5 6 | client6 7 | -------------------------------------------------------------------------------- /test/ChangeUser/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DEPS_PATH=../../deps 6 | 7 | MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client 8 | MARIADB_IDIR=$(MARIADB_PATH)/include 9 | MARIADB_LDIR=$(MARIADB_PATH)/libmariadb 10 | 11 | 12 | DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon 13 | DAEMONPATH_IDIR=$(DAEMONPATH) 14 | DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs 15 | 16 | JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc 17 | JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc 18 | JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib 19 | 20 | LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 21 | LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib 22 | LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs 23 | 24 | LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent 25 | LIBEVENT_IDIR=$(LIBEVENT_PATH)/include 26 | LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs 27 | 28 | RE2_PATH=$(DEPS_PATH)/re2/re2 29 | RE2_IDIR=$(RE2_PATH) 30 | 31 | SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 32 | 33 | IDIR=../../include 34 | LDIR=../../lib 35 | IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(RE2_IDIR) 36 | LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) 37 | 38 | 39 | MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb 40 | LDFLAGS+= 41 | MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) 42 | 43 | UNAME_S := $(shell uname -s) 44 | ifeq ($(UNAME_S),Linux) 45 | MYLIBS+= -ldl 46 | endif 47 | ifeq ($(UNAME_S),FreeBSD) 48 | MYLIBS+= -lexecinfo 49 | endif 50 | 51 | LIBPROXYSQLAR=$(LDIR)/libproxysql.a 52 | 53 | .PHONY: default 54 | default: client1 55 | 56 | client1: client1.cpp 57 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 58 | 59 | client2: client2.cpp 60 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 61 | 62 | client3: client3.cpp 63 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 64 | 65 | client4: client4.cpp 66 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 67 | 68 | client5: client5.cpp 69 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 70 | 71 | client6: client6.cpp 72 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 73 | 74 | 75 | default: $(EXECUTABLE) 76 | 77 | clean: 78 | rm -f *~ core $(default) 79 | 80 | -------------------------------------------------------------------------------- /test/ChangeUser/client1.cpp: -------------------------------------------------------------------------------- 1 | #include "proxysql.h" 2 | #include "cpp.h" 3 | 4 | 5 | static int wait_for_mysql(MYSQL *mysql, int status) { 6 | struct pollfd pfd; 7 | int timeout, res; 8 | 9 | pfd.fd = mysql_get_socket(mysql); 10 | pfd.events = 11 | (status & MYSQL_WAIT_READ ? POLLIN : 0) | 12 | (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | 13 | (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); 14 | // if (status & MYSQL_WAIT_TIMEOUT) 15 | // timeout = 1000*mysql_get_timeout_value(mysql); 16 | // else 17 | timeout = -1; 18 | res = poll(&pfd, 1, timeout); 19 | if (res == 0) 20 | return MYSQL_WAIT_TIMEOUT; 21 | else if (res < 0) 22 | return MYSQL_WAIT_TIMEOUT; 23 | else { 24 | int status = 0; 25 | if (pfd.revents & POLLIN) status |= MYSQL_WAIT_READ; 26 | if (pfd.revents & POLLOUT) status |= MYSQL_WAIT_WRITE; 27 | if (pfd.revents & POLLPRI) status |= MYSQL_WAIT_EXCEPT; 28 | return status; 29 | } 30 | } 31 | 32 | 33 | 34 | int main() { 35 | // initialize mysql 36 | mysql_library_init(0,NULL,NULL); 37 | 38 | MYSQL *mysql=mysql_init(NULL); 39 | mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); 40 | MYSQL *ret_mysql=NULL; 41 | int async_exit_status=0; 42 | my_bool ret_bool; 43 | async_exit_status=mysql_real_connect_start(&ret_mysql,mysql,"127.0.0.1","msandbox","msandbox","information_schema",21891,NULL,0); 44 | while (async_exit_status) { 45 | async_exit_status=wait_for_mysql(mysql, async_exit_status); 46 | async_exit_status=mysql_real_connect_cont(&ret_mysql, mysql, async_exit_status); 47 | } 48 | if (ret_mysql==NULL) { 49 | fprintf(stderr, "Failed to connect, error: %s\n", mysql_error(mysql)); 50 | exit(EXIT_FAILURE); 51 | } 52 | async_exit_status=mysql_change_user_start(&ret_bool, mysql,"msandbox2","msandbox2","information_schema"); 53 | while (async_exit_status) { 54 | async_exit_status=wait_for_mysql(mysql, async_exit_status); 55 | async_exit_status=mysql_change_user_cont(&ret_bool, mysql, async_exit_status); 56 | } 57 | if (ret_bool==TRUE) { 58 | fprintf(stderr, "Failed to change user, error: %s\n", mysql_error(mysql)); 59 | exit(EXIT_FAILURE); 60 | } 61 | // if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox","information_schema",21891,NULL,0)) { 62 | // fprintf(stderr, "Failed to connect, error: %s\n", mysql_error(mysql)); 63 | // exit(EXIT_FAILURE); 64 | // } 65 | // if (mysql_change_user(mysql,"msandbox2","msandbox2","information_schema")) { 66 | // fprintf(stderr, "Failed to change user, error: %s\n", mysql_error(mysql)); 67 | // exit(EXIT_FAILURE); 68 | // } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /test/PrepStmt/.gitignore: -------------------------------------------------------------------------------- 1 | client1 2 | client2 3 | client3 4 | client4 5 | client5 6 | client6 7 | client7 8 | client8 9 | client9 10 | client10 11 | client11 12 | -------------------------------------------------------------------------------- /test/PrepStmt/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DEPS_PATH=../../deps 6 | 7 | MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client 8 | MARIADB_IDIR=$(MARIADB_PATH)/include 9 | MARIADB_LDIR=$(MARIADB_PATH)/libmariadb 10 | 11 | 12 | DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon 13 | DAEMONPATH_IDIR=$(DAEMONPATH) 14 | DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs 15 | 16 | JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc 17 | JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc 18 | JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib 19 | 20 | LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 21 | LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib 22 | LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs 23 | 24 | 25 | RE2_PATH=$(DEPS_PATH)/re2/re2 26 | RE2_IDIR=$(RE2_PATH) 27 | 28 | SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 29 | 30 | IDIR=../../include 31 | LDIR=../../lib 32 | IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) 33 | LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) 34 | 35 | DEBUG=-DDEBUG 36 | MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb 37 | LDFLAGS+= 38 | MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) 39 | 40 | UNAME_S := $(shell uname -s) 41 | ifeq ($(UNAME_S),Linux) 42 | MYLIBS+= -ldl 43 | endif 44 | ifeq ($(UNAME_S),FreeBSD) 45 | MYLIBS+= -lexecinfo 46 | endif 47 | 48 | LIBPROXYSQLAR=$(LDIR)/libproxysql.a 49 | 50 | .PHONY: default 51 | default: client1 52 | 53 | client1: client1.cpp 54 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 55 | 56 | client2: client2.cpp 57 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 58 | 59 | client3: client3.cpp 60 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 61 | 62 | client4: client4.cpp 63 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 64 | 65 | client5: client5.cpp 66 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 67 | 68 | client6: client6.cpp 69 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 70 | 71 | client7: client7.cpp 72 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 73 | 74 | client8: client8.cpp 75 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 76 | 77 | client9: client9.cpp 78 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 79 | 80 | 81 | default: $(EXECUTABLE) 82 | 83 | clean: 84 | rm -f *~ core $(default) 85 | 86 | -------------------------------------------------------------------------------- /test/PrepStmt/client1.cpp: -------------------------------------------------------------------------------- 1 | #include "proxysql.h" 2 | #include "cpp.h" 3 | 4 | #define QUERY1 "SELECT ? + ? + ?" 5 | MYSQL *mysql; 6 | MYSQL_STMT *stmt; 7 | uint32_t statement_id; 8 | uint16_t num_params; 9 | uint16_t num_columns; 10 | uint16_t warning_count; 11 | 12 | int run_stmt(MYSQL_STMT *stmt, int int_data) { 13 | MYSQL_BIND bind[3]; 14 | MYSQL_RES *prepare_meta_result; 15 | bind[0].buffer_type= MYSQL_TYPE_LONG; 16 | bind[0].buffer= (char *)&int_data; 17 | bind[0].is_null= 0; 18 | bind[0].length= 0; 19 | bind[1].buffer_type= MYSQL_TYPE_LONG; 20 | bind[1].buffer= (char *)&int_data; 21 | bind[1].is_null= 0; 22 | bind[1].length= 0; 23 | bind[2].buffer_type= MYSQL_TYPE_LONG; 24 | bind[2].buffer= (char *)&int_data; 25 | bind[2].is_null= 0; 26 | bind[2].length= 0; 27 | if (mysql_stmt_bind_param(stmt, bind)) { 28 | fprintf(stderr, " mysql_stmt_bind_param() failed\n"); 29 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 30 | exit(EXIT_FAILURE); 31 | } 32 | prepare_meta_result = mysql_stmt_result_metadata(stmt); // FIXME: no error check 33 | if (mysql_stmt_execute(stmt)) { 34 | fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); 35 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 36 | exit(EXIT_FAILURE); 37 | } 38 | // memset(bind, 0, sizeof(bind)); 39 | if (mysql_stmt_store_result(stmt)) { 40 | fprintf(stderr, " mysql_stmt_store_result() failed\n"); 41 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 42 | exit(EXIT_FAILURE); 43 | } 44 | mysql_free_result(prepare_meta_result); 45 | return 0; 46 | } 47 | 48 | 49 | int main() { 50 | std::mt19937 mt_rand(time(0)); 51 | mysql = mysql_init(NULL); 52 | if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox","test",6033,NULL,0)) { 53 | //if (!mysql_real_connect(mysql,"127.0.0.1","root","","test",3306,NULL,0)) { 54 | fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); 55 | exit(EXIT_FAILURE); 56 | } 57 | stmt = mysql_stmt_init(mysql); 58 | if (!stmt) { 59 | fprintf(stderr, " mysql_stmt_init(), out of memory\n"); 60 | exit(EXIT_FAILURE); 61 | } 62 | if (mysql_stmt_prepare(stmt, QUERY1, strlen(QUERY1))) { 63 | fprintf(stderr, " mysql_stmt_prepare(), failed: %d, %s\n" , mysql_errno(mysql), mysql_stmt_error(stmt)); 64 | exit(EXIT_FAILURE); 65 | } 66 | // param_count= mysql_stmt_param_count(stmt); 67 | // fprintf(stdout, " total parameters in Query1 : %d\n", param_count); 68 | statement_id=stmt->stmt_id; 69 | num_params=stmt->param_count; 70 | num_columns=stmt->field_count; 71 | warning_count=stmt->upsert_status.warning_count; 72 | fprintf(stdout, "statement_id=%d , columns=%d , params=%d , warnings=%d\n", statement_id, num_columns, num_params, warning_count); 73 | run_stmt(stmt,(uint32_t)mt_rand()); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /test/PrepStmt/client8.cpp: -------------------------------------------------------------------------------- 1 | #include "proxysql.h" 2 | #include "cpp.h" 3 | 4 | // dummy copy of client1.cpp 5 | 6 | #define QUERY1 "SELECT * from sbtest limit 10" 7 | MYSQL *mysql; 8 | MYSQL_STMT *stmt; 9 | uint32_t statement_id; 10 | uint16_t num_params; 11 | uint16_t num_columns; 12 | uint16_t warning_count; 13 | 14 | int run_stmt(MYSQL_STMT *stmt, int int_data) { 15 | MYSQL_BIND bind[3]; 16 | MYSQL_RES *prepare_meta_result; 17 | bind[0].buffer_type= MYSQL_TYPE_LONG; 18 | bind[0].buffer= (char *)&int_data; 19 | bind[0].is_null= 0; 20 | bind[0].length= 0; 21 | bind[1].buffer_type= MYSQL_TYPE_LONG; 22 | bind[1].buffer= (char *)&int_data; 23 | bind[1].is_null= 0; 24 | bind[1].length= 0; 25 | bind[2].buffer_type= MYSQL_TYPE_LONG; 26 | bind[2].buffer= (char *)&int_data; 27 | bind[2].is_null= 0; 28 | bind[2].length= 0; 29 | /* 30 | if (mysql_stmt_bind_param(stmt, bind)) { 31 | fprintf(stderr, " mysql_stmt_bind_param() failed\n"); 32 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 33 | exit(EXIT_FAILURE); 34 | } 35 | */ 36 | prepare_meta_result = mysql_stmt_result_metadata(stmt); // FIXME: no error check 37 | if (mysql_stmt_execute(stmt)) { 38 | fprintf(stderr, " mysql_stmt_execute(), 1 failed\n"); 39 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 40 | exit(EXIT_FAILURE); 41 | } 42 | // memset(bind, 0, sizeof(bind)); 43 | if (mysql_stmt_store_result(stmt)) { 44 | fprintf(stderr, " mysql_stmt_store_result() failed\n"); 45 | fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); 46 | exit(EXIT_FAILURE); 47 | } 48 | mysql_free_result(prepare_meta_result); 49 | return 0; 50 | } 51 | 52 | 53 | int main() { 54 | std::mt19937 mt_rand(time(0)); 55 | mysql = mysql_init(NULL); 56 | if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox","sbtest",6033,NULL,0)) { 57 | //if (!mysql_real_connect(mysql,"127.0.0.1","root","","test",3306,NULL,0)) { 58 | fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); 59 | exit(EXIT_FAILURE); 60 | } 61 | stmt = mysql_stmt_init(mysql); 62 | if (!stmt) { 63 | fprintf(stderr, " mysql_stmt_init(), out of memory\n"); 64 | exit(EXIT_FAILURE); 65 | } 66 | if (mysql_stmt_prepare(stmt, QUERY1, strlen(QUERY1))) { 67 | fprintf(stderr, " mysql_stmt_prepare(), failed: %d, %s\n" , mysql_errno(mysql), mysql_stmt_error(stmt)); 68 | exit(EXIT_FAILURE); 69 | } 70 | // param_count= mysql_stmt_param_count(stmt); 71 | // fprintf(stdout, " total parameters in Query1 : %d\n", param_count); 72 | statement_id=stmt->stmt_id; 73 | num_params=stmt->param_count; 74 | num_columns=stmt->field_count; 75 | warning_count=stmt->upsert_status.warning_count; 76 | fprintf(stdout, "statement_id=%d , columns=%d , params=%d , warnings=%d\n", statement_id, num_columns, num_params, warning_count); 77 | run_stmt(stmt,(uint32_t)mt_rand()); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/test/__init__.py -------------------------------------------------------------------------------- /test/admin_tables_test.py: -------------------------------------------------------------------------------- 1 | from multiprocessing.pool import ThreadPool 2 | import random 3 | 4 | from proxysql_base_test import ProxySQLBaseTest 5 | 6 | class AdminTablesTest(ProxySQLBaseTest): 7 | 8 | def test_monitor_tables_locking_errors(self): 9 | """Test that intensive read/write operations to the MySQL Monitor tables 10 | do not trigger locking errors. 11 | 12 | This test will be successful if there will be no generated error at 13 | the end. 14 | """ 15 | 16 | # Setting these variables will cause the Monitor to connect more 17 | # frequently to the backend hosts to check their health, thus increasing 18 | # the probability of locking errors to appear. 19 | self.run_query_proxysql_admin("UPDATE global_variables SET variable_value=100 WHERE variable_name='mysql-monitor_connect_interval'") 20 | self.run_query_proxysql_admin("UPDATE global_variables SET variable_value=100 WHERE variable_name='mysql-monitor_ping_interval'") 21 | self.run_query_proxysql_admin("LOAD MYSQL VARIABLES TO RUNTIME") 22 | 23 | queries = [] 24 | q1 = "select * from monitor.mysql_server_connect_log ORDER BY RANDOM() LIMIT 10" 25 | q2 = "select * from monitor.mysql_server_ping_log ORDER BY RANDOM() LIMIT 10" 26 | for _ in xrange(10000): 27 | queries.append(random.choice([q1, q2])) 28 | 29 | pool = ThreadPool(processes=5) 30 | pool.map(self.run_query_proxysql_admin, queries) 31 | 32 | # If we reached this point without an error, it means that the test 33 | # has passed. 34 | self.assertEqual(1, 1) -------------------------------------------------------------------------------- /test/admin_test.py: -------------------------------------------------------------------------------- 1 | from proxysql_base_test import ProxySQLBaseTest 2 | 3 | from MySQLdb import OperationalError 4 | 5 | class AdminTest(ProxySQLBaseTest): 6 | 7 | def test_stop_main_thread(self): 8 | try: 9 | # This test will just assert that PROXYSQL STOP works correctly 10 | # Since September 2015, the behaviour has been changed - PROXYSQL STOP 11 | # executes faster and immediately shuts down the connections, thus this 12 | # test is expected to raise OperationalError 13 | self.run_query_proxysql_admin("PROXYSQL STOP") 14 | self.assertEqual(0, 1) 15 | except OperationalError: 16 | self.assertEqual(1, 1) -------------------------------------------------------------------------------- /test/authentication_test.py: -------------------------------------------------------------------------------- 1 | import MySQLdb 2 | from MySQLdb import OperationalError 3 | from nose.tools import raises 4 | 5 | from proxysql_base_test import ProxySQLBaseTest 6 | 7 | class AuthenticationTest(ProxySQLBaseTest): 8 | 9 | def test_existing_user_with_correct_password_works(self): 10 | version1 = self.run_query_mysql( 11 | "SELECT @@version_comment LIMIT 1", "test", 12 | return_result=True, 13 | username="john", password="doe") 14 | 15 | version2 = self.run_query_proxysql( 16 | "SELECT @@version_comment LIMIT 1", "test", 17 | return_result=True, 18 | username="john", password="doe") 19 | 20 | self.assertEqual(version1, version2) 21 | 22 | def test_existing_user_with_correct_password_but_not_registerd_within_proxysql_does_not_work(self): 23 | try: 24 | self.run_query_proxysql("SELECT @@version_comment LIMIT 1", "test", 25 | return_result=True, 26 | username="danny", password="white") 27 | # We shouldn't reach this point successfully, because it means we 28 | # managed to authenticate with the wrong password 29 | self.assertEqual(1, 0) 30 | except OperationalError: 31 | self.assertEqual(1, 1) 32 | 33 | def test_existing_user_with_incorrect_password_does_not_work(self): 34 | try: 35 | self.run_query_proxysql("SELECT @@version_comment LIMIT 1", "test", 36 | return_result=True, 37 | username="john", password="doe2") 38 | # We shouldn't reach this point successfully, because it means we 39 | # managed to authenticate with the wrong password 40 | self.assertEqual(1, 0) 41 | except OperationalError: 42 | self.assertEqual(1, 1) 43 | 44 | def test_inexisting_user_with_random_password_does_not_work(self): 45 | try: 46 | self.run_query_proxysql("SELECT @@version_comment LIMIT 1", "test", 47 | return_result=True, 48 | username="johnny", password="randomdoe") 49 | self.assertEqual(1, 0) 50 | except OperationalError: 51 | self.assertEqual(1, 1) -------------------------------------------------------------------------------- /test/check_result.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import MySQLdb 3 | 4 | 5 | def execute(conn, sql): 6 | select = True 7 | if not sql.startswith('SELECT') and not sql.startswith('SHOW'): 8 | select = False 9 | 10 | curs = conn.cursor(MySQLdb.cursors.SSDictCursor) 11 | curs.execute(sql) 12 | if select: 13 | rows = curs.fetchall() 14 | curs.close() 15 | return select, rows 16 | 17 | ret = conn.affected_rows() 18 | curs.close() 19 | return select, ret 20 | 21 | if __name__ == '__main__': 22 | assert len(sys.argv) == 6 23 | user = sys.argv[1] 24 | passwd = sys.argv[2] 25 | db = sys.argv[3] 26 | host = sys.argv[4] 27 | port = sys.argv[5] 28 | 29 | conn = MySQLdb.connect(host=host, port=int(port), user=user, passwd=passwd, db=db) 30 | conn.autocommit(False) 31 | for line in sys.stdin: 32 | print line.rstrip() 33 | (select, rows) = execute(conn,line.rstrip()) 34 | if select: 35 | for row in rows: 36 | print row 37 | -------------------------------------------------------------------------------- /test/encrypt/.gitignore: -------------------------------------------------------------------------------- 1 | client1 2 | client2 3 | client3 4 | client4 5 | client5 6 | client6 7 | -------------------------------------------------------------------------------- /test/encrypt/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DEPS_PATH=../../deps 6 | 7 | MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client 8 | MARIADB_IDIR=$(MARIADB_PATH)/include 9 | MARIADB_LDIR=$(MARIADB_PATH)/libmariadb 10 | 11 | 12 | DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon 13 | DAEMONPATH_IDIR=$(DAEMONPATH) 14 | DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs 15 | 16 | JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc 17 | JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc 18 | JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib 19 | 20 | LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 21 | LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib 22 | LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs 23 | 24 | LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent 25 | LIBEVENT_IDIR=$(LIBEVENT_PATH)/include 26 | LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs 27 | 28 | RE2_PATH=$(DEPS_PATH)/re2/re2 29 | RE2_IDIR=$(RE2_PATH) 30 | 31 | SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 32 | 33 | IDIR=../../include 34 | LDIR=../../lib 35 | IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) 36 | LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) 37 | 38 | 39 | MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb 40 | LDFLAGS+= 41 | MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) 42 | 43 | UNAME_S := $(shell uname -s) 44 | ifeq ($(UNAME_S),Linux) 45 | MYLIBS+= -ldl 46 | endif 47 | ifeq ($(UNAME_S),FreeBSD) 48 | MYLIBS+= -lexecinfo 49 | endif 50 | 51 | LIBPROXYSQLAR=$(LDIR)/libproxysql.a 52 | 53 | .PHONY: default 54 | default: client1 55 | 56 | client1: client1.cpp 57 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 58 | 59 | client2: client2.cpp 60 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 61 | 62 | client3: client3.cpp 63 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 64 | 65 | client4: client4.cpp 66 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 67 | 68 | client5: client5.cpp 69 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 70 | 71 | client6: client6.cpp 72 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 73 | 74 | 75 | default: $(EXECUTABLE) 76 | 77 | clean: 78 | rm -f *~ core $(default) 79 | 80 | -------------------------------------------------------------------------------- /test/fast_rand.c: -------------------------------------------------------------------------------- 1 | static unsigned int g_seed; 2 | 3 | 4 | inline void fast_srand( int seed ) { 5 | g_seed = seed; 6 | } 7 | inline int fastrand() { 8 | g_seed = (214013*g_seed+2531011); 9 | return (g_seed>>16)&0x7FFF; 10 | } 11 | 12 | static char _s[128]; 13 | 14 | void gen_random_stdstring(string *s, const int len) { 15 | //char *_s=(char *)alloca(len+1); 16 | static const char alphanum[] = 17 | "0123456789" 18 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 19 | "abcdefghijklmnopqrstuvwxyz"; 20 | for (int i = 0; i < len; ++i) { 21 | _s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; 22 | } 23 | _s[len] = '\0'; 24 | *s=string(_s); 25 | //return s; 26 | } 27 | 28 | 29 | 30 | char * gen_random_string(const int len) { 31 | char *s=(char *)malloc(len+1); 32 | static const char alphanum[] = 33 | "0123456789" 34 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 35 | "abcdefghijklmnopqrstuvwxyz"; 36 | 37 | for (int i = 0; i < len; ++i) { 38 | s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; 39 | } 40 | 41 | s[len] = 0; 42 | return s; 43 | } 44 | -------------------------------------------------------------------------------- /test/jemalloc/issue522.c: -------------------------------------------------------------------------------- 1 | // cc -O2 issue522.c -o issue522 -L../../deps/jemalloc/jemalloc/lib -Wl,-Bstatic -ljemalloc -Wl,-Bdynamic -lpthread -lm -ldl 2 | #include 3 | int main() { 4 | int i; 5 | char *c=NULL; 6 | for (i=0;i<500000000;i++) { 7 | c=(char *)malloc(100); 8 | if (__builtin_expect(c==NULL, 0)) return -1; 9 | free(c); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/test/main -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include "polygon.hpp" 2 | #include 3 | #include 4 | 5 | class Query_Cache; 6 | 7 | int main() { 8 | using std::cout; 9 | using std::cerr; 10 | 11 | // load the triangle library 12 | /* 13 | void* QC = dlopen("../lib/Shared_Query_Cache.so", RTLD_LAZY); 14 | if (!QC) { 15 | cerr << "Cannot load library: " << dlerror() << " " << errno << '\n'; 16 | return 1; 17 | } 18 | */ 19 | void* triangle = dlopen("./triangle.so", RTLD_LAZY); 20 | if (!triangle) { 21 | cerr << "Cannot load library: " << dlerror() << '\n'; 22 | return 1; 23 | } 24 | 25 | // reset errors 26 | dlerror(); 27 | 28 | // load the symbols 29 | create_t* create_triangle = (create_t*) dlsym(triangle, "create"); 30 | const char* dlsym_error = dlerror(); 31 | if (dlsym_error) { 32 | cerr << "Cannot load symbol create: " << dlsym_error << '\n'; 33 | return 1; 34 | } 35 | 36 | destroy_t* destroy_triangle = (destroy_t*) dlsym(triangle, "destroy"); 37 | dlsym_error = dlerror(); 38 | if (dlsym_error) { 39 | cerr << "Cannot load symbol destroy: " << dlsym_error << '\n'; 40 | return 1; 41 | } 42 | 43 | // create an instance of the class 44 | polygon* poly = create_triangle(); 45 | 46 | // use the class 47 | poly->set_side_length(7); 48 | cout << "The area is: " << poly->area() << '\n'; 49 | 50 | // destroy the class 51 | destroy_triangle(poly); 52 | 53 | // unload the triangle library 54 | dlclose(triangle); 55 | } 56 | -------------------------------------------------------------------------------- /test/monot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/proxysql/15aa536a6e4c569ad7cac9538f70c1ec6aeabb0a/test/monot -------------------------------------------------------------------------------- /test/monot.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | long monotonic_time() { 6 | struct timespec ts; 7 | clock_gettime(CLOCK_MONOTONIC, &ts); 8 | return (((long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); 9 | } 10 | 11 | 12 | #define LOOPS 10000000 13 | 14 | int main() { 15 | volatile int i; 16 | volatile long l; 17 | struct timespec req; 18 | req.tv_sec=0; 19 | req.tv_nsec=1; 20 | for (i=0;i= self.max_failed_connections: 58 | self.send_error_email() 59 | self.running = False 60 | return 61 | 62 | def stop(self): 63 | self.running = False 64 | 65 | def send_error_email(self): 66 | msg = MIMEText("ProxySQL daemon stopped responding during tests.\n" 67 | "Please check if it has crashed and you have been left with a gdb console on!") 68 | 69 | # me == the sender's email address 70 | # you == the recipient's email address 71 | msg['Subject'] = 'Daemon has stopped responding' 72 | msg['From'] = self.config.get('Email', 'from') 73 | msg['To'] = self.config.get('Email', 'to') 74 | 75 | # Send the message via our own SMTP server, but don't include the 76 | # envelope header. 77 | s = smtplib.SMTP(self.config.get('Email', 'smtp_server'), 78 | int(self.config.get('Email', 'smtp_port'))) 79 | s.ehlo() 80 | s.starttls() 81 | s.login(self.config.get('Email', 'username'), 82 | self.config.get('Email', 'password')) 83 | s.sendmail(self.config.get('Email', 'from'), 84 | [self.config.get('Email', 'to')], 85 | msg.as_string()) 86 | s.quit() 87 | 88 | -------------------------------------------------------------------------------- /test/proxysql_tests_config.py: -------------------------------------------------------------------------------- 1 | from ConfigParser import ConfigParser 2 | 3 | class ProxySQL_Tests_Config(object): 4 | 5 | DEFAULT_PROXYSQL_TESTS_LOCATION = 'proxysql-tests.ini' 6 | 7 | def __init__(self, location=DEFAULT_PROXYSQL_TESTS_LOCATION, overrides={}): 8 | self.location = location 9 | self.config = ConfigParser() 10 | self.config.read(self.location) 11 | self.overrides = overrides 12 | 13 | def get(self, section, variable, default=None): 14 | """ Returns the value of a variable in a given section, or the default 15 | value if the variable or section don't exist.""" 16 | if section in self.overrides and variable in self.overrides[section]: 17 | return self.overrides[section][variable] 18 | 19 | return self.config.get(section, variable) -------------------------------------------------------------------------------- /test/regextest/.gitignore: -------------------------------------------------------------------------------- 1 | client1 2 | client2 3 | client3 4 | client4 5 | client5 6 | client6 7 | -------------------------------------------------------------------------------- /test/regextest/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DEPS_PATH=../../deps 6 | 7 | MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client 8 | MARIADB_IDIR=$(MARIADB_PATH)/include 9 | MARIADB_LDIR=$(MARIADB_PATH)/libmariadb 10 | 11 | 12 | DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon 13 | DAEMONPATH_IDIR=$(DAEMONPATH) 14 | DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs 15 | 16 | JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc 17 | JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc 18 | JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib 19 | 20 | LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 21 | LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib 22 | LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs 23 | 24 | LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent 25 | LIBEVENT_IDIR=$(LIBEVENT_PATH)/include 26 | LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs 27 | 28 | RE2_PATH=$(DEPS_PATH)/re2/re2 29 | RE2_IDIR=$(RE2_PATH) 30 | 31 | SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 32 | 33 | IDIR=../../include 34 | LDIR=../../lib 35 | IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(RE2_IDIR) 36 | LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) 37 | 38 | 39 | MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb 40 | LDFLAGS+= 41 | MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) 42 | 43 | UNAME_S := $(shell uname -s) 44 | ifeq ($(UNAME_S),Linux) 45 | MYLIBS+= -ldl 46 | endif 47 | ifeq ($(UNAME_S),FreeBSD) 48 | MYLIBS+= -lexecinfo 49 | endif 50 | 51 | LIBPROXYSQLAR=$(LDIR)/libproxysql.a 52 | 53 | .PHONY: default 54 | default: client1 55 | 56 | client1: client1.cpp 57 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 58 | 59 | client2: client2.cpp 60 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 61 | 62 | client3: client3.cpp 63 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 64 | 65 | client4: client4.cpp 66 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 67 | 68 | client5: client5.cpp 69 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 70 | 71 | client6: client6.cpp 72 | $(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 73 | 74 | 75 | default: $(EXECUTABLE) 76 | 77 | clean: 78 | rm -f *~ core $(default) 79 | 80 | -------------------------------------------------------------------------------- /test/regextest/client1.cpp: -------------------------------------------------------------------------------- 1 | #include "re2/re2.h" 2 | #include "re2/regexp.h" 3 | #include "proxysql.h" 4 | #include "cpp.h" 5 | 6 | #include 7 | #include 8 | 9 | struct __RE2_objects_t { 10 | re2::RE2::Options *opt; 11 | RE2 *re; 12 | }; 13 | 14 | typedef struct __RE2_objects_t re2_t; 15 | 16 | int main() { 17 | re2_t *r=(re2_t *)malloc(sizeof(re2_t)); 18 | r->opt=new re2::RE2::Options(RE2::Quiet); 19 | r->opt->set_case_sensitive(false); 20 | //char *myq=(char *)" sEt NAmEs 'utf8' "; 21 | char *myq=(char *)"sEt NAmEs 'utf8' "; 22 | r->re=new RE2(" *SET *NAMES *.* *", *r->opt); 23 | bool rc; 24 | for (int i=0;i<100000;i++) { 25 | string *new_query=new std::string(myq); 26 | rc=RE2::PartialMatch(myq,*r->re); 27 | //RE2::Replace(new_query,(char *)" *(\\w+) *(.*) *(.*) *",(char *)"\1 \2 \3 a"); 28 | RE2::Replace(new_query,(char *)" *(\\w+)\\s+(\\w+)\\s+(\\w+)\\s*",(char *)"\\1 \\2 \\3"); 29 | //std::cout << new_query->c_str() << std::endl; 30 | delete new_query; 31 | } 32 | printf("%d\n",rc); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/set_parser_test/.gitignore: -------------------------------------------------------------------------------- 1 | setparsertest 2 | -------------------------------------------------------------------------------- /test/set_parser_test/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DEPS_PATH=../../deps 6 | 7 | RE2_PATH=$(DEPS_PATH)/re2/re2 8 | RE2_IDIR=$(RE2_PATH) 9 | 10 | MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client 11 | MARIADB_IDIR=$(MARIADB_PATH)/include 12 | MARIADB_LDIR=$(MARIADB_PATH)/libmariadb 13 | 14 | DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon 15 | DAEMONPATH_IDIR=$(DAEMONPATH) 16 | DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs 17 | 18 | JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc 19 | JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc 20 | JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib 21 | 22 | LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9 23 | LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib 24 | LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs 25 | 26 | SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 27 | 28 | IDIR=../../include 29 | LDIR=../../lib 30 | IDIRS=-I$(IDIR) -I$(RE2_IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) 31 | LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) 32 | 33 | UNAME_S := $(shell uname -s) 34 | ifeq ($(UNAME_S),Darwin) 35 | IDIRS+= -I/usr/local/opt/openssl/include 36 | endif 37 | 38 | LIBPROXYSQLAR=$(LDIR)/libproxysql.a 39 | 40 | MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb 41 | LDFLAGS+= 42 | MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lproxysql -ldaemon -ljemalloc -lre2 -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) 43 | 44 | ifeq ($(UNAME_S),Darwin) 45 | MYLIBS=-lre2 -lpthread -lm -lz -liconv 46 | endif 47 | ifeq ($(UNAME_S),Linux) 48 | MYLIBS+= -ldl 49 | endif 50 | ifeq ($(UNAME_S),FreeBSD) 51 | MYLIBS+= -lexecinfo 52 | endif 53 | 54 | .PHONY: default 55 | default: setparsertest 56 | 57 | setparsertest: setparsertest.cpp $(RE2_PATH)/util/test.cc $(LDIR)/set_parser.cpp $(LIBPROXYSQLAR) 58 | $(CXX) -o $@ $@.cpp $(RE2_PATH)/util/test.cc $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS) 59 | 60 | clean: 61 | rm -f *~ core $(default) 62 | 63 | -------------------------------------------------------------------------------- /test/sysbench_test.py: -------------------------------------------------------------------------------- 1 | from proxysql_base_test import ProxySQLBaseTest 2 | 3 | class SysBenchTest(ProxySQLBaseTest): 4 | 5 | def test_proxy_doesnt_crash_under_mild_sysbench_load(self): 6 | self.run_sysbench_proxysql() -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | eventslog_reader_sample: eventslog_reader_sample.cpp 2 | $(CXX) -ggdb -o eventslog_reader_sample eventslog_reader_sample.cpp 3 | -------------------------------------------------------------------------------- /tools/check_variables.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use warnings; 4 | use DBI; 5 | use DBD::mysql; 6 | 7 | 8 | use Getopt::Long qw(:config permute no_ignore_case); 9 | 10 | 11 | my %opts; 12 | 13 | 14 | sub main { 15 | @ARGV = @_; 16 | $opts{'user'} = $ENV{"DBI_USER"} || ""; 17 | $opts{'password'} = $ENV{"MYSQL_PWD"} || ""; 18 | $opts{'host'} = $ENV{"MYSQL_HOST"} || "127.0.0.1"; 19 | $opts{'port'} = $ENV{"MYSQL_TCP_PORT"} || 6032; 20 | GetOptions(\%opts, 21 | 'user|u=s', 22 | 'password|p=s', 23 | 'host|h=s', 24 | 'port|P=i', 25 | ); 26 | my $dbn="dbi:mysql:main:".$opts{'host'}.":".$opts{'port'}; 27 | my $dbh=DBI->connect($dbn, $opts{'user'}, $opts{'password'}) or die "Unable to connect: $DBI::errstr\n"; 28 | my $query="SELECT * FROM runtime_global_variables"; 29 | my $selh=$dbh->prepare($query) or die "Unable to prepare: $DBI::errstr\n"; 30 | $selh->execute() or die "Unable to execute: $DBI::errstr\n"; 31 | my %data; 32 | while (my $res=$selh->fetchrow_hashref) { 33 | $data{$res->{'variable_name'}}=$res->{'variable_value'} 34 | } 35 | 36 | # printf "ProxySQL is running with: $data{'mysql-threads'} threads\n"; 37 | 38 | my $warns=0; 39 | if ($data{'mysql-poll_timeout'}*2 > $data{'mysql-ping_interval_server_msec'}) { 40 | printf "WARN: mysql-ping_interval_server_msec ($data{'mysql-ping_interval_server_msec'}) is too small compared to mysql-poll_timeout ($data{'mysql-poll_timeout'})\n"; 41 | $warns+=1; 42 | } 43 | if ($data{'mysql-ping_interval_server_msec'} < $data{'mysql-ping_timeout_server'}*5) { 44 | printf "WARN: mysql-ping_interval_server_msec ($data{'mysql-ping_interval_server_msec'}) is too small compared to mysql-ping_timeout_server ($data{'mysql-ping_timeout_server'})\n"; 45 | $warns+=1; 46 | } 47 | if ($data{'mysql-monitor_ping_interval'} < $data{'mysql-monitor_ping_timeout'}*5) { 48 | printf "WARN: mysql-monitor_ping_interval ($data{'mysql-monitor_ping_interval'}) is too small compared to mysql-monitor_ping_timeout ($data{'mysql-monitor_ping_timeout'})\n"; 49 | $warns+=1; 50 | } 51 | if ($data{'mysql-monitor_read_only_interval'} < $data{'mysql-monitor_read_only_timeout'}*5) { 52 | printf "WARN: mysql-monitor_read_only_interval ($data{'mysql-monitor_read_only_interval'}) is too small compared to mysql-monitor_read_only_timeout ($data{'mysql-monitor_read_only_timeout'})\n"; 53 | $warns+=1; 54 | } 55 | if ($data{'mysql-monitor_replication_lag_interval'} < $data{'mysql-monitor_replication_lag_timeout'}*5) { 56 | printf "WARN: mysql-monitor_replication_lag_interval ($data{'mysql-monitor_replication_lag_interval'}) is too small compared to mysql-monitor_replication_lag_timeout ($data{'mysql-monitor_replication_lag_timeout'})\n"; 57 | $warns+=1; 58 | } 59 | if ($data{'mysql-connect_timeout_server_max'} < $data{'mysql-connect_timeout_server'}*2) { 60 | printf "WARN: mysql-connect_timeout_server_max ($data{'mysql-connect_timeout_server_max'}) is too small compared to mysql-connect_timeout_server ($data{'mysql-connect_timeout_server'})\n"; 61 | $warns+=1; 62 | } 63 | 64 | printf "Check variables completed with $warns warnings.\n"; 65 | 66 | return 0; 67 | } 68 | 69 | if(!caller) { exit(main(@ARGV)); } 70 | --------------------------------------------------------------------------------