Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/dbtest/src/sql_cntl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ bool DBConnector::ExecWriteSql(int sql_id, const std::string& sql, TestResultSet
SQLHSTMT m_hStatement;
SQLHDBC m_hDatabaseConnection = DBConnector::conn_pool_[session_id - 1];

//sleeep time_interval_ ms
usleep(1000 * time_interval_);

// Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function.
ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
std::string err_info_stmt = DBConnector::SqlExecuteErr(session_id, sql_id, sql, "stmt", m_hStatement, ret, test_process_file);
Expand Down Expand Up @@ -278,6 +281,9 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult
// Get the expected result set list from test_result_set
std::vector<std::unordered_map<int, std::vector<std::string>>> expected_result_set_list = test_result_set.ExpectedResultSetList();

//sleeep time_interval_ ms
usleep(1000 * time_interval_);

// Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function.
ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
// Check if allocating a statement handle was successful. If it fails, release the handle and return false.
Expand Down Expand Up @@ -385,6 +391,7 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult
* @return True if the operation is successful, false otherwise.
*/
bool DBConnector::SQLEndTnx(std::string opt, int session_id, int sql_id, TestResultSet& test_result_set, const std::string& db_type, std::string test_process_file) {

if (sql_id != 1024) {
std::string blank(blank_base*(session_id - 1), ' ');
std::string output_info;
Expand Down
10 changes: 6 additions & 4 deletions src/dbtest/src/sql_cntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class DBConnector {
private:
// Each SQLHDBC is a handle for a single database connection.
std::vector<SQLHDBC> conn_pool_;
std::int32_t time_interval_; //time interval between sql execution
public:
// Initializes the database connector, stablishes a specified number of database connections and adds them to the connection pool.
bool InitDBConnector(std::string& user, std::string& passwd, std::string& db_type, int conn_pool_size) {
bool InitDBConnector(std::string& user, std::string& passwd, std::string& db_type, int conn_pool_size, int32_t time_interval) {
this->time_interval_ = time_interval;
for (int i = 0; i < (int)conn_pool_size; i++) {
// Initializes the ODBC environment handle m_hEnviroment.
SQLHENV m_hEnviroment;
Expand All @@ -30,8 +32,8 @@ class DBConnector {
// Allocates the ODBC environment handle using SQLAllocHandle.
ret = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &m_hEnviroment);
if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
std::cerr << "get env failed" << std::endl;
return false;
std::cerr << "get env failed" << std::endl;
return false;
}

// Sets the ODBC version to ODBC 3.0.
Expand All @@ -41,7 +43,7 @@ class DBConnector {
ret = SQLAllocHandle(SQL_HANDLE_DBC, m_hEnviroment, &m_hDatabaseConnection);
if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) {
std::cerr << "get conn failed" << std::endl;
return false;
return false;
}
// connect
// Connects to the database using SQLConnect.
Expand Down
6 changes: 6 additions & 0 deletions src/dbtest/src/sql_cntl_v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ bool DBConnector::ExecWriteSql(int sql_id, const std::string& sql, TestResultSet
SQLHSTMT m_hStatement;
SQLHDBC m_hDatabaseConnection = DBConnector::conn_pool_[session_id - 1];

//sleeep time_interval_ ms
usleep(1000 * time_interval_);

ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
std::string err_info_stmt = DBConnector::SqlExecuteErr(session_id, sql_id, sql, "stmt", m_hStatement, ret, test_process_file);
if (!err_info_stmt.empty()) {
Expand Down Expand Up @@ -313,6 +316,9 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult
// Get the expected result set list from test_result_set
std::vector<std::unordered_map<int, std::vector<std::string>>> expected_result_set_list = test_result_set.ExpectedResultSetList();

//sleeep time_interval_ ms
usleep(1000 * time_interval_);

// Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function.
ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
// Check if allocating a statement handle was successful. If it fails, release the handle and return false.
Expand Down
4 changes: 3 additions & 1 deletion src/dbtest/src/sqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEFINE_int32(conn_pool_size, 6, "db_conn pool size");
DEFINE_string(isolation, "serializable", "transation isolation level: read-uncommitted read-committed repeatable-read serializable");
DEFINE_string(case_dir, "mysql", "test case dir name");
DEFINE_string(timeout, "20", "timeout");
DEFINE_int32(exec_inteval, 0, "sql execution time interval");

// std::vector<std::mutex *> mutex_txn(5); // same as conn_pool_size
std::vector<pthread_mutex_t *> mutex_txn(FLAGS_conn_pool_size); // same as conn_pool_size
Expand Down Expand Up @@ -416,6 +417,7 @@ int main(int argc, char* argv[]) {
std::cout << " user: " + FLAGS_user << std::endl;
std::cout << " passwd: " + FLAGS_passwd << std::endl;
std::cout << " isolation: " + FLAGS_isolation << std::endl;
std::cout << " exec_interval: " + FLAGS_exec_inteval << std::endl;

// mutex for txn
for(int i=0;i<FLAGS_conn_pool_size;++i) {
Expand Down Expand Up @@ -523,7 +525,7 @@ int main(int argc, char* argv[]) {
// init db_connector
std::cout << dash + "init db_connector start" + dash << std::endl;
DBConnector db_connector;
if (!db_connector.InitDBConnector(FLAGS_user, FLAGS_passwd, FLAGS_db_type, FLAGS_conn_pool_size)) {
if (!db_connector.InitDBConnector(FLAGS_user, FLAGS_passwd, FLAGS_db_type, FLAGS_conn_pool_size, FLAGS_exec_inteval)) {
std::cout << "init db_connector failed" << std::endl;
}
// set TXN_ISOLATION
Expand Down
4 changes: 3 additions & 1 deletion src/dbtest/src/sqltest_v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DEFINE_int32(conn_pool_size, 30, "db_conn pool size");
DEFINE_string(isolation, "serializable", "transation isolation level: read-uncommitted read-committed repeatable-read serializable");
DEFINE_string(case_dir, "mysql", "test case dir name");
DEFINE_string(timeout, "3", "timeout");
DEFINE_int32(exec_inteval, 0, "sql execution time interval");


std::vector<pthread_mutex_t *> mutex_txn(FLAGS_conn_pool_size); // same as conn_pool_size
Expand Down Expand Up @@ -373,6 +374,7 @@ int main(int argc, char* argv[]) {
std::cout << " user: " + FLAGS_user << std::endl;
std::cout << " passwd: " + FLAGS_passwd << std::endl;
std::cout << " isolation: " + FLAGS_isolation << std::endl;
std::cout << " exec_interval: " + FLAGS_exec_inteval << std::endl;

// mutex for txn
for(int i=0;i<FLAGS_conn_pool_size;++i) {
Expand Down Expand Up @@ -473,7 +475,7 @@ int main(int argc, char* argv[]) {
// init db_connector
std::cout << dash + "init db_connector start" + dash << std::endl;
DBConnector db_connector;
if (!db_connector.InitDBConnector(FLAGS_user, FLAGS_passwd, FLAGS_db_type, FLAGS_conn_pool_size)) {
if (!db_connector.InitDBConnector(FLAGS_user, FLAGS_passwd, FLAGS_db_type, FLAGS_conn_pool_size, FLAGS_exec_inteval)) {
std::cout << "init db_connector failed" << std::endl;
}
// set TXN_ISOLATION
Expand Down