| 1 | /* |
| 2 | * namespace_ce.c |
| 3 | * |
| 4 | * Copyright (C) 2014-2018 Aerospike, Inc. |
| 5 | * |
| 6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
| 7 | * license agreements. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU Affero General Public License as published by the Free |
| 11 | * Software Foundation, either version 3 of the License, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
| 21 | */ |
| 22 | |
| 23 | //========================================================== |
| 24 | // Includes. |
| 25 | // |
| 26 | |
| 27 | #include <stdbool.h> |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | #include "citrusleaf/alloc.h" |
| 31 | |
| 32 | #include "arenax.h" |
| 33 | #include "fault.h" |
| 34 | #include "vmapx.h" |
| 35 | |
| 36 | #include "base/cfg.h" |
| 37 | #include "base/datamodel.h" |
| 38 | #include "base/index.h" |
| 39 | |
| 40 | |
| 41 | //========================================================== |
| 42 | // Forward declarations. |
| 43 | // |
| 44 | |
| 45 | static void setup_namespace(as_namespace* ns); |
| 46 | |
| 47 | |
| 48 | //========================================================== |
| 49 | // Public API. |
| 50 | // |
| 51 | |
| 52 | void |
| 53 | as_namespace_xmem_shutdown(as_namespace *ns, uint32_t instance) |
| 54 | { |
| 55 | // For enterprise version only. |
| 56 | } |
| 57 | |
| 58 | |
| 59 | //========================================================== |
| 60 | // Private API - for enterprise separation only. |
| 61 | // |
| 62 | |
| 63 | void |
| 64 | as_namespaces_setup(bool cold_start_cmd, uint32_t instance) |
| 65 | { |
| 66 | for (uint32_t i = 0; i < g_config.n_namespaces; i++) { |
| 67 | setup_namespace(g_config.namespaces[i]); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | as_namespace_finish_setup(as_namespace *ns, uint32_t instance) |
| 73 | { |
| 74 | // For enterprise version only. |
| 75 | } |
| 76 | |
| 77 | |
| 78 | //========================================================== |
| 79 | // Local helpers. |
| 80 | // |
| 81 | |
| 82 | static void |
| 83 | setup_namespace(as_namespace* ns) |
| 84 | { |
| 85 | ns->cold_start = true; |
| 86 | |
| 87 | cf_info(AS_NAMESPACE, "{%s} beginning cold start" , ns->name); |
| 88 | |
| 89 | //-------------------------------------------- |
| 90 | // Set up the set name vmap. |
| 91 | // |
| 92 | |
| 93 | ns->p_sets_vmap = (cf_vmapx*)cf_malloc(cf_vmapx_sizeof(sizeof(as_set), AS_SET_MAX_COUNT)); |
| 94 | |
| 95 | cf_vmapx_init(ns->p_sets_vmap, sizeof(as_set), AS_SET_MAX_COUNT, 1024, AS_SET_NAME_MAX_SIZE); |
| 96 | |
| 97 | // Transfer configuration file information about sets. |
| 98 | if (! as_namespace_configure_sets(ns)) { |
| 99 | cf_crash(AS_NAMESPACE, "{%s} can't configure sets" , ns->name); |
| 100 | } |
| 101 | |
| 102 | //-------------------------------------------- |
| 103 | // Set up the bin name vmap. |
| 104 | // |
| 105 | |
| 106 | if (! ns->single_bin) { |
| 107 | ns->p_bin_name_vmap = (cf_vmapx*)cf_malloc(cf_vmapx_sizeof(AS_BIN_NAME_MAX_SZ, MAX_BIN_NAMES)); |
| 108 | |
| 109 | cf_vmapx_init(ns->p_bin_name_vmap, AS_BIN_NAME_MAX_SZ, MAX_BIN_NAMES, 4096, AS_BIN_NAME_MAX_SZ); |
| 110 | } |
| 111 | |
| 112 | //-------------------------------------------- |
| 113 | // Set up the index arena. |
| 114 | // |
| 115 | |
| 116 | ns->arena = (cf_arenax*)cf_malloc(cf_arenax_sizeof()); |
| 117 | ns->tree_shared.arena = ns->arena; |
| 118 | |
| 119 | uint32_t element_size = (uint32_t)sizeof(as_index); |
| 120 | uint32_t stage_capacity = (uint32_t)(ns->index_stage_size / element_size); |
| 121 | |
| 122 | cf_arenax_init(ns->arena, ns->xmem_type, ns->xmem_type_cfg, 0, element_size, 1, stage_capacity, 0, CF_ARENAX_BIGLOCK); |
| 123 | } |
| 124 | |