Skip to content

Commit e15cf94

Browse files
committed
build: Fix compilation errors for boost 1.9
This also changes from posix_timer (which I think is system time) to steady_timer (monotonic time), which should help avoid bugs with system time. Signed-off-by: Urmas Rist <urmas@leil.io>
1 parent 84c158a commit e15cf94

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

cmake/Libraries.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ else()
7070
endif()
7171

7272
# Find Boost
73-
find_package(Boost CONFIG REQUIRED COMPONENTS filesystem iostreams program_options system)
73+
find_package(Boost CONFIG REQUIRED COMPONENTS filesystem iostreams program_options)
7474

7575
# Find Thrift
7676
find_package(Thrift COMPONENTS library)

src/chunkserver/chunkserver-common/hdd_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "common/platform.h"
2222

23+
#include <boost/shared_ptr.hpp>
2324
#include <deque>
2425

2526
#include "chunkserver-common/chunk_interface.h"

src/chunkserver/chunkserver-common/plugin_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <boost/dll/import.hpp>
2626
#include <boost/filesystem.hpp>
2727
#include <boost/function.hpp>
28+
#include <boost/shared_ptr.hpp>
2829

2930
#include "chunkserver-common/disk_plugin.h"
3031

src/uraft/uraft.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,20 @@ bool uRaft::validPacket(const uint8_t *data, size_t size) {
152152
void uRaft::startElectionTimer() {
153153
int timeout = opt_.election_timeout_min +
154154
rand() % (opt_.election_timeout_max - opt_.election_timeout_min);
155-
election_timer_.expires_from_now(boost::posix_time::millisec(timeout));
155+
election_timer_.expires_after(std::chrono::milliseconds(timeout));
156156
election_timer_.async_wait(boost::bind(&uRaft::electionTimeout, this,
157157
boost::asio::placeholders::error));
158158
}
159159

160160
void uRaft::startHearbeatTimer() {
161-
heartbeat_timer_.expires_from_now(boost::posix_time::millisec(opt_.heartbeat_period));
161+
heartbeat_timer_.expires_after(std::chrono::milliseconds(opt_.heartbeat_period));
162162
heartbeat_timer_.async_wait(boost::bind(&uRaft::heartbeat, this,
163163
boost::asio::placeholders::error));
164164
}
165165

166166
void uRaft::signLoyaltyAgreement() {
167167
state_.loyalty_agreement = true;
168-
loyalty_agreement_timer_.expires_from_now(boost::posix_time::millisec(opt_.election_timeout_min));
168+
loyalty_agreement_timer_.expires_after(std::chrono::milliseconds(opt_.election_timeout_min));
169169
loyalty_agreement_timer_.async_wait([this](const boost::system::error_code & error) {
170170
if (!error) {
171171
state_.loyalty_agreement = false;

src/uraft/uraft.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <boost/array.hpp>
66
#include <boost/asio.hpp>
7+
#include <boost/asio/steady_timer.hpp>
78

89
/*! \brief Implementation of modified Raft consensus algorithm.
910
*
@@ -222,8 +223,8 @@ class uRaft {
222223
protected:
223224
boost::asio::io_context &io_service_;
224225
boost::asio::ip::udp::socket socket_;
225-
boost::asio::deadline_timer election_timer_,heartbeat_timer_;
226-
boost::asio::deadline_timer loyalty_agreement_timer_;
226+
boost::asio::steady_timer election_timer_,heartbeat_timer_;
227+
boost::asio::steady_timer loyalty_agreement_timer_;
227228
boost::array<uint8_t,kMaxPacketLength> packet_data_;
228229
boost::asio::ip::udp::endpoint sender_endpoint_;
229230

src/uraft/uraftcontroller.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/bind.hpp>
1818
#include <boost/lexical_cast.hpp>
1919
#include <boost/version.hpp>
20+
#include <boost/chrono.hpp>
2021

2122
constexpr int kCommandTimeoutMs = 5000; ///< Default command timeout in milliseconds.
2223

@@ -57,11 +58,11 @@ void uRaftController::init() {
5758
return;
5859
}
5960

60-
check_cmd_status_timer_.expires_from_now(boost::posix_time::millisec(opt_.check_cmd_status_period));
61+
check_cmd_status_timer_.expires_after(std::chrono::milliseconds(opt_.check_cmd_status_period));
6162
check_cmd_status_timer_.async_wait(boost::bind(&uRaftController::checkCommandStatus, this,
6263
boost::asio::placeholders::error));
6364

64-
check_node_status_timer_.expires_from_now(boost::posix_time::millisec(opt_.check_node_status_period));
65+
check_node_status_timer_.expires_after(std::chrono::milliseconds(opt_.check_node_status_period));
6566
check_node_status_timer_.async_wait(boost::bind(&uRaftController::checkNodeStatus, this,
6667
boost::asio::placeholders::error));
6768

@@ -249,7 +250,7 @@ void uRaftController::checkCommandStatus(const boost::system::error_code &error)
249250
}
250251
}
251252

252-
check_cmd_status_timer_.expires_from_now(boost::posix_time::millisec(opt_.check_cmd_status_period));
253+
check_cmd_status_timer_.expires_after(std::chrono::milliseconds(opt_.check_cmd_status_period));
253254
check_cmd_status_timer_.async_wait(boost::bind(&uRaftController::checkCommandStatus, this,
254255
boost::asio::placeholders::error));
255256
}
@@ -295,7 +296,7 @@ void uRaftController::checkNodeStatus(const boost::system::error_code &error) {
295296
}
296297
}
297298

298-
check_node_status_timer_.expires_from_now(boost::posix_time::millisec(opt_.check_node_status_period));
299+
check_node_status_timer_.expires_after(std::chrono::milliseconds(opt_.check_node_status_period));
299300
check_node_status_timer_.async_wait(boost::bind(&uRaftController::checkNodeStatus, this,
300301
boost::asio::placeholders::error));
301302
}
@@ -328,7 +329,7 @@ void uRaftController::scheduleDeadRecovery() {
328329
if (dead_recovery_pending_) { return; }
329330
dead_recovery_pending_ = true;
330331

331-
dead_recovery_timer_.expires_from_now(boost::posix_time::millisec(kDeadRecoveryDelayMs));
332+
dead_recovery_timer_.expires_after(std::chrono::milliseconds(kDeadRecoveryDelayMs));
332333
dead_recovery_timer_.async_wait([this](const boost::system::error_code &ec) {
333334
if (ec) { return; }
334335

@@ -353,7 +354,7 @@ void uRaftController::scheduleDeadRecovery() {
353354
}
354355

355356
void uRaftController::setSlowCommandTimeout(int timeout) {
356-
cmd_timeout_timer_.expires_from_now(boost::posix_time::millisec(timeout));
357+
cmd_timeout_timer_.expires_after(std::chrono::milliseconds(timeout));
357358
cmd_timeout_timer_.async_wait([this, timeout](const boost::system::error_code & error) {
358359
if (!error) {
359360
syslog(LOG_ERR, "Metadata server mode switching timeout after %d ms", timeout);
@@ -631,7 +632,7 @@ void uRaftController::startPromotionBackoff(bool reset) {
631632
syslog(LOG_WARNING, "Promotion backoff enabled (%d ms), streak=%d", backoff_ms,
632633
promotion_failure_streak_);
633634

634-
promotion_backoff_timer_.expires_from_now(boost::posix_time::millisec(backoff_ms));
635+
promotion_backoff_timer_.expires_after(std::chrono::milliseconds(backoff_ms));
635636
promotion_backoff_timer_.async_wait([this](const boost::system::error_code &ec) {
636637
if (ec) { return; }
637638
promotion_backoff_active_ = false;

src/uraft/uraftcontroller.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,20 @@ class uRaftController : public uRaftStatus {
153153
int computePromotionBackoffMs() const;
154154

155155
protected:
156-
boost::asio::deadline_timer check_cmd_status_timer_;
157-
boost::asio::deadline_timer check_node_status_timer_;
158-
boost::asio::deadline_timer cmd_timeout_timer_;
156+
boost::asio::steady_timer check_cmd_status_timer_;
157+
boost::asio::steady_timer check_node_status_timer_;
158+
boost::asio::steady_timer cmd_timeout_timer_;
159159

160160
/// @brief Timer used to implement promotion backoff after failed promotions.
161-
boost::asio::deadline_timer promotion_backoff_timer_;
161+
boost::asio::steady_timer promotion_backoff_timer_;
162162
/// @brief Number of consecutive promotion failures used to compute exponential backoff.
163163
/// This value is reset on successful promotion.
164164
int promotion_failure_streak_ = 0;
165165
/// @brief True while promotion backoff is active (promotions are temporarily blocked).
166166
bool promotion_backoff_active_ = false;
167167

168168
/// @brief Timer used to schedule delayed recovery after detecting dead metadata.
169-
boost::asio::deadline_timer dead_recovery_timer_;
169+
boost::asio::steady_timer dead_recovery_timer_;
170170
/// @brief True while a dead recovery timer is scheduled (prevents stacking retries).
171171
bool dead_recovery_pending_ = false;
172172

0 commit comments

Comments
 (0)