All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_partition.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <aerospike/as_node.h>
20 #include <citrusleaf/cf_digest.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /******************************************************************************
27  * MACROS
28  *****************************************************************************/
29 
30 /**
31  * Maximum namespace size including null byte. Effective maximum length is 31.
32  */
33 #define AS_MAX_NAMESPACE_SIZE 32
34 
35 /******************************************************************************
36  * TYPES
37  *****************************************************************************/
38 
39 /**
40  * @private
41  * Map of namespace data partitions to nodes.
42  */
43 typedef struct as_partition_s {
44  /**
45  * @private
46  * Master node for this partition.
47  */
49 
50  /**
51  * @private
52  * Prole node for this partition.
53  * TODO - not ideal for replication factor > 2.
54  */
56 } as_partition;
57 
58 /**
59  * @private
60  * Map of namespace to data partitions.
61  */
62 typedef struct as_partition_table_s {
63  /**
64  * @private
65  * Namespace
66  */
68 
69  /**
70  * @private
71  * Fixed length of partition array.
72  */
73  uint32_t size;
74 
75  /**
76  * @private
77  * Array of partitions for a given namespace.
78  */
79  as_partition partitions[];
81 
82 /**
83  * @private
84  * Reference counted array of partition table pointers.
85  */
86 typedef struct as_partition_tables_s {
87  /**
88  * @private
89  * Reference count of partition table array.
90  */
91  uint32_t ref_count;
92 
93  /**
94  * @private
95  * Length of partition table array.
96  */
97  uint32_t size;
98 
99  /**
100  * @private
101  * Partition table array.
102  */
105 
106 /******************************************************************************
107  * FUNCTIONS
108  ******************************************************************************/
109 
110 /**
111  * @private
112  * Create reference counted structure containing partition tables.
113  */
115 as_partition_tables_create(uint32_t capacity);
116 
117 /**
118  * @private
119  * Destroy and release memory for partition table.
120  */
121 void
123 
124 /**
125  * @private
126  * Get partition table given namespace.
127  */
129 as_partition_tables_get(as_partition_tables* tables, const char* ns);
130 
131 /**
132  * @private
133  * Is node referenced in any partition table.
134  */
135 bool
137 
138 /**
139  * @private
140  * Return partition ID given digest.
141  */
142 static inline uint32_t
143 as_partition_getid(const uint8_t* digest, uint32_t n_partitions)
144 {
145  return (*(uint16_t*)digest) & (n_partitions - 1);
146 }
147 
148 #ifdef __cplusplus
149 } // end extern "C"
150 #endif
as_namespace ns
Definition: as_scan.h:345
as_node * master
Definition: as_partition.h:48
as_node * prole
Definition: as_partition.h:55
void as_partition_table_destroy(as_partition_table *table)
as_partition_table * as_partition_tables_get(as_partition_tables *tables, const char *ns)
bool as_partition_tables_find_node(as_partition_tables *tables, as_node *node)
static uint32_t as_partition_getid(const uint8_t *digest, uint32_t n_partitions)
Definition: as_partition.h:143
#define AS_MAX_NAMESPACE_SIZE
Definition: as_partition.h:33
as_partition_tables * as_partition_tables_create(uint32_t capacity)