Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_node.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2008-2014 by Aerospike.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to
6
* deal in the Software without restriction, including without limitation the
7
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
* sell copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
* IN THE SOFTWARE.
21
*****************************************************************************/
22
#pragma once
23
24
#include <
aerospike/as_vector.h
>
25
#include <citrusleaf/cf_queue.h>
26
#include <netinet/in.h>
27
#include "ck_pr.h"
28
29
/******************************************************************************
30
* MACROS
31
*****************************************************************************/
32
33
/**
34
* Maximum size of node name
35
*/
36
#define AS_NODE_NAME_MAX_SIZE 20
37
38
/******************************************************************************
39
* TYPES
40
*****************************************************************************/
41
42
/**
43
* Socket address information.
44
*/
45
typedef
struct
as_address_s {
46
/**
47
* Socket IP address.
48
*/
49
struct
sockaddr_in addr;
50
51
/**
52
* Socket IP address string representation (xxx.xxx.xxx.xxx).
53
*/
54
char
name[INET_ADDRSTRLEN];
55
}
as_address
;
56
57
struct
as_cluster_s;
58
59
/**
60
* Server node representation.
61
*/
62
typedef
struct
as_node_s {
63
/**
64
* @private
65
* Reference count of node.
66
*/
67
uint32_t
ref_count
;
68
69
/**
70
* @private
71
* Server's generation count for partition management.
72
*/
73
uint32_t
partition_generation
;
74
75
/**
76
* The name of the node.
77
*/
78
char
name[
AS_NODE_NAME_MAX_SIZE
];
79
80
/**
81
* @private
82
* Primary host address index into addresses array.
83
*/
84
uint32_t
address_index
;
85
86
/**
87
* @private
88
* Vector of sockaddr_in which the host is currently known by.
89
* Only used by tend thread. Not thread-safe.
90
*/
91
as_vector
/* <as_address> */
addresses
;
92
93
struct
as_cluster_s*
cluster
;
94
95
/**
96
* @private
97
* Pool of current, cached FDs.
98
*/
99
cf_queue*
conn_q
;
100
101
/**
102
* @private
103
* Socket used exclusively for cluster tend thread info requests.
104
*/
105
int
info_fd
;
106
107
/**
108
* @private
109
* FDs for async command execution. Not currently used.
110
*/
111
// cf_queue* conn_q_asyncfd;
112
113
/**
114
* @private
115
* Asynchronous work queue. Not currently used.
116
*/
117
// cf_queue* asyncwork_q;
118
119
/**
120
* @private
121
* Number of other nodes that consider this node a member of the cluster.
122
*/
123
uint32_t
friends
;
124
125
/**
126
* @private
127
* Number of consecutive info request failures.
128
*/
129
uint32_t
failures
;
130
131
/**
132
* @private
133
* Is node currently active.
134
*/
135
uint8_t
active
;
136
}
as_node
;
137
138
/**
139
* @private
140
* Friend host address information.
141
*/
142
typedef
struct
as_friend_s {
143
/**
144
* @private
145
* Socket IP address string representation (xxx.xxx.xxx.xxx).
146
*/
147
char
name[INET_ADDRSTRLEN];
148
149
/**
150
* @private
151
* Socket IP address.
152
*/
153
in_addr_t
addr
;
154
155
/**
156
* @private
157
* Socket IP port.
158
*/
159
in_port_t
port
;
160
}
as_friend
;
161
162
/******************************************************************************
163
* FUNCTIONS
164
******************************************************************************/
165
166
/**
167
* @private
168
* Create new cluster node.
169
*/
170
as_node
*
171
as_node_create
(
struct
as_cluster_s* cluster,
const
char
* name,
struct
sockaddr_in* addr);
172
173
/**
174
* @private
175
* Close all connections in pool and free resources.
176
*/
177
void
178
as_node_destroy
(
as_node
* node);
179
180
/**
181
* @private
182
* Set node to inactive.
183
*/
184
static
inline
void
185
as_node_deactivate
(
as_node
* node)
186
{
187
// Make volatile write so changes are reflected in other threads.
188
ck_pr_store_8(&node->
active
,
false
);
189
}
190
191
/**
192
* @private
193
* Reserve existing cluster node.
194
*/
195
static
inline
void
196
as_node_reserve
(
as_node
* node)
197
{
198
//ck_pr_fence_acquire();
199
ck_pr_inc_32(&node->
ref_count
);
200
}
201
202
/**
203
* @private
204
* Release existing cluster node.
205
*/
206
static
inline
void
207
as_node_release
(
as_node
* node)
208
{
209
//ck_pr_fence_release();
210
211
bool
destroy;
212
ck_pr_dec_32_zero(&node->
ref_count
, &destroy);
213
214
if
(destroy) {
215
as_node_destroy
(node);
216
}
217
}
218
219
/**
220
* @private
221
* Add socket address to node addresses.
222
*/
223
void
224
as_node_add_address
(
as_node
* node,
struct
sockaddr_in* addr);
225
226
/**
227
* @private
228
* Get socket address and name.
229
*/
230
static
inline
struct
sockaddr_in*
231
as_node_get_address
(
as_node
* node)
232
{
233
as_address
* address = (
as_address
*)
as_vector_get
(&node->
addresses
, node->
address_index
);
234
return
&address->
addr
;
235
}
236
237
/**
238
* Get socket address and name.
239
*/
240
static
inline
as_address
*
241
as_node_get_address_full
(
as_node
* node)
242
{
243
return
(
as_address
*)
as_vector_get
(&node->
addresses
, node->
address_index
);
244
}
245
246
/**
247
* @private
248
* Get a connection to the given node from pool. Return fd on success and -1 on error.
249
*/
250
int
251
as_node_fd_get
(
as_node
* node);
252
253
/**
254
* @private
255
* Put connection back into pool.
256
*/
257
void
258
as_node_fd_put
(
as_node
* node,
int
fd);