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-2023 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_atomic.h>
20 #include <aerospike/as_std.h>
21 #include <aerospike/as_status.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /******************************************************************************
28  * MACROS
29  *****************************************************************************/
30 
31 /**
32  * If the server removes then adds namespaces, the client may contain more
33  * than the server max of 32.
34  */
35 #define AS_MAX_NAMESPACES 128
36 
37 /**
38  * Maximum namespace size including null byte. Effective maximum length is 31.
39  */
40 #define AS_MAX_NAMESPACE_SIZE 32
41 
42 /**
43  * Maximum number of stored replicas in partition map.
44  */
45 #define AS_MAX_REPLICATION_FACTOR 3
46 
47 /******************************************************************************
48  * TYPES
49  *****************************************************************************/
50 struct as_node_s;
51 struct as_cluster_s;
52 struct as_error_s;
53 struct as_key_s;
54 
55 /**
56  * @private
57  * Map of namespace data partitions to nodes.
58  */
59 typedef struct as_partition_s {
60  struct as_node_s* nodes[AS_MAX_REPLICATION_FACTOR];
61  uint32_t regime;
62 } as_partition;
63 
64 /**
65  * @private
66  * Map of namespace to data partitions.
67  */
68 typedef struct as_partition_table_s {
70  uint32_t size;
71  uint8_t replica_size; // replication-factor on server.
72  bool sc_mode;
73  char pad[2];
74  as_partition partitions[];
76 
77 /**
78  * @private
79  * Array of partition table pointers.
80  */
81 typedef struct as_partition_tables_s {
83  uint32_t size;
85 
86 /**
87  * @private
88  * Partition info.
89  */
90 typedef struct as_partition_info_s {
91  const char* ns;
92  void* partition; // as_partition or as_shm_partition.
93  uint32_t partition_id;
94  uint8_t replica_size;
95  bool sc_mode;
97 
98 /******************************************************************************
99  * FUNCTIONS
100  ******************************************************************************/
101 
102 /**
103  * @private
104  * Destroy partition tables.
105  */
106 void
108 
109 /**
110  * @private
111  * Get partition table given namespace.
112  */
114 as_partition_tables_get(as_partition_tables* tables, const char* ns);
115 
116 /**
117  * @private
118  * Return partition ID given digest.
119  */
120 static inline uint32_t
121 as_partition_getid(const uint8_t* digest, uint32_t n_partitions)
122 {
123  return (*(uint16_t*)digest) & (n_partitions - 1);
124 }
125 
126 /**
127  * @private
128  * Initialize partition info given key. If this function succeeds and not using shared memory,
129  * as_partition_tables_release() must be called when done with partition.
130  */
131 as_status
133  as_partition_info* pi, struct as_cluster_s* cluster, struct as_error_s* err,
134  const struct as_key_s* key
135  );
136 
137 /**
138  * @private
139  * Log all partition maps in the cluster.
140  */
141 void
142 as_partition_tables_dump(struct as_cluster_s* cluster);
143 
144 #ifdef __cplusplus
145 } // end extern "C"
146 #endif
uint32_t partition_id
Definition: as_partition.h:93
as_namespace ns
Definition: as_scan.h:267
as_status
Definition: as_status.h:30
void as_partition_tables_dump(struct as_cluster_s *cluster)
#define AS_MAX_REPLICATION_FACTOR
Definition: as_partition.h:45
void as_partition_tables_destroy(as_partition_tables *tables)
const char * ns
Definition: as_partition.h:91
as_status as_partition_info_init(as_partition_info *pi, struct as_cluster_s *cluster, struct as_error_s *err, const struct as_key_s *key)
#define AS_MAX_NAMESPACES
Definition: as_partition.h:35
uint32_t regime
Definition: as_partition.h:61
as_partition_table * as_partition_tables_get(as_partition_tables *tables, const char *ns)
static uint32_t as_partition_getid(const uint8_t *digest, uint32_t n_partitions)
Definition: as_partition.h:121
uint8_t replica_size
Definition: as_partition.h:94
#define AS_MAX_NAMESPACE_SIZE
Definition: as_partition.h:40