[PATCH 07/12] space: pass new format instead of new space to space_vtab::check_format

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


The check_format method is supposed to check that all tuples stored in
an altered space conform to the new format. Let's change its signature
accordingly.
---
 src/box/alter.cc         |  2 +-
 src/box/memtx_space.c    |  8 ++++----
 src/box/space.h          | 16 +++++++---------
 src/box/sysview_engine.c |  6 +++---
 src/box/vinyl.c          | 10 +++++-----
 5 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 947716c8..9dd8d8d5 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -914,7 +914,7 @@ CheckSpaceFormat::alter(struct alter_space *alter)
 		assert(new_format != NULL);
 		if (!tuple_format1_can_store_format2_tuples(new_format,
 							    old_format))
-		    space_check_format_xc(new_space, old_space);
+		    space_check_format_xc(old_space, new_format);
 	}
 }
 
diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index ca7b5937..be687288 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -704,11 +704,11 @@ memtx_space_add_primary_key(struct space *space)
 }
 
 static int
-memtx_space_check_format(struct space *new_space, struct space *old_space)
+memtx_space_check_format(struct space *space, struct tuple_format *format)
 {
-	if (old_space->index_count == 0)
+	if (space->index_count == 0)
 		return 0;
-	struct index *pk = old_space->index[0];
+	struct index *pk = space->index[0];
 	if (index_size(pk) == 0)
 		return 0;
 
@@ -723,7 +723,7 @@ memtx_space_check_format(struct space *new_space, struct space *old_space)
 		 * Check that the tuple is OK according to the
 		 * new format.
 		 */
-		rc = tuple_validate(new_space->format, tuple);
+		rc = tuple_validate(format, tuple);
 		if (rc != 0)
 			break;
 	}
diff --git a/src/box/space.h b/src/box/space.h
index 0cc1b00f..70da58b1 100644
--- a/src/box/space.h
+++ b/src/box/space.h
@@ -91,11 +91,10 @@ struct space_vtab {
 	 */
 	void (*drop_primary_key)(struct space *);
 	/**
-	 * Check that new fields of a space format are
-	 * compatible with existing tuples.
+	 * Check that all tuples stored in a space are compatible
+	 * with the new format.
 	 */
-	int (*check_format)(struct space *new_space,
-			    struct space *old_space);
+	int (*check_format)(struct space *space, struct tuple_format *format);
 	/**
 	 * Build a new index, primary or secondary, and fill it
 	 * with tuples stored in the given space. The function is
@@ -317,10 +316,9 @@ space_add_primary_key(struct space *space)
 }
 
 static inline int
-space_check_format(struct space *new_space, struct space *old_space)
+space_check_format(struct space *space, struct tuple_format *format)
 {
-	assert(old_space->vtab == new_space->vtab);
-	return new_space->vtab->check_format(new_space, old_space);
+	return space->vtab->check_format(space, format);
 }
 
 static inline void
@@ -472,9 +470,9 @@ space_add_primary_key_xc(struct space *space)
 }
 
 static inline void
-space_check_format_xc(struct space *new_space, struct space *old_space)
+space_check_format_xc(struct space *space, struct tuple_format *format)
 {
-	if (space_check_format(new_space, old_space) != 0)
+	if (space_check_format(space, format) != 0)
 		diag_raise();
 }
 
diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c
index 8cfdeeba..bb31edbf 100644
--- a/src/box/sysview_engine.c
+++ b/src/box/sysview_engine.c
@@ -154,10 +154,10 @@ sysview_space_prepare_alter(struct space *old_space, struct space *new_space)
 }
 
 static int
-sysview_space_check_format(struct space *new_space, struct space *old_space)
+sysview_space_check_format(struct space *space, struct tuple_format *format)
 {
-	(void)old_space;
-	(void)new_space;
+	(void)space;
+	(void)format;
 	unreachable();
 	return 0;
 }
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 7db7a60f..cbafa122 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -1035,14 +1035,14 @@ vinyl_space_prepare_alter(struct space *old_space, struct space *new_space)
 }
 
 static int
-vinyl_space_check_format(struct space *new_space, struct space *old_space)
+vinyl_space_check_format(struct space *space, struct tuple_format *format)
 {
-	(void)new_space;
-	struct vy_env *env = vy_env(old_space->engine);
+	(void)format;
+	struct vy_env *env = vy_env(space->engine);
 	/* @sa vy_prepare_alter_space for checks below. */
-	if (old_space->index_count == 0)
+	if (space->index_count == 0)
 		return 0;
-	struct vy_lsm *pk = vy_lsm(old_space->index[0]);
+	struct vy_lsm *pk = vy_lsm(space->index[0]);
 	if (env->status != VINYL_ONLINE)
 		return 0;
 	if (pk->stat.disk.count.rows == 0 && pk->stat.memory.count.rows == 0)
-- 
2.11.0




More information about the Tarantool-patches mailing list