[tarantool-patches] [PATCH v4 06/20] refactoring: remove exceptions from schema_find_grants

Ilya Kosarev i.kosarev at tarantool.org
Mon Sep 23 18:56:57 MSK 2019


schema_find_grants is used in some triggers therefore it has to be
cleared from exceptions. Now it doesn't throw any more.
It's usages are updated.

Part of #4247
---
 src/box/alter.cc  | 18 +++++++++++++++---
 src/box/schema.cc | 28 ++++++++++++++++++++++------
 src/box/schema.h  |  8 ++++----
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 85304c47d..8d565e189 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -2026,7 +2026,11 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event)
 				  "the space has indexes");
 			return -1;
 		}
-		if (schema_find_grants("space", old_space->def->id)) {
+		bool out;
+		if (schema_find_grants("space", old_space->def->id, &out) != 0) {
+			return -1;
+		}
+		if (out) {
 			diag_set(ClientError, ER_DROP_SPACE,
 				  space_name(old_space),
 				  "the space has grants");
@@ -3048,7 +3052,11 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event)
 				 PRIV_D) != 0)
 			return -1;
 		/* Can only delete func if it has no grants. */
-		if (schema_find_grants("function", old_func->def->fid)) {
+		bool out;
+		if (schema_find_grants("function", old_func->def->fid, &out) != 0) {
+			return -1;
+		}
+		if (out) {
 			diag_set(ClientError, ER_DROP_FUNCTION,
 				  (unsigned) old_func->def->uid,
 				  "function has grants");
@@ -3938,7 +3946,11 @@ on_replace_dd_sequence(struct trigger * /* trigger */, void *event)
 				  seq->def->name, "the sequence is in use");
 			return -1;
 		}
-		if (schema_find_grants("sequence", seq->def->id)) {
+		bool out;
+		if (schema_find_grants("sequence", seq->def->id, &out) != 0) {
+			return -1;
+		}
+		if (out) {
 			diag_set(ClientError, ER_DROP_SEQUENCE,
 				  seq->def->name, "the sequence has grants");
 			return -1;
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 8d8aae448..9767207e0 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -599,12 +599,22 @@ func_by_name(const char *name, uint32_t name_len)
 	return (struct func *) mh_strnptr_node(funcs_by_name, func)->val;
 }
 
-bool
-schema_find_grants(const char *type, uint32_t id)
+int
+schema_find_grants(const char *type, uint32_t id, bool *out)
 {
-	struct space *priv = space_cache_find_xc(BOX_PRIV_ID);
+	struct space *priv = space_cache_find(BOX_PRIV_ID);
+	if (priv == NULL)
+		return -1;
+
 	/** "object" index */
-	struct index *index = index_find_system_xc(priv, 2);
+	if (!space_is_memtx(priv)) {
+		diag_set(ClientError, ER_UNSUPPORTED,
+			 priv->engine->name, "system data");
+		return -1;
+	}
+	struct index *index = index_find(priv, 2);
+	if (index == NULL)
+		return -1;
 	/*
 	 * +10 = max(mp_sizeof_uint32) +
 	 *       max(mp_sizeof_strl(uint32)).
@@ -612,9 +622,15 @@ schema_find_grants(const char *type, uint32_t id)
 	char key[GRANT_NAME_MAX + 10];
 	assert(strlen(type) <= GRANT_NAME_MAX);
 	mp_encode_uint(mp_encode_str(key, type, strlen(type)), id);
-	struct iterator *it = index_create_iterator_xc(index, ITER_EQ, key, 2);
+	struct iterator *it = index_create_iterator(index, ITER_EQ, key, 2);
+	if (it == NULL)
+		return -1;
 	IteratorGuard iter_guard(it);
-	return iterator_next_xc(it);
+	struct tuple *tuple;
+	if (iterator_next(it, &tuple) != 0)
+		return -1;
+	*out = (tuple != NULL);
+	return 0;
 }
 
 struct sequence *
diff --git a/src/box/schema.h b/src/box/schema.h
index f9d15b38d..66555ab14 100644
--- a/src/box/schema.h
+++ b/src/box/schema.h
@@ -185,11 +185,11 @@ func_cache_find(uint32_t fid)
  * Check whether or not an object has grants on it (restrict
  * constraint in drop object).
  * _priv space to look up by space id
- * @retval true object has grants
- * @retval false object has no grants
+ * @retval (bool *out) true object has grants
+ * @retval (bool *out) false object has no grants
  */
-bool
-schema_find_grants(const char *type, uint32_t id);
+int
+schema_find_grants(const char *type, uint32_t id, bool *out);
 
 /**
  * A wrapper around sequence_by_id() that raises an exception
-- 
2.17.1





More information about the Tarantool-patches mailing list