[Tarantool-patches] [PATCH v2 4/6] alter: parse data dictionary version

Mergen Imeev imeevma at tarantool.org
Fri Aug 6 22:47:25 MSK 2021


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 at 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;


More information about the Tarantool-patches mailing list