int model::init_model (report_system *rep, const cmd_params &cmd) { if (io_files.construct_names (rep, cmd) < 0) return -1; if (strcmp (cmd.equip_lines_arg, enum_to_string (equip_lines_mode::asymptotics)) == 0) { calc_mode = equip_lines_mode::asymptotics; rep->print ("Info: '%s' mode is activated.\n", cmd.equip_lines_arg); } else if (strcmp (cmd.equip_lines_arg, enum_to_string (equip_lines_mode::global_picture)) == 0) { calc_mode = equip_lines_mode::global_picture; rep->print ("Info: '%s mode is activated.\n", cmd.equip_lines_arg); } else { rep->print ("Error: unknown equip_line mode '%s'.\n", cmd.equip_lines_arg); return -1; } if (io_files.create_result_dir (rep) < 0) return -1; if (init_params_by_file (rep) < 0) { rep->print ("Error: cannot initialize model by file.\n"); return -1; } if (om_k_eval.init (MAX_OM_POLY_DEG, MAX_K_POLY_DEG) < 0) return -1; return 0; }
void replica::assign_primary(configuration_update_request& proposal) { dassert(proposal.node == primary_address(), ""); if (status() == PS_PRIMARY) { dwarn( "%s: invalid assgin primary proposal as the node is in %s", name(), enum_to_string(status())); return; } if (proposal.type == CT_UPGRADE_TO_PRIMARY && (status() != PS_SECONDARY || _secondary_states.checkpoint_task != nullptr)) { dwarn( "%s: invalid upgrade to primary proposal as the node is in %s or during checkpointing", name(), enum_to_string(status())); // TODO: tell meta server so new primary is built more quickly return; } proposal.config.primary = primary_address(); replica_helper::remove_node(primary_address(), proposal.config.secondaries); update_configuration_on_meta_server(proposal.type, proposal.node, proposal.config); }
void list_Q(enum QUEUES queue) { struct queue_t *structqueue = get_process(queue); struct process_control_block *temp = structqueue->head; printf("Start of %s.\n", enum_to_string(queue)); while (temp) { printprocess(*temp); temp = temp->prev; } printf("End of %s.\n\n", enum_to_string(queue)); }
void printprocess(struct process_control_block process) { int i = 0; printf("pid: "); textcolor(BRIGHT, RED, BLACK); printf("%d\t", process.pid); textcolor(RESET, -1, -1); printf("psw: %d\t", process.psw); printf("p_table: %d\t", process.page_table); printf("regs:"); for (i = 0; i < NUM_REGS; i++) { printf(" %d", process.regs[i]); } if (scheduler == GROUP){ printf("\tgroup: "); textcolor(BRIGHT, MAGENTA, BLACK); printf("%s", enum_to_string(process.group)); textcolor(RESET, -1, -1); } else{ printf("\tpriority: "); textcolor(BRIGHT, CYAN, BLACK); printf("%d", process.priority); textcolor(RESET, -1, -1); printf("\tquantum_count: %d", process.quantum_count); } printf("\n"); }
vogleditor_stateTreeProgramEnumItem::vogleditor_stateTreeProgramEnumItem(QString name, GLenum (vogl_program_state::* func)(void) const, vogleditor_stateTreeItem* parent, const vogl_program_state& state) : vogleditor_stateTreeProgramDiffableItem(name, "", parent, state), m_pFunc(func) { GLenum val = (state.*func)(); setValue(enum_to_string(val)); }
void replica::send_prepare_message( ::dsn::rpc_address addr, partition_status status, mutation_ptr& mu, int timeout_milliseconds, int64_t learn_signature) { dsn_message_t msg = dsn_msg_create_request(RPC_PREPARE, timeout_milliseconds, gpid_to_hash(get_gpid())); replica_configuration rconfig; _primary_states.get_replica_config(status, rconfig, learn_signature); { rpc_write_stream writer(msg); marshall(writer, get_gpid()); marshall(writer, rconfig); mu->write_to(writer); } mu->remote_tasks()[addr] = rpc::call(addr, msg, this, [=](error_code err, dsn_message_t request, dsn_message_t reply) { on_prepare_reply(std::make_pair(mu, rconfig.status), err, request, reply); }, gpid_to_hash(get_gpid()) ); ddebug( "%s: mutation %s send_prepare_message to %s as %s", name(), mu->name(), addr.to_string(), enum_to_string(rconfig.status) ); }
void replica::send_prepare_message(const dsn_address_t& addr, partition_status status, mutation_ptr& mu, int timeout_milliseconds) { dsn_message_t msg = dsn_msg_create_request(RPC_PREPARE, timeout_milliseconds, gpid_to_hash(get_gpid())); replica_configuration rconfig; _primary_states.get_replica_config(status, rconfig); { msg_binary_writer writer(msg); marshall(writer, get_gpid()); marshall(writer, rconfig); mu->write_to(writer); } mu->remote_tasks()[addr] = rpc::call(addr, msg, this, std::bind(&replica::on_prepare_reply, this, std::make_pair(mu, rconfig.status), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), gpid_to_hash(get_gpid()) ); ddebug( "%s: mutation %s send_prepare_message to %s:%hu as %s", name(), mu->name(), addr.name, addr.port, enum_to_string(rconfig.status) ); }
void replica::send_prepare_message(const end_point& addr, partition_status status, mutation_ptr& mu, int timeout_milliseconds) { message_ptr msg = message::create_request(RPC_PREPARE, timeout_milliseconds, gpid_to_hash(get_gpid())); marshall(msg, get_gpid()); replica_configuration rconfig; _primary_states.get_replica_config(status, rconfig); marshall(msg, rconfig); mu->write_to(msg); dbg_dassert (mu->remote_tasks().find(addr) == mu->remote_tasks().end()); mu->remote_tasks()[addr] = rpc::call(addr, msg, this, std::bind(&replica::on_prepare_reply, this, std::make_pair(mu, rconfig.status), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), gpid_to_hash(get_gpid()) ); ddebug( "%s: mutation %s send_prepare_message to %s:%d as %s", name(), mu->name(), addr.name.c_str(), static_cast<int>(addr.port), enum_to_string(rconfig.status) ); }
void replica::catch_up_with_private_logs(partition_status s) { learn_state state; _private_log->get_learn_state( get_gpid(), _app->last_committed_decree() + 1, state ); auto err = apply_learned_state_from_private_log(state); tasking::enqueue( LPC_CHECKPOINT_REPLICA_COMPLETED, this, [this, err, s]() { if (PS_SECONDARY == s) this->on_checkpoint_completed(err); else if (PS_POTENTIAL_SECONDARY == s) this->on_learn_remote_state_completed(err); else { dassert(false, "invalid state %s", enum_to_string(s)); } }, gpid_to_hash(get_gpid()) ); }
vogleditor_stateTreeVertexArrayEnumItem::vogleditor_stateTreeVertexArrayEnumItem(QString name, GLenum vogl_vertex_attrib_desc::* pVal, vogleditor_stateTreeItem* parent, const vogl_vertex_attrib_desc& state, unsigned int arrayIndex) : vogleditor_stateTreeVertexArrayDiffableItem(name, "", parent, arrayIndex), m_pState(&state), m_pVal(pVal) { GLenum val = state.*pVal; setValue(enum_to_string(val)); }
void log_init(configuration_ptr config) { logging_start_level = enum_from_string( config->get_string_value("core", "logging_start_level", enum_to_string(logging_start_level)).c_str(), logging_level::log_level_INVALID ); dassert(logging_start_level != logging_level::log_level_INVALID, "invalid [core] logging_start_level specified"); }
// meta server => partition server void server_load_balancer::send_proposal(::dsn::rpc_address node, const configuration_update_request& proposal) { dinfo("send proposal %s of %s, current ballot = %" PRId64, enum_to_string(proposal.type), proposal.node.to_string(), proposal.config.ballot ); rpc::call_one_way_typed(node, RPC_CONFIG_PROPOSAL, proposal, gpid_to_hash(proposal.config.gpid)); }
vogleditor_stateTreeRenderbufferEnumItem::vogleditor_stateTreeRenderbufferEnumItem(QString name, GLenum enumName, vogleditor_stateTreeItem *parent, const vogl_renderbuffer_state &state) : vogleditor_stateTreeRenderbufferDiffableItem(name, "", parent), m_enum(enumName), m_pState(&state) { int val = 0; if (m_pState->get_desc().get_int(m_enum, &val)) { setValue(enum_to_string(val)); } }
void timer_task::exec() { if (dsn_likely(_cb != nullptr)) { _cb(); } // valid interval, we reset task state to READY if (dsn_likely(_interval_milliseconds > 0)) { dassert(set_retry(true), "timer task set retry failed, with state = %s", enum_to_string(state())); set_delay(_interval_milliseconds); } }
static GtkWidget* create_aligned (GtkAlign halign, GtkAlign valign) { GtkWidget *widget; char *label; label = g_strdup_printf ("h=%s v=%s", enum_to_string (GTK_TYPE_ALIGN, halign), enum_to_string (GTK_TYPE_ALIGN, valign)); widget = create_widget_visible_border (label); g_object_set (G_OBJECT (TEST_WIDGET (widget)), "halign", halign, "valign", valign, "hexpand", TRUE, "vexpand", TRUE, NULL); return widget; }
void replica::handle_local_failure(int error) { ddebug( "%s: handle local failure error %x, status = %s", name(), error, enum_to_string(status()) ); if (status() == PS_PRIMARY) { _stub->remove_replica_on_meta_server(_primary_states.membership); } update_local_configuration_with_no_ballot_change(PS_ERROR); }
void replica::handle_remote_failure(partition_status st, const end_point& node, int error) { ddebug( "%s: handle remote failure error %u, status = %s, node = %s:%d", name(), error, enum_to_string(st), node.name.c_str(), static_cast<int>(node.port) ); dassert (status() == PS_PRIMARY, ""); dassert(node != primary_address(), ""); switch (st) { case PS_SECONDARY: dassert (_primary_states.check_exist(node, PS_SECONDARY), ""); { configuration_update_request request; request.node = node; request.type = CT_DOWNGRADE_TO_INACTIVE; request.config = _primary_states.membership; downgrade_to_inactive_on_primary(request); } break; case PS_POTENTIAL_SECONDARY: // potential secondary failure does not lead to ballot change // therefore, it is possible to have multiple exec here if (_primary_states.learners.erase(node) > 0) { if (_primary_states.check_exist(node, PS_INACTIVE)) _primary_states.statuses[node] = PS_INACTIVE; else _primary_states.statuses.erase(node); } break; case PS_INACTIVE: case PS_ERROR: break; default: dassert (false, ""); break; } }
void replica::close() { dassert( status() == partition_status::PS_ERROR || status() == partition_status::PS_INACTIVE, "%s: invalid state %s when calling replica::close", name(), enum_to_string(status()) ); if (nullptr != _checkpoint_timer) { _checkpoint_timer->cancel(true); _checkpoint_timer = nullptr; } cleanup_preparing_mutations(true); dassert(_primary_states.is_cleaned(), "primary context is not cleared"); if (partition_status::PS_INACTIVE == status()) { dassert(_secondary_states.is_cleaned(), "secondary context is not cleared"); dassert(_potential_secondary_states.is_cleaned(), "potential secondary context is not cleared"); } // for partition_status::PS_ERROR, context cleanup is done here as they may block else { bool r = _secondary_states.cleanup(true); dassert(r, "secondary context is not cleared"); r = _potential_secondary_states.cleanup(true); dassert(r, "potential secondary context is not cleared"); } if (_private_log != nullptr) { _private_log->close(); _private_log = nullptr; } if (_app != nullptr) { _app->close(false); } }
QString vogleditor_stateTreeItem::getValueFromEnums(const int* values, uint count) const { QString tmp; if (count == 0 || values == NULL) { return ""; } else if (count == 1) { tmp = enum_to_string(*values); } else { tmp = tmp.sprintf("%s, %s", getValueFromEnums(values, 1).toStdString().c_str(), getValueFromEnums(&(values[1]), count-1).toStdString().c_str()); } return tmp; }
int model::calc_equip_lines (report_system *rep) { const std::vector<om_k> &points = real_axe.get_points (); std::vector<om_k>::const_iterator point_iter = points.begin () + 1; // skip k = (0, 0) for (; point_iter != points.end () - 1; point_iter++) // and last k { // line with positive d_omega equip_lines.emplace_back (*point_iter); if (equip_lines.back ().self_build (rep, param, param.d_om, param.d_om_total, om_k_eval) < 0) { rep->print ("Cannot build equipotential line from reference k = (%5.12lf,%5.12lf).\n", point_iter->k.real (), point_iter->k.imag ()); return -1; } // line with negative d_omega equip_lines.emplace_back (*point_iter); if (equip_lines.back ().self_build (rep, param, -param.d_om, param.d_om_total, om_k_eval) < 0) { rep->print ("Cannot build equipotential line from reference k = (%5.12lf,%5.12lf).\n", point_iter->k.real (), point_iter->k.imag ()); return -1; } } // dump points to file for (const equip_line &line : equip_lines) { std::string file_name = io_files.results_path.toStdString () + std::string ("equip_line_from_k=") + std::to_string (line.get_ref_point ().k.real ()) + std::string (enum_to_string (line.get_direction ())) + io_files.res_suffix.toStdString (); if (line.dump_points (rep, file_name) < 0) { rep->print ("Error: unable to save equip_line coming from reference k = (%5.12lf,%5.12lf) to file.\n", line.get_ref_point ().k.real (), line.get_ref_point ().k.imag ()); return -1; } } return 0; }
QString vogleditor_stateTreeVertexArrayEnumItem::getDiffedValue() const { if (m_pDiffBaseState == NULL) return ""; if (m_arrayIndex >= m_pDiffBaseState->get_vertex_attrib_count()) { // the current node does not exist in the base snapshot, so it must be new and different. return "non-existent"; } else { const vogl_vertex_attrib_desc& baseDesc = m_pDiffBaseState->get_vertex_attrib_desc(m_arrayIndex); GLenum value = baseDesc.*m_pVal; return enum_to_string(value); } return ""; }
void replica::handle_remote_failure(partition_status st, ::dsn::rpc_address node, error_code error) { derror( "%s: handle remote failure error %s, status = %s, node = %s", name(), error.to_string(), enum_to_string(st), node.to_string() ); error.end_tracking(); dassert (status() == PS_PRIMARY, ""); dassert (node != _stub->_primary_address, ""); switch (st) { case PS_SECONDARY: dassert (_primary_states.check_exist(node, PS_SECONDARY), ""); { configuration_update_request request; request.node = node; request.type = CT_DOWNGRADE_TO_INACTIVE; request.config = _primary_states.membership; downgrade_to_inactive_on_primary(request); } break; case PS_POTENTIAL_SECONDARY: // potential secondary failure does not lead to ballot change // therefore, it is possible to have multiple exec here _primary_states.learners.erase(node); _primary_states.statuses.erase(node); break; case PS_INACTIVE: case PS_ERROR: break; default: dassert (false, ""); break; } }
void replica::broadcast_group_check() { dassert (nullptr != _primary_states.group_check_task, ""); ddebug("%s: start to broadcast group check", name()); if (_primary_states.group_check_pending_replies.size() > 0) { dwarn( "%s: %u group check replies are still pending when doing next round check, cancel first", name(), static_cast<int>(_primary_states.group_check_pending_replies.size()) ); for (auto it = _primary_states.group_check_pending_replies.begin(); it != _primary_states.group_check_pending_replies.end(); ++it) { it->second->cancel(true); } _primary_states.group_check_pending_replies.clear(); } for (auto it = _primary_states.statuses.begin(); it != _primary_states.statuses.end(); ++it) { if (it->first == _stub->_primary_address) continue; ::dsn::rpc_address addr = it->first; std::shared_ptr<group_check_request> request(new group_check_request); request->app = _app_info; request->node = addr; _primary_states.get_replica_config(it->second, request->config); request->last_committed_decree = last_committed_decree(); if (request->config.status == partition_status::PS_POTENTIAL_SECONDARY) { auto it = _primary_states.learners.find(addr); dassert(it != _primary_states.learners.end(), "learner %s is missing", addr.to_string()); request->config.learner_signature = it->second.signature; } ddebug( "%s: send group check to %s with state %s", name(), addr.to_string(), enum_to_string(it->second) ); dsn::task_ptr callback_task = rpc::call( addr, RPC_GROUP_CHECK, *request, this, [=](error_code err, group_check_response&& resp) { auto alloc = std::make_shared<group_check_response>(std::move(resp)); on_group_check_reply(err, request, alloc); }, std::chrono::milliseconds(0), gpid_to_thread_hash(get_gpid()) ); _primary_states.group_check_pending_replies[addr] = callback_task; } // send empty prepare when necessary if (!_options->empty_write_disabled && dsn_now_ms() >= _primary_states.last_prepare_ts_ms + _options->group_check_interval_ms) { mutation_ptr mu = new_mutation(invalid_decree); mu->add_client_request(RPC_REPLICATION_WRITE_EMPTY, nullptr); init_prepare(mu); } }
void replica::on_group_check(const group_check_request& request, /*out*/ group_check_response& response) { check_hashed_access(); ddebug( "%s: process group check, primary = %s, ballot = %" PRId64 ", status = %s, last_committed_decree = %" PRId64, name(), request.config.primary.to_string(), request.config.ballot, enum_to_string(request.config.status), request.last_committed_decree ); if (request.config.ballot < get_ballot()) { response.err = ERR_VERSION_OUTDATED; dwarn("%s: on_group_check reply %s", name(), response.err.to_string()); return; } else if (request.config.ballot > get_ballot()) { if (!update_local_configuration(request.config)) { response.err = ERR_INVALID_STATE; dwarn("%s: on_group_check reply %s", name(), response.err.to_string()); return; } } else if (is_same_ballot_status_change_allowed(status(), request.config.status)) { update_local_configuration(request.config, true); } switch (status()) { case partition_status::PS_INACTIVE: break; case partition_status::PS_SECONDARY: if (request.last_committed_decree > last_committed_decree()) { _prepare_list->commit(request.last_committed_decree, COMMIT_TO_DECREE_HARD); } break; case partition_status::PS_POTENTIAL_SECONDARY: init_learn(request.config.learner_signature); break; case partition_status::PS_ERROR: break; default: dassert (false, ""); } response.pid = get_gpid(); response.node = _stub->_primary_address; response.err = ERR_OK; if (status() == partition_status::PS_ERROR) { response.err = ERR_INVALID_STATE; dwarn("%s: on_group_check reply %s", name(), response.err.to_string()); } response.last_committed_decree_in_app = _app->last_committed_decree(); response.last_committed_decree_in_prepare_list = last_committed_decree(); response.learner_status_ = _potential_secondary_states.learning_status; response.learner_signature = _potential_secondary_states.learning_version; }
vogleditor_stateTreeProgramItem::vogleditor_stateTreeProgramItem(QString name, QString value, vogleditor_stateTreeItem* parentNode, vogl_program_state& state, const vogl_context_info& info) : vogleditor_stateTreeItem(name, value, parentNode), m_pState(&state) { QString tmp; // basic info this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_LINK_STATUS", &vogl_program_state::get_link_status, this, state)); if (info.supports_extension("GL_ARB_separate_shader_objects")) this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_PROGRAM_SEPARABLE", &vogl_program_state::get_separable, this, state)); this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_DELETE_STATUS", &vogl_program_state::get_marked_for_deletion, this, state)); this->appendChild(new vogleditor_stateTreeProgramBoolItem("GL_VALIDATE_STATUS", &vogl_program_state::get_verify_status, this, state)); if (info.get_version() >= VOGL_GL_VERSION_3_1) { this->appendChild(new vogleditor_stateTreeProgramUIntItem("GL_ACTIVE_UNIFORM_BLOCKS", &vogl_program_state::get_num_active_uniform_blocks, this, state)); } // program binary this->appendChild(new vogleditor_stateTreeItem("GL_PROGRAM_BINARY_RETRIEVABLE_HINT", "TODO", this)); this->appendChild(new vogleditor_stateTreeProgramUIntItem("GL_PROGRAM_BINARY_LENGTH", &vogl_program_state::get_program_binary_size, this, state)); this->appendChild(new vogleditor_stateTreeProgramEnumItem("GL_PROGRAM_BINARY_FORMAT", &vogl_program_state::get_program_binary_format, this, state)); if (m_pState->get_program_binary().size() > 0) { this->appendChild(new vogleditor_stateTreeItem("Program Binary", "TODO: open in a new tab", this)); } // info log this->appendChild(new vogleditor_stateTreeProgramLogItem("GL_INFO_LOG_LENGTH", &vogl_program_state::get_info_log, this, state)); // linked shaders const vogl_unique_ptr<vogl_program_state> &linked_program = m_pState->get_link_time_snapshot(); if (linked_program.get()) { uint num_attached_shaders = linked_program->get_shaders().size(); vogleditor_stateTreeItem* pLinkedShadersNode = new vogleditor_stateTreeItem("Linked Shaders", tmp.sprintf("[%u]", num_attached_shaders), this); this->appendChild(pLinkedShadersNode); for (uint i = 0; i < num_attached_shaders; i++) { vogl_shader_state& shader = const_cast<vogl_shader_state&>(linked_program->get_shaders()[i]); GLuint64 shaderId = shader.get_snapshot_handle(); pLinkedShadersNode->appendChild(new vogleditor_stateTreeShaderItem(tmp.sprintf("%" PRIu64, shaderId), enum_to_string(shader.get_shader_type()), pLinkedShadersNode, shader)); } } // attached shaders uint num_attached_shaders = m_pState->get_shaders().size(); vogleditor_stateTreeItem* pAttachedShadersNode = new vogleditor_stateTreeItem("GL_ATTACHED_SHADERS", tmp.sprintf("[%u]", num_attached_shaders), this); this->appendChild(pAttachedShadersNode); for (uint i = 0; i < num_attached_shaders; i++) { vogl_shader_state& shader = const_cast<vogl_shader_state&>(m_pState->get_shaders()[i]); GLuint64 shaderId = shader.get_snapshot_handle(); pAttachedShadersNode->appendChild(new vogleditor_stateTreeShaderItem(tmp.sprintf("%" PRIu64, shaderId), enum_to_string(shader.get_shader_type()), pAttachedShadersNode, shader)); } // active attribs vogleditor_stateTreeItem* pAttribsNode = new vogleditor_stateTreeItem("GL_ACTIVE_ATTRIBUTES", tmp.sprintf("[%u]", m_pState->get_num_active_attribs()), this); this->appendChild(pAttribsNode); uint num_active_attributes = m_pState->get_attrib_state_vec().size(); for (uint i = 0; i < num_active_attributes; i++) { const vogl_program_attrib_state& attrib = m_pState->get_attrib_state_vec()[i]; vogleditor_stateTreeProgramAttribItem* pItem = new vogleditor_stateTreeProgramAttribItem(tmp.sprintf("%s", attrib.m_name.get_ptr()), pAttribsNode, attrib); m_attribItems.push_back(pItem); pAttribsNode->appendChild(pItem); } // uniforms vogleditor_stateTreeItem* pUniformsNode = new vogleditor_stateTreeItem("GL_ACTIVE_UNIFORMS", tmp.sprintf("[%u]", m_pState->get_num_active_uniforms()), this); this->appendChild(pUniformsNode); uint num_uniforms = m_pState->get_uniform_state_vec().size(); for (uint i = 0; i < num_uniforms; i++) { const vogl_program_uniform_state& uniform = m_pState->get_uniform_state_vec()[i]; // pUniformsNode->appendChild(new vogleditor_stateTreeItem(QString(uniform.m_name.get_ptr()), tmp.sprintf("Loc: %d, Size: %d, Type: %s", uniform.m_base_location, uniform.m_size, enum_to_string(uniform.m_type).toStdString().c_str()), pUniformsNode)); vogleditor_stateTreeProgramUniformItem* pItem = new vogleditor_stateTreeProgramUniformItem(QString(uniform.m_name.get_ptr()), pUniformsNode, uniform); m_uniformItems.push_back(pItem); pUniformsNode->appendChild(pItem); } // uniform blocks }
vogleditor_stateTreeProgramUniformItem::vogleditor_stateTreeProgramUniformItem(QString name, vogleditor_stateTreeItem* parent, const vogl_program_uniform_state& state) : vogleditor_stateTreeItem(name, "", parent), m_pState(&state), m_pDiffBaseState(NULL) { QString tmp; setValue(tmp.sprintf("Loc: %d, Size: %d, Type: %s", state.m_base_location, state.m_size, enum_to_string(state.m_type).toStdString().c_str())); }
void replica::on_prepare(dsn_message_t request) { check_hashed_access(); replica_configuration rconfig; mutation_ptr mu; { rpc_read_stream reader(request); unmarshall(reader, rconfig); mu = mutation::read_from(reader, request); } decree decree = mu->data.header.decree; dinfo("%s: mutation %s on_prepare", name(), mu->name()); dassert(mu->data.header.ballot == rconfig.ballot, ""); if (mu->data.header.ballot < get_ballot()) { derror("%s: mutation %s on_prepare skipped due to old view", name(), mu->name()); // no need response because the rpc should have been cancelled on primary in this case return; } // update configuration when necessary else if (rconfig.ballot > get_ballot()) { if (!update_local_configuration(rconfig)) { derror( "%s: mutation %s on_prepare failed as update local configuration failed, state = %s", name(), mu->name(), enum_to_string(status()) ); ack_prepare_message(ERR_INVALID_STATE, mu); return; } } if (PS_INACTIVE == status() || PS_ERROR == status()) { derror( "%s: mutation %s on_prepare failed as invalid replica state, state = %s", name(), mu->name(), enum_to_string(status()) ); ack_prepare_message( (PS_INACTIVE == status() && _inactive_is_transient) ? ERR_INACTIVE_STATE : ERR_INVALID_STATE, mu ); return; } else if (PS_POTENTIAL_SECONDARY == status()) { // new learning process if (rconfig.learner_signature != _potential_secondary_states.learning_signature) { init_learn(rconfig.learner_signature); // no need response as rpc is already gone return; } if (!(_potential_secondary_states.learning_status == LearningWithPrepare || _potential_secondary_states.learning_status == LearningSucceeded)) { derror( "%s: mutation %s on_prepare skipped as invalid learning status, state = %s, learning_status = %s", name(), mu->name(), enum_to_string(status()), enum_to_string(_potential_secondary_states.learning_status) ); // no need response as rpc is already gone return; } } dassert (rconfig.status == status(), ""); if (decree <= last_committed_decree()) { ack_prepare_message(ERR_OK, mu); return; } // real prepare start auto mu2 = _prepare_list->get_mutation_by_decree(decree); if (mu2 != nullptr && mu2->data.header.ballot == mu->data.header.ballot) { if (mu2->is_logged()) { ack_prepare_message(ERR_OK, mu); } else { derror("%s: mutation %s on_prepare skipped as it is duplicate", name(), mu->name()); // response will be unnecessary when we add retry logic in rpc engine. // the retried rpc will use the same id therefore it will be considered responsed // even the response is for a previous try. } return; } error_code err = _prepare_list->prepare(mu, status()); dassert (err == ERR_OK, ""); if (PS_POTENTIAL_SECONDARY == status()) { dassert (mu->data.header.decree <= last_committed_decree() + _options->max_mutation_count_in_prepare_list, ""); } else { dassert (PS_SECONDARY == status(), ""); dassert (mu->data.header.decree <= last_committed_decree() + _options->staleness_for_commit, ""); } dassert(mu->log_task() == nullptr, ""); mu->log_task() = _stub->_log->append(mu, LPC_WRITE_REPLICATION_LOG, this, std::bind(&replica::on_append_log_completed, this, mu, std::placeholders::_1, std::placeholders::_2), gpid_to_hash(get_gpid()) ); }
DSN_API const char* dsn_task_priority_to_string(dsn_task_priority_t tt) { return enum_to_string(tt); }
DSN_API const char* dsn_task_type_to_string(dsn_task_type_t tt) { return enum_to_string(tt); }
simple_logger::simple_logger(const char* log_dir, logging_provider* inner) : logging_provider(log_dir, inner) { _log_dir = std::string(log_dir); //we assume all valid entries are positive _start_index = 0; _index = 1; _lines = 0; _log = nullptr; _short_header = dsn_config_get_value_bool("tools.simple_logger", "short_header", true, "whether to use short header (excluding file/function etc.)"); _fast_flush = dsn_config_get_value_bool("tools.simple_logger", "fast_flush", false, "whether to flush immediately"); _stderr_start_level = enum_from_string( dsn_config_get_value_string("tools.simple_logger", "stderr_start_level", enum_to_string(LOG_LEVEL_WARNING), "copy log messages at or above this level to stderr in addition to logfiles"), LOG_LEVEL_INVALID ); dassert(_stderr_start_level != LOG_LEVEL_INVALID, "invalid [tools.simple_logger] stderr_start_level specified"); _max_number_of_log_files_on_disk = dsn_config_get_value_uint64( "tools.simple_logger", "max_number_of_log_files_on_disk", 20, "max number of log files reserved on disk, older logs are auto deleted" ); // check existing log files std::vector<std::string> sub_list; if (!dsn::utils::filesystem::get_subfiles(_log_dir, sub_list, false)) { dassert(false, "Fail to get subfiles in %s.", _log_dir.c_str()); } for (auto& fpath : sub_list) { auto&& name = dsn::utils::filesystem::get_file_name(fpath); if (name.length() <= 8 || name.substr(0, 4) != "log.") continue; int index; if (1 != sscanf(name.c_str(), "log.%d.txt", &index) || index <= 0) continue; if (index > _index) _index = index; if (_start_index == 0 || index < _start_index) _start_index = index; } sub_list.clear(); if (_start_index == 0) { _start_index = _index; } else ++_index; create_log_file(); }