From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 2/6] Merge sysview_index.[hc] and sysview_engine.[hc] Date: Fri, 20 Jul 2018 20:43:31 +0300 Message-Id: <4e8cd4e1c3a64080d61eda881e8401226cbc79b5.1532107326.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: They are fairly small and closely related so let's merge them and call the result sysview.[hc]. --- src/box/CMakeLists.txt | 3 +- src/box/box.cc | 2 +- src/box/{sysview_index.c => sysview.c} | 175 +++++++++++++++++++++++++++++-- src/box/{sysview_engine.h => sysview.h} | 16 +-- src/box/sysview_engine.c | 177 -------------------------------- src/box/sysview_index.h | 60 ----------- 6 files changed, 174 insertions(+), 259 deletions(-) rename src/box/{sysview_index.c => sysview.c} (71%) rename src/box/{sysview_engine.h => sysview.h} (84%) delete mode 100644 src/box/sysview_engine.c delete mode 100644 src/box/sysview_index.h diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index f4899091..fabeb3fd 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -68,8 +68,7 @@ add_library(box STATIC engine.c memtx_engine.c memtx_space.c - sysview_engine.c - sysview_index.c + sysview.c vinyl.c vy_stmt.c vy_mem.c diff --git a/src/box/box.cc b/src/box/box.cc index b07eefa8..9c3f87f0 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -50,7 +50,7 @@ #include "schema.h" #include "engine.h" #include "memtx_engine.h" -#include "sysview_engine.h" +#include "sysview.h" #include "vinyl.h" #include "space.h" #include "index.h" diff --git a/src/box/sysview_index.c b/src/box/sysview.c similarity index 71% rename from src/box/sysview_index.c rename to src/box/sysview.c index 309618ca..fb4ecf2d 100644 --- a/src/box/sysview_index.c +++ b/src/box/sysview.c @@ -28,17 +28,41 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include "sysview_index.h" -#include "sysview_engine.h" +#include "sysview.h" + +#include +#include +#include +#include #include -#include "fiber.h" + +#include "diag.h" +#include "error.h" +#include "errcode.h" #include "schema.h" #include "sequence.h" #include "space.h" +#include "index.h" +#include "engine.h" #include "func.h" #include "tuple.h" #include "session.h" +typedef bool (*sysview_filter_f)(struct space *, struct tuple *); + +struct sysview_engine { + struct engine base; + /** Memory pool for index iterator. */ + struct mempool iterator_pool; +}; + +struct sysview_index { + struct index base; + uint32_t source_space_id; + uint32_t source_index_id; + sysview_filter_f filter; +}; + struct sysview_iterator { struct iterator base; struct iterator *source; @@ -182,6 +206,55 @@ static const struct index_vtab sysview_index_vtab = { /* .end_build = */ generic_index_end_build, }; +static void +sysview_space_destroy(struct space *space) +{ + free(space); +} + +static int +sysview_space_execute_replace(struct space *space, struct txn *txn, + struct request *request, struct tuple **result) +{ + (void)txn; + (void)request; + (void)result; + diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); + return -1; +} + +static int +sysview_space_execute_delete(struct space *space, struct txn *txn, + struct request *request, struct tuple **result) +{ + (void)txn; + (void)request; + (void)result; + diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); + return -1; +} + +static int +sysview_space_execute_update(struct space *space, struct txn *txn, + struct request *request, struct tuple **result) +{ + (void)txn; + (void)request; + (void)result; + diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); + return -1; +} + +static int +sysview_space_execute_upsert(struct space *space, struct txn *txn, + struct request *request) +{ + (void)txn; + (void)request; + diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); + return -1; +} + /* * System view filters. * Filter gives access to an object, if one of the following conditions is true: @@ -329,12 +402,12 @@ vsequence_filter(struct space *source, struct tuple *tuple) ((PRIV_WRDA | PRIV_X) & effective); } -struct sysview_index * -sysview_index_new(struct sysview_engine *sysview, - struct index_def *def, const char *space_name) +static struct index * +sysview_space_create_index(struct space *space, struct index_def *def) { assert(def->type == TREE); + struct sysview_engine *sysview = (struct sysview_engine *)space->engine; if (!mempool_is_initialized(&sysview->iterator_pool)) { mempool_create(&sysview->iterator_pool, cord_slab_cache(), sizeof(struct sysview_iterator)); @@ -377,7 +450,7 @@ sysview_index_new(struct sysview_engine *sysview, break; default: diag_set(ClientError, ER_MODIFY_INDEX, - def->name, space_name, + def->name, space_name(space), "unknown space for system view"); return NULL; } @@ -398,5 +471,91 @@ sysview_index_new(struct sysview_engine *sysview, index->source_space_id = source_space_id; index->source_index_id = source_index_id; index->filter = filter; - return index; + return &index->base; +} + +static const struct space_vtab sysview_space_vtab = { + /* .destroy = */ sysview_space_destroy, + /* .bsize = */ generic_space_bsize, + /* .apply_initial_join_row = */ generic_space_apply_initial_join_row, + /* .execute_replace = */ sysview_space_execute_replace, + /* .execute_delete = */ sysview_space_execute_delete, + /* .execute_update = */ sysview_space_execute_update, + /* .execute_upsert = */ sysview_space_execute_upsert, + /* .init_system_space = */ generic_init_system_space, + /* .check_index_def = */ generic_space_check_index_def, + /* .create_index = */ sysview_space_create_index, + /* .add_primary_key = */ generic_space_add_primary_key, + /* .drop_primary_key = */ generic_space_drop_primary_key, + /* .check_format = */ generic_space_check_format, + /* .build_index = */ generic_space_build_index, + /* .swap_index = */ generic_space_swap_index, + /* .prepare_alter = */ generic_space_prepare_alter, +}; + +static void +sysview_engine_shutdown(struct engine *engine) +{ + struct sysview_engine *sysview = (struct sysview_engine *)engine; + if (mempool_is_initialized(&sysview->iterator_pool)) + mempool_destroy(&sysview->iterator_pool); + free(engine); +} + +static struct space * +sysview_engine_create_space(struct engine *engine, struct space_def *def, + struct rlist *key_list) +{ + struct space *space = (struct space *)calloc(1, sizeof(*space)); + if (space == NULL) { + diag_set(OutOfMemory, sizeof(*space), + "malloc", "struct space"); + return NULL; + } + if (space_create(space, engine, &sysview_space_vtab, + def, key_list, NULL) != 0) { + free(space); + return NULL; + } + return space; +} + +static const struct engine_vtab sysview_engine_vtab = { + /* .shutdown = */ sysview_engine_shutdown, + /* .create_space = */ sysview_engine_create_space, + /* .join = */ generic_engine_join, + /* .begin = */ generic_engine_begin, + /* .begin_statement = */ generic_engine_begin_statement, + /* .prepare = */ generic_engine_prepare, + /* .commit = */ generic_engine_commit, + /* .rollback_statement = */ generic_engine_rollback_statement, + /* .rollback = */ generic_engine_rollback, + /* .bootstrap = */ generic_engine_bootstrap, + /* .begin_initial_recovery = */ generic_engine_begin_initial_recovery, + /* .begin_final_recovery = */ generic_engine_begin_final_recovery, + /* .end_recovery = */ generic_engine_end_recovery, + /* .begin_checkpoint = */ generic_engine_begin_checkpoint, + /* .wait_checkpoint = */ generic_engine_wait_checkpoint, + /* .commit_checkpoint = */ generic_engine_commit_checkpoint, + /* .abort_checkpoint = */ generic_engine_abort_checkpoint, + /* .collect_garbage = */ generic_engine_collect_garbage, + /* .backup = */ generic_engine_backup, + /* .memory_stat = */ generic_engine_memory_stat, + /* .reset_stat = */ generic_engine_reset_stat, + /* .check_space_def = */ generic_engine_check_space_def, +}; + +struct sysview_engine * +sysview_engine_new(void) +{ + struct sysview_engine *sysview = calloc(1, sizeof(*sysview)); + if (sysview == NULL) { + diag_set(OutOfMemory, sizeof(*sysview), + "malloc", "struct sysview_engine"); + return NULL; + } + + sysview->base.vtab = &sysview_engine_vtab; + sysview->base.name = "sysview"; + return sysview; } diff --git a/src/box/sysview_engine.h b/src/box/sysview.h similarity index 84% rename from src/box/sysview_engine.h rename to src/box/sysview.h index fd4ca351..e27ab05f 100644 --- a/src/box/sysview_engine.h +++ b/src/box/sysview.h @@ -1,5 +1,5 @@ -#ifndef TARANTOOL_BOX_SYSVIEW_ENGINE_H_INCLUDED -#define TARANTOOL_BOX_SYSVIEW_ENGINE_H_INCLUDED +#ifndef TARANTOOL_BOX_SYSVIEW_H_INCLUDED +#define TARANTOOL_BOX_SYSVIEW_H_INCLUDED /* * Copyright 2010-2016, Tarantool AUTHORS, please see AUTHORS file. * @@ -30,19 +30,13 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include - -#include "engine.h" +#include #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ -struct sysview_engine { - struct engine base; - /** Memory pool for index iterator. */ - struct mempool iterator_pool; -}; +struct sysview_engine; struct sysview_engine * sysview_engine_new(void); @@ -63,4 +57,4 @@ sysview_engine_new_xc(void) #endif /* defined(__plusplus) */ -#endif /* TARANTOOL_BOX_SYSVIEW_ENGINE_H_INCLUDED */ +#endif /* TARANTOOL_BOX_SYSVIEW_H_INCLUDED */ diff --git a/src/box/sysview_engine.c b/src/box/sysview_engine.c deleted file mode 100644 index f2f27381..00000000 --- a/src/box/sysview_engine.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2010-2016, Tarantool AUTHORS, please see AUTHORS file. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include "sysview_engine.h" -#include "sysview_index.h" -#include "schema.h" -#include "space.h" - -static void -sysview_space_destroy(struct space *space) -{ - free(space); -} - -static int -sysview_space_execute_replace(struct space *space, struct txn *txn, - struct request *request, struct tuple **result) -{ - (void)txn; - (void)request; - (void)result; - diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); - return -1; -} - -static int -sysview_space_execute_delete(struct space *space, struct txn *txn, - struct request *request, struct tuple **result) -{ - (void)txn; - (void)request; - (void)result; - diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); - return -1; -} - -static int -sysview_space_execute_update(struct space *space, struct txn *txn, - struct request *request, struct tuple **result) -{ - (void)txn; - (void)request; - (void)result; - diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); - return -1; -} - -static int -sysview_space_execute_upsert(struct space *space, struct txn *txn, - struct request *request) -{ - (void)txn; - (void)request; - diag_set(ClientError, ER_VIEW_IS_RO, space->def->name); - return -1; -} - -static struct index * -sysview_space_create_index(struct space *space, struct index_def *index_def) -{ - struct sysview_engine *sysview = (struct sysview_engine *)space->engine; - return (struct index *)sysview_index_new(sysview, index_def, - space_name(space)); -} - -static const struct space_vtab sysview_space_vtab = { - /* .destroy = */ sysview_space_destroy, - /* .bsize = */ generic_space_bsize, - /* .apply_initial_join_row = */ generic_space_apply_initial_join_row, - /* .execute_replace = */ sysview_space_execute_replace, - /* .execute_delete = */ sysview_space_execute_delete, - /* .execute_update = */ sysview_space_execute_update, - /* .execute_upsert = */ sysview_space_execute_upsert, - /* .init_system_space = */ generic_init_system_space, - /* .check_index_def = */ generic_space_check_index_def, - /* .create_index = */ sysview_space_create_index, - /* .add_primary_key = */ generic_space_add_primary_key, - /* .drop_primary_key = */ generic_space_drop_primary_key, - /* .check_format = */ generic_space_check_format, - /* .build_index = */ generic_space_build_index, - /* .swap_index = */ generic_space_swap_index, - /* .prepare_alter = */ generic_space_prepare_alter, -}; - -static void -sysview_engine_shutdown(struct engine *engine) -{ - struct sysview_engine *sysview = (struct sysview_engine *)engine; - if (mempool_is_initialized(&sysview->iterator_pool)) - mempool_destroy(&sysview->iterator_pool); - free(engine); -} - -static struct space * -sysview_engine_create_space(struct engine *engine, struct space_def *def, - struct rlist *key_list) -{ - struct space *space = (struct space *)calloc(1, sizeof(*space)); - if (space == NULL) { - diag_set(OutOfMemory, sizeof(*space), - "malloc", "struct space"); - return NULL; - } - if (space_create(space, engine, &sysview_space_vtab, - def, key_list, NULL) != 0) { - free(space); - return NULL; - } - return space; -} - -static const struct engine_vtab sysview_engine_vtab = { - /* .shutdown = */ sysview_engine_shutdown, - /* .create_space = */ sysview_engine_create_space, - /* .join = */ generic_engine_join, - /* .begin = */ generic_engine_begin, - /* .begin_statement = */ generic_engine_begin_statement, - /* .prepare = */ generic_engine_prepare, - /* .commit = */ generic_engine_commit, - /* .rollback_statement = */ generic_engine_rollback_statement, - /* .rollback = */ generic_engine_rollback, - /* .bootstrap = */ generic_engine_bootstrap, - /* .begin_initial_recovery = */ generic_engine_begin_initial_recovery, - /* .begin_final_recovery = */ generic_engine_begin_final_recovery, - /* .end_recovery = */ generic_engine_end_recovery, - /* .begin_checkpoint = */ generic_engine_begin_checkpoint, - /* .wait_checkpoint = */ generic_engine_wait_checkpoint, - /* .commit_checkpoint = */ generic_engine_commit_checkpoint, - /* .abort_checkpoint = */ generic_engine_abort_checkpoint, - /* .collect_garbage = */ generic_engine_collect_garbage, - /* .backup = */ generic_engine_backup, - /* .memory_stat = */ generic_engine_memory_stat, - /* .reset_stat = */ generic_engine_reset_stat, - /* .check_space_def = */ generic_engine_check_space_def, -}; - -struct sysview_engine * -sysview_engine_new(void) -{ - struct sysview_engine *sysview = calloc(1, sizeof(*sysview)); - if (sysview == NULL) { - diag_set(OutOfMemory, sizeof(*sysview), - "malloc", "struct sysview_engine"); - return NULL; - } - - sysview->base.vtab = &sysview_engine_vtab; - sysview->base.name = "sysview"; - return sysview; -} diff --git a/src/box/sysview_index.h b/src/box/sysview_index.h deleted file mode 100644 index 74f57d4b..00000000 --- a/src/box/sysview_index.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef TARANTOOL_BOX_SYSVIEW_INDEX_H_INCLUDED -#define TARANTOOL_BOX_SYSVIEW_INDEX_H_INCLUDED -/* - * Copyright 2010-2016, Tarantool AUTHORS, please see AUTHORS file. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include "index.h" - -#if defined(__cplusplus) -extern "C" { -#endif /* defined(__cplusplus) */ - -struct space; -struct tuple; -struct sysview_engine; - -typedef bool (*sysview_filter_f)(struct space *source, struct tuple *); - -struct sysview_index { - struct index base; - uint32_t source_space_id; - uint32_t source_index_id; - sysview_filter_f filter; -}; - -struct sysview_index * -sysview_index_new(struct sysview_engine *sysview, - struct index_def *def, const char *space_name); - -#if defined(__cplusplus) -} /* extern "C" */ -#endif /* defined(__cplusplus) */ - -#endif /* TARANTOOL_BOX_SYSVIEW_INDEX_H_INCLUDED */ -- 2.11.0