Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org
Subject: [PATCH 1/2] vinyl: allocate upsert counter on lsregion
Date: Fri, 30 Mar 2018 18:47:18 +0300	[thread overview]
Message-ID: <ca46913dc043b385a9e2e6eb0c1fd2ddba42029c.1522423771.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1522423771.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1522423771.git.vdavydov.dev@gmail.com>

Currently, we store upsert counter in tuple metadata (that's what
upsert_format is for), but since it's only relevant for tuples of
the memory level, we can store it on lsregion, right before tuple
data. Let's do it now so that we can get rid of upsert_format.
---
 src/box/vy_stmt.c | 24 ++++++++++++++++--------
 src/box/vy_stmt.h | 23 ++++++++++++++---------
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c
index 84182e76..ac60c89e 100644
--- a/src/box/vy_stmt.c
+++ b/src/box/vy_stmt.c
@@ -134,13 +134,26 @@ struct tuple *
 vy_stmt_dup_lsregion(const struct tuple *stmt, struct lsregion *lsregion,
 		     int64_t alloc_id)
 {
+	enum iproto_type type = vy_stmt_type(stmt);
 	size_t size = tuple_size(stmt);
+	size_t alloc_size = size;
 	struct tuple *mem_stmt;
-	mem_stmt = lsregion_alloc(lsregion, size, alloc_id);
+
+	/* Reserve one byte for UPSERT counter. */
+	if (type == IPROTO_UPSERT)
+		alloc_size++;
+
+	mem_stmt = lsregion_alloc(lsregion, alloc_size, alloc_id);
 	if (mem_stmt == NULL) {
 		diag_set(OutOfMemory, size, "lsregion_alloc", "mem_stmt");
 		return NULL;
 	}
+
+	if (type == IPROTO_UPSERT) {
+		*(uint8_t *)mem_stmt = 0;
+		mem_stmt = (struct tuple *)((uint8_t *)mem_stmt + 1);
+	}
+
 	memcpy(mem_stmt, stmt, size);
 	/*
 	 * Region allocated statements can't be referenced or unreferenced
@@ -269,13 +282,8 @@ vy_stmt_new_upsert(struct tuple_format *format, const char *tuple_begin,
 	 * memory.
 	 */
 	assert(format->extra_size == sizeof(uint8_t));
-	struct tuple *upsert =
-		vy_stmt_new_with_ops(format, tuple_begin, tuple_end,
-				     operations, ops_cnt, IPROTO_UPSERT);
-	if (upsert == NULL)
-		return NULL;
-	vy_stmt_set_n_upserts(upsert, 0);
-	return upsert;
+	return vy_stmt_new_with_ops(format, tuple_begin, tuple_end,
+				    operations, ops_cnt, IPROTO_UPSERT);
 }
 
 struct tuple *
diff --git a/src/box/vy_stmt.h b/src/box/vy_stmt.h
index a33739d6..8958adb5 100644
--- a/src/box/vy_stmt.h
+++ b/src/box/vy_stmt.h
@@ -146,23 +146,28 @@ vy_stmt_set_type(struct tuple *stmt, enum iproto_type type)
 	((struct vy_stmt *) stmt)->type = type;
 }
 
-/** Get upserts count of the vinyl statement. */
+/**
+ * Get upserts count of the vinyl statement.
+ * Only for UPSERT statements allocated on lsregion.
+ */
 static inline uint8_t
 vy_stmt_n_upserts(const struct tuple *stmt)
 {
-	assert(tuple_format(stmt)->extra_size == sizeof(uint8_t));
-	return *((const uint8_t *) tuple_extra(stmt));
+	assert(stmt->refs == 0);
+	assert(vy_stmt_type(stmt) == IPROTO_UPSERT);
+	return *((uint8_t *)stmt - 1);
 }
 
-/** Set upserts count of the vinyl statement. */
+/**
+ * Set upserts count of the vinyl statement.
+ * Only for UPSERT statements allocated on lsregion.
+ */
 static inline void
 vy_stmt_set_n_upserts(struct tuple *stmt, uint8_t n)
 {
-	struct tuple_format *format = tuple_format(stmt);
-	assert(format->extra_size == sizeof(uint8_t));
-	char *extra = (char *) stmt + stmt->data_offset -
-		      tuple_format_meta_size(format);
-	*((uint8_t *) extra) = n;
+	assert(stmt->refs == 0);
+	assert(vy_stmt_type(stmt) == IPROTO_UPSERT);
+	*((uint8_t *)stmt - 1) = n;
 }
 
 /** Get the column mask of the specified tuple. */
-- 
2.11.0

  reply	other threads:[~2018-03-30 15:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30 15:47 [PATCH 0/2] vinyl: zap upsert_format Vladimir Davydov
2018-03-30 15:47 ` Vladimir Davydov [this message]
2018-04-02 10:27   ` [tarantool-patches] Re: [PATCH 1/2] vinyl: allocate upsert counter on lsregion v.shpilevoy
2018-04-02 10:50     ` Vladimir Davydov
2018-03-30 15:47 ` [PATCH 2/2] vinyl: zap upsert_format Vladimir Davydov
2018-04-02 10:58   ` v.shpilevoy
2018-04-02 11:06     ` 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=ca46913dc043b385a9e2e6eb0c1fd2ddba42029c.1522423771.git.vdavydov.dev@gmail.com \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [PATCH 1/2] vinyl: allocate upsert counter on lsregion' \
    /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