[PATCH 03/12] alter: move dictionary update from ModifySpace::alter_def to alter

Vladimir Davydov vdavydov.dev at gmail.com
Sat Apr 7 16:38:00 MSK 2018


We may yield while rebuilding a vinyl index hence we must not modify
the old space before we are done building all indexes, otherwise the
user might see an inconsistent state while a space is being altered.
Currently, this requirement doesn't hold - we both modify the old space
and build the new indexes in AlterSpaceOp::alter. We need to introduce
AlterSpaceOp::prepare method that would perform all yielding operations
and forbid yielding in AlterSpaceOp::alter.

Dictionary update, which is currently done by ModifySpace::alter_def,
modifies the old space hence it should live in ModifySpace::alter.
Let's move it there.
---
 src/box/alter.cc       | 45 +++++++++++++++++++--------------------------
 src/box/tuple_format.c |  2 --
 2 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 0af4ac09..ec7af24b 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -923,17 +923,12 @@ public:
 	 * created, it allocates new dictionary. Alter moves new
 	 * names into an old dictionary and deletes new one.
 	 */
-	struct tuple_dictionary *new_dict;
-	/**
-	 * Old tuple dictionary stored to rollback in destructor,
-	 * if an exception had been raised after alter_def(), but
-	 * before alter().
-	 */
-	struct tuple_dictionary *old_dict;
+	struct tuple_dictionary *dict;
 	/* New space definition. */
 	struct space_def *def;
 	virtual void alter_def(struct alter_space *alter);
-	virtual void commit(struct alter_space *alter, int64_t signature);
+	virtual void alter(struct alter_space *alter);
+	virtual void rollback(struct alter_space *alter);
 	virtual ~ModifySpace();
 };
 
@@ -942,15 +937,13 @@ void
 ModifySpace::alter_def(struct alter_space *alter)
 {
 	/*
-	 * Move new names into an old dictionary, which already is
-	 * referenced by existing tuple formats. New dictionary
-	 * object is deleted later, in destructor.
+	 * Use the old dictionary for the new space, because
+	 * it is already referenced by existing tuple formats.
+	 * We will update it in place in ModifySpace::alter.
 	 */
-	new_dict = def->dict;
-	old_dict = alter->old_space->def->dict;
-	tuple_dictionary_swap(new_dict, old_dict);
-	def->dict = old_dict;
-	tuple_dictionary_ref(old_dict);
+	dict = def->dict;
+	def->dict = alter->old_space->def->dict;
+	tuple_dictionary_ref(def->dict);
 
 	space_def_delete(alter->space_def);
 	alter->space_def = def;
@@ -959,21 +952,21 @@ ModifySpace::alter_def(struct alter_space *alter)
 }
 
 void
-ModifySpace::commit(struct alter_space *alter, int64_t signature)
+ModifySpace::alter(struct alter_space *alter)
 {
-	(void) alter;
-	(void) signature;
-	old_dict = NULL;
+	tuple_dictionary_swap(alter->new_space->def->dict, dict);
+}
+
+void
+ModifySpace::rollback(struct alter_space *alter)
+{
+	tuple_dictionary_swap(alter->new_space->def->dict, dict);
 }
 
 ModifySpace::~ModifySpace()
 {
-	if (new_dict != NULL) {
-		/* Return old names into the old dict. */
-		if (old_dict != NULL)
-			tuple_dictionary_swap(new_dict, old_dict);
-		tuple_dictionary_unref(new_dict);
-	}
+	if (dict != NULL)
+		tuple_dictionary_unref(dict);
 	if (def != NULL)
 		space_def_delete(def);
 }
diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index d3a7702d..11481473 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -262,8 +262,6 @@ tuple_format_new(struct tuple_format_vtab *vtab, struct key_def * const *keys,
 		 const struct field_def *space_fields,
 		 uint32_t space_field_count, struct tuple_dictionary *dict)
 {
-	assert((dict == NULL && space_field_count == 0) ||
-	       (dict != NULL && space_field_count == dict->name_count));
 	struct tuple_format *format =
 		tuple_format_alloc(keys, key_count, space_field_count, dict);
 	if (format == NULL)
-- 
2.11.0




More information about the Tarantool-patches mailing list