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 1 commit
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
37 changes: 27 additions & 10 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,13 @@ 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*) {

std::vector<boost::shared_ptr<QueryLogEntry> > *entries=
new std::vector<boost::shared_ptr<QueryLogEntry> >();

Expand Down Expand Up @@ -137,13 +141,16 @@ void* ParseQueryLogFunc::operator() (void*) {
tmp_entry.reset(new QueryLogEntry());
(*this->nr_entries)++;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing spaces on this line

Copy link
Author

@elshadaghazade elshadaghazade Nov 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right sir. It is fault of IDE and my careless. I removed all trailing spaces which you commented. You can see on the commit with title "Update query_log.cc 15.11.2016"

if (p[0] == '#')
tmp_entry->parse_metadata(std::string(line));
else
{
(*nr_queries)++;
tmp_entry->add_query_line(std::string(line));
if((is_ro_mode && (strncmp("select", line, strlen("select")) == 0 || strncmp("SELECT", line, strlen("SELECT")) == 0)) || !is_ro_mode)
{
(*nr_queries)++;
tmp_entry->add_query_line(std::string(line));
}
do {
if ((len= getline(&line, &buflen, input_file)) == -1)
{
Expand All @@ -156,7 +163,9 @@ void* ParseQueryLogFunc::operator() (void*) {
next_len= len;
break;
}
tmp_entry->add_query_line(std::string(line));

if((is_ro_mode && (strncmp("select", line, strlen("select")) == 0 || strncmp("SELECT", line, strlen("SELECT")) == 0)) || !is_ro_mode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use strnicmp() here instead of two compares? why do we need to do two strlen() calls for a static string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I corrected this mistake on the commit with title "Update query_log.cc 15.11.2016"

tmp_entry->add_query_line(std::string(line));
} while(true);
}
next:
Expand Down Expand Up @@ -333,15 +342,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 +369,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 +383,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 @@ -436,14 +448,18 @@ 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;
}

virtual void run(percona_playback_run_result &result)
{
FILE* input_file;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing spaces

if (std_in)
{
input_file = stdin;
Expand All @@ -463,7 +479,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