static void test_fail(sqlx_cache_t *cache) { GError *err; /* Lock an negative base ID */ err = sqlx_cache_lock_base(cache, -1); if (err == NULL) { err = g_error_new(GQ(), 0, "DESIGN ERROR"); FAIL(err); } g_debug("sqlx_cache_lock_base(-1) : failed as expected : code=%d %s", err->code, err->message); g_error_free(err); /* Lock an big base ID */ err = sqlx_cache_lock_base(cache, 32767); if (err == NULL) { err = g_error_new(GQ(), 0, "DESIGN ERROR"); FAIL(err); } g_debug("sqlx_cache_lock_base(32767) : failed as expected : code=%d %s", err->code, err->message); g_error_free(err); /* Lock an closed base ID */ err = sqlx_cache_lock_base(cache, 0); if (err == NULL) { err = g_error_new(GQ(), 0, "DESIGN ERROR"); FAIL(err); } g_debug("sqlx_cache_lock_base(0) : failed as expected : code=%d %s", err->code, err->message); g_error_free(err); }
static void test_create_bad_config(void) { struct election_manager_s *m = NULL; GError *err; struct replication_config_s cfg0 = { NULL, _get_peers, _get_vers, NULL, ELECTION_MODE_NONE}; err = election_manager_create(&cfg0, &m); g_assert_error(err, GQ(), ERRCODE_PARAM); g_clear_error(&err); struct replication_config_s cfg1 = { _get_id, NULL, _get_vers, NULL, ELECTION_MODE_NONE}; err = election_manager_create(&cfg1, &m); g_assert_error(err, GQ(), ERRCODE_PARAM); g_clear_error(&err); struct replication_config_s cfg2 = { _get_id, _get_peers, NULL, NULL, ELECTION_MODE_NONE}; err = election_manager_create(&cfg2, &m); g_assert_error(err, GQ(), ERRCODE_PARAM); g_clear_error(&err); struct replication_config_s cfg3 = { _get_id, _get_peers, _get_vers, NULL, ELECTION_MODE_NONE+3}; err = election_manager_create(&cfg3, &m); g_assert_error(err, GQ(), ERRCODE_PARAM); g_clear_error(&err); }
// We can ignore scale(i) here, because it factors out. efloat_t DParrayConstrained::path_P(const vector<int>& g_path) const { const int I = size()-1; int i=I; int l=g_path.size()-1; int state2 = g_path[l]; vector<double> transition(nstates()); efloat_t Pr=1.0; while (l>0) { transition.resize(states(i).size()); for(int s1=0; s1<transition.size(); s1++) { int state1 = states(i)[s1]; transition[s1] = (*this)(i,state1)*GQ(state1,state2); } int state1 = g_path[l-1]; int s1 = find_index(states(i),state1); assert(s1 != -1); double p = choose_P(s1,transition); assert(p > 0.0); if (di(state1)) i--; l--; state2 = state1; Pr *= p; assert(Pr > 0.0); } // In column 0, all states are allowed: // - silent states can't contradict anything // - non-silent states reprent the start state. transition.resize(states(0).size()); // include probability of choosing 'Start' vs ---+ ! for(int state1=0; state1<nstates(); state1++) transition[state1] = (*this)(0,state1) * GQ(state1,state2); // Get the probability that the previous state was 'Start' double p=0.0; for(int state1=0; state1<nstates(); state1++) if (not silent(state1)) p += choose_P(state1,transition); Pr *= p; assert(Pr > 0.0); return Pr; }
vector<int> DParray::sample_path() const { vector<int> path; const int I = size()-1; int i = I; int state2 = endstate(); vector<double> transition(nstates()); while(i >= 0) { path.push_back(state2); for(int state1=0; state1<nstates(); state1++) transition[state1] = (*this)(i,state1)*GQ(state1,state2); int state1 = choose_scratch(transition); if (di(state1)) i--; state2 = state1; } assert(i+di(state2)==0); std::reverse(path.begin(),path.end()); #ifndef NDEBUG_DP check_sampling_probability(path); #endif return path; }
static void _round_lock(sqlx_cache_t *cache) { hashstr_t *hn0 = NULL, *hn1 = NULL; HASHSTR_ALLOCA(hn0, name0); HASHSTR_ALLOCA(hn1, name1); gint id0; GError *err = sqlx_cache_open_and_lock_base(cache, hn0, &id0); g_assert_no_error (err); for (int i=0; i<5 ;i++) { gint id = g_random_int(); err = sqlx_cache_open_and_lock_base(cache, hn0, &id); g_assert_no_error (err); g_assert_cmpint(id0, ==, id); } for (int i=0; i<6 ;i++) { err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE); g_assert_no_error (err); } err = sqlx_cache_unlock_and_close_base(cache, id0, FALSE); g_assert_error (err, GQ(), CODE_INTERNAL_ERROR); g_clear_error (&err); for (int i=0; i<5 ;i++) { gint id = g_random_int (); err = sqlx_cache_open_and_lock_base(cache, hn1, &id); g_assert_no_error (err); err = sqlx_cache_unlock_and_close_base(cache, id, FALSE); g_assert_no_error (err); } }
efloat_t DParray::Pr_sum_all_paths() const { const int I = size()-1; double total = 0.0; for(int state1=0; state1<nstates(); state1++) total += (*this)(I,state1) * GQ(state1,endstate()); return pow<efloat_t>(2.0,scale(I)) * total; }
// We can ignore scale(i) here, because it factors out. efloat_t DParray::path_P(const vector<int>& g_path) const { const int I = size()-1; int i=I; int l=g_path.size()-1; int state2 = g_path[l]; vector<double> transition(nstates()); efloat_t Pr=1.0; while (l>0) { for(int state1=0; state1<nstates(); state1++) transition[state1] = (*this)(i,state1)*GQ(state1,state2); int state1 = g_path[l-1]; double p = choose_P(state1,transition); assert(p > 0.0); if (di(state1)) i--; l--; state2 = state1; Pr *= p; } // include probability of choosing 'Start' vs ---+ ! for(int state1=0; state1<nstates(); state1++) transition[state1] = (*this)(0,state1) * GQ(state1,state2); // Get the probability that the previous state was 'Start' double p=0.0; for(int state1=0; state1<nstates(); state1++) if (not silent(state1)) p += choose_P(state1,transition); Pr *= p; assert(Pr > 0.0); return Pr; }
efloat_t DParrayConstrained::Pr_sum_all_paths() const { const int I = size()-1; double total = 0.0; for(int s1=0; s1<states(I).size(); s1++) { int state1 = states(I)[s1]; total += (*this)(I,state1) * GQ(state1,endstate()); } return pow<efloat_t>(2.0,scale(I)) * total; }
inline void DParrayConstrained::forward(int i2) { assert(i2<size()); // determine initial scale for this cell if (i2==0) scale(i2) = 0; else scale(i2) = scale(i2-1); double maximum = 0; for(int s2=0; s2<states(i2).size(); s2++) { int S2 = states(i2)[s2]; int i1 = i2; if (di(S2)) i1--; //----- don't go off the boundary -----// if (i1<0) continue; //---- compute arrival probability ----// unsigned MAX = states(i1).size(); if (not di(S2)) MAX = s2; double temp = 0; for(int s1=0; s1<MAX; s1++) { int S1 = states(i1)[s1]; temp += (*this)(i1,S1) * GQ(S1,S2); } // record maximum if (temp > maximum) maximum = temp; // store the result (*this)(i2,S2) = temp; } //------- if exponent is too low, rescale ------// if (maximum > 0 and maximum < fp_scale::cutoff) { int logs = -(int)log2(maximum); double scale_ = pow2(logs); for(int s2=0; s2<states(i2).size(); s2++) { int S2 = states(i2)[s2]; (*this)(i2,S2) *= scale_; } scale(i2) -= logs; } }
static void _test_reference_cycle_round (void) { GError *err = NULL; struct oio_url_s *url = oio_url_empty (); _random_url (url); struct oio_directory_s *dir = oio_directory__create_proxy (ns); g_assert_nonnull (dir); /* link with no reference */ gchar **srvtab = NULL; err = oio_directory__link (dir, url, NAME_SRVTYPE_META2, FALSE, &srvtab); g_assert_error (err, GQ(), CODE_USER_NOTFOUND); g_assert_null (srvtab); g_clear_error (&err); /* create */ err = oio_directory__create (dir, url); g_assert_no_error (err); /* link with a reference */ err = oio_directory__link (dir, url, NAME_SRVTYPE_META2, FALSE, &srvtab); g_assert_no_error (err); g_assert_nonnull (srvtab); g_strfreev (srvtab); /* list */ gchar **dirtab = NULL; err = oio_directory__list (dir, url, NAME_SRVTYPE_META2, &dirtab, &srvtab); g_assert_no_error (err); g_assert_nonnull (dirtab); g_assert_nonnull (srvtab); g_strfreev (dirtab); g_strfreev (srvtab); oio_url_pclean (&url); oio_directory__destroy (dir); }
static GError * m2b_open(struct meta2_backend_s *m2, struct oio_url_s *url, enum m2v2_open_type_e how, struct sqlx_sqlite3_s **result) { GError *err = NULL; struct sqlx_sqlite3_s *sq3 = NULL; EXTRA_ASSERT(url != NULL); EXTRA_ASSERT(result != NULL); EXTRA_ASSERT(m2 != NULL); EXTRA_ASSERT(m2->backend.repo != NULL); /* TODO */ gboolean no_peers = FALSE; if (no_peers) { how &= ~M2V2_OPEN_REPLIMODE; how |= M2V2_OPEN_LOCAL|M2V2_OPEN_NOREFCHECK; } struct sqlx_name_mutable_s n; sqlx_name_fill (&n, url, NAME_SRVTYPE_META2, 1); err = sqlx_repository_open_and_lock(m2->backend.repo, sqlx_name_mutable_to_const(&n), m2_to_sqlx(how), &sq3, NULL); sqlx_name_clean (&n); if (NULL != err) { if (err->code == CODE_CONTAINER_NOTFOUND) err->domain = GQ(); return err; } sq3->no_peers = how & (M2V2_OPEN_LOCAL|M2V2_OPEN_NOREFCHECK); // XXX If the container is being deleted, this is sad ... // This MIGHT happen if a cache is present (and this is the // common case for m2v2), because the deletion will happen // when the base exit the cache. // In facts this SHOULD NOT happend because a base being deleted // is closed with an instruction to exit the cache immediately. // TODO FIXME this is maybe a good place for an assert(). if (sq3->deleted) { err = NEWERROR(CODE_CONTAINER_FROZEN, "destruction pending"); m2b_close(sq3); return err; } // Complete URL with full VNS and container name void set(gchar *k, int f) { if (oio_url_has(url, f)) return; gchar *s = sqlx_admin_get_str (sq3, k); if (s) { oio_url_set (url, f, s); g_free (s); } } set (SQLX_ADMIN_NAMESPACE, OIOURL_NS); set (SQLX_ADMIN_ACCOUNT, OIOURL_ACCOUNT); set (SQLX_ADMIN_USERNAME, OIOURL_USER); set (SQLX_ADMIN_USERTYPE, OIOURL_TYPE); *result = sq3; return NULL; }