Skip to content

Commit

Permalink
Merge pull request mysql#15 from planetscale/piki/cherry-picks
Browse files Browse the repository at this point in the history
Cherry picks from 8.0.23 -> 8.0.28
  • Loading branch information
piki authored May 27, 2022
2 parents 4e6d30c + c83f148 commit 9ae00a1
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 24 deletions.
10 changes: 9 additions & 1 deletion .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
set -eu

TODAY=$(date +"%Y%m%d")
[ -n "$TODAY" ]
echo "Today = \"${TODAY}\""

git log -25000 --format='%H' | sort > tmp-log
git show-ref | grep tags/mysql-8 | sort > tmp-tags
export CONTAINER_SEMVER=$(join tmp-log tmp-tags | sort -k2 | tail -1 | cut -d- -f2)
export CONTAINER_SEMVER=$(join tmp-log tmp-tags | sort -t. -n -k3 | tail -1 | cut -d- -f2)
[ -n "$CONTAINER_SEMVER" ]
export CONTAINER_SEMVER="$CONTAINER_SEMVER.$TODAY"
echo "Semantic version = \"${CONTAINER_SEMVER}\""

export CONTAINER_SHORT_SHA=$(git log -1 --pretty='%h')
[ -n "$CONTAINER_SHORT_SHA" ]
echo "Short SHA = \"${CONTAINER_SHORT_SHA}\""

export CONTAINER_BRANCH_NAME=$(echo "$BUILDKITE_BRANCH" | sed -e 's/[\/:]/_/g')
[ -n "$CONTAINER_BRANCH_NAME" ]
echo "Safe branch name = \"${CONTAINER_BRANCH_NAME}\""
2 changes: 0 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ env:
steps:
- name: "Build mysql-server"
label: ":docker: Build and package"
agents:
queue: "whopper"
command: bash build.sh
artifact_paths:
- "dist/*.tar.gz"
Expand Down
19 changes: 18 additions & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@ RUN apt-get install -y \
libaio1 \
libnuma1 \
libtcmalloc-minimal4 \
binutils
binutils \
bzip2 \
ca-certificates \
dirmngr \
gnupg \
libatomic1 \
libcurl4 \
libdbd-mysql-perl \
libwww-perl \
libev4 \
libjemalloc2 \
procps \
rsync \
strace \
sysstat \
wget \
curl \
percona-toolkit

ADD dist/ /dist

Expand Down
30 changes: 18 additions & 12 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -e

if [ $(id -u) -eq 0 ]; then
su bob -c ./build.sh
cp build/*.tar.gz /dist/
exit
su bob -c ./build.sh
cp build/*.tar.gz /dist/
exit
fi

if [ -d build ]; then
Expand All @@ -15,27 +15,33 @@ fi
mkdir build
cd build

# The first group of build flags are from the rules file in
# https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community_8.0.23-1debian9.debian.tar.xz
# The second group are intended to speed up the build by skipping binaries
# and debug symbols we don't need.
cmake \
-DWITH_BOOST=boost-lib \
-DDOWNLOAD_BOOST=1 \
-DBUILD_CONFIG=mysql_release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \
-DDOWNLOAD_BOOST=1 \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DWITH_INNODB_MEMCACHED=1 \
-DWITH_MECAB=system \
-DWITH_NUMA=ON \
-DCOMPILATION_COMMENT="PlanetScale MySQL" \
-DCOMPILATION_COMMENT_SERVER="PlanetScale MySQL Server" \
-DREPRODUCIBLE_BUILD=OFF \
\
-DENABLED_PROFILING=0 \
-DENABLE_DEBUG_SYNC=0 \
-DENABLE_DTRACE=0 \
-DENABLE_GCOV=0 \
-DENABLE_GPROF=0 \
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DOPTIMIZER_TRACE=0 \
-DSYSCONFDIR=/etc/mysql \
-DWITH_BOOST=boost-lib \
-DWITH_CLIENT_PROTOCOL_TRACING=0 \
-DWITH_DEBUG=0 \
-DWITH_INNODB_EXTRA_DEBUG=0 \
-DWITH_INNODB_MEMCACHED=1 \
-DWITH_MECAB=system \
-DWITH_NUMA=ON \
-DWITH_ROUTER=OFF \
..

Expand Down
24 changes: 23 additions & 1 deletion sql/auth/sql_security_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void Security_context::init() {
m_has_drop_policy = false;
m_executed_drop_policy = false;
m_registration_sandbox_mode = false;
m_exclude_user_from_rows_read = false;
}

void Security_context::logout() {
Expand Down Expand Up @@ -816,6 +817,8 @@ void Security_context::set_user_ptr(const char *user_arg,

// set new user value to m_user.
m_user.set(user_arg, user_arg_length, system_charset_info);

recheck_exclude_rows_read();
}

/**
Expand All @@ -838,6 +841,25 @@ void Security_context::assign_user(const char *user_arg,
m_user.copy(user_arg, user_arg_length, system_charset_info);
else
m_user.set((const char *)nullptr, 0, system_charset_info);

recheck_exclude_rows_read();
}

char *rows_read_exclude_users = nullptr;

void Security_context::recheck_exclude_rows_read() {
m_exclude_user_from_rows_read = false;
if (rows_read_exclude_users) {
char *copy = strdup(rows_read_exclude_users);
char *saveptr, *tok;
for (tok=my_strtok_r(copy, ",", &saveptr); tok; tok=my_strtok_r(NULL, ",", &saveptr)) {
if (!strcmp(tok, m_user.ptr())) {
m_exclude_user_from_rows_read = true;
break;
}
}
free(copy);
}
}

/**
Expand Down Expand Up @@ -881,7 +903,7 @@ void Security_context::set_host_ptr(const char *host_arg,
/**
Setter method for member m_host.
Copies host_arg value to the m_host if it is not null else m_user is set
Copies host_arg value to the m_host if it is not null else m_host is set
to empty string.
Expand Down
4 changes: 4 additions & 0 deletions sql/auth/sql_security_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Security_context {
void skip_grants(const char *user = "skip-grants user",
const char *host = "skip-grants host");
bool is_skip_grants_user();
bool exclude_user_from_rows_read() const { return m_exclude_user_from_rows_read; }

/**
Getter method for member m_user.
Expand Down Expand Up @@ -381,6 +382,9 @@ class Security_context {
*/
bool m_is_skip_grants_user;

bool m_exclude_user_from_rows_read;
void recheck_exclude_rows_read();

bool m_executed_drop_policy;
bool m_has_drop_policy;
std::unique_ptr<std::function<void(Security_context *)>> m_drop_policy;
Expand Down
16 changes: 11 additions & 5 deletions sql/protocol_classic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1332,11 +1332,17 @@ bool Protocol_classic::send_eof(uint server_status, uint statement_warn_count) {
if (has_client_capability(CLIENT_DEPRECATE_EOF) &&
(m_thd->get_command() != COM_BINLOG_DUMP &&
m_thd->get_command() != COM_BINLOG_DUMP_GTID)) {
char message[64] = "";
snprintf(message+1, sizeof(message)-1, "{\"rows_read\":%llu}", m_thd->get_stmt_da()->rows_read());

retval = net_send_ok(m_thd, server_status, statement_warn_count, 0, 0,
message, 1+strlen(message+1), true);
ulonglong rows_read = m_thd->get_stmt_da()->rows_read();
if (rows_read) {
char message[64] = "";
snprintf(message+1, sizeof(message)-1, "{\"rows_read\":%llu}", rows_read);
retval = net_send_ok(m_thd, server_status, statement_warn_count, 0, 0,
message, 1+strlen(message+1), true);
}
else {
retval = net_send_ok(m_thd, server_status, statement_warn_count, 0, 0,
NULL, 0, true);
}
}
else
retval = net_send_eof(m_thd, server_status, statement_warn_count);
Expand Down
7 changes: 7 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,13 @@ static Sys_var_charptr Sys_my_bind_addr(
READ_ONLY NON_PERSIST GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG),
IN_FS_CHARSET, DEFAULT(MY_BIND_ALL_ADDRESSES));

extern char *rows_read_exclude_users;
static Sys_var_charptr Sys_my_rows_read_exclude_users(
"rows_read_exclude_users",
"Comma-separated list of users whose queries do not increment rows_read",
READ_ONLY NON_PERSIST GLOBAL_VAR(rows_read_exclude_users), CMD_LINE(REQUIRED_ARG),
IN_FS_CHARSET, DEFAULT(nullptr));

static Sys_var_charptr Sys_admin_addr(
"admin_address",
"IP address to bind to for service connection. Address can be an IPv4"
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10131,7 +10131,7 @@ int ha_innobase::index_read(
if (m_prebuilt->table->is_system_table) {
srv_stats.n_system_rows_read.add(
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
} else {
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {
srv_stats.n_rows_read.add(thd_get_thread_id(m_prebuilt->trx->mysql_thd),
1);
m_user_thd->get_stmt_da()->inc_rows_read();
Expand Down Expand Up @@ -10379,7 +10379,7 @@ int ha_innobase::general_fetch(
if (m_prebuilt->table->is_system_table) {
srv_stats.n_system_rows_read.add(
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
} else {
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {
srv_stats.n_rows_read.add(thd_get_thread_id(m_prebuilt->trx->mysql_thd),
1);
m_user_thd->get_stmt_da()->inc_rows_read();
Expand Down

0 comments on commit 9ae00a1

Please sign in to comment.