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-2017 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 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /******************************************************************************
26  * MACROS
27  *****************************************************************************/
28 
29 /**
30  * Maximum namespace size including null byte. Effective maximum length is 31.
31  */
32 #define AS_MAX_NAMESPACE_SIZE 32
33 
34 /******************************************************************************
35  * TYPES
36  *****************************************************************************/
37 
38 /**
39  * @private
40  * Map of namespace data partitions to nodes.
41  */
42 typedef struct as_partition_s {
43  /**
44  * @private
45  * Master node for this partition.
46  */
48 
49  /**
50  * @private
51  * Prole node for this partition.
52  * TODO - not ideal for replication factor > 2.
53  */
55 
56  /**
57  * @private
58  * Currrent regime for CP mode.
59  */
60  uint32_t regime;
61 } as_partition;
62 
63 /**
64  * @private
65  * Map of namespace to data partitions.
66  */
67 typedef struct as_partition_table_s {
68  /**
69  * @private
70  * Namespace
71  */
73 
74  /**
75  * @private
76  * Is namespace running in CP mode.
77  */
78  bool cp_mode;
79  char pad[3];
80 
81  /**
82  * @private
83  * Fixed length of partition array.
84  */
85  uint32_t size;
86 
87  /**
88  * @private
89  * Array of partitions for a given namespace.
90  */
91  as_partition partitions[];
93 
94 /**
95  * @private
96  * Reference counted array of partition table pointers.
97  */
98 typedef struct as_partition_tables_s {
99  /**
100  * @private
101  * Reference count of partition table array.
102  */
103  uint32_t ref_count;
104 
105  /**
106  * @private
107  * Length of partition table array.
108  */
109  uint32_t size;
110 
111  /**
112  * @private
113  * Partition table array.
114  */
117 
118 /******************************************************************************
119  * FUNCTIONS
120  ******************************************************************************/
121 
122 /**
123  * @private
124  * Create reference counted structure containing partition tables.
125  */
127 as_partition_tables_create(uint32_t capacity);
128 
129 /**
130  * @private
131  * Destroy and release memory for partition table.
132  */
133 void
135 
136 /**
137  * @private
138  * Get partition table given namespace.
139  */
141 as_partition_tables_get(as_partition_tables* tables, const char* ns);
142 
143 /**
144  * @private
145  * Is node referenced in any partition table.
146  */
147 bool
149 
150 /**
151  * @private
152  * Return partition ID given digest.
153  */
154 static inline uint32_t
155 as_partition_getid(const uint8_t* digest, uint32_t n_partitions)
156 {
157  return (*(uint16_t*)digest) & (n_partitions - 1);
158 }
159 
160 #ifdef __cplusplus
161 } // end extern "C"
162 #endif
as_namespace ns
Definition: as_scan.h:380
as_node * master
Definition: as_partition.h:47
as_node * prole
Definition: as_partition.h:54
void as_partition_table_destroy(as_partition_table *table)
uint32_t regime
Definition: as_partition.h:60
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:155
#define AS_MAX_NAMESPACE_SIZE
Definition: as_partition.h:32
as_partition_tables * as_partition_tables_create(uint32_t capacity)