Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH 02/13] vinyl: embed index in vy_lsm
Date: Sat, 10 Aug 2019 13:03:29 +0300	[thread overview]
Message-ID: <3ba5ca48f66a85de7141712155ff8dadc422df45.1565430177.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1565430177.git.vdavydov.dev@gmail.com>

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

  parent reply	other threads:[~2019-08-10 10:03 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-10 10:03 [PATCH 00/13] Join replicas off the current read view Vladimir Davydov
2019-08-10 10:03 ` [PATCH 01/13] vinyl: embed engine in vy_env Vladimir Davydov
2019-08-12 22:14   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 13:09   ` Vladimir Davydov
2019-08-10 10:03 ` Vladimir Davydov [this message]
2019-08-12 22:14   ` [tarantool-patches] Re: [PATCH 02/13] vinyl: embed index in vy_lsm Konstantin Osipov
2019-08-14 13:09   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 03/13] vinyl: move reference counting from vy_lsm to index Vladimir Davydov
2019-08-12 22:16   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 13:09   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 04/13] vinyl: don't pin index for iterator lifetime Vladimir Davydov
2019-08-10 10:03 ` [PATCH 05/13] vinyl: don't exempt dropped indexes from dump and compaction Vladimir Davydov
2019-08-10 10:03 ` [PATCH 06/13] memtx: don't store pointers to index internals in iterator Vladimir Davydov
2019-08-12 22:21   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 13:10   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 07/13] memtx: use ref counting to pin indexes for snapshot Vladimir Davydov
2019-08-12 22:24   ` [tarantool-patches] " Konstantin Osipov
2019-08-13 10:56     ` Vladimir Davydov
2019-08-13 16:08       ` Georgy Kirichenko
2019-08-10 10:03 ` [PATCH 08/13] memtx: allow snapshot iterator to fail Vladimir Davydov
2019-08-12 22:25   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 13:10   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 09/13] memtx: enter small delayed free mode from snapshot iterator Vladimir Davydov
2019-08-12 22:27   ` [tarantool-patches] " Konstantin Osipov
2019-08-13 10:59     ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 10/13] wal: make wal_sync fail on write error Vladimir Davydov
2019-08-12 22:29   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 16:48   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 11/13] xrow: factor out helper for setting REPLACE request body Vladimir Davydov
2019-08-12 22:29   ` [tarantool-patches] " Konstantin Osipov
2019-08-14 13:11   ` Vladimir Davydov
2019-08-10 10:03 ` [PATCH 12/13] test: disable replication/on_schema_init Vladimir Davydov
2019-08-12 22:31   ` [tarantool-patches] " Konstantin Osipov
2019-08-10 10:03 ` [PATCH 13/13] relay: join new replicas off read view Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ba5ca48f66a85de7141712155ff8dadc422df45.1565430177.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH 02/13] vinyl: embed index in vy_lsm' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox