Commit 18ec2dc5 authored by Marko Mäkelä's avatar Marko Mäkelä

Merge 10.4 into 10.4-mdev-15562

parents 3e8339ae a53b99bf
......@@ -2088,5 +2088,11 @@ Warning 1292 Truncated incorrect time value: '-7487797330456870912'
DROP TABLE t1;
SET optimizer_use_condition_selectivity=DEFAULT;
#
# MDEV-17417 TIME(99991231235959) returns 838:59:59 instead of 23:59:58
#
SELECT TIME(99991231235957), TIME(99991231235958), TIME(99991231235959);
TIME(99991231235957) TIME(99991231235958) TIME(99991231235959)
23:59:57 23:59:58 23:59:59
#
# End of 10.4 tests
#
......@@ -1361,6 +1361,11 @@ SELECT 1 FROM t1 WHERE it < -7487797330456870912;
DROP TABLE t1;
SET optimizer_use_condition_selectivity=DEFAULT;
--echo #
--echo # MDEV-17417 TIME(99991231235959) returns 838:59:59 instead of 23:59:58
--echo #
SELECT TIME(99991231235957), TIME(99991231235958), TIME(99991231235959);
--echo #
--echo # End of 10.4 tests
......
......@@ -1444,7 +1444,7 @@ longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res,
int number_to_time(my_bool neg, ulonglong nr, ulong sec_part,
MYSQL_TIME *ltime, int *was_cut)
{
if (nr > 9999999 && nr < 99991231235959ULL && neg == 0)
if (nr > 9999999 && nr <= 99991231235959ULL && neg == 0)
return number_to_datetime(nr, sec_part, ltime,
C_TIME_INVALID_DATES, was_cut) < 0 ? -1 : 0;
......
......@@ -44,8 +44,7 @@ sync_array_get()
return(sync_wait_array[0]);
}
return(sync_wait_array[default_indexer_t<>::get_rnd_index()
% sync_array_size]);
return(sync_wait_array[get_rnd_value() % sync_array_size]);
}
/******************************************************************//**
......
......@@ -31,6 +31,7 @@ Created 2012/04/12 by Sunny Bains
#include <my_rdtsc.h>
#include "univ.i"
#include "os0thread.h"
#include <atomic>
/** CPU cache line size */
#ifdef CPU_LEVEL1_DCACHE_LINESIZE
......@@ -42,113 +43,79 @@ Created 2012/04/12 by Sunny Bains
/** Default number of slots to use in ib_counter_t */
#define IB_N_SLOTS 64
/** Get the offset into the counter array. */
template <typename Type, int N>
struct generic_indexer_t {
/** @return offset within m_counter */
static size_t offset(size_t index) UNIV_NOTHROW
{
return(((index % N) + 1) * (CACHE_LINE_SIZE / sizeof(Type)));
}
};
/** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles
as a random value. See the comments for my_timer_cycles() */
/** @return result from RDTSC or similar functions. */
static inline size_t
get_rnd_value()
{
size_t c = static_cast<size_t>(my_timer_cycles());
if (c != 0) {
return c;
}
/** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles,
to index into the counter array. See the comments for my_timer_cycles() */
template <typename Type=ulint, int N=1>
struct counter_indexer_t : public generic_indexer_t<Type, N> {
/** @return result from RDTSC or similar functions. */
static size_t get_rnd_index() UNIV_NOTHROW
{
size_t c = static_cast<size_t>(my_timer_cycles());
if (c != 0) {
return(c);
} else {
/* We may go here if my_timer_cycles() returns 0,
so we have to have the plan B for the counter. */
/* We may go here if my_timer_cycles() returns 0,
so we have to have the plan B for the counter. */
#if !defined(_WIN32)
return(size_t(os_thread_get_curr_id()));
return static_cast<size_t>(os_thread_get_curr_id());
#else
LARGE_INTEGER cnt;
QueryPerformanceCounter(&cnt);
LARGE_INTEGER cnt;
QueryPerformanceCounter(&cnt);
return(static_cast<size_t>(cnt.QuadPart));
return static_cast<size_t>(cnt.QuadPart);
#endif /* !_WIN32 */
}
}
}
/** @return a random offset to the array */
static size_t get_rnd_offset() UNIV_NOTHROW
{
return(generic_indexer_t<Type, N>::offset(get_rnd_index()));
}
};
#define default_indexer_t counter_indexer_t
/** Class for using fuzzy counters. The counter is not protected by any
mutex and the results are not guaranteed to be 100% accurate but close
/** Class for using fuzzy counters. The counter is multi-instance relaxed atomic
so the results are not guaranteed to be 100% accurate but close
enough. Creates an array of counters and separates each element by the
CACHE_LINE_SIZE bytes */
template <
typename Type,
int N = IB_N_SLOTS,
template<typename, int> class Indexer = default_indexer_t>
struct MY_ALIGNED(CACHE_LINE_SIZE) ib_counter_t
{
#ifdef UNIV_DEBUG
~ib_counter_t()
{
size_t n = (CACHE_LINE_SIZE / sizeof(Type));
/* Check that we aren't writing outside our defined bounds. */
for (size_t i = 0; i < UT_ARR_SIZE(m_counter); i += n) {
for (size_t j = 1; j < n - 1; ++j) {
ut_ad(m_counter[i + j] == 0);
}
}
}
#endif /* UNIV_DEBUG */
template <typename Type, int N = IB_N_SLOTS>
struct ib_counter_t {
/** Increment the counter by 1. */
void inc() UNIV_NOTHROW { add(1); }
void inc() { add(1); }
/** Increment the counter by 1.
@param[in] index a reasonably thread-unique identifier */
void inc(size_t index) UNIV_NOTHROW { add(index, 1); }
void inc(size_t index) { add(index, 1); }
/** Add to the counter.
@param[in] n amount to be added */
void add(Type n) UNIV_NOTHROW { add(m_policy.get_rnd_offset(), n); }
void add(Type n) { add(get_rnd_value(), n); }
/** Add to the counter.
@param[in] index a reasonably thread-unique identifier
@param[in] n amount to be added */
void add(size_t index, Type n) UNIV_NOTHROW {
size_t i = m_policy.offset(index);
void add(size_t index, Type n) {
index = index % N;
ut_ad(i < UT_ARR_SIZE(m_counter));
ut_ad(index < UT_ARR_SIZE(m_counter));
m_counter[i] += n;
m_counter[index].value.fetch_add(n, std::memory_order_relaxed);
}
/* @return total value - not 100% accurate, since it is not atomic. */
operator Type() const UNIV_NOTHROW {
/* @return total value - not 100% accurate, since it is relaxed atomic*/
operator Type() const {
Type total = 0;
for (size_t i = 0; i < N; ++i) {
total += m_counter[m_policy.offset(i)];
for (const auto &counter : m_counter) {
total += counter.value.load(std::memory_order_relaxed);
}
return(total);
}
private:
/** Indexer into the array */
Indexer<Type, N>m_policy;
/** Slot 0 is unused. */
Type m_counter[(N + 1) * (CACHE_LINE_SIZE / sizeof(Type))];
/** Atomic which occupies whole CPU cache line */
struct MY_ALIGNED(CACHE_LINE_SIZE) ib_counter_element_t {
std::atomic<Type> value;
byte padding[CACHE_LINE_SIZE - sizeof(value)];
};
static_assert(sizeof(ib_counter_element_t) == CACHE_LINE_SIZE, "");
/** Array of counter elements */
ib_counter_element_t m_counter[N];
};
#endif /* ut0counter_h */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment