Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] box: sql prepare and execute statistics should be reflected in box.stat()
@ 2020-02-10 18:35 Maria Khaydich
  2020-02-10 23:06 ` Nikita Pettik
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Maria Khaydich @ 2020-02-10 18:35 UTC (permalink / raw)
  To: tarantool-patches, Alexander Turenko, Vladislav Shpilevoy

[-- Attachment #1: Type: text/plain, Size: 3144 bytes --]


Calling prepare and execute did not update corresponding request statistics
in the box.stat table. This happened because methods that collect stats were
never called where they should have been.
 
Closes #4756

---
Issue:
https://github.com/tarantool/tarantool/issues/4756
Branch:
https://github.com/tarantool/tarantool/compare/eljashm/gh-4756-box-stat-execute-and-prepare-not-updated
 
 src/box/execute.c         |  4 ++++
 test/box-tap/cfg.test.lua | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/box/execute.c b/src/box/execute.c
index dc8dce81c..e775055b4 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -48,6 +48,7 @@
 #include "box/lua/execute.h"
 #include "box/sql_stmt_cache.h"
 #include "session.h"
+#include "rmean.h"
 
 const char *sql_info_key_strs[] = {
     "row_count",
@@ -608,6 +609,7 @@ sql_prepare(const char *sql, int len, struct port *port)
 {
     uint32_t stmt_id = sql_stmt_calculate_id(sql, len);
     struct sql_stmt *stmt = sql_stmt_cache_find(stmt_id);
+    rmean_collect(rmean_box, IPROTO_PREPARE, 1);
     if (stmt == NULL) {
         if (sql_stmt_compile(sql, len, NULL, &stmt, NULL) != 0)
             return -1;
@@ -669,6 +671,7 @@ static inline int
 sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region)
 {
     int rc, column_count = sql_column_count(stmt);
+    rmean_collect(rmean_box, IPROTO_EXECUTE, 1);
     if (column_count > 0) {
         /* Either ROW or DONE or ERROR. */
         while ((rc = sql_step(stmt)) == SQL_ROW) {
@@ -732,6 +735,7 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind,
     if (sql_stmt_compile(sql, len, NULL, &stmt, NULL) != 0)
         return -1;
     assert(stmt != NULL);
+    rmean_collect(rmean_box, IPROTO_PREPARE, 1);
     enum sql_serialization_format format = sql_column_count(stmt) > 0 ?
                        DQL_EXECUTE : DML_EXECUTE;
     port_sql_create(port, stmt, format, true);
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index d529447bb..d367aab07 100755
--- a/test/box-tap/cfg.test.lua
+++ b/test/box-tap/cfg.test.lua
@@ -6,7 +6,7 @@ local socket = require('socket')
 local fio = require('fio')
 local uuid = require('uuid')
 local msgpack = require('msgpack')
-test:plan(104)
+test:plan(106)
 
 --------------------------------------------------------------------------------
 -- Invalid values
@@ -592,6 +592,16 @@ box.cfg{read_only=true}
 ]]
 test:is(run_script(code), PANIC, "panic on bootstrapping a read-only instance as master")
 
+--
+-- gh-4756: PREPARE and EXECUTE statistics should be present in box.stat()
+--
+local p = box.stat().PREPARE.total
+local e = box.stat().EXECUTE.total
 
-test:check()
-os.exit(0)
+s = box.prepare([[ SELECT ?; ]])
+s:execute({42})
+
+test:is(box.stat().PREPARE.total, p + 1, "prepare stat is incremented")
+test:is(box.stat().EXECUTE.total, e + 1, "execute stat is incremented")
+
+os.exit(test:check() and 0 or 1)
-- 
2.24.0
 
--
Maria Khaydich
 

[-- Attachment #2: Type: text/html, Size: 4549 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-03-06 15:09 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 18:35 [Tarantool-patches] [PATCH] box: sql prepare and execute statistics should be reflected in box.stat() Maria Khaydich
2020-02-10 23:06 ` Nikita Pettik
2020-02-13 21:44 ` Vladislav Shpilevoy
2020-02-19 16:37   ` Maria Khaydich
2020-02-19 17:16     ` Nikita Pettik
2020-02-25 11:08       ` Maria Khaydich
2020-02-25 13:02         ` Nikita Pettik
2020-02-25 20:29           ` Vladislav Shpilevoy
2020-02-26 15:50             ` Maria Khaydich
2020-02-27  0:08               ` Vladislav Shpilevoy
2020-02-27 13:21                 ` Nikita Pettik
2020-03-03 16:42                   ` Maria Khaydich
2020-03-03 22:39                     ` Vladislav Shpilevoy
2020-03-06 11:34                       ` Maria Khaydich
2020-03-06 14:32                         ` Nikita Pettik
2020-03-06 15:09                           ` Nikita Pettik
2020-03-04 13:47                     ` Nikita Pettik
2020-02-25 22:26 ` Kirill Yukhin
2020-02-25 23:30   ` Nikita Pettik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox