| 1 | /* |
| 2 | * truncate.h |
| 3 | * |
| 4 | * Copyright (C) 2017 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 | #pragma once |
| 24 | |
| 25 | //========================================================== |
| 26 | // Includes. |
| 27 | // |
| 28 | |
| 29 | #include <stdbool.h> |
| 30 | #include <stdint.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | #include "cf_mutex.h" |
| 34 | #include "shash.h" |
| 35 | |
| 36 | |
| 37 | //========================================================== |
| 38 | // Forward declarations. |
| 39 | // |
| 40 | |
| 41 | struct as_index_s; |
| 42 | struct as_namespace_s; |
| 43 | |
| 44 | |
| 45 | //========================================================== |
| 46 | // Typedefs & constants. |
| 47 | // |
| 48 | |
| 49 | #define MAX_TRUNCATE_THREADS 128 |
| 50 | |
| 51 | typedef enum { |
| 52 | TRUNCATE_IDLE, |
| 53 | TRUNCATE_RUNNING, |
| 54 | TRUNCATE_RESTART |
| 55 | } truncate_state; |
| 56 | |
| 57 | typedef struct as_truncate_s { |
| 58 | uint64_t lut; |
| 59 | cf_shash* startup_set_hash; // relevant only for enterprise edition |
| 60 | truncate_state state; |
| 61 | cf_mutex state_lock; |
| 62 | uint32_t n_threads_running; |
| 63 | uint32_t pid; |
| 64 | uint64_t n_records_this_run; |
| 65 | uint64_t n_records; |
| 66 | } as_truncate; |
| 67 | |
| 68 | |
| 69 | //========================================================== |
| 70 | // Public API. |
| 71 | // |
| 72 | |
| 73 | void as_truncate_init(struct as_namespace_s* ns); |
| 74 | void as_truncate_init_smd(); |
| 75 | void as_truncate_list_cenotaphs(struct as_namespace_s* ns); |
| 76 | bool as_truncate_lut_is_truncated(uint64_t rec_lut, struct as_namespace_s* ns, const char* set_name, uint32_t set_name_len); |
| 77 | void as_truncate_done_startup(struct as_namespace_s* ns); |
| 78 | bool as_truncate_cmd(const char* ns_name, const char* set_name, const char* lut_str); |
| 79 | bool as_truncate_undo_cmd(const char* ns_name, const char* set_name); |
| 80 | bool as_truncate_now_is_truncated(struct as_namespace_s* ns, uint16_t set_id); |
| 81 | bool as_truncate_record_is_truncated(const struct as_index_s* r, struct as_namespace_s* ns); |
| 82 | |
| 83 | |
| 84 | //========================================================== |
| 85 | // For enterprise separation only. |
| 86 | // |
| 87 | |
| 88 | typedef struct truncate_hval_s { |
| 89 | uint64_t cenotaph:1; |
| 90 | uint64_t unused:23; |
| 91 | uint64_t lut:40; |
| 92 | } truncate_hval; |
| 93 | |
| 94 | void truncate_startup_hash_init(struct as_namespace_s* ns); |
| 95 | void truncate_action_startup(struct as_namespace_s* ns, const char* set_name, uint64_t lut); |
| 96 | |