示例#1
0
void
test_txn5_05()
{
	GlobalTransactionId gxid;
	int rc;

	SETUP();

	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
	_ASSERT( gxid != InvalidGlobalTransactionId );

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	rc = commit_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	system("./promote.sh");

	GTMPQfinish(conn);
	connect2();

	rc = commit_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	TEARDOWN();
}
示例#2
0
文件: commit_tests.c 项目: b-k/tea
int testBegin(){

	commit_transaction();
	commit_transaction();
	begin_transaction();
	begin_transaction();
	commit_transaction();
	begin_transaction();
	commit_transaction();
	begin_transaction();
	begin_transaction();
	commit_transaction();
	return 0;
}
示例#3
0
int run(LOGGER log, struct config config) {
	sqlite3* db = sqlite_service_connect(log, config.dbpath);

	curl_global_init(CURL_GLOBAL_SSL);

	if (!db) {
		return 1;
	}

	if (config.single) {
		QUIT = 1;
	}
	if (prepare_statements(log, db)) {
		return 2;
	}
	spider(log, db, config.hash, config.tree);
	while(!QUIT) {
		begin_transaction(log, db);
		spider(log, db, config.hash, config.tree);
		commit_transaction(log, db);
		sleep(config.sleep);
	}
	finalize_statements(log);
	sqlite_service_close(log, db);

	curl_global_cleanup();
	return 0;
}
示例#4
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Query table for specified rows
 * _h: structure representing database connection
 * _k: key names
 * _op: operators
 * _v: values of the keys that must match
 * _c: column names to return
 * _n: nmber of key=values pairs to compare
 * _nc: number of columns to return
 * _o: order by the specified column
 */
int db_query(db_con_t* _h, db_key_t* _k, db_op_t* _op,
	     db_val_t* _v, db_key_t* _c, int _n, int _nc,
	     db_key_t _o, db_res_t** _r)
{
	int off, rv;
	if (!_c) {
		off = snprintf(sql_buf, SQL_BUF_LEN,
			"select * from %s ", CON_TABLE(_h));
	} else {
		off = snprintf(sql_buf, SQL_BUF_LEN, "select ");
		off += print_columns(sql_buf + off, SQL_BUF_LEN - off, _c, _nc);
		off += snprintf(sql_buf + off, SQL_BUF_LEN - off,
			"from %s ", CON_TABLE(_h));
	}
	if (_n) {
		off += snprintf(sql_buf + off, SQL_BUF_LEN - off, "where ");
		off += print_where(sql_buf + off, SQL_BUF_LEN - off,
			_k, _op, _v, _n);
	}
	if (_o) {
		off += snprintf(sql_buf + off, SQL_BUF_LEN - off,
			"order by %s", _o);
	}

	if(begin_transaction(_h, sql_buf)) return(-1);
	if (submit_query(_h, sql_buf) < 0) {
		LOG(L_ERR, "db_query(): Error while submitting query\n");
		return -2;
	}
	rv = get_result(_h, _r);
	free_query(_h);
	commit_transaction(_h);
	return(rv);
}
示例#5
0
void
test_txn5_11()
{
	GlobalTransactionId gxid;
	int rc;
	
	SETUP();
        sleep(3);
	
	system("killall -9 gtm_standby");
	
	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
        _ASSERT( gxid != InvalidGlobalTransactionId );
        _ASSERT( grep_count(LOG_ACTIVE, "Sending transaction id 3")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "Sending transaction id 3")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=0")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=1")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=2")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "communication error with standby")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "Calling report_xcwatch_gtm_failure()...")==1 );
	
	rc = commit_transaction(conn, gxid);
        _ASSERT( rc>=0 );
        _ASSERT( grep_count(LOG_ACTIVE, "Committing transaction id 3")==1 );
        _ASSERT( grep_count(LOG_STANDBY, "Committing transaction id 3")==0 );
	
	TEARDOWN();
}
示例#6
0
int
CommitTranGTM(GlobalTransactionId gxid)
{
	int ret;

	if (!GlobalTransactionIdIsValid(gxid))
		return 0;
	CheckConnection();
	ret = commit_transaction(conn, gxid);

	/*
	 * If something went wrong (timeout), try and reset GTM connection. 
	 * We will close the transaction locally anyway, and closing GTM will force
	 * it to be closed on GTM.
	 */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}

	/* Close connection in case commit is done by autovacuum worker or launcher */
	if (IsAutoVacuumWorkerProcess() || IsAutoVacuumLauncherProcess())
		CloseGTM();

	return ret;
}
示例#7
0
int validate_transaction(tr_submit_msg* t) {
	if (SKIP_VALIDATION) {
		commit_transaction(t);
		return 1;
	}
	
    if ((t->start >= (vs.ST - MaxPreviousST)) && (t->start <= vs.ST)) {
        if (validate(t)) {
            commit_transaction(t);
            return 1;
        }
    } else {
        too_old++;
    }
    abort_transaction(t);
    return 0;
}
示例#8
0
int
main(int argc, char *argv[])
{
	int ii;
	int jj;

#define TXN_COUNT		10000
#define LOOP_COUNT		10
	
	GlobalTransactionId gxid[TXN_COUNT];
	GTM_Conn *conn;
	char connect_string[100];

	sprintf(connect_string, "host=localhost port=6666 node_name=one remote_type=%d", GTM_NODE_COORDINATOR);

	conn = PQconnectGTM(connect_string);
	if (conn == NULL)
	{
		client_log(("Error in connection\n"));
		exit(1);
	}

	for (jj = 0; jj < LOOP_COUNT; jj++)
	{
		for (ii = 0; ii < TXN_COUNT; ii++)
		{
			int kk;
			GTM_Snapshot snapshot;

			gxid[ii] = begin_transaction(conn, GTM_ISOLATION_RC);
			if (gxid[ii] != InvalidGlobalTransactionId)
				client_log(("Started a new transaction (GXID:%u)\n", gxid[ii]));
			else
				client_log(("BEGIN transaction failed for ii=%d\n", ii));
			snapshot = get_snapshot(conn, gxid[ii], true);


			if (ii % 2 == 0)
			{
				if (!abort_transaction(conn, gxid[ii]))
					client_log(("ROLLBACK successful (GXID:%u)\n", gxid[ii]));
				else
					client_log(("ROLLBACK failed (GXID:%u)\n", gxid[ii]));
			}
			else
			{
				if (!commit_transaction(conn, gxid[ii]))
					client_log(("COMMIT successful (GXID:%u)\n", gxid[ii]));
				else
					client_log(("COMMIT failed (GXID:%u)\n", gxid[ii]));
			}
		}
	}

	GTMPQfinish(conn);
	return 0;
}
示例#9
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Execute a raw SQL query
 */
int db_raw_query(db_con_t* _h, char* _s, db_res_t** _r)
{
	int rv;

	if(begin_transaction(_h, sql_buf)) return(-1);
	if (submit_query(_h, _s) < 0) {
		LOG(L_ERR, "db_raw_query(): Error while submitting query\n");
		return -2;
	}
	rv = get_result(_h, _r);
	free_query(_h);
	commit_transaction(_h);
	return(rv);
}
示例#10
0
void
SocketInstance::lookup_table_page_down ()
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "lookup_table_page_up (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN);
    trans.put_data (m_peer_id);

    commit_transaction (trans);
}
示例#11
0
void
SocketInstance::reset ()
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "reset (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_RESET);
    trans.put_data (m_peer_id);

    commit_transaction (trans);
}
示例#12
0
void
SocketInstance::focus_out ()
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "focus_out (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_FOCUS_OUT);
    trans.put_data (m_peer_id);

    commit_transaction (trans);
}
示例#13
0
int
CommitTranGTM(GlobalTransactionId gxid, int waited_xid_count,
		GlobalTransactionId *waited_xids)
{
	int ret;

	if (!GlobalTransactionIdIsValid(gxid))
		return 0;
	CheckConnection();
#ifdef XCP
	ret = -1;
	if (conn)
#endif
	ret = commit_transaction(conn, gxid, waited_xid_count, waited_xids);

	/*
	 * If something went wrong (timeout), try and reset GTM connection.
	 * We will close the transaction locally anyway, and closing GTM will force
	 * it to be closed on GTM.
	 */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
#ifdef XCP
		if (conn)
			ret = commit_transaction(conn, gxid, waited_xid_count, waited_xids);
#endif
	}

	/* Close connection in case commit is done by autovacuum worker or launcher */
	if (IsAutoVacuumWorkerProcess() || IsAutoVacuumLauncherProcess())
		CloseGTM();

	currentGxid = InvalidGlobalTransactionId;
	return ret;
}
示例#14
0
void
SocketInstance::update_lookup_table_page_size (unsigned int page_size)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "update_lookup_table_page_size (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE);
    trans.put_data (m_peer_id);
    trans.put_data ((uint32) page_size);

    commit_transaction (trans);
}
示例#15
0
void
SocketInstance::move_preedit_caret (unsigned int pos)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "move_preedit_caret (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_MOVE_PREEDIT_CARET);
    trans.put_data (m_peer_id);
    trans.put_data ((uint32) pos);

    commit_transaction (trans);
}
示例#16
0
void
SocketInstance::update_client_capabilities (unsigned int cap)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "update_client_capabilities (" << m_peer_id << ", " << cap << ")\n";

    trans.put_command (SCIM_TRANS_CMD_UPDATE_CLIENT_CAPABILITIES);
    trans.put_data (m_peer_id);
    trans.put_data ((uint32) cap);

    commit_transaction (trans);
}
示例#17
0
bool
SocketInstance::process_key_event (const KeyEvent& key)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "process_key_event (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_PROCESS_KEY_EVENT);
    trans.put_data (m_peer_id);
    trans.put_data (key);

    return commit_transaction (trans);
}
示例#18
0
void
SocketInstance::trigger_property (const String &property)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "trigger_property (" << m_peer_id << ", " << property << ")\n";

    trans.put_command (SCIM_TRANS_CMD_TRIGGER_PROPERTY);
    trans.put_data (m_peer_id);
    trans.put_data (property);

    commit_transaction (trans);
}
示例#19
0
void
SocketInstance::select_candidate (unsigned int item)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "select_candidate (" << m_peer_id << ")\n";

    trans.put_command (SCIM_TRANS_CMD_SELECT_CANDIDATE);
    trans.put_data (m_peer_id);
    trans.put_data ((uint32) item);

    commit_transaction (trans);
}
示例#20
0
void
SocketInstance::process_helper_event (const String &helper_uuid, const Transaction &helper_trans)
{
    Transaction trans;

    global->init_transaction (trans);

    SCIM_DEBUG_IMENGINE(1) << "process_helper_event (" << m_peer_id << ", " << helper_uuid << ")\n";

    trans.put_command (SCIM_TRANS_CMD_PROCESS_HELPER_EVENT);
    trans.put_data (m_peer_id);
    trans.put_data (helper_uuid);
    trans.put_data (helper_trans);

    commit_transaction (trans);
}
示例#21
0
SocketInstance::~SocketInstance ()
{
    Transaction trans;

    SCIM_DEBUG_IMENGINE(1) << "Destroy IMEngine Instance " << m_peer_id << ".\n";

    m_signal_reconnect_connection.disconnect ();

    if (m_peer_id >= 0) {
        global->init_transaction (trans);

        trans.put_command (SCIM_TRANS_CMD_DELETE_INSTANCE);
        trans.put_data (m_peer_id);

        commit_transaction (trans);
    }
}
示例#22
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Delete a row from the specified table
 * _h: structure representing database connection
 * _k: key names
 * _o: operators
 * _v: values of the keys that must match
 * _n: number of key=value pairs
 */
int db_delete(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n)
{
	int off;
	off = snprintf(sql_buf, SQL_BUF_LEN, "delete from %s", CON_TABLE(_h));
	if (_n) {
		off += snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
		off += print_where(sql_buf + off, SQL_BUF_LEN - off, _k,
			_o, _v, _n);
	}
	if(begin_transaction(_h, sql_buf)) return(-1);
	if (submit_query(_h, sql_buf) < 0) {
		LOG(L_ERR, "db_delete(): Error while deleting\n");
		return -2;
	}
	free_query(_h);
	commit_transaction(_h);
	return(0);
}
示例#23
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Insert a row into specified table
 * _h: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
int db_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
{
	int off;
	off = snprintf(sql_buf, SQL_BUF_LEN, "insert into %s (", CON_TABLE(_h));
	off += print_columns(sql_buf + off, SQL_BUF_LEN - off, _k, _n);
	off += snprintf(sql_buf + off, SQL_BUF_LEN - off, ") values (");
	off += print_values(sql_buf + off, SQL_BUF_LEN - off, _v, _n);
	*(sql_buf + off++) = ')';
	*(sql_buf + off) = '\0';

	if(begin_transaction(_h, sql_buf)) return(-1);
	if (submit_query(_h, sql_buf) < 0) {
		LOG(L_ERR, "db_insert(): Error while inserting\n");
		return -2;
	}
	free_query(_h);
	commit_transaction(_h);
	return(0);
}
示例#24
0
文件: db.cpp 项目: AleksKots/Manitou
bool
db_cnx::next_seq_val(const char* seqName, int* id)
{
  try {
    begin_transaction();
    sql_stream update(QString("UPDATE sequence set value=value+1 where name='%1'").arg(seqName),
                      *this);
    sql_stream select(QString("SELECT value from sequence where name='%1'").arg(seqName),
                      *this);
    commit_transaction();
    select >> *id;
    -- *id;
  }
  catch(db_excpt& p) {
    DBEXCPT(p);
    return false;
  }
  return true;
}
示例#25
0
文件: checkout.c 项目: b-k/tea
void check_out_impute(char **origin, char **destin, int *imputation_number, char **subset, char **filltabin){
    char *filltab = (filltabin && *filltabin) ? *filltabin : "filled";
    Tea_stopif(!origin || !*origin, return, 0, "NULL origin table, but I need that.");
    char *id_column= get_key_word(NULL, "id");
    const char *dest = destin ? *destin : NULL;
    int use_rowids = 0;
    if (!id_column) {
        use_rowids++;
        id_column = strdup("rowid");
    }
    sprintf(apop_opts.db_name_column, "%s",  id_column);
    begin_transaction();
    if (dest && strcmp(*origin, dest)){
        apop_table_exists(dest, 'd');
        apop_query("create table %s as select %s * from %s %s %s", 
                        dest, 
                        use_rowids ? "rowid as id_col, " : " ", *origin,
                        (subset && *subset) ? "where" : " ",
                        (subset && *subset) ? *subset : " "
                        );
    } else dest = *origin;
    create_index(dest, use_rowids ? "id_col" : id_column);
    Tea_stopif(!apop_table_exists(filltab), return , 0, "No table named '%s'; did you already doMImpute()?", filltab);
    apop_data *fills = apop_query_to_text("select %s, field, value from %s where (draw=%i or draw = -1)"
                                              , id_column, filltab, *imputation_number);
    Tea_stopif(!fills || fills->error, return, 0, "Expected fill-in table "
                "%s, but couldn't query it.", filltab);
    for(int i=0; i< *fills->textsize; i++){
        _Bool is_null = !strcmp(fills->text[i][1], apop_opts.nan_string);
        char tick = is_null ? ' ' : '\'';
        apop_query("update %s set %s = %c%s%c "
                   "where cast(%s as numeric) = %s", 
                      dest, fills->text[i][0], 
                      tick, is_null ? "NULL" : fills->text[i][1], tick,
                      id_column, fills->names->row[i]);
    }
    commit_transaction();
    apop_data_free(fills);
    free(id_column);
}
示例#26
0
文件: dbase.c 项目: OPSF/uClinux
/*
 * Update some rows in the specified table
 * _h: structure representing database connection
 * _k: key names
 * _o: operators
 * _v: values of the keys that must match
 * _uk: updated columns
 * _uv: updated values of the columns
 * _n: number of key=value pairs
 * _un: number of columns to update
 */
int db_update(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
	      db_key_t* _uk, db_val_t* _uv, int _n, int _un)
{
	int off;
	off = snprintf(sql_buf, SQL_BUF_LEN, "update %s set ", CON_TABLE(_h));
	off += print_set(sql_buf + off, SQL_BUF_LEN - off, _uk, _uv, _un);
	if (_n) {
		off += snprintf(sql_buf + off, SQL_BUF_LEN - off, " where ");
		off += print_where(sql_buf + off, SQL_BUF_LEN - off, _k,
			_o, _v, _n);
		*(sql_buf + off) = '\0';
	}

	if(begin_transaction(_h, sql_buf)) return(-1);
	if (submit_query(_h, sql_buf) < 0) {
		LOG(L_ERR, "db_update(): Error while updating\n");
		return -2;
	}
	free_query(_h);
	commit_transaction(_h);
	return(0);
}
示例#27
0
int validate_phase2(tr_submit_msg* t, int commit) {
	int i;
	flat_key_hash* rs_hashes;
	
	if (commit) {
		rs_hashes = TR_SUBMIT_MSG_RS_HASH(t);
		for (i = 0; i < t->readset_count; i++) {
	        if (bloom_contains_hashes(vs.ws, rs_hashes[i].hash)) {
	            ws_conflict++;
				commit = 0;
				break;
	        }
	    }
	}
	
	if (commit)
		commit_transaction(t);
	else 
		abort_transaction(t);

	return commit;
}
/**
 * Safely resave a database by renaming all of its tables, recreating
 * everything, and then dropping the backup tables only if there were
 * no errors. If there are errors, drop the new tables and restore the
 * originals.
 *
 * @param book: QofBook to be saved in the database.
 */
template <DbType Type> void
GncDbiBackend<Type>::safe_sync (QofBook* book)
{
    auto conn = dynamic_cast<GncDbiSqlConnection*>(m_conn);

    g_return_if_fail (conn != nullptr);
    g_return_if_fail (book != nullptr);

    ENTER ("book=%p, primary=%p", book, m_book);
    if (!conn->begin_transaction())
    {
        LEAVE("Failed to obtain a transaction.");
        return;
    }
    if (!conn->table_operation (TableOpType::backup))
    {
        conn->rollback_transaction();
        LEAVE ("Failed to rename tables");
        return;
    }
    if (!conn->drop_indexes())
    {
        conn->rollback_transaction();
        LEAVE ("Failed to drop indexes");
        return;
    }

    sync(m_book);
    if (check_error())
    {
        conn->rollback_transaction();
        LEAVE ("Failed to create new database tables");
        return;
    }
    conn->table_operation (TableOpType::drop_backup);
    conn->commit_transaction();
    LEAVE ("book=%p", m_book);
}
示例#29
0
void
test_txn4_01()
{
	GlobalTransactionId gxid;
	int rc;

	SETUP();

	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
	_ASSERT( gxid != InvalidGlobalTransactionId );

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	rc = commit_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	_ASSERT( grep_count(LOG_STANDBY, "Sending transaction id 3")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Preparing transaction id 3")==1 );
	_ASSERT( grep_count(LOG_STANDBY, "Committing transaction id 3")==1 );

	TEARDOWN();
}
示例#30
0
文件: checkout.c 项目: rforge/tea
void check_out_impute(char **origin, char **destin, int *imputation_number, char **subset, char **filltabin){
    char *filltab = (filltabin && *filltabin) ? *filltabin : "filled";
    Apop_stopif(!origin || !*origin, return, 0, "NULL origin table, but I need that.");
    char *id_column= get_key_word(NULL, "id");
    const char *dest = destin ? *destin : NULL;
    int use_rowids = 0;
    if (!id_column) {
        use_rowids++;
        id_column = strdup("rowid");
    }
    sprintf(apop_opts.db_name_column, "%s",  id_column);
    if (dest){
        apop_table_exists(dest, 'd');
        apop_query("create table %s as select %s * from %s %s %s", 
                        dest, 
                        use_rowids ? "rowid as id_col, " : " ", *origin,
                        (subset && *subset) ? "where" : " ",
                        (subset && *subset) ? *subset : " "
                        );
    } else dest = *origin;
    has_sqlite3_index(dest, use_rowids ? "id_col" : id_column, 'y');
    Apop_stopif(!apop_table_exists(filltab), return , 0, "No table named '%s'; did you already doMImpute()?", filltab);
    apop_data *fills = apop_query_to_text("select %s, field, value from %s where draw+0.0=%i"
                                              , id_column, filltab, *imputation_number);
    Apop_stopif(!fills || fills->error, return, 0, "Expected fill-in table "
                "%s, but couldn't query it.", filltab);
    begin_transaction();
    if (fills)
        for(int i=0; i< *fills->textsize; i++)
            apop_query("update %s set %s = '%s' "
                       "where %s = %s", 
                          dest, fills->text[i][0], fills->text[i][1], 
                          id_column, fills->names->row[i]);
    commit_transaction();
    apop_data_free(fills);
    free(id_column);
}