From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 6/7] Always store built-in collations in the cache
Date: Thu, 26 Apr 2018 02:29:06 +0300 [thread overview]
Message-ID: <574fe7b8bc787018edaab0b3c8cf572a8f091fd7.1524698920.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1524698920.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1524698920.git.v.shpilevoy@tarantool.org>
To be able to use collations out of box.cfg it is needed to be
sure, that they are available always. Else it can break non-box
collation usage. So when a built-in collation is deleted from
_collation (for example, on box.internal.bootstrap()), it is not
deleted from the cache. When a built-in collation is inserted
into _collation, it does not touch the cache (it already contains
all built-in collations).
---
src/box/alter.cc | 14 ++++++++++++++
src/coll_cache.c | 34 ++++++++++++++++++++++++++++++++++
src/coll_def.c | 7 +++++++
src/coll_def.h | 13 +++++++++++++
4 files changed, 68 insertions(+)
diff --git a/src/box/alter.cc b/src/box/alter.cc
index be2ccc061..39fcc8de4 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -2429,6 +2429,13 @@ on_replace_dd_collation(struct trigger * /* trigger */, void *event)
/* TODO: Check that no index uses the collation */
int32_t old_id = tuple_field_u32_xc(old_tuple,
BOX_COLLATION_FIELD_ID);
+ if (coll_is_system(old_id)) {
+ /*
+ * Built-in collations can be deleted from
+ * _collation, but not from the cache.
+ */
+ return;
+ }
struct coll *old_coll = coll_by_id(old_id);
assert(old_coll != NULL);
access_check_ddl(old_coll->name, old_coll->owner_id,
@@ -2451,6 +2458,13 @@ on_replace_dd_collation(struct trigger * /* trigger */, void *event)
coll_def_new_from_tuple(new_tuple, &new_def);
access_check_ddl(new_def.name, new_def.owner_id, SC_COLLATION,
PRIV_C, false);
+ if (coll_is_system(new_def.id)) {
+ /*
+ * Built-in collation is in the cache
+ * already.
+ */
+ return;
+ }
/*
* Set on_rollback before the collation is
* inserted into the cache. Else if the trigger
diff --git a/src/coll_cache.c b/src/coll_cache.c
index b7eb3edb9..b7fce5aba 100644
--- a/src/coll_cache.c
+++ b/src/coll_cache.c
@@ -45,7 +45,41 @@ coll_cache_init()
"coll_cache_id");
return -1;
}
+ struct coll *replaced, *unicode_coll, *unicode_ci_coll;
+ struct coll_def def;
+ memset(&def, 0, sizeof(def));
+ def.id = COLLATION_ID_UNICODE;
+ def.owner_id = 1;
+ def.name = "unicode";
+ def.name_len = strlen(def.name);
+ def.locale = "";
+ def.type = COLL_TYPE_ICU;
+ unicode_coll = coll_new(&def);
+ if (unicode_coll == NULL)
+ goto err_unicode;
+ if (coll_cache_replace(unicode_coll, &replaced) != 0)
+ goto err_unicode_replace;
+ assert(replaced == NULL);
+
+ def.id = COLLATION_ID_UNICODE_CI;
+ def.name = "unicode_ci";
+ def.name_len = strlen(def.name);
+ def.icu.strength = COLL_ICU_STRENGTH_PRIMARY;
+ unicode_ci_coll = coll_new(&def);
+ if (unicode_ci_coll == NULL)
+ goto err_unicode_ci;
+ if (coll_cache_replace(unicode_ci_coll, &replaced) != 0)
+ goto err_unicode_ci_replace;
return 0;
+err_unicode_ci_replace:
+ coll_delete(unicode_ci_coll);
+err_unicode_ci:
+ coll_cache_delete(unicode_coll);
+err_unicode_replace:
+ coll_delete(unicode_coll);
+err_unicode:
+ mh_i32ptr_delete(coll_cache_id);
+ return -1;
}
/** Delete global hash tables. */
diff --git a/src/coll_def.c b/src/coll_def.c
index f849845b3..0a0ead9a1 100644
--- a/src/coll_def.c
+++ b/src/coll_def.c
@@ -63,6 +63,13 @@ const char *coll_icu_strength_strs[] = {
"IDENTICAL"
};
+bool
+coll_is_system(int coll_id)
+{
+ return coll_id == COLLATION_ID_UNICODE ||
+ coll_id == COLLATION_ID_UNICODE_CI;
+}
+
static int64_t
icu_on_off_from_str(const char *str, uint32_t len)
{
diff --git a/src/coll_def.h b/src/coll_def.h
index 7a1027a1e..e86c546e5 100644
--- a/src/coll_def.h
+++ b/src/coll_def.h
@@ -49,6 +49,19 @@ enum coll_type {
extern const char *coll_type_strs[];
+/** Built-in collations. */
+enum {
+ COLLATION_ID_UNICODE = 1,
+ COLLATION_ID_UNICODE_CI = 2,
+};
+
+/**
+ * Check if a collation is system by its ID. System collations can
+ * not be deleted.
+ */
+bool
+coll_is_system(int coll_id);
+
/*
* ICU collation options. See
* http://icu-project.org/apiref/icu4c/ucol_8h.html#a583fbe7fc4a850e2fcc692e766d2826c
--
2.15.1 (Apple Git-101)
next prev parent reply other threads:[~2018-04-25 23:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-25 23:29 [tarantool-patches] [PATCH 0/7] Expose ICU into Lua Vladislav Shpilevoy
2018-04-25 23:29 ` [tarantool-patches] [PATCH 1/7] lua: expose ICU upper/lower functions to Lua Vladislav Shpilevoy
2018-04-28 0:56 ` [tarantool-patches] " Alexander Turenko
2018-04-25 23:29 ` [tarantool-patches] [PATCH 2/7] lua: implement string.u_count Vladislav Shpilevoy
2018-04-26 10:36 ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-26 16:07 ` Vladislav Shpilevoy
2018-04-26 23:57 ` Vladislav Shpilevoy
2018-04-28 1:10 ` Alexander Turenko
2018-04-25 23:29 ` [tarantool-patches] [PATCH 3/7] alter: fix assertion in collations alter Vladislav Shpilevoy
2018-04-25 23:29 ` [tarantool-patches] [PATCH 4/7] Move struct on_access_denied_ctx into error.h Vladislav Shpilevoy
2018-04-25 23:29 ` [tarantool-patches] [PATCH 5/7] Merge box_error, stat and collations into core library Vladislav Shpilevoy
2018-04-25 23:29 ` Vladislav Shpilevoy [this message]
2018-04-25 23:29 ` [tarantool-patches] [PATCH 7/7] lua: expose u_compare/u_icompare into Lua Vladislav Shpilevoy
2018-04-28 1:55 ` [tarantool-patches] Re: [PATCH 0/7] Expose ICU " Alexander Turenko
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=574fe7b8bc787018edaab0b3c8cf572a8f091fd7.1524698920.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH 6/7] Always store built-in collations in the cache' \
/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