Skip to content

Read only mode #12

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 20 additions & 8 deletions percona_playback/query_log/query_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ class ParseQueryLogFunc: public tbb::filter {
ParseQueryLogFunc(FILE *input_file_,
unsigned int run_count_,
tbb::atomic<uint64_t> *entries_,
tbb::atomic<uint64_t> *queries_)
tbb::atomic<uint64_t> *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*);
Expand All @@ -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<boost::shared_ptr<QueryLogEntry> > *entries=
new std::vector<boost::shared_ptr<QueryLogEntry> >();

Expand Down Expand Up @@ -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)
{
Expand All @@ -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:
Expand Down Expand Up @@ -333,15 +338,15 @@ 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<uint64_t> entries;
tbb::atomic<uint64_t> queries;
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);
Expand All @@ -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) :
Expand All @@ -373,6 +379,8 @@ class QueryLogPlugin : public percona_playback::InputPlugin
options.add_options()
("query-log-file",
po::value<std::string>(), _("Query log file"))
("read-only",
po::value<bool>(), _("Read only mode"))
("query-log-stdin",
po::value<bool>()->default_value(false)->zero_tokens(),
_("Read query log from stdin"))
Expand Down Expand Up @@ -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<bool>();

return 0;
}
Expand Down Expand Up @@ -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);
Expand Down