move SleepFor* to libcommon

This commit is contained in:
Nikita Lapkov 2019-05-19 09:14:23 +00:00
parent 27732baeb6
commit 1dd87261ae
9 changed files with 30 additions and 42 deletions

View File

@ -1,20 +0,0 @@
#pragma once
#include <Common/Exception.h>
#include <Core/Types.h>
#include <time.h>
#include <errno.h>
namespace DB
{
void SleepForNanoseconds(UInt64 nanoseconds);
void SleepForMicroseconds(UInt64 microseconds);
void SleepForMilliseconds(UInt64 milliseconds);
void SleepForSeconds(UInt64 seconds);
}

View File

@ -6,7 +6,7 @@
#include <Common/Stopwatch.h>
#include <Common/Exception.h>
#include <Common/ProfileEvents.h>
#include <Common/Sleep.h>
#include <common/Sleep.h>
#include <IO/WriteHelpers.h>
#include <port/clock.h>

View File

@ -3,7 +3,7 @@
#include <Interpreters/ProcessList.h>
#include <Interpreters/Quota.h>
#include <Common/CurrentThread.h>
#include <Common/Sleep.h>
#include <common/Sleep.h>
namespace ProfileEvents
{

View File

@ -4,7 +4,7 @@
#include <Columns/ColumnConst.h>
#include <DataTypes/DataTypesNumber.h>
#include <Common/FieldVisitors.h>
#include <Common/Sleep.h>
#include <common/Sleep.h>
#include <IO/WriteHelpers.h>

View File

@ -19,7 +19,7 @@
#include <Common/setThreadName.h>
#include <Common/Stopwatch.h>
#include <Common/randomSeed.h>
#include <Common/Sleep.h>
#include <common/Sleep.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeArray.h>

View File

@ -22,6 +22,7 @@ add_library (common
src/demangle.cpp
src/setTerminalEcho.cpp
src/getThreadNumber.cpp
src/Sleep.cpp
include/common/Backtrace.h
include/common/Types.h
@ -45,6 +46,7 @@ add_library (common
include/common/constexpr_helpers.h
include/common/Pipe.h
include/common/getThreadNumber.h
include/common/Sleep.h
include/ext/bit_cast.h
include/ext/collection_cast.h

View File

@ -0,0 +1,13 @@
#pragma once
#include <cstdint>
#include <time.h>
#include <errno.h>
void SleepForNanoseconds(uint64_t nanoseconds);
void SleepForMicroseconds(uint64_t microseconds);
void SleepForMilliseconds(uint64_t milliseconds);
void SleepForSeconds(uint64_t seconds);

View File

@ -1,26 +1,18 @@
#include "Sleep.h"
#include "common/Sleep.h"
#include <iostream>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
void SleepForNanoseconds(UInt64 nanoseconds)
void SleepForNanoseconds(uint64_t nanoseconds)
{
const auto clock_type = CLOCK_REALTIME;
struct timespec current_time;
clock_gettime(clock_type, &current_time);
const UInt64 resolution = 1'000'000'000;
const uint64_t resolution = 1'000'000'000;
struct timespec finish_time = current_time;
finish_time.tv_nsec += nanoseconds % resolution;
const UInt64 extra_second = finish_time.tv_nsec / resolution;
const uint64_t extra_second = finish_time.tv_nsec / resolution;
finish_time.tv_nsec %= resolution;
finish_time.tv_sec += (nanoseconds / resolution) + extra_second;
@ -28,18 +20,17 @@ void SleepForNanoseconds(UInt64 nanoseconds)
while (clock_nanosleep(clock_type, TIMER_ABSTIME, &finish_time, nullptr) == EINTR);
}
void SleepForMicroseconds(UInt64 microseconds)
void SleepForMicroseconds(uint64_t microseconds)
{
SleepForNanoseconds(microseconds * 1000);
}
void SleepForMilliseconds(UInt64 milliseconds)
void SleepForMilliseconds(uint64_t milliseconds)
{
SleepForMicroseconds(milliseconds * 1000);
}
void SleepForSeconds(UInt64 seconds)
void SleepForSeconds(uint64_t seconds)
{
SleepForMilliseconds(seconds * 1000);
}
}

View File

@ -8,6 +8,8 @@
#include <mysqlxx/Pool.h>
#include <common/Sleep.h>
#include <Poco/Util/Application.h>
#include <Poco/Util/LayeredConfiguration.h>
@ -133,7 +135,7 @@ Pool::Entry Pool::Get()
}
lock.unlock();
::sleep(MYSQLXX_POOL_SLEEP_ON_CONNECT_FAIL);
SleepForSeconds(MYSQLXX_POOL_SLEEP_ON_CONNECT_FAIL);
lock.lock();
}
}
@ -184,7 +186,7 @@ void Pool::Entry::forceConnected() const
if (first)
first = false;
else
::sleep(MYSQLXX_POOL_SLEEP_ON_CONNECT_FAIL);
SleepForSeconds(MYSQLXX_POOL_SLEEP_ON_CONNECT_FAIL);
app.logger().information("MYSQL: Reconnecting to " + pool->description);
data->conn.connect(