-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging options for recent N queries #43
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test it. The option should work without --pquery . So basically it should log last N sql into a file. by command . pstress-ms --table=1 --threads=1 --seconds=1
The changes you implement will work with option --pquery the requirement is it should work without that mode. Thanks for your time. Please make it work with default option
src/thread.cpp
Outdated
general_log << "Unable to open logfile for client output " << cl.str() | ||
<< ": " << std::strerror(errno) << std::endl; | ||
return; | ||
if (options->at(Option::LOG_N_QUERIES) && options->at(Option::LOG_N_QUERIES)->getInt() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user pass --log-n-query=0, It should not log any query.
src/thread.cpp
Outdated
size_t n_queries = 5; | ||
|
||
if (options->at(Option::LOG_N_QUERIES) && | ||
options->at(Option::LOG_N_QUERIES)->getInt() >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic Corrected for --log-N-queries=0.
Now it will save an empty log file in myParams.logdir i.e /tmp here.
Testing Examples :Command 1 : ./pstress-ms --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 Default case : will save recent 5 logs to Command 2 : ./pstress-ms --log-N-queries=10 --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 Recent Query Case : will save recent 10 logs to Command 3 : ./pstress-ms --log-all-queries --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Command 4 : ./pstress-ms --log-all-queries --log-N-queries=10 --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Testing Examples (--pquery) :Command 5 : ./pstress-ms --pquery --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Command 6 : ./pstress-ms --log-N-queries=10 --pquery --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Command 7 : ./pstress-ms --log-all-queries --pquery --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Command 8 : ./pstress-ms --log-all-queries --log-N-queries=10 --pquery --socket=/var/run/mysqld/mysqld.sock --password=<password> --database=<testdb> --no-encryption --no-tbs --grammar-sql=0 --no-ddl --table=1 --threads=1 --seconds=3 All Query Case : will save all logs to Observation :
|
e832120
to
fed18f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean implementation. Good work. Getting there.
The requirement is to log last N queries executed by pstress in thread.sql. Two important changes.
- use the same file that write log with --log-all-queries i.e thread_log file.
- Last N queries by each thread and not overall. so one hint that structure should be part of Thread class.
.vscode/settings.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this added automatically by vscode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add it .gitignore file. so it doesn't get upload and remove it.
src/random_test.hpp
Outdated
@@ -192,9 +192,9 @@ struct Index { | |||
struct Thd1 { | |||
Thd1(int id, std::ofstream &tl, std::ofstream &ddl_l, std::ofstream &client_l, | |||
MYSQL *c, std::atomic<unsigned long long> &p, | |||
std::atomic<unsigned long long> &f) | |||
std::atomic<unsigned long long> &f,int log_N_count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding New arg for Thd1 structure
src/thread.cpp
Outdated
? (log_filename.str() + ".sql") // All queries log | ||
: (log_filename.str() + "_recent" | ||
+ "-" + std::to_string(n_queries) + ".sql"); | ||
std::string full_log_filename = log_filename.str() + ".sql" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting single file name for logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address review comments.
.vscode/settings.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add it .gitignore file. so it doesn't get upload and remove it.
src/random_test.cpp
Outdated
@@ -2679,11 +2679,16 @@ void Table::Compare_between_engine(const std::string &sql, Thd1 *thd) { | |||
set_default(); | |||
} | |||
|
|||
// Data structures for recent queries | |||
static std::deque<std::string> recent_queries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it used any where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have corrected the logic and removed it
src/random_test.hpp
Outdated
@@ -42,6 +43,10 @@ std::string rand_float(float upper, float lower = 0); | |||
std::string rand_double(double upper, double lower = 0); | |||
std::string rand_string(int upper, int lower = 2); | |||
|
|||
// Introduction of new function to retrive deque of recent queries | |||
std::deque<std::string> get_recent_queries(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't better to make it part of Thd class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Removed and it is already part of Thd class
src/random_test.hpp
Outdated
@@ -42,6 +43,10 @@ std::string rand_float(float upper, float lower = 0); | |||
std::string rand_double(double upper, double lower = 0); | |||
std::string rand_string(int upper, int lower = 2); | |||
|
|||
// Introduction of new function to retrive deque of recent queries | |||
std::deque<std::string> get_recent_queries(); | |||
extern std::mutex recent_queries_mutex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recent_queries_mutex is used no where
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
src/random_test.cpp
Outdated
@@ -2797,6 +2810,10 @@ bool execute_sql(const std::string &sql, Thd1 *thd) { | |||
|
|||
return (res == 0 ? 1 : 0); | |||
} | |||
// Retrive the formed deque | |||
std::deque<std::string> get_recent_queries() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you duplicating the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed as its already present in Thd Class
src/thread.cpp
Outdated
@@ -9,6 +9,10 @@ | |||
std::atomic_flag lock_metadata = ATOMIC_FLAG_INIT; | |||
std::atomic<bool> metadata_loaded(false); | |||
|
|||
// Mutex for thread-safe logging | |||
std::mutex general_log_mutex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not used anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
src/random_test.cpp
Outdated
bool execute_sql(const std::string &sql, Thd1 *thd) { | ||
auto query = sql.c_str(); | ||
static auto log_all = opt_bool(LOG_ALL_QUERIES); | ||
static auto log_failed = opt_bool(LOG_FAILED_QUERIES); | ||
static auto log_success = opt_bool(LOG_SUCCEDED_QUERIES); | ||
static auto log_N = opt_bool(LOG_N_QUERIES); | ||
thd->max_recent_queries = options->at(Option::LOG_N_QUERIES)->getInt(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are reassigning this variable . This is done as part of Thd class initialization as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed
src/random_test.cpp
Outdated
bool execute_sql(const std::string &sql, Thd1 *thd) { | ||
auto query = sql.c_str(); | ||
static auto log_all = opt_bool(LOG_ALL_QUERIES); | ||
static auto log_failed = opt_bool(LOG_FAILED_QUERIES); | ||
static auto log_success = opt_bool(LOG_SUCCEDED_QUERIES); | ||
static auto log_N = opt_bool(LOG_N_QUERIES); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user would provide a value for --log-N-queries. So either a option is Bool or Int. Can't be both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this line and code is giving correct query logs i have tested
src/random_test.cpp
Outdated
@@ -2716,6 +2721,10 @@ bool execute_sql(const std::string &sql, Thd1 *thd) { | |||
if (res != 0) { // query failed | |||
thd->failed_queries_total++; | |||
thd->max_con_fail_count++; | |||
// Manage recent queries for failed queries | |||
if (!log_N) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the condition should be if(options->at(Option::LOG_N_QUERIES)->getInt()>0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/thread.cpp
Outdated
/* connection can be changed if we thd->tryreconnect is called */ | ||
conn = thd->conn; | ||
delete thd; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this empty lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
src/thread.cpp
Outdated
@@ -155,11 +170,21 @@ void Node::workerThread(int number) { | |||
break; | |||
} | |||
} | |||
logDeque = thd->get_recent_queries(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work ? in the case of mode pquery. you are not saving query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, removed, this will not work and as usual give 1-2 queries even if i ran --log-all-queries
#ifdef DUCKDB | ||
try { | ||
// Create DuckDB connection | ||
duckdb::DuckDB db(nullptr); // In-memory database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For each SQL to execute , It create new in memory database. This is not what is required here.
We have to create in memory database just once. use connection based on --thread we have to open a connection against that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a new pull request and not append with N queries. The start look good. compile tryreconnect only for mysql. disable kill query for option for DUCKDB
This update introduces new query logging option:
--log-N-queries=N : Saves the last N queries to tmp/node.3306/step-1/thread-0/recent-.sql. Defaults to 5 if not specified.
--log-all-queries : Saves a full query log to tmp/node.3306/step-1/thread-0.sql.
How to Test: