Skip to content

Commit

Permalink
Use dedicated call and progress event for progress reporting in status
Browse files Browse the repository at this point in the history
reporter interface.

Refs #174
  • Loading branch information
ayurchen committed Dec 8, 2021
1 parent 3e13905 commit 5540c2f
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 129 deletions.
2 changes: 1 addition & 1 deletion dbsim/db_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ void db::server::log_state_change(enum wsrep::server_state::state from,
enum wsrep::server_state::state to)
{
wsrep::log_info() << "State changed " << from << " -> " << to;
reporter_.report_state(to, 0);
reporter_.report_state(to);
}
20 changes: 14 additions & 6 deletions include/wsrep/reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ namespace wsrep

virtual ~reporter();

// indefinite progress value
static float constexpr indefinite = -1.0f;

void report_state(enum server_state::state state,
float progress = indefinite);
void report_state(enum server_state::state state);

/**
* Report progres in the form of a JSON string (all values integers):
* {
* "from": FROM, // from wsrep API state number
* "to": TO, // to wsrep API state number
* "total": TOTAL, // total work to do
* "done": DONE, // work already done
* "indefinite": INDEFINITE // indefinite value of work constant
* }
*/
void report_progress(const std::string& json);

enum log_level
{
Expand Down Expand Up @@ -80,9 +88,9 @@ namespace wsrep

wsrep::mutex& mutex_;
std::string const file_name_;
std::string progress_;
char* template_;
substates state_;
float progress_;
bool initialized_;

typedef struct {
Expand Down
103 changes: 41 additions & 62 deletions src/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@

static std::string const TEMP_EXTENSION(".XXXXXX");

static std::string make_progress_string(int const from, int const to,
int const total,int const done,
int const indefinite)
{
std::ostringstream os;

os << "{ \"from\": " << from << ", "
<< "\"to\": " << to << ", "
<< "\"total\": " << total << ", "
<< "\"done\": " << done << ", "
<< "\"indefinite\": " << indefinite << " }";

return os.str();
}

static std::string const indefinite_progress
(make_progress_string(-1, -1, -1, -1, -1));
static std::string const steady_state
(make_progress_string(-1, -1, 0, 0, -1));

static inline double
timestamp()
{
Expand All @@ -46,9 +66,9 @@ wsrep::reporter::reporter(wsrep::mutex& mutex,
size_t const max_msg)
: mutex_(mutex)
, file_name_(file_name)
, progress_(indefinite_progress)
, template_(new char [file_name_.length() + TEMP_EXTENSION.length() + 1])
, state_(wsrep::reporter::s_disconnected_disconnected)
, progress_(indefinite)
, initialized_(false)
, err_msg_()
, warn_msg_()
Expand Down Expand Up @@ -117,48 +137,6 @@ wsrep::reporter::substate_map(enum wsrep::server_state::state const state)
}
}

static float const SST_SHARE = 0.5f; // SST share of JOINING progress
static float const INIT_SHARE = 0.1f; // initialization share of JOINING progress
static float const IST_SHARE = (1.0f - SST_SHARE - INIT_SHARE); // IST share

float
wsrep::reporter::progress_map(float const progress) const
{
assert(progress >= 0.0f);
assert(progress <= 1.0f);

switch (state_)
{
case s_disconnected_disconnected:
return indefinite;
case s_disconnected_initializing:
return indefinite;
case s_disconnected_initialized:
return indefinite;
case s_connected_waiting:
return indefinite;
case s_joining_initialized:
return progress;
case s_joining_sst:
return progress * SST_SHARE;
case s_joining_initializing:
return SST_SHARE + progress * INIT_SHARE;
case s_joining_ist:
return SST_SHARE + INIT_SHARE + progress * IST_SHARE;
case s_joined_syncing:
return progress;
case s_synced_running:
return 1.0;
case s_donor_sending:
return progress;
case s_disconnecting_disconnecting:
return indefinite;
default:
assert(0);
return progress;
}
}

void
wsrep::reporter::write_log_msg(std::ostream& os,
const log_msg& msg)
Expand Down Expand Up @@ -250,8 +228,7 @@ wsrep::reporter::write_file(double const tstamp)
os << "\t\"status\": {\n";
os << "\t\t\"state\": \"" << strings[state_].state << "\",\n";
os << "\t\t\"comment\": \"" << strings[state_].comment << "\",\n";
os << "\t\t\"progress\": " << std::showpoint << std::setprecision(6)
<< progress_ << "\n";
os << "\t\t\"progress\": " << progress_ << "\n";
os << "\t}\n";
os << "}\n";

Expand All @@ -270,36 +247,38 @@ wsrep::reporter::write_file(double const tstamp)
}

void
wsrep::reporter::report_state(enum server_state::state const s, float const p)
wsrep::reporter::report_state(enum server_state::state const s)
{
assert(p >= -1);
assert(p <= 1);

bool flush(false);

wsrep::unique_lock<wsrep::mutex> lock(mutex_);

substates const state(substate_map(s));

if (state != state_)
{
state_ = state;
flush = true;
}

float const progress(progress_map(p));
assert(progress >= -1);
assert(progress <= 1);
if (state_ == s_synced_running)
progress_ = steady_state;
else
progress_ = indefinite_progress;

if (progress != progress_)
{
progress_ = progress;
flush = true;
write_file(timestamp());
}
}

if (flush)
void
wsrep::reporter::report_progress(const std::string& json)
{
wsrep::unique_lock<wsrep::mutex> lock(mutex_);

if (json != progress_)
{
write_file(timestamp());
if (state_ != s_synced_running)
{
// ignore any progress in SYNCED state
progress_ = json;
write_file(timestamp());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wsrep_provider_v26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ namespace
static int init_event_service(void* dlh,
wsrep::event_service* service)
{
assert(event_service);
assert(service);
if (not wsrep::event_service_v1_probe(dlh))
{
return wsrep::event_service_v1_init(dlh, service);
Expand Down
Loading

0 comments on commit 5540c2f

Please sign in to comment.