From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <tarantool-patches-bounces@dev.tarantool.org>
Received: from [87.239.111.99] (localhost [127.0.0.1])
	by dev.tarantool.org (Postfix) with ESMTP id 5D2D37F62A;
	Fri,  6 Aug 2021 22:47:29 +0300 (MSK)
DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5D2D37F62A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev;
	t=1628279249; bh=nFIWMUQ9d8JGcWIEg0fKUcQQzRSsO4Cl2dD4qIsrBrs=;
	h=Date:To:Cc:References:In-Reply-To:Subject:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=vnGvm2H966GYTny3dssJ1PV7phYo4c56xB+uy34iOjx+87s+iFTgRJLpCwbxo/qBQ
	 5EBeKAJPexNM9SWf+rUogsbi1em124icpld1DnIaCLzeBenvjzvRd60c1+3unUBCG4
	 PPROTQ4QtOL2tex5ybdmphEmj9bCvUZKVOrGGSJY=
Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [94.100.177.110])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by dev.tarantool.org (Postfix) with ESMTPS id A4E1B7F62A
 for <tarantool-patches@dev.tarantool.org>;
 Fri,  6 Aug 2021 22:47:27 +0300 (MSK)
DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A4E1B7F62A
Received: by smtp50.i.mail.ru with esmtpa (envelope-from
 <imeevma@tarantool.org>)
 id 1mC5oU-0006s1-Tv; Fri, 06 Aug 2021 22:47:27 +0300
Date: Fri, 6 Aug 2021 22:47:25 +0300
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Message-ID: <20210806194725.GD11107@tarantool.org>
References: <cover.1628081224.git.imeevma@gmail.com>
 <6033113bc5174be7b6e2b38b7dc07a2c61755e13.1628081224.git.imeevma@gmail.com>
 <2e871a92-4bd0-faae-2bc3-2dc9948757ce@tarantool.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
In-Reply-To: <2e871a92-4bd0-faae-2bc3-2dc9948757ce@tarantool.org>
X-4EC0790: 10
X-7564579A: 646B95376F6C166E
X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9736CF3E71F18CE0C3E1D5927724F4AAA182A05F53808504046EC50F12733AE1CCAF5466D9A61C434271EC02284089B853AB1BC5951D1F362
X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75C3A43A35AA60CB6EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372A1456D053D20C618638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C36CC9FF94AD251CA1B0FD3220368DEC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B8FBB52F5C7ECD1BBD8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE37BD21ED50D08CA4D302FCEF25BFAB345C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637AF8E4F18C523FAA9EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A
X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D07F83226743E198FA
X-C1DE0DAB: 0D63561A33F958A5997E3A2517AEC5E49650F8975EEE244FE85A2F6DB1B5DBC1D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75AF0B556A5A327A45410CA545F18667F91A7EA1CDA0B5A7A0
X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344B4608D01B1CB59AACCDC45741E58A24C90C95FFE5B4834CCD2EDB780E5EC90656F7F00A8D419CC01D7E09C32AA3244CDE51DC04AB8689CBE8FF379514C12E6E60759606DA2E136A729B2BEF169E0186
X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojFhlvmGwdUwTzPo4jvJvqCQ==
X-Mailru-Sender: 3A338A78718AEC5A7171F149183FF3A7FD081DA3DF91357D67BD02D49B01EDDF28D355B7A611FBA9A3E7B4BFDCAD2EFE027D9DD7AE851095A2E8D17B49942DB0CBEE3F9BE14373499437F6177E88F7363CDA0F3B3F5B9367
X-Mras: Ok
Subject: Re: [Tarantool-patches] [PATCH v2 4/6] alter: parse data dictionary
 version
X-BeenThere: tarantool-patches@dev.tarantool.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Tarantool development patches <tarantool-patches.dev.tarantool.org>
List-Unsubscribe: <https://lists.tarantool.org/mailman/options/tarantool-patches>, 
 <mailto:tarantool-patches-request@dev.tarantool.org?subject=unsubscribe>
List-Archive: <https://lists.tarantool.org/pipermail/tarantool-patches/>
List-Post: <mailto:tarantool-patches@dev.tarantool.org>
List-Help: <mailto:tarantool-patches-request@dev.tarantool.org?subject=help>
List-Subscribe: <https://lists.tarantool.org/mailman/listinfo/tarantool-patches>, 
 <mailto:tarantool-patches-request@dev.tarantool.org?subject=subscribe>
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
Reply-To: Mergen Imeev <imeevma@tarantool.org>
Errors-To: tarantool-patches-bounces@dev.tarantool.org
Sender: "Tarantool-patches" <tarantool-patches-bounces@dev.tarantool.org>

Thank you for the review! My answer, diff and newpatch below.

On Fri, Aug 06, 2021 at 12:17:30AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> > diff --git a/src/box/schema.cc b/src/box/schema.cc
> > index 963278b19..35026619a 100644
> > --- a/src/box/schema.cc
> > +++ b/src/box/schema.cc
> > @@ -70,6 +71,9 @@ uint32_t schema_version = 0;
> >   */
> >  uint32_t space_cache_version = 0;
> >  
> > +/** Persistent version of the schema, stored in _schema["version"]. */
> > +uint32_t dd_version_id = tarantool_version_id();
> 
> I propose to assign it to 0. Because at start there is no
> schema at all until box.cfg{} is called first time. (Also then
> version.h include could be dropped above.)
> 
Thanks! Fixed.

> > +
> >  struct rlist on_schema_init = RLIST_HEAD_INITIALIZER(on_schema_init);
> >  struct rlist on_alter_space = RLIST_HEAD_INITIALIZER(on_alter_space);
> >  struct rlist on_alter_sequence = RLIST_HEAD_INITIALIZER(on_alter_sequence);


Diff:

diff --git a/src/box/schema.cc b/src/box/schema.cc
index 35026619a..5659e15b7 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -38,7 +38,6 @@
 #include "user.h"
 #include "vclock/vclock.h"
 #include "fiber.h"
-#include "version.h"
 
 /**
  * @module Data Dictionary
@@ -72,7 +71,7 @@ uint32_t schema_version = 0;
 uint32_t space_cache_version = 0;
 
 /** Persistent version of the schema, stored in _schema["version"]. */
-uint32_t dd_version_id = tarantool_version_id();
+uint32_t dd_version_id = 0;
 
 struct rlist on_schema_init = RLIST_HEAD_INITIALIZER(on_schema_init);
 struct rlist on_alter_space = RLIST_HEAD_INITIALIZER(on_alter_space);


Patch:

commit ae9274f3f0ee8de36b8060c1236aa0d4279a5172
Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date:   Tue Sep 12 17:46:25 2017 +0300

    alter: parse data dictionary version
    
    Version is needed to disallow creation of SQL built-in functions using
    _func starting with 2.9.0.
    
    Needed for #6106

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 935790df4..217b882ba 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -4167,6 +4167,24 @@ on_replace_dd_schema(struct trigger * /* trigger */, void *event)
 			return -1;
 		REPLICASET_UUID = uu;
 		say_info("cluster uuid %s", tt_uuid_str(&uu));
+	} else if (strcmp(key, "version") == 0) {
+		if (new_tuple != NULL) {
+			uint32_t major, minor, patch;
+			if (tuple_field_u32(new_tuple, 1, &major) != 0 ||
+			    tuple_field_u32(new_tuple, 2, &minor) != 0)
+				tnt_raise(ClientError, ER_WRONG_DD_VERSION);
+			/* Version can be major.minor with no patch. */
+			if (tuple_field_u32(new_tuple, 3, &patch) != 0)
+				patch = 0;
+			dd_version_id = version_id(major, minor, patch);
+		} else {
+			assert(old_tuple != NULL);
+			/*
+			 * _schema:delete({'version'}) for
+			 * example, for box.internal.bootstrap().
+			 */
+			dd_version_id = tarantool_version_id();
+		}
 	}
 	return 0;
 }
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 963278b19..5659e15b7 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -70,6 +70,9 @@ uint32_t schema_version = 0;
  */
 uint32_t space_cache_version = 0;
 
+/** Persistent version of the schema, stored in _schema["version"]. */
+uint32_t dd_version_id = 0;
+
 struct rlist on_schema_init = RLIST_HEAD_INITIALIZER(on_schema_init);
 struct rlist on_alter_space = RLIST_HEAD_INITIALIZER(on_alter_space);
 struct rlist on_alter_sequence = RLIST_HEAD_INITIALIZER(on_alter_sequence);
diff --git a/src/box/schema.h b/src/box/schema.h
index 25ac6f110..d3bbdd590 100644
--- a/src/box/schema.h
+++ b/src/box/schema.h
@@ -44,6 +44,7 @@ struct func;
 
 extern uint32_t schema_version;
 extern uint32_t space_cache_version;
+extern uint32_t dd_version_id;
 
 /** Triggers invoked after schema initialization. */
 extern struct rlist on_schema_init;