| 1 | /* | 
| 2 |  * smd.h | 
| 3 |  * | 
| 4 |  * Copyright (C) 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 | #pragma once | 
| 24 |  | 
| 25 | //========================================================== | 
| 26 | // Includes. | 
| 27 | // | 
| 28 |  | 
| 29 | #include <stdbool.h> | 
| 30 | #include <stdint.h> | 
| 31 |  | 
| 32 | #include "citrusleaf/cf_vector.h" | 
| 33 |  | 
| 34 | #include "dynbuf.h" | 
| 35 |  | 
| 36 |  | 
| 37 | //========================================================== | 
| 38 | // Typedefs & constants. | 
| 39 | // | 
| 40 |  | 
| 41 | // These values are used on the wire - don't change them. | 
| 42 | typedef enum { | 
| 43 | 	AS_SMD_MODULE_EVICT, | 
| 44 | 	AS_SMD_MODULE_ROSTER, | 
| 45 | 	AS_SMD_MODULE_SECURITY, | 
| 46 | 	AS_SMD_MODULE_SINDEX, | 
| 47 | 	AS_SMD_MODULE_TRUNCATE, | 
| 48 | 	AS_SMD_MODULE_UDF, | 
| 49 |  | 
| 50 | 	AS_SMD_NUM_MODULES | 
| 51 | } as_smd_id; | 
| 52 |  | 
| 53 | typedef struct as_smd_item_s { | 
| 54 | 	char* key; | 
| 55 | 	char* value; // NULL means delete | 
| 56 | 	uint64_t timestamp; | 
| 57 | 	uint32_t generation; | 
| 58 | } as_smd_item; | 
| 59 |  | 
| 60 | typedef enum { | 
| 61 | 	AS_SMD_ACCEPT_OPT_START, | 
| 62 | 	AS_SMD_ACCEPT_OPT_SET | 
| 63 | } as_smd_accept_type; | 
| 64 |  | 
| 65 | typedef void (*as_smd_accept_fn)(const cf_vector* items, as_smd_accept_type accept_type); | 
| 66 | // Return false to choose item0, true to choose item1. | 
| 67 | typedef bool (*as_smd_conflict_fn)(const as_smd_item* item0, const as_smd_item* item1); | 
| 68 | typedef void (*as_smd_get_all_fn)(const cf_vector* items, void* udata); | 
| 69 | typedef void (*as_smd_set_fn)(bool result, void* udata); | 
| 70 |  | 
| 71 |  | 
| 72 | //========================================================== | 
| 73 | // Public API. | 
| 74 | // | 
| 75 |  | 
| 76 | void as_smd_module_load(as_smd_id id, as_smd_accept_fn accept_cb, as_smd_conflict_fn conflict_cb, const cf_vector* default_items); | 
| 77 | void as_smd_start(void); | 
| 78 | // timeout 0 is default timeout in msec. | 
| 79 | void as_smd_set(as_smd_id id, const char* key, const char* value, as_smd_set_fn set_cb, void* udata, uint64_t timeout); | 
| 80 | bool as_smd_set_blocking(as_smd_id id, const char* key, const char* value, uint64_t timeout); | 
| 81 | void as_smd_get_all(as_smd_id id, as_smd_get_all_fn cb, void* udata); | 
| 82 | void as_smd_get_info(cf_dyn_buf* db); | 
| 83 |  | 
| 84 | static inline void | 
| 85 | as_smd_set_and_forget(as_smd_id id, const char* key, const char* value) | 
| 86 | { | 
| 87 | 	as_smd_set(id, key, value, NULL, NULL, 0); | 
| 88 | } | 
| 89 |  | 
| 90 | static inline void | 
| 91 | as_smd_delete(as_smd_id id, const char* key, as_smd_set_fn set_cb, void* udata, uint64_t timeout) | 
| 92 | { | 
| 93 | 	as_smd_set(id, key, NULL, set_cb, udata, timeout); | 
| 94 | } | 
| 95 |  | 
| 96 | static inline bool | 
| 97 | as_smd_delete_blocking(as_smd_id id, const char* key, uint64_t timeout) | 
| 98 | { | 
| 99 | 	return as_smd_set_blocking(id, key, NULL, timeout); | 
| 100 | } | 
| 101 |  | 
| 102 | static inline void | 
| 103 | as_smd_delete_and_forget(as_smd_id id, const char* key) | 
| 104 | { | 
| 105 | 	as_smd_set(id, key, NULL, NULL, NULL, 0); | 
| 106 | } | 
| 107 |  |