Skip to content

Commit

Permalink
pegasus_server: update rdsn to fix replica close problem; add cancel_…
Browse files Browse the repository at this point in the history
…background_work() method (#49)
  • Loading branch information
qinzuoyan committed May 30, 2018
1 parent 6d2415c commit ac5a28c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/server/pegasus_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <rocksdb/convenience.h>
#include <rocksdb/table.h>
#include <rocksdb/utilities/checkpoint.h>
#include <dsn/utility/utils.h>
Expand Down Expand Up @@ -1810,7 +1811,7 @@ ::dsn::error_code pegasus_server_impl::start(int argc, char **argv)
_is_open = true;

dinfo("%s: start the updating sstsize timer task", replica_name());
::dsn::tasking::enqueue_timer(
_updating_rocksdb_sstsize_timer_task = ::dsn::tasking::enqueue_timer(
LPC_UPDATING_ROCKSDB_SSTSIZE,
&_tracker,
[this]() { this->updating_rocksdb_sstsize(); },
Expand All @@ -1825,6 +1826,12 @@ ::dsn::error_code pegasus_server_impl::start(int argc, char **argv)
}
}

void pegasus_server_impl::cancel_background_work(bool wait)
{
dassert(_db != nullptr, "");
rocksdb::CancelAllBackgroundWork(_db, wait);
}

::dsn::error_code pegasus_server_impl::stop(bool clear_state)
{
if (!_is_open) {
Expand All @@ -1842,10 +1849,15 @@ ::dsn::error_code pegasus_server_impl::stop(bool clear_state)
}
}

_context_cache.clear();
// stop all tracked tasks when pegasus server is stopped.
if (_updating_rocksdb_sstsize_timer_task != nullptr) {
_updating_rocksdb_sstsize_timer_task->cancel(true);
_updating_rocksdb_sstsize_timer_task = nullptr;
}
_tracker.cancel_outstanding_tasks();

_context_cache.clear();

_is_open = false;
delete _db;
_db = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions src/server/pegasus_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service
// - ERR_LOCAL_APP_FAILURE
virtual ::dsn::error_code start(int argc, char **argv) override;

virtual void cancel_background_work(bool wait) override;

// returns:
// - ERR_OK
// - ERR_FILE_OPERATION_FAILED
Expand Down Expand Up @@ -247,6 +249,7 @@ class pegasus_server_impl : public ::dsn::apps::rrdb_service

pegasus_context_cache _context_cache;

::dsn::task_ptr _updating_rocksdb_sstsize_timer_task;
uint32_t _updating_rocksdb_sstsize_interval_seconds;

pagasus_manual_compact_service _manual_compact_svc;
Expand Down

0 comments on commit ac5a28c

Please sign in to comment.