[PATCH 02/13] vinyl: embed index in vy_lsm
Vladimir Davydov
vdavydov.dev at gmail.com
Sat Aug 10 13:03:29 MSK 2019
There's no point in having vinyl_engine and vinyl_index wrapper structs
to bind vy_env and vy_lsm to struct engine and index. Instead we can
simply embed engine and index in vy_env and vy_lsm. This will simplify
further development, e.g. this will allow us to move reference counting
from vy_lsm up to struct index so that it can be used in the generic
code.
---
src/box/vinyl.c | 39 ++++++++++++---------------------------
src/box/vy_lsm.h | 3 ++-
2 files changed, 14 insertions(+), 28 deletions(-)
diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index 327d0c39..645e36ca 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -142,19 +142,6 @@ struct vy_env {
bool force_recovery;
};
-struct vinyl_index {
- struct index base;
- /** LSM tree that stores index data. */
- struct vy_lsm *lsm;
-};
-
-/** Extract vy_lsm from an index object. */
-struct vy_lsm *
-vy_lsm(struct index *index)
-{
- return ((struct vinyl_index *)index)->lsm;
-}
-
/** Mask passed to vy_gc(). */
enum {
/** Delete incomplete runs. */
@@ -206,6 +193,14 @@ vy_env(struct engine *engine)
return (struct vy_env *)engine;
}
+/** Extract vy_lsm from an index object. */
+struct vy_lsm *
+vy_lsm(struct index *index)
+{
+ assert(index->vtab == &vinyl_index_vtab);
+ return (struct vy_lsm *)index;
+}
+
/**
* A quick intro into Vinyl cosmology and file format
* --------------------------------------------------
@@ -688,12 +683,6 @@ static struct index *
vinyl_space_create_index(struct space *space, struct index_def *index_def)
{
assert(index_def->type == TREE);
- struct vinyl_index *index = calloc(1, sizeof(*index));
- if (index == NULL) {
- diag_set(OutOfMemory, sizeof(*index),
- "malloc", "struct vinyl_index");
- return NULL;
- }
struct vy_env *env = vy_env(space->engine);
struct vy_lsm *pk = NULL;
if (index_def->iid > 0) {
@@ -703,18 +692,15 @@ vinyl_space_create_index(struct space *space, struct index_def *index_def)
struct vy_lsm *lsm = vy_lsm_new(&env->lsm_env, &env->cache_env,
&env->mem_env, index_def, space->format,
pk, space_group_id(space));
- if (lsm == NULL) {
- free(index);
+ if (lsm == NULL)
return NULL;
- }
- if (index_create(&index->base, &env->base,
+
+ if (index_create(&lsm->base, &env->base,
&vinyl_index_vtab, index_def) != 0) {
vy_lsm_delete(lsm);
- free(index);
return NULL;
}
- index->lsm = lsm;
- return &index->base;
+ return &lsm->base;
}
static void
@@ -727,7 +713,6 @@ vinyl_index_destroy(struct index *index)
* is gone.
*/
vy_lsm_unref(lsm);
- free(index);
}
/**
diff --git a/src/box/vy_lsm.h b/src/box/vy_lsm.h
index d9e4b582..327a886b 100644
--- a/src/box/vy_lsm.h
+++ b/src/box/vy_lsm.h
@@ -37,6 +37,7 @@
#include <small/mempool.h>
#include <small/rlist.h>
+#include "index.h"
#include "index_def.h"
#define HEAP_FORWARD_DECLARATION
#include "salad/heap.h"
@@ -51,7 +52,6 @@ extern "C" {
#endif /* defined(__cplusplus) */
struct histogram;
-struct index;
struct tuple;
struct tuple_format;
struct vy_lsm;
@@ -179,6 +179,7 @@ vy_lsm_env_destroy(struct vy_lsm_env *env);
* secondary key, i.e. the tuple stored. This is key_def.
*/
struct vy_lsm {
+ struct index base;
/** Common LSM tree environment. */
struct vy_lsm_env *env;
/**
--
2.20.1
More information about the Tarantool-patches
mailing list