From 50c2f9a3b3e8d0e745e95cdf8031cb87bb3c5046 Mon Sep 17 00:00:00 2001
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Sun, 16 Feb 2020 18:04:26 +0100
Subject: [PATCH] box: forbid to update/replace _space_sequence

Anyway this does not work for generated sequences. A proper
support of update would complicate the code and won't give
anything useful.

Part of #4771

(cherry picked from commit 1a84b80e3f30a9f87d22ec285ab3e1b5ab596af2)
---
 src/box/alter.cc           | 12 ++++++++++--
 test/box/sequence.result   | 19 +++++++++++++++++++
 test/box/sequence.test.lua |  9 +++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 0f8ba082a3..720d2cdd67 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -3834,9 +3834,17 @@ on_replace_dd_space_sequence(struct trigger * /* trigger */, void *event)
 	struct space *space = space_cache_find_xc(space_id);
 	struct sequence *seq = sequence_cache_find(sequence_id);
 
+	if (stmt->new_tuple != NULL && stmt->old_tuple != NULL) {
+		/*
+		 * Makes no sense to support update, it would
+		 * complicate the code, and won't simplify
+		 * anything else.
+		 */
+		tnt_raise(ClientError, ER_UNSUPPORTED,
+			  "space \"_space_sequence\"", "update");
+	}
+
 	enum priv_type priv_type = stmt->new_tuple ? PRIV_C : PRIV_D;
-	if (stmt->new_tuple && stmt->old_tuple)
-		priv_type = PRIV_A;
 
 	/* Check we have the correct access type on the sequence.  * */
 	if (is_generated || !stmt->new_tuple) {
diff --git a/test/box/sequence.result b/test/box/sequence.result
index 917952909f..0a6cfee2c4 100644
--- a/test/box/sequence.result
+++ b/test/box/sequence.result
@@ -2270,3 +2270,22 @@ sq:next() -- 2
 sq:drop()
 ---
 ...
+--
+-- Update on _space_sequence is forbidden.
+--
+s = box.schema.create_space('test')
+---
+...
+pk = s:create_index('pk', {sequence = true})
+---
+...
+t = box.space._space_sequence:get({s.id})
+---
+...
+box.space._space_sequence:update({s.id}, {{'=', 2, t[2]}})
+---
+- error: space "_space_sequence" does not support update
+...
+s:drop()
+---
+...
diff --git a/test/box/sequence.test.lua b/test/box/sequence.test.lua
index b0ec020ed7..8e00571e50 100644
--- a/test/box/sequence.test.lua
+++ b/test/box/sequence.test.lua
@@ -771,3 +771,12 @@ sq:next() -- 1
 box.begin() box.space._sequence_data:delete{sq.id} box.rollback()
 sq:next() -- 2
 sq:drop()
+
+--
+-- Update on _space_sequence is forbidden.
+--
+s = box.schema.create_space('test')
+pk = s:create_index('pk', {sequence = true})
+t = box.space._space_sequence:get({s.id})
+box.space._space_sequence:update({s.id}, {{'=', 2, t[2]}})
+s:drop()
-- 
GitLab