Skip to content

Commit

Permalink
[myrocks] PS-8164: Make MyRocks buildable
Browse files Browse the repository at this point in the history
Import all functions and changes required to compile MyRocks (-DWITH_ROCKSDB=1).

----------------------------------------------------------------------

PS-9218 merge: Merge MySQL 8.4.0 (GCC 12.3 RelWithDebInfo fixes) (percona#5356)

https://perconadev.atlassian.net/browse/PS-9218

Added more warning suppressions for RocksDB submodule files that
appeared in GCC 12.3 in RelWithDebInfo mode.

----------------------------------------------------------------------

PS-9218: Merge MySQL 8.4.0 (fix gcc-14 build) #2 (rocksdb part)
  • Loading branch information
inikep committed Jan 17, 2025
1 parent 729ad31 commit fb90c56
Show file tree
Hide file tree
Showing 16 changed files with 520 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ INCLUDE(component)
INCLUDE(install_macros)
INCLUDE(mysql_add_executable)
INCLUDE(curl)
INCLUDE(prepend_append_cflags_if_supported)
INCLUDE(rapidjson)
INCLUDE(fprofile)
INCLUDE(fido2)
Expand Down
84 changes: 84 additions & 0 deletions cmake/prepend_append_cflags_if_supported.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (c) 2017, Percona and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

# helper macros to prepend or append c and cxx flags if supported by compiler

INCLUDE (CheckCCompilerFlag)
INCLUDE (CheckCXXCompilerFlag)

MACRO (prepend_cflags_if_supported)
FOREACH (flag ${ARGN})
STRING (REGEX REPLACE "-" "_" temp_flag ${flag})
check_c_compiler_flag (${flag} HAVE_C_${temp_flag})
IF (HAVE_C_${temp_flag})
SET (CMAKE_C_FLAGS "${flag} ${CMAKE_C_FLAGS}")
ENDIF ()
check_cxx_compiler_flag (${flag} HAVE_CXX_${temp_flag})
IF (HAVE_CXX_${temp_flag})
SET (CMAKE_CXX_FLAGS "${flag} ${CMAKE_CXX_FLAGS}")
ENDIF ()
ENDFOREACH (flag)
ENDMACRO (prepend_cflags_if_supported)

MACRO (append_cflags_if_supported)
FOREACH (flag ${ARGN})
STRING (REGEX REPLACE "-" "_" temp_flag ${flag})
check_c_compiler_flag (${flag} HAVE_C_${temp_flag})
IF (HAVE_C_${temp_flag})
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
ENDIF ()
check_cxx_compiler_flag (${flag} HAVE_CXX_${temp_flag})
IF (HAVE_CXX_${temp_flag})
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ENDIF ()
ENDFOREACH (flag)
ENDMACRO (append_cflags_if_supported)

MACRO (remove_compile_flags)
FOREACH (flag ${ARGN})
IF(CMAKE_C_FLAGS MATCHES ${flag})
STRING(REGEX REPLACE "${flag}( |$)" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
ENDIF(CMAKE_C_FLAGS MATCHES ${flag})
IF(CMAKE_CXX_FLAGS MATCHES ${flag})
STRING(REGEX REPLACE "${flag}( |$)" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF(CMAKE_CXX_FLAGS MATCHES ${flag})
ENDFOREACH (flag)
ENDMACRO (remove_compile_flags)

## ADD_CXX_COMPILE_FLAGS_TO_FILES(<flags> FILES <source files>)
## Add compile flags to given c++ files for all supported flags
MACRO(ADD_CXX_COMPILE_FLAGS_TO_FILES)
SET(FILES "")
SET(FLAGS "")
SET(FILES_SEEN)
FOREACH(ARG ${ARGV})
IF("x${ARG}" STREQUAL "xFILES")
SET(FILES_SEEN 1)
ELSEIF(FILES_SEEN)
LIST(APPEND FILES ${ARG})
ELSE()
LIST(APPEND FLAGS ${ARG})
ENDIF()
ENDFOREACH()
SET(CHECKED_FLAGS "")
FOREACH (flag ${FLAGS})
STRING (REGEX REPLACE "-" "_" temp_flag ${flag})
MY_CHECK_CXX_COMPILER_FLAG(${flag} HAVE_CXX_${temp_flag})
IF (HAVE_CXX_${temp_flag})
STRING_APPEND(CHECKED_FLAGS "${flag} ")
ENDIF()
ENDFOREACH(flag)
ADD_COMPILE_FLAGS(${FILES} COMPILE_FLAGS ${CHECKED_FLAGS})
ENDMACRO(ADD_CXX_COMPILE_FLAGS_TO_FILES)
84 changes: 84 additions & 0 deletions include/atomic_stat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* This is an atomic integer abstract data type, for high-performance
tracking of a single stat. It intentionally permits inconsistent
atomic operations and reads, for better performance. This means
that, though no data should ever be lost by this stat, reads of it
at any time may not include all changes up to any particular point.
So, values read from these may only be approximately correct.
If your use-case will fail under these conditions, do not use this.
Copyright (C) 2012 - 2014 Steaphan Greene <steaphan@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the
Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301, USA.
*/

#ifndef _atomic_stat_h_
#define _atomic_stat_h_

#include <atomic>

template <typename TYPE>
class atomic_stat {
public:
// Initialize value to the default for the type
atomic_stat() : value_(TYPE()){};

// This enforces a strict order, as all absolute sets should
void clear() { value_.store(TYPE(), std::memory_order_seq_cst); };

// Reads can get any valid value, it doesn't matter which, exactly
TYPE load() const { return value_.load(std::memory_order_relaxed); };

// This only supplies relative arithmetic operations
// These are all done atomically, and so can show up in any order
void inc(const TYPE &other) {
value_.fetch_add(other, std::memory_order_relaxed);
};

void dec(const TYPE &other) {
value_.fetch_sub(other, std::memory_order_relaxed);
};

void inc() { value_.fetch_add(1, std::memory_order_relaxed); };

void dec() { value_.fetch_sub(1, std::memory_order_relaxed); };

// This will make one attempt to set the value to the max of
// the current value, and the passed-in value. It can fail
// for any reason, and we only try it once.
void set_max_maybe(const TYPE &new_val) {
TYPE old_val = value_;
if (new_val > old_val) {
value_.compare_exchange_weak(old_val, new_val, std::memory_order_relaxed,
std::memory_order_relaxed);
}
};

// This will make one attempt to assign the value to the passed-in
// value. It can fail for any reason, and we only try it once.
void set_maybe(const TYPE &new_val) {
TYPE old_val = value_;
value_.compare_exchange_weak(old_val, new_val, std::memory_order_relaxed,
std::memory_order_relaxed);
};

private:
std::atomic<TYPE> value_;
};

#endif // _atomic_stat_h_
7 changes: 7 additions & 0 deletions include/my_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/types.h>

#include "my_inttypes.h"
#include "mysql/psi/mysql_mutex.h" /* mysql_mutex_t */

typedef uint32 my_bitmap_map;

Expand All @@ -45,6 +46,12 @@ struct MY_BITMAP {
uint n_bits{0}; /* number of bits occupied by the above */
my_bitmap_map last_word_mask{0};
my_bitmap_map *last_word_ptr{nullptr};
/*
mutex will be acquired for the duration of each bitmap operation if
thread_safe flag in bitmap_init was set. Otherwise, we optimize by not
acquiring the mutex
*/
mysql_mutex_t *mutex{nullptr};
};

extern void create_last_word_mask(MY_BITMAP *map);
Expand Down
14 changes: 14 additions & 0 deletions include/my_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ constexpr bool unlikely(bool expr) { return expr; }
#define __func__ __FUNCTION__
#endif

#if defined(__cplusplus) && defined(__cpp_attributes) && \
defined(__has_cpp_attribute)
#if __has_cpp_attribute(nodiscard)
#define MY_NODISCARD [[nodiscard]]
#elif __has_cpp_attribute(gnu::warn_unused_result)
#define MY_NODISCARD [[gnu::warn_unused_result]]
#endif /* __has_cpp_attribute(gnu::warn_unused_result) */
#endif /* defined(__cplusplus) && defined(__cpp_attributes) && \
defined(__has_cpp_attribute) */

#ifndef MY_NODISCARD
#define MY_NODISCARD MY_ATTRIBUTE((warn_unused_result))
#endif /* MY_NODISCARD */

#if defined(_MSC_VER)
#define ALWAYS_INLINE __forceinline
#else
Expand Down
143 changes: 143 additions & 0 deletions include/my_io_perf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* Copyright (c) 2016, Percona and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#ifndef _io_perf_h_
#define _io_perf_h_

#include <memory.h>
#include <algorithm>
#include "atomic_stat.h"
#include "my_inttypes.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Per-table operation and IO statistics */

/* Struct used for IO performance counters within a single thread */
struct my_io_perf_struct {
ulonglong bytes;
ulonglong requests;
ulonglong svc_time; /*!< time to do read or write operation */
ulonglong svc_time_max;
ulonglong wait_time; /*!< total time in the request array */
ulonglong wait_time_max;
ulonglong slow_ios; /*!< requests that take too long */

/* Initialize a my_io_perf_t struct. */
inline void init() { memset(this, 0, sizeof(*this)); }

/* Sets this to a - b in diff */
inline void diff(const my_io_perf_struct &a, const my_io_perf_struct &b) {
if (a.bytes > b.bytes)
bytes = a.bytes - b.bytes;
else
bytes = 0;

if (a.requests > b.requests)
requests = a.requests - b.requests;
else
requests = 0;

if (a.svc_time > b.svc_time)
svc_time = a.svc_time - b.svc_time;
else
svc_time = 0;

if (a.wait_time > b.wait_time)
wait_time = a.wait_time - b.wait_time;
else
wait_time = 0;

if (a.slow_ios > b.slow_ios)
slow_ios = a.slow_ios - b.slow_ios;
else
slow_ios = 0;

svc_time_max = std::max(a.svc_time_max, b.svc_time_max);
wait_time_max = std::max(a.wait_time_max, b.wait_time_max);
}

/* Accumulates io perf values */
inline void sum(const my_io_perf_struct &that) {
bytes += that.bytes;
requests += that.requests;
svc_time += that.svc_time;
svc_time_max = std::max(svc_time_max, that.svc_time_max);
wait_time += that.wait_time;
wait_time_max = std::max(wait_time_max, that.wait_time_max);
slow_ios += that.slow_ios;
}
};
typedef struct my_io_perf_struct my_io_perf_t;

/* Struct used for IO performance counters, shared among multiple threads */
struct my_io_perf_atomic_struct {
atomic_stat<ulonglong> bytes;
atomic_stat<ulonglong> requests;
atomic_stat<ulonglong> svc_time; /*!< time to do read or write operation */
atomic_stat<ulonglong> svc_time_max;
atomic_stat<ulonglong> wait_time; /*!< total time in the request array */
atomic_stat<ulonglong> wait_time_max;
atomic_stat<ulonglong> slow_ios; /*!< requests that take too long */

/* Initialize an my_io_perf_atomic_t struct. */
inline void init() {
bytes.clear();
requests.clear();
svc_time.clear();
svc_time_max.clear();
wait_time.clear();
wait_time_max.clear();
slow_ios.clear();
}

/* Accumulates io perf values using atomic operations */
inline void sum(const my_io_perf_struct &that) {
bytes.inc(that.bytes);
requests.inc(that.requests);

svc_time.inc(that.svc_time);
wait_time.inc(that.wait_time);

// In the unlikely case that two threads attempt to update the max
// value at the same time, only the first will succeed. It's possible
// that the second thread would have set a larger max value, but we
// would rather error on the side of simplicity and avoid looping the
// compare-and-swap.
svc_time_max.set_max_maybe(that.svc_time);
wait_time_max.set_max_maybe(that.wait_time);

slow_ios.inc(that.slow_ios);
}

/* These assignments allow for races. That is OK. */
inline void set_maybe(const my_io_perf_struct &that) {
bytes.set_maybe(that.bytes);
requests.set_maybe(that.requests);
svc_time.set_maybe(that.svc_time);
svc_time_max.set_maybe(that.svc_time_max);
wait_time.set_maybe(that.wait_time);
wait_time_max.set_maybe(that.wait_time_max);
slow_ios.set_maybe(that.slow_ios);
}
};
typedef struct my_io_perf_atomic_struct my_io_perf_atomic_t;

#ifdef __cplusplus
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
#define PLUGIN_VAR_PERSIST_AS_READ_ONLY 0x20000
#define PLUGIN_VAR_INVISIBLE 0x40000 /**< Variable should not be shown */
#define PLUGIN_VAR_SENSITIVE 0x80000 /**< Sensitive variable */
/**
This flag enables variables to be recognized by SET_VAR() HINT. Should
be used only THDVAR() variables, ie variables which have session scope.
*/
#define PLUGIN_VAR_HINTUPDATEABLE 0x100000
/** @} */

/**
Expand Down
6 changes: 6 additions & 0 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,12 @@ int handler::ha_index_next(uchar *buf) {
return result;
}

bool handler::is_using_full_key(key_part_map keypart_map,
uint actual_key_parts) noexcept {
return (keypart_map == HA_WHOLE_KEY) ||
(keypart_map == ((key_part_map(1) << actual_key_parts) - 1));
}

/**
Reads the previous row via index.
Expand Down
Loading

0 comments on commit fb90c56

Please sign in to comment.