diff --git a/percona_playback/query_log/query_log.cc b/percona_playback/query_log/query_log.cc index 8feb860..24fa20b 100644 --- a/percona_playback/query_log/query_log.cc +++ b/percona_playback/query_log/query_log.cc @@ -57,14 +57,16 @@ class ParseQueryLogFunc: public tbb::filter { ParseQueryLogFunc(FILE *input_file_, unsigned int run_count_, tbb::atomic *entries_, - tbb::atomic *queries_) + tbb::atomic *queries_, + bool p_is_ro_mode = false) : tbb::filter(true), nr_entries(entries_), nr_queries(queries_), input_file(input_file_), run_count(run_count_), next_line(NULL), - next_len(0) + next_len(0), + is_ro_mode(p_is_ro_mode) {}; void* operator() (void*); @@ -75,11 +77,12 @@ class ParseQueryLogFunc: public tbb::filter { unsigned int run_count; char *next_line; ssize_t next_len; + bool is_ro_mode; }; void* dispatch(void *input_); -void* ParseQueryLogFunc::operator() (void*) { +void* ParseQueryLogFunc::operator() (void*) { std::vector > *entries= new std::vector >(); @@ -144,6 +147,7 @@ void* ParseQueryLogFunc::operator() (void*) { { (*nr_queries)++; tmp_entry->add_query_line(std::string(line)); + do { if ((len= getline(&line, &buflen, input_file)) == -1) { @@ -156,7 +160,8 @@ void* ParseQueryLogFunc::operator() (void*) { next_len= len; break; } - tmp_entry->add_query_line(std::string(line)); + if((is_ro_mode && strnicmp("select", line, strlen("select")) == 0) || !is_ro_mode) + tmp_entry->add_query_line(std::string(line)); } while(true); } next: @@ -333,7 +338,7 @@ class DispatchQueriesFunc : public tbb::filter { } }; -static void LogReaderThread(FILE* input_file, unsigned int run_count, struct percona_playback_run_result *r) +static void LogReaderThread(FILE* input_file, unsigned int run_count, struct percona_playback_run_result *r, bool is_ro_mode = false) { tbb::pipeline p; tbb::atomic entries; @@ -341,7 +346,7 @@ static void LogReaderThread(FILE* input_file, unsigned int run_count, struct per entries=0; queries=0; - ParseQueryLogFunc f2(input_file, run_count, &entries, &queries); + ParseQueryLogFunc f2(input_file, run_count, &entries, &queries, is_ro_mode); DispatchQueriesFunc f4; p.add_filter(f2); p.add_filter(f4); @@ -360,6 +365,7 @@ class QueryLogPlugin : public percona_playback::InputPlugin std::string file_name; unsigned int read_count; bool std_in; + bool is_ro_mode; public: QueryLogPlugin(const std::string &_name) : @@ -373,6 +379,8 @@ class QueryLogPlugin : public percona_playback::InputPlugin options.add_options() ("query-log-file", po::value(), _("Query log file")) + ("read-only", + po::value(), _("Read only mode")) ("query-log-stdin", po::value()->default_value(false)->zero_tokens(), _("Read query log from stdin")) @@ -435,7 +443,10 @@ class QueryLogPlugin : public percona_playback::InputPlugin { fprintf(stderr, _("ERROR: --query-log-file is a required option.\n")); return -1; - } + } + // sets read only mode + if(vm.count("read-only")) + is_ro_mode = vm["read-only"].as(); return 0; } @@ -463,7 +474,8 @@ class QueryLogPlugin : public percona_playback::InputPlugin boost::thread log_reader_thread(LogReaderThread, input_file, read_count, - &result); + &result, + is_ro_mode); log_reader_thread.join(); fclose(input_file);