Esempio n. 1
0
static void
leak_tx_tx_tx_set_get_commit1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	void *a = sp_begin(env);
	t( a != NULL );

	void *b = sp_begin(env);
	t( b != NULL );

	void *c = sp_begin(env);
	t( c != NULL );

	int key = 123;
	void *o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(c, o) == 0 );

	t( sp_getint(env, "performance.documents") == 1 );
	t( sp_commit(c) == 0 );
	t( sp_getint(env, "performance.documents") == 1 );

	key = 124;
	o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(b, o) == 0 );

	t( sp_getint(env, "performance.documents") == 2 );
	t( sp_commit(b) == 0 );
	t( sp_getint(env, "performance.documents") == 2 );

	key = 125;
	o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(a, o) == 0 );

	t( sp_getint(env, "performance.documents") == 3 );
	t( sp_commit(a) == 0 );
	t( sp_getint(env, "performance.documents") == 3 );

	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_getint(env, "performance.documents") == 0 );

	t( sp_destroy(env) == 0 );
}
static void
mt_upsert2(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 5) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.index.upsert", upsert_op, 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );
	uint32_t n = 700000;
	uint32_t i, k = 1234;
	uint32_t value = 1;

	void *tx = sp_begin(env);
	t( tx != NULL );

	for (i = 0; i < n; i++) {
		if (i > 0 && (i % 1000) == 0) {
			void *o = sp_document(db);
			t( o != NULL );
			t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
			void *c = sp_cursor(env);
			t( c != NULL );
			o = sp_get(c, o);
			t( o != NULL );
			t( *(uint32_t*)sp_getstring(o, "value", NULL) == i);
			sp_destroy(o);
			sp_destroy(c);

			t( sp_commit(tx) == 0 );
			tx = sp_begin(env);
			t( tx != NULL );
		}
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
		t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
		t( sp_upsert(db, o) == 0 );

		print_current(i);
	}

	t( sp_commit(tx) == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 3
0
static void
hc_prepare_rollback1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");

	int rc;
	void *tx = sp_begin(env);
	t( tx != NULL );

	int key = 7;
	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
	t( sp_set(tx, o) == 0 );
	o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(tx, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == key );
	sp_destroy(o);

	t( sp_setint(tx, "half_commit", 1) == 0 );
	rc = sp_commit(tx);
	t( rc == 0 );
	rc = sp_destroy(tx);
	t( rc == 0 );

	tx = sp_begin(env);
	t( tx != NULL );
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "half_commit", 1) == 0 );
	rc = sp_commit(tx);
	t( rc == 0 );
	rc = sp_commit(tx);
	t( rc == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 4
0
static void
shutdown_transaction1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );

	void *txn = sp_begin(env);
	t( txn != NULL );

	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

	sp_destroy(db); /* unref */
	sp_destroy(db); /* schedule shutdown, unlink */

	void *dbp = sp_getobject(env, "db.test");
	t( dbp == NULL );

	/* process shutdown, txn not binded */
	t( sp_setint(env, "scheduler.run", 0) == 1 );
	t( sp_destroy(txn) == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 5
0
static void
transaction_batch_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );

	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	void *tx = sp_begin(env);
	t( tx != NULL );

	uint32_t a = 7;
	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &a, sizeof(a)) == 0 );
	t( sp_set(tx, o) == 0 );

	t( sp_setstring(tx, "isolation", "batch", 0) == -1 );
	t( sp_destroy(tx) == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 6
0
static void
drop_test(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );

	void *txn = sp_begin(env);
	t( txn != NULL );

	sp_destroy(db); /* unref */
	t( sp_drop(db) == 0); /* scheduler drop */

	void *dbp = sp_getobject(env, "db.test");
	t( dbp == NULL );

	t( sp_setint(env, "scheduler.run", 0) == 0 );
	t( sp_destroy(txn) == 0 );

	t( exists(st_r.conf->db_dir, "") == 1 );
	t( sp_setint(env, "scheduler.run", 0) == 1 ); /* proceed drop */
	t( exists(st_r.conf->db_dir, "") == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 7
0
static void
hc_prepare_commit_empty(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );

	int rc;
	void *tx = sp_begin(env);
	t( tx != NULL );
	t( sp_setint(tx, "half_commit", 1) == 0 );
	rc = sp_commit(tx);
	t( rc == 0 );
	rc = sp_commit(tx);
	t( rc == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 8
0
static inline void *multi_stmt_thread(void *arg) 
{
	ssthread *self = arg;
	void *env = ((void**)self->arg)[0];
	void *db  = ((void**)self->arg)[1];
	int i = 0;
	while (i < 2000) {
		int rc;
		void *tx = sp_begin(env);
		assert( tx != NULL );
		int j = 0;
		while (j < 10) {
			char key[100];
			int keylen = snprintf(key, sizeof(key), "key_%" PRIiPTR "_%d_%d",
			                      (uintptr_t)self, i, j);
			void *o = sp_document(db);
			assert(o != NULL);
			sp_setstring(o, "key", key, keylen + 1);
			rc = sp_set(tx, o);
			assert(rc != -1);
			j++;
		}
		rc = sp_commit(tx);
		assert(rc == 0);
		i++;
	}
	return NULL;
}
Esempio n. 9
0
Matcher::sp_iterator Matcher::setSourceFile(StringRef target)
{
  // If target is empty, we assume it's a self-testing:
  // i.e., the beginning of the compilation unit will be
  // used.
  if (target.empty()) {
    processSubprograms(module); 
    patchname="";
    initialized = true;
    return sp_begin();
  }
  std::string oldfile = filename;
  if (!initName(target))
    return sp_end();
  if (oldfile == filename) {
    if (DEBUG_MATCHER) 
      errs() << "Target source didn't change since last time, reuse old processing.\n";
  }
  else {
    cu_iterator ci = matchCompileUnit(target);
    if (ci == cu_end())
      return sp_end();
    MySPs.clear();
    processSubprograms(*ci);
    std::sort(MySPs.begin(), MySPs.end(), cmpDISPCopy);
    if (DEBUG_MATCHER) 
      dumpSPs();
  }
  initialized = true;
  // shouldn't just return MySPs.begin(). because a CU may contain SPs from other CUs.
  return slideToFile(filename); 
}
Esempio n. 10
0
static inline void *multi_stmt_conflict_thread0(void *arg)
{
	ssthread *self = arg;
	void *env = ((void**)self->arg)[0];
	void *db  = ((void**)self->arg)[1];
	int i = 0;
	while (i < 2000) {
		int rc;
		void *tx = sp_begin(env);
		assert( tx != NULL );
		int j = 0;
		while (j < 10) {
			void *o = sp_document(db);
			int key = i + j;
			assert(o != NULL);
			sp_setstring(o, "key", &key, sizeof(key));
			rc = sp_set(tx, o);
			assert(rc != -1);
			j++;
		}
		rc = sp_commit(tx);
		assert(rc != -1);
		if (rc == 2)
			sp_destroy(tx);
		i++;
	}
	return NULL;
}
Esempio n. 11
0
static void
hc_prepare_commit_conflict(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");

	int key = 7;

	int rc;
	void *a = sp_begin(env);
	t( a != NULL );

	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(a, o) == 0 );
	t( sp_setint(a, "half_commit", 1) == 0 );
	rc = sp_commit(a);
	t( rc == 0 );

	void *b = sp_begin(env);
	t( b != NULL );
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(b, o) == 0 );
	t( sp_setint(b, "half_commit", 1) == 0 );
	rc = sp_commit(b); /* this should fail in default conditions */
	t( rc == 0 );

	rc = sp_commit(a);
	t( rc == 0 );
	rc = sp_commit(b);
	t( rc == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 12
0
static void
secondary_index_test0(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );

	/* unique */
	t( sp_setstring(env, "db", "primary", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.a", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.b", "u32", 0) == 0 );
	t( sp_setint(env, "db.primary.sync", 0) == 0 );

	/* non-unique */
	t( sp_setstring(env, "db", "secondary", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.a", "u32,key(1)", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.b", "u32,key(0)", 0) == 0 );
	t( sp_setint(env, "db.secondary.sync", 0) == 0 );

	void *primary = sp_getobject(env, "db.primary");
	void *secondary = sp_getobject(env, "db.secondary");

	t( primary != NULL );
	t( secondary != NULL );

	t( sp_open(env) == 0 );

	void *tx = sp_begin(env);
	uint32_t a = 0;
	uint32_t b = 0;
	void *po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_open(po) == 0 );
	t( sp_set(tx, po) == 0 );
	void *so = sp_document(secondary);
	t( sp_setobject(so, "reuse", po) == 0 );
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );
	sp_destroy(po);

	t( sp_getint(env, "performance.documents") == 1 );

	t( sp_setint(env, "db.primary.branch", 0) == 0 );
	t( sp_setint(env, "db.secondary.branch", 0) == 0 );

	sp_destroy(env);
}
Esempio n. 13
0
static PyObject *
sophia_db_begin(SophiaDB *db)
{
    ensure_is_opened(db, NULL);
    
    if (sp_begin(db->db) == -1) {
        PyErr_SetString(SophiaError, sp_error(db->db));
        return NULL;
    }
    Py_RETURN_NONE;
}
Esempio n. 14
0
jlong JNICALL Java_eu_unicredit_sophia_SophiaInterface_sp_1begin
  (JNIEnv * env, jobject obj, jlongArray args)
{
    jlong* array = (*env)->GetLongArrayElements(env, args,JNI_FALSE);
    jint size = (*env)->GetArrayLength(env, args);
    void* ret = NULL;
    switch(size) {
      case 0:
        printf("Not supported\n");
        break;
      case 1:
        ret = sp_begin((void*)array[0]);
        break;
      default:
        printf("Not supported\n");
        break;
    };
    return (jlong)ret;
}
Esempio n. 15
0
static void
shutdown_transaction6(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

	void *a = sp_begin(env);
	t( a != NULL );

	sp_destroy(db); /* unref */
	sp_destroy(db); /* schedule shutdown, unlink */

	void *o = sp_object(db);
	t( o != NULL );
	uint32_t key = 7;
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
	t( sp_set(a, o) == 0 ); /* ok */

	key = 8;
	o = sp_object(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(db, o) == -1 );

	t( sp_setint(env, "scheduler.run", 0) == 0 );
	t( sp_destroy(a) == 0 );
	t( sp_setint(env, "scheduler.run", 0) == 1 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 16
0
/* *
 * Adjust sp_iterator to the starting position of
 * the target source file region.
 *
 * Assumption: MySPs contains the sorted subprograms
 * */
Matcher::sp_iterator Matcher::slideToFile(StringRef fname)
{
  if (!processed) {
    errs() << "Warning: Matcher hasn't processed module\n";
    return sp_end();
  }
  sp_iterator I = sp_begin(), E = sp_end();

  while(I != E) {
    std::string debugname;
    if (I->filename.size() > 0 && I->filename[0] == '/')
      debugname = I->filename;
    else
      debugname = I->directory + "/" + I->filename;
    if (endswith(debugname.c_str(), patchname)) {
      break;
    }
    I++;
  }
  if (I == E)
    errs() << "Warning: no matching file(" << patchname << ") was found in the CU\n";
  return I;
}
Esempio n. 17
0
static void
shutdown_transaction2(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

	void *txn = sp_begin(env);
	t( txn != NULL );

	/* shutdown properly closes used index */
	t( sp_destroy(env) == 0 );
}
Esempio n. 18
0
static void timer(param, psize)
/*ARGSUSED*/
{
    static int watch_count;

    for (;;) {
	sleep(60);
	time_update();

	/* We must keep the time, which is stored with the directory entries
	 * consistent among the members.  Otherwise programs like 'make' might
	 * be confused.
	 */
	broadcast_time();

	if ((watch_count++ % WATCHDOG_INTERVAL) == 0) {
	    if (dirsvr_functioning()) {
		MON_EVENT("watchdog");
		sp_begin();
		watchdog();		/* which calls sp_end() */
	    }
	}
    }
}
Esempio n. 19
0
static inline void *multi_stmt_conflict_thread1(void *arg)
{
	ssthread *self = arg;
	void *env = ((void**)self->arg)[0];
	void *db  = ((void**)self->arg)[1];
	int id = 1;
	int rc;
	int i = 0;
	while (i < 100) {
		rc = 0;
		do {
			void *tx = sp_begin(env);
			void *o = sp_document(db);
			sp_setstring(o, "key", &id, sizeof(id));
			o = sp_get(tx, o);
			int v = 0;
			if (o) {
				v = *(int*)sp_getstring(o, "value", NULL);
				sp_destroy(o);
			}
			v++;

			o = sp_document(db);
			sp_setstring(o, "key", &id, sizeof(id));
			sp_setstring(o, "value", &v, sizeof(v));
			rc = sp_set(tx, o);
			assert(rc == 0);

			rc = sp_commit(tx);
			if (2 == rc) sp_destroy(tx);
			assert(rc != -1);
		} while (rc != 0);
		i++;
	}
	return NULL;
}
Esempio n. 20
0
static void
gc_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setint(env, "db.test.compaction.cache", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );

	void *t0 = sp_begin(env);

	int value = 0;
	int i = 0;
	while ( i < 100 ) {
		value = i;
		void *o = sp_document(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &i, sizeof(i)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}

	i = 0;
	while ( i < 100 ) {
		value = i + 1;
		void *o = sp_document(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}
	t( sp_setint(env, "db.test.compaction.compact", 0) == 0 );

	i = 0;
	void *o = sp_document(db);
	t( o != NULL );
	void *cur = sp_cursor(env);
	while ((o = sp_get(cur, o))) {
		t( *(int*)sp_getstring(o, "key", NULL) == i );
		t( *(int*)sp_getstring(o, "value", NULL) == i + 1);
		i++;
	}
	sp_destroy(cur);

	t( sp_getint(env, "db.test.index.count") == 200 );
	t( sp_getint(env, "db.test.index.count_dup") == 100 );

	t( sp_setint(env, "db.test.compaction.compact", 0) == 0 );

	i = 0;
	o = sp_document(db);
	t( o != NULL );
	cur = sp_cursor(env);
	while ((o = sp_get(cur, o))) {
		t( *(int*)sp_getstring(o, "key", NULL) == i );
		t( *(int*)sp_getstring(o, "value", NULL) == i + 1);
		i++;
	}
	sp_destroy(cur);

	t( sp_getint(env, "db.test.index.count") == 200 );
	t( sp_getint(env, "db.test.index.count_dup") == 100 );

	sp_destroy(t0);
	t( sp_destroy(env) == 0 );
}
Esempio n. 21
0
static inline int
workflow_write_read(void *env, void *db)
{
	/* write */
	void *o = sp_document(db);
	if (o == NULL)
		return -1;
	uint32_t key = 123;
	int rc;
	rc = sp_setstring(o, "key", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		return -1;
	}
	rc = sp_setstring(o, "value", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		return -1;
	}
	rc = sp_set(db, o);
	if (rc == -1)
		return -1;

	/* transaction */
	void *tx = sp_begin(env);
	if (tx == NULL)
		return -1;
	o = sp_document(db);
	if (o == NULL)
		return -1;
	key = 123;
	rc = sp_setstring(o, "key", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		sp_destroy(tx);
		return -1;
	}
	rc = sp_setstring(o, "value", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		sp_destroy(tx);
		return -1;
	}
	rc = sp_set(tx, o);
	if (rc == -1) {
		sp_destroy(tx);
		return -1;
	}
	o = sp_document(db);
	if (o == NULL)
		return -1;
	rc = sp_setstring(o, "key", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		sp_destroy(tx);
		return -1;
	}
	o = sp_get(tx, o);
	if (o == NULL) {
		sp_destroy(tx);
		return -1;
	}
	sp_destroy(o);
	rc = sp_commit(tx);
	if (rc == -1)
		return -1;

	/* read */
	o = sp_document(db);
	if (o == NULL)
		return -1;
	rc = sp_setstring(o, "key", &key, sizeof(key));
	if (rc == -1) {
		sp_destroy(o);
		return -1;
	}
	o = sp_get(db, o);
	if (o == NULL)
		return -1;
	sp_destroy(o);

	/* cursor */
	void *c = sp_cursor(env);
	if (c == NULL)
		return -1;
	o = sp_document(db);
	if (o == NULL) {
		sp_destroy(c);
		return -1;
	}
	o = sp_get(c, o);
	if (o == NULL) {
		sp_destroy(c);
		return -1;
	}
	sp_destroy(o);
	sp_destroy(c);
	return 0;
}
Esempio n. 22
0
static void
npr_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "sophia.recover", 1) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );
	char *v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "online") == 0 );
	free(v);
	int key = 7;
	int value = 8;
	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_setint(env, "db.test.branch", 0) == 0 );
	key = 7;
	value = 9;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_destroy(env) == 0 );

	/* recover */

	env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "sophia.recover", 3 /* << */) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 ); /* online */

	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 ); /* online */

	v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "online") == 0 );
	free(v);

	t( sp_open(env) == 0 ); /* recover */

	void *tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 8;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 1) == 0 );
	t( sp_commit(tx) == 0 ); /* skip */

	tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 9;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 2) == 0 );
	t( sp_commit(tx) == 0 ); /* commit */

	/* retry duplicate */
	tx = sp_begin(env);
	t( tx != NULL );
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 2) == 0 );
	t( sp_commit(tx) == 0 ); /* skip from in-memory scheme */

	/* retry duplicate with lower lsn */
	tx = sp_begin(env);
	t( tx != NULL );
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 1) == 0 );
	t( sp_commit(tx) == 0 ); /* skip from in-memory scheme */


	t( sp_open(env) == 0 ); /* online */

	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(db, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == 9 );
	t( sp_getint(o, "lsn") == 2ULL );
	t( sp_destroy(o) == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 23
0
static void
tpr_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "log.two_phase_recover", 1) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );

	t( sp_open(env) == 0 );

	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );
	t( sp_open(env) == 0 );

	int key = 7;
	int value = 8;
	void *o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_setint(env, "db.test.branch", 0) == 0 );
	key = 7;
	value = 9;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_destroy(env) == 0 );

	env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "log.two_phase_recover", 1) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );

	char *v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "recover") == 0 );
	free(v);

	void *tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 8;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 1) == 0 );
	t( sp_commit(tx) == 0 ); /* skip */

	tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 9;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 2) == 0 );
	t( sp_commit(tx) == 0 ); /* commit */

	t( sp_open(env) == 0 );

	v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "online") == 0 );
	free(v);

	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(db, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == 9 );
	t( sp_getint(o, "lsn") == 2ULL );
	t( sp_destroy(o) == 0 );

	t( sp_destroy(env) == 0 );
}
Esempio n. 24
0
static void
secondary_index_test_unique0(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );

	/* unique */
	t( sp_setstring(env, "db", "primary", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.a", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.b", "u32", 0) == 0 );
	t( sp_setint(env, "db.primary.sync", 0) == 0 );

	/* unique */
	t( sp_setstring(env, "db", "secondary", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.a", "u32", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.b", "u32,key(0)", 0) == 0 );
	t( sp_setint(env, "db.secondary.sync", 0) == 0 );

	void *primary = sp_getobject(env, "db.primary");
	void *secondary = sp_getobject(env, "db.secondary");

	t( primary != NULL );
	t( secondary != NULL );

	t( sp_open(env) == 0 );

	void *tx;
	void *po, *so;
	uint32_t a, b;

	tx = sp_begin(env);
	a = 0;
	b = 3;
	po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, po) == 0 );
	so = sp_document(secondary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );

	tx = sp_begin(env);
	a = 1;
	b = 2;
	po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, po) == 0 );
	so = sp_document(secondary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );

	tx = sp_begin(env);
	a = 2;
	b = 1;
	po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, po) == 0 );
	so = sp_document(secondary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );

	tx = sp_begin(env);
	a = 3;
	b = 0;
	po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, po) == 0 );
	so = sp_document(secondary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );

	uint32_t current_a = 0;
	uint32_t current_b = 3;
	void *cur = sp_cursor(env);
	po = sp_document(primary);
	sp_setstring(po, "order", ">=", 0);
	while ((po = sp_get(cur, po))) {
		t( *(uint32_t*)sp_getstring(po, "a", NULL) == current_a );
		t( *(uint32_t*)sp_getstring(po, "b", NULL) == current_b );
		current_a++;
		current_b--;
	}
	sp_destroy(cur);

	current_a = 3;
	current_b = 0;
	cur = sp_cursor(env);
	so = sp_document(secondary);
	sp_setstring(so, "order", ">=", 0);
	while ((so = sp_get(cur, so))) {
		t( *(uint32_t*)sp_getstring(so, "a", NULL) == current_a );
		t( *(uint32_t*)sp_getstring(so, "b", NULL) == current_b );
		current_a--;
		current_b++;
	}
	sp_destroy(cur);

	sp_destroy(env);
}