~tsarev/percona-server/5.5-processlist_rows_stats-sporadic_fails-fix

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/client/hsclient.cpp

Merge release branch, update version

Create release-5.5.12-20.3 with 5.5.12 changes and release branch from
5.5.11. Update versions to 5.5.12 and 20.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vim:sw=2:ai
 
3
 
 
4
#include "hstcpcli.hpp"
 
5
#include "string_util.hpp"
 
6
 
 
7
namespace dena {
 
8
 
 
9
int
 
10
hstcpcli_main(int argc, char **argv)
 
11
{
 
12
  config conf;
 
13
  parse_args(argc, argv, conf);
 
14
  socket_args sockargs;
 
15
  sockargs.set(conf);
 
16
  hstcpcli_ptr cli = hstcpcli_i::create(sockargs);
 
17
  const std::string dbname = conf.get_str("dbname", "hstest");
 
18
  const std::string table = conf.get_str("table", "hstest_table1");
 
19
  const std::string index = conf.get_str("index", "PRIMARY");
 
20
  const std::string fields = conf.get_str("fields", "k,v");
 
21
  const int limit = conf.get_int("limit", 0);
 
22
  const int skip = conf.get_int("skip", 0);
 
23
  std::vector<std::string> keys;
 
24
  std::vector<string_ref> keyrefs;
 
25
  size_t num_keys = 0;
 
26
  while (true) {
 
27
    const std::string conf_key = std::string("k") + to_stdstring(num_keys);
 
28
    const std::string k = conf.get_str(conf_key, "");
 
29
    const std::string kx = conf.get_str(conf_key, "x");
 
30
    if (k.empty() && kx == "x") {
 
31
      break;
 
32
    }
 
33
    ++num_keys;
 
34
    keys.push_back(k);
 
35
  }
 
36
  for (size_t i = 0; i < keys.size(); ++i) {
 
37
    const string_ref ref(keys[i].data(), keys[i].size());
 
38
    keyrefs.push_back(ref);
 
39
  }
 
40
  const std::string op = conf.get_str("op", "=");
 
41
  const string_ref op_ref(op.data(), op.size());
 
42
  cli->request_buf_open_index(0, dbname.c_str(), table.c_str(),
 
43
    index.c_str(), fields.c_str());
 
44
  cli->request_buf_exec_generic(0, op_ref, num_keys == 0 ? 0 : &keyrefs[0],
 
45
    num_keys, limit, skip, string_ref(), 0, 0);
 
46
  int code = 0;
 
47
  size_t numflds = 0;
 
48
  do {
 
49
    if (cli->request_send() != 0) {
 
50
      fprintf(stderr, "request_send: %s\n", cli->get_error().c_str());
 
51
      break;
 
52
    }
 
53
    if ((code = cli->response_recv(numflds)) != 0) {
 
54
      fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str());
 
55
      break;
 
56
    }
 
57
  } while (false);
 
58
  cli->response_buf_remove();
 
59
  do {
 
60
    if ((code = cli->response_recv(numflds)) != 0) {
 
61
      fprintf(stderr, "response_recv: %s\n", cli->get_error().c_str());
 
62
      break;
 
63
    }
 
64
    while (true) {
 
65
      const string_ref *const row = cli->get_next_row();
 
66
      if (row == 0) {
 
67
        break;
 
68
      }
 
69
      printf("REC:");
 
70
      for (size_t i = 0; i < numflds; ++i) {
 
71
        const std::string val(row[i].begin(), row[i].size());
 
72
        printf(" %s", val.c_str());
 
73
      }
 
74
      printf("\n");
 
75
    }
 
76
  } while (false);
 
77
  cli->response_buf_remove();
 
78
  return 0;
 
79
}
 
80
 
 
81
};
 
82
 
 
83
int
 
84
main(int argc, char **argv)
 
85
{
 
86
  return dena::hstcpcli_main(argc, argv);
 
87
}
 
88