Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH] sql: fix recovery of VIEW space
Date: Tue, 19 Mar 2019 20:21:03 +0300	[thread overview]
Message-ID: <20190319172103.92279-1-korablev@tarantool.org> (raw)

During creation of VIEW space, string containing its definition (i.e.
"SELECT ...") is parsed to fetch names of referenced spaces. By those
names real struct space objects are found using schema_find_id().
This function processes lookup in _space using its secondary index.
On the other hand, secondary indexes of _space are unavailable during
this stage of recovery, so this lookup fails and whole recovery process
aborts.

It is worth mentioning that now we can fetch space directly from
in-memory cache using its name (originally, when view reference counter
was introduced, we couldn't do this due to absence of name-cache). So,
to fix this issue, let's use space_by_name() instead of schema_find_id()

Closes #3814
---
Branch: https://github.com/tarantool/tarantool/tree/np/gh-3814-view-update-references-recovery
Issue: https://github.com/tarantool/tarantool/issues/3814

 src/box/alter.cc       | 10 ++--------
 test/sql/view.result   | 28 ++++++++++++++++++++++++++++
 test/sql/view.test.lua | 13 +++++++++++++
 3 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 431da12da..080a72b9f 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -1501,13 +1501,8 @@ update_view_references(struct Select *select, int update_value,
 		const char *space_name = sql_src_list_entry_name(list, i);
 		if (space_name == NULL)
 			continue;
-		uint32_t space_id;
-		if (schema_find_id(BOX_SPACE_ID, 2, space_name,
-				   strlen(space_name), &space_id) != 0) {
-			sqlSrcListDelete(sql_get(), list);
-			return -1;
-		}
-		if (space_id == BOX_ID_NIL) {
+		struct space *space = space_by_name(space_name);
+		if (space == NULL) {
 			if (! suppress_error) {
 				assert(not_found_space != NULL);
 				*not_found_space = tt_sprintf("%s", space_name);
@@ -1516,7 +1511,6 @@ update_view_references(struct Select *select, int update_value,
 			}
 			continue;
 		}
-		struct space *space = space_by_id(space_id);
 		assert(space->def->view_ref_count > 0 || update_value > 0);
 		space->def->view_ref_count += update_value;
 	}
diff --git a/test/sql/view.result b/test/sql/view.result
index fd8fe00e3..e99a9bd7e 100644
--- a/test/sql/view.result
+++ b/test/sql/view.result
@@ -241,6 +241,34 @@ box.sql.execute("DROP TABLE c;")
 box.sql.execute("DROP TABLE b;")
 ---
 ...
+-- gh-3814: make sure that recovery of view processed without
+-- unexpected errors.
+--
+box.snapshot()
+---
+- ok
+...
+box.sql.execute("CREATE TABLE t2 (id INT PRIMARY KEY);")
+---
+...
+box.sql.execute("CREATE VIEW v2 AS SELECT * FROM t2;")
+---
+...
+test_run:cmd('restart server default')
+box.sql.execute("DROP TABLE t2;")
+---
+- error: 'Can''t drop space ''T2'': other views depend on this space'
+...
+box.sql.execute("SELECT * FROM v2;")
+---
+- []
+...
+box.space.V2:drop()
+---
+...
+box.space.T2:drop()
+---
+...
 -- Cleanup
 box.sql.execute("DROP VIEW v1;");
 ---
diff --git a/test/sql/view.test.lua b/test/sql/view.test.lua
index d05fb4a8c..592d7889c 100644
--- a/test/sql/view.test.lua
+++ b/test/sql/view.test.lua
@@ -104,6 +104,19 @@ box.space.BCV:drop()
 box.sql.execute("DROP TABLE c;")
 box.sql.execute("DROP TABLE b;")
 
+-- gh-3814: make sure that recovery of view processed without
+-- unexpected errors.
+--
+box.snapshot()
+box.sql.execute("CREATE TABLE t2 (id INT PRIMARY KEY);")
+box.sql.execute("CREATE VIEW v2 AS SELECT * FROM t2;")
+test_run:cmd('restart server default')
+
+box.sql.execute("DROP TABLE t2;")
+box.sql.execute("SELECT * FROM v2;")
+box.space.V2:drop()
+box.space.T2:drop()
+
 -- Cleanup
 box.sql.execute("DROP VIEW v1;");
 box.sql.execute("DROP TABLE t1;");
-- 
2.15.1

             reply	other threads:[~2019-03-19 17:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19 17:21 Nikita Pettik [this message]
2019-03-20 10:29 ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190319172103.92279-1-korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] sql: fix recovery of VIEW space' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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