From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, Vladimir Davydov <vdavydov.dev@gmail.com> Subject: Re: [tarantool-patches] Re: [PATCH v1 1/1] xlog: fix out of static memory on metadata load Date: Fri, 17 Aug 2018 15:39:50 +0300 [thread overview] Message-ID: <7f51f275-0c09-103b-cb8a-207dc3f77420@tarantool.org> (raw) In-Reply-To: <20180817101410.zomayvmosk5cp33j@esperanza> > Too much of code duplication. Please add a helper for key matching. Hi! ok. =========================================== src/box/xlog.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/box/xlog.c b/src/box/xlog.c index 5ed11fc..c870d9d 100644 --- a/src/box/xlog.c +++ b/src/box/xlog.c @@ -183,6 +183,13 @@ parse_vclock(const char *val, const char *val_end, struct vclock *vclock) return 0; } +static inline bool +xlog_meta_key_cmp(const char *key, uint32_t key_len, const char *str, + uint32_t str_len) +{ + return key_len != str_len || memcmp(key, str, key_len); +} + /** * Parse xlog meta from buffer, update buffer read * position in case of success @@ -261,8 +268,11 @@ xlog_meta_parse(struct xlog_meta *meta, const char **data, assert(val <= val_end); pos = eol + 1; - if (memcmp(key, INSTANCE_UUID_KEY, key_end - key) == 0 || - memcmp(key, INSTANCE_UUID_KEY_V12, key_end - key) == 0) { + size_t len = key_end - key; + if (xlog_meta_key_cmp(key, len, INSTANCE_UUID_KEY, + strlen(INSTANCE_UUID_KEY)) == 0 || + xlog_meta_key_cmp(key, len, INSTANCE_UUID_KEY_V12, + strlen(INSTANCE_UUID_KEY_V12)) == 0) { /* * Instance: <uuid> */ @@ -277,19 +287,22 @@ xlog_meta_parse(struct xlog_meta *meta, const char **data, diag_set(XlogError, "can't parse instance UUID"); return -1; } - } else if (memcmp(key, VCLOCK_KEY, key_end - key) == 0){ + } else if (xlog_meta_key_cmp(key, len, VCLOCK_KEY, + strlen(VCLOCK_KEY)) == 0) { /* * VClock: <vclock> */ if (parse_vclock(val, val_end, &meta->vclock) != 0) return -1; - } else if (memcmp(key, PREV_VCLOCK_KEY, key_end - key) == 0) { + } else if (xlog_meta_key_cmp(key, len, PREV_VCLOCK_KEY, + strlen(PREV_VCLOCK_KEY)) == 0) { /* * PrevVClock: <vclock> */ if (parse_vclock(val, val_end, &meta->prev_vclock) != 0) return -1; - } else if (memcmp(key, VERSION_KEY, key_end - key) == 0) { + } else if (xlog_meta_key_cmp(key, len, VERSION_KEY, + strlen(VERSION_KEY)) == 0) { /* Ignore Version: for now */ } else { /* -- 2.7.4
next prev parent reply other threads:[~2018-08-17 12:39 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-15 12:32 Kirill Shcherbatov 2018-08-17 10:14 ` Vladimir Davydov 2018-08-17 12:39 ` Kirill Shcherbatov [this message] 2018-08-17 12:46 ` [tarantool-patches] " Vladimir Davydov 2018-08-17 14:46 ` Kirill Shcherbatov 2018-08-17 15:20 ` 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=7f51f275-0c09-103b-cb8a-207dc3f77420@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [tarantool-patches] Re: [PATCH v1 1/1] xlog: fix out of static memory on metadata load' \ /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