From 3b448157a865bec9eeef21dbbace5a16310a9f20 Mon Sep 17 00:00:00 2001
From: Dmitry Simonenko <pmwkaa@gmail.com>
Date: Mon, 19 Jan 2015 18:43:54 +0400
Subject: [PATCH] sophia-snapshot: refactoring space callbacks

---
 src/box/box.cc    |  5 +++--
 src/box/engine.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 src/box/engine.h  | 14 +++++++++++++
 src/box/schema.cc | 51 -----------------------------------------------
 src/box/schema.h  | 15 --------------
 5 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/src/box/box.cc b/src/box/box.cc
index b4867af3d4..0a3a80adf8 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -634,6 +634,9 @@ box_snapshot(void)
 	if (status != 0)
 		goto error;
 
+	/* complete snapshot */
+	tuple_end_snapshot();
+
 	/* wait for engine snapshot completion */
 	engine_foreach(box_snapshot_wait_engine, &snap_lsn);
 
@@ -646,8 +649,6 @@ box_snapshot(void)
 	/* remove previous snapshot reference */
 	engine_foreach(box_snapshot_delete_engine, &snapshot_last_lsn);
 
-	/* complete snapshot */
-	tuple_end_snapshot();
 
 	snapshot_last_lsn = snap_lsn;
 	snapshot_pid = 0;
diff --git a/src/box/engine.cc b/src/box/engine.cc
index ffa5283039..4c4d5f119c 100644
--- a/src/box/engine.cc
+++ b/src/box/engine.cc
@@ -28,6 +28,7 @@
  */
 #include "engine.h"
 #include "space.h"
+#include "schema.h"
 #include "exception.h"
 #include "salad/rlist.h"
 #include <stdlib.h>
@@ -108,3 +109,53 @@ void engine_shutdown()
 		delete e;
 	}
 }
+
+static void
+do_one_recover_step(struct space *space, void * /* param */)
+{
+	if (space_index(space, 0)) {
+		space->engine->recover(space);
+	} else {
+		/* in case of space has no primary index,
+		 * derive it's engine handler recovery state from
+		 * the global one. */
+		space->engine->initRecovery();
+	}
+}
+
+static inline void
+space_end_recover_snapshot_cb(EngineFactory *f, void *udate)
+{
+	(void)udate;
+	f->recoveryEvent(END_RECOVERY_SNAPSHOT);
+}
+
+void
+space_end_recover_snapshot()
+{
+	/*
+	 * For all new spaces created from now on, when the
+	 * PRIMARY key is added, enable it right away.
+	 */
+	engine_foreach(space_end_recover_snapshot_cb, NULL);
+	space_foreach(do_one_recover_step, NULL);
+}
+
+static inline void
+space_end_recover_cb(EngineFactory *f, void *udate)
+{
+	(void)udate;
+	f->recoveryEvent(END_RECOVERY);
+}
+
+void
+space_end_recover()
+{
+	/*
+	 * For all new spaces created after recovery is complete,
+	 * when the primary key is added, enable all keys.
+	 */
+	engine_foreach(space_end_recover_cb, NULL);
+
+	space_foreach(do_one_recover_step, NULL);
+}
diff --git a/src/box/engine.h b/src/box/engine.h
index e141345102..9bc0f5c692 100644
--- a/src/box/engine.h
+++ b/src/box/engine.h
@@ -218,4 +218,18 @@ engine_id(Engine *engine)
 	return engine->factory->id;
 }
 
+/**
+ * Called at the end of recovery from snapshot.
+ * Build primary keys in all spaces.
+ * */
+void
+space_end_recover_snapshot();
+
+/**
+ * Called at the end of recovery.
+ * Build secondary keys in all spaces.
+ */
+void
+space_end_recover();
+
 #endif /* TARANTOOL_BOX_ENGINE_H_INCLUDED */
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 6ce440d429..be69a71973 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -163,19 +163,6 @@ space_cache_replace(struct space *space)
 	return p_old ? (struct space *) p_old->val : NULL;
 }
 
-static void
-do_one_recover_step(struct space *space, void * /* param */)
-{
-	if (space_index(space, 0)) {
-		space->engine->recover(space);
-	} else {
-		/* in case of space has no primary index,
-		 * derive it's engine handler recovery state from
-		 * the global one. */
-		space->engine->initRecovery();
-	}
-}
-
 /** A wrapper around space_new() for data dictionary spaces. */
 struct space *
 sc_space_new(struct space_def *space_def,
@@ -307,44 +294,6 @@ schema_init()
 	key_def_delete(key_def);
 }
 
-static inline void
-space_end_recover_snapshot_cb(EngineFactory *f, void *udate)
-{
-	(void)udate;
-	f->recoveryEvent(END_RECOVERY_SNAPSHOT);
-}
-
-void
-space_end_recover_snapshot()
-{
-	/*
-	 * For all new spaces created from now on, when the
-	 * PRIMARY key is added, enable it right away.
-	 */
-	engine_foreach(space_end_recover_snapshot_cb, NULL);
-
-	space_foreach(do_one_recover_step, NULL);
-}
-
-static inline void
-space_end_recover_cb(EngineFactory *f, void *udate)
-{
-	(void)udate;
-	f->recoveryEvent(END_RECOVERY);
-}
-
-void
-space_end_recover()
-{
-	/*
-	 * For all new spaces created after recovery is complete,
-	 * when the primary key is added, enable all keys.
-	 */
-	engine_foreach(space_end_recover_cb, NULL);
-
-	space_foreach(do_one_recover_step, NULL);
-}
-
 void
 schema_free(void)
 {
diff --git a/src/box/schema.h b/src/box/schema.h
index cbd77926c2..5aea8ea7f6 100644
--- a/src/box/schema.h
+++ b/src/box/schema.h
@@ -105,20 +105,6 @@ schema_init();
 void
 schema_free();
 
-/**
- * Called at the end of recovery from snapshot.
- * Build primary keys in all spaces.
- * */
-void
-space_end_recover_snapshot();
-
-/**
- * Called at the end of recovery.
- * Build secondary keys in all spaces.
- */
-void
-space_end_recover();
-
 struct space *schema_space(uint32_t id);
 
 /*
@@ -163,5 +149,4 @@ func_by_name(const char *name, uint32_t name_len)
 bool
 schema_find_grants(const char *type, uint32_t id);
 
-
 #endif /* INCLUDES_TARANTOOL_BOX_SCHEMA_H */
-- 
GitLab