void learn_keys (void) { gboolean save_old_esc_mode = old_esc_mode; gboolean save_alternate_plus_minus = mc_global.tty.alternate_plus_minus; int result; /* old_esc_mode cannot work in learn keys dialog */ old_esc_mode = 0; /* don't translate KP_ADD, KP_SUBTRACT and KP_MULTIPLY to '+', '-' and '*' in correct_key_code */ mc_global.tty.alternate_plus_minus = TRUE; application_keypad_mode (); init_learn (); result = dlg_run (learn_dlg); old_esc_mode = save_old_esc_mode; mc_global.tty.alternate_plus_minus = save_alternate_plus_minus; if (!mc_global.tty.alternate_plus_minus) numeric_keypad_mode (); if (result == B_ENTER) learn_save (); learn_done (); }
void learn_keys (void) { int save_old_esc_mode = old_esc_mode; int save_alternate_plus_minus = alternate_plus_minus; old_esc_mode = 0; /* old_esc_mode cannot work in learn keys dialog */ alternate_plus_minus = 1; /* don't translate KP_ADD, KP_SUBTRACT and KP_MULTIPLY to '+', '-' and '*' in correct_key_code */ application_keypad_mode (); init_learn (); run_dlg (learn_dlg); old_esc_mode = save_old_esc_mode; alternate_plus_minus = save_alternate_plus_minus; if (!alternate_plus_minus) numeric_keypad_mode (); switch (learn_dlg->ret_value) { case B_ENTER: learn_save (); break; } learn_done (); }
void replica::on_group_check(const group_check_request& request, __out_param group_check_response& response) { ddebug( "%s: on_group_check from %s:%d", name(), request.config.primary.name.c_str(), request.config.primary.port ); if (request.config.ballot < get_ballot()) { response.err = ERR_VERSION_OUTDATED; return; } else if (request.config.ballot > get_ballot()) { update_local_configuration(request.config); } else if (is_same_ballot_status_change_allowed(status(), request.config.status)) { update_local_configuration(request.config, true); } switch (status()) { case PS_INACTIVE: break; case PS_SECONDARY: if (request.last_committed_decree > last_committed_decree()) { _prepare_list->commit(request.last_committed_decree, true); } break; case PS_POTENTIAL_SECONDARY: init_learn(request.learner_signature); break; case PS_ERROR: break; default: dassert (false, ""); } response.gpid = get_gpid(); response.node = primary_address(); response.err = ERR_SUCCESS; if (status() == PS_ERROR) { response.err = ERR_INVALID_STATE; } 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_signature; }
JNIEXPORT void JNIFn(zebra, ZebraEngine, zeGlobalInit)(JNIEnv *env, jobject thiz, jstring files_dir) { DROIDZEBRA_JNI_SETUP; char binbookpath[FILENAME_MAX], cmpbookpath[FILENAME_MAX]; time_t timer; echo = TRUE; display_pv = DEFAULT_DISPLAY_PV; skill[BLACKSQ] = skill[WHITESQ] = -1; player_time[BLACKSQ] = player_time[WHITESQ] = INFINIT_TIME; player_increment[BLACKSQ] = player_increment[WHITESQ] = 0.0; const char *str; str = (*env)->GetStringUTFChars(env, files_dir, NULL); if (str == NULL) { DROIDZEBRA_JNI_CLEAN; return; /* OutOfMemoryError already thrown */ } strncpy(android_files_dir, str, sizeof(android_files_dir) - 1); (*env)->ReleaseStringUTFChars(env, files_dir, str); toggle_status_log(USE_LOG); global_setup(DEFAULT_RANDOM, DEFAULT_HASH_BITS); init_thor_database(); sprintf(cmpbookpath, "%s/book.cmp.z", android_files_dir); sprintf(binbookpath, "%s/book.bin", android_files_dir); if (access(cmpbookpath, R_OK) == 0) { init_osf(FALSE); unpack_compressed_database_gz(cmpbookpath, binbookpath); unlink(cmpbookpath); } init_learn(binbookpath, TRUE); time(&timer); my_srandom(timer); DROIDZEBRA_JNI_CLEAN; }
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; }
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()) ); }