From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH v2 1/8] vinyl: allocate key parts in vy_recovery_do_create_lsm
Date: Sun, 27 May 2018 22:05:49 +0300 [thread overview]
Message-ID: <f1478ed23f84b13bff0c8bc9bed4a82806e65de2.1527446023.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1527446023.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1527446023.git.vdavydov.dev@gmail.com>
Allocation of vy_lsm_recovery_info::key_parts is a part of the struct
initialization, which is handled by vy_recovery_do_create_lsm().
---
src/box/vy_log.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/src/box/vy_log.c b/src/box/vy_log.c
index 4d561354..bdf9eee3 100644
--- a/src/box/vy_log.c
+++ b/src/box/vy_log.c
@@ -1254,19 +1254,35 @@ vy_recovery_lookup_slice(struct vy_recovery *recovery, int64_t slice_id)
*/
static struct vy_lsm_recovery_info *
vy_recovery_do_create_lsm(struct vy_recovery *recovery, int64_t id,
- uint32_t space_id, uint32_t index_id)
+ uint32_t space_id, uint32_t index_id,
+ const struct key_part_def *key_parts,
+ uint32_t key_part_count)
{
+ if (key_parts == NULL) {
+ diag_set(ClientError, ER_INVALID_VYLOG_FILE,
+ tt_sprintf("Missing key definition for LSM tree %lld",
+ (long long)id));
+ return NULL;
+ }
struct vy_lsm_recovery_info *lsm = malloc(sizeof(*lsm));
if (lsm == NULL) {
diag_set(OutOfMemory, sizeof(*lsm),
"malloc", "struct vy_lsm_recovery_info");
return NULL;
}
+ lsm->key_parts = malloc(sizeof(*key_parts) * key_part_count);
+ if (lsm->key_parts == NULL) {
+ diag_set(OutOfMemory, sizeof(*key_parts) * key_part_count,
+ "malloc", "struct key_part_def");
+ free(lsm);
+ return NULL;
+ }
struct mh_i64ptr_t *h = recovery->lsm_hash;
struct mh_i64ptr_node_t node = { id, lsm };
struct mh_i64ptr_node_t *old_node = NULL;
if (mh_i64ptr_put(h, &node, &old_node, NULL) == mh_end(h)) {
diag_set(OutOfMemory, 0, "mh_i64ptr_put", "mh_i64ptr_node_t");
+ free(lsm->key_parts);
free(lsm);
return NULL;
}
@@ -1274,8 +1290,8 @@ vy_recovery_do_create_lsm(struct vy_recovery *recovery, int64_t id,
lsm->id = id;
lsm->space_id = space_id;
lsm->index_id = index_id;
- lsm->key_parts = NULL;
- lsm->key_part_count = 0;
+ memcpy(lsm->key_parts, key_parts, sizeof(*key_parts) * key_part_count);
+ lsm->key_part_count = key_part_count;
lsm->create_lsn = -1;
lsm->modify_lsn = -1;
lsm->drop_lsn = -1;
@@ -1306,12 +1322,6 @@ vy_recovery_create_lsm(struct vy_recovery *recovery, int64_t id,
uint32_t key_part_count, int64_t create_lsn,
int64_t modify_lsn, int64_t dump_lsn)
{
- if (key_parts == NULL) {
- diag_set(ClientError, ER_INVALID_VYLOG_FILE,
- tt_sprintf("Missing key definition for LSM tree %lld",
- (long long)id));
- return -1;
- }
if (vy_recovery_lookup_lsm(recovery, id) != NULL) {
diag_set(ClientError, ER_INVALID_VYLOG_FILE,
tt_sprintf("Duplicate LSM tree id %lld",
@@ -1326,18 +1336,11 @@ vy_recovery_create_lsm(struct vy_recovery *recovery, int64_t id,
(unsigned)space_id, (unsigned)index_id));
return -1;
}
- lsm = vy_recovery_do_create_lsm(recovery, id, space_id, index_id);
+ lsm = vy_recovery_do_create_lsm(recovery, id, space_id, index_id,
+ key_parts, key_part_count);
if (lsm == NULL)
return -1;
- lsm->key_parts = malloc(sizeof(*key_parts) * key_part_count);
- if (lsm->key_parts == NULL) {
- diag_set(OutOfMemory, sizeof(*key_parts) * key_part_count,
- "malloc", "struct key_part_def");
- return -1;
- }
- memcpy(lsm->key_parts, key_parts, sizeof(*key_parts) * key_part_count);
- lsm->key_part_count = key_part_count;
lsm->create_lsn = create_lsn;
lsm->modify_lsn = modify_lsn;
lsm->dump_lsn = dump_lsn;
--
2.11.0
next prev parent reply other threads:[~2018-05-27 19:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-27 19:05 [PATCH v2 0/8] Allow to build indexes for vinyl spaces Vladimir Davydov
2018-05-27 19:05 ` Vladimir Davydov [this message]
2018-05-30 11:51 ` [PATCH v2 1/8] vinyl: allocate key parts in vy_recovery_do_create_lsm Konstantin Osipov
2018-05-27 19:05 ` [PATCH v2 2/8] vinyl: update recovery context with records written during recovery Vladimir Davydov
2018-05-30 11:51 ` Konstantin Osipov
2018-05-27 19:05 ` [PATCH v2 3/8] vinyl: log new index before WAL write on DDL Vladimir Davydov
2018-06-06 18:01 ` Konstantin Osipov
2018-05-27 19:05 ` [PATCH v2 4/8] vinyl: bump mem version after committing statement Vladimir Davydov
2018-06-07 5:41 ` Konstantin Osipov
2018-05-27 19:05 ` [PATCH v2 5/8] vinyl: allow to commit statements to mem in arbitrary order Vladimir Davydov
2018-06-07 5:41 ` Konstantin Osipov
2018-05-27 19:05 ` [PATCH v2 6/8] vinyl: relax limitation imposed on run min/max lsn Vladimir Davydov
2018-05-27 19:05 ` [PATCH v2 7/8] vinyl: factor out vy_check_is_unique_secondary Vladimir Davydov
2018-05-27 19:05 ` [PATCH v2 8/8] vinyl: allow to build secondary index for non-empty space 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=f1478ed23f84b13bff0c8bc9bed4a82806e65de2.1527446023.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH v2 1/8] vinyl: allocate key parts in vy_recovery_do_create_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