1/*
2 * fabric.h
3 *
4 * Copyright (C) 2008-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 <stddef.h>
31#include <stdint.h>
32
33#include "citrusleaf/alloc.h"
34
35#include "msg.h"
36#include "node.h"
37#include "socket.h"
38#include "tls.h"
39
40
41//==========================================================
42// Forward declarations.
43//
44
45struct as_endpoint_list_s;
46struct as_hb_plugin_node_data_s;
47
48
49//==========================================================
50// Typedefs & constants.
51//
52
53#define AS_FABRIC_SUCCESS (0)
54#define AS_FABRIC_ERR_UNKNOWN (-1) // used by transact
55#define AS_FABRIC_ERR_NO_NODE (-3)
56#define AS_FABRIC_ERR_TIMEOUT (-6) // used by transact
57
58typedef enum {
59 AS_FABRIC_CHANNEL_RW = 0, // duplicate resolution and replica writes
60 AS_FABRIC_CHANNEL_CTRL = 1, // clustering, migration ctrl and services info
61 AS_FABRIC_CHANNEL_BULK = 2, // migrate records
62 AS_FABRIC_CHANNEL_META = 3, // smd
63
64 AS_FABRIC_N_CHANNELS
65} as_fabric_channel;
66
67#define MAX_FABRIC_CHANNEL_THREADS 128
68#define MAX_FABRIC_CHANNEL_SOCKETS 128
69
70typedef struct fabric_rate_s {
71 uint64_t s_bytes[AS_FABRIC_N_CHANNELS];
72 uint64_t r_bytes[AS_FABRIC_N_CHANNELS];
73} fabric_rate;
74
75typedef int (*as_fabric_msg_fn) (cf_node node_id, msg *m, void *udata);
76typedef int (*as_fabric_transact_recv_fn) (cf_node node_id, msg *m, void *transact_data, void *udata);
77typedef int (*as_fabric_transact_complete_fn) (msg *rsp, void *udata, int err);
78
79
80//==========================================================
81// Globals.
82//
83
84extern cf_serv_cfg g_fabric_bind;
85extern cf_tls_info *g_fabric_tls;
86
87
88//==========================================================
89// Public API.
90//
91
92//------------------------------------------------
93// msg
94//
95
96void as_fabric_msg_queue_dump(void);
97
98static inline msg *
99as_fabric_msg_get(msg_type type)
100{
101 // Never returns NULL. Will assert if type is not registered.
102 return msg_create(type);
103}
104
105static inline void
106as_fabric_msg_put(msg *m)
107{
108 if (cf_rc_release(m) == 0) {
109 msg_reset(m);
110 msg_put(m);
111 }
112}
113
114//------------------------------------------------
115// as_fabric
116//
117
118void as_fabric_init(void);
119void as_fabric_start(void);
120void as_fabric_set_recv_threads(as_fabric_channel channel, uint32_t count);
121int as_fabric_send(cf_node node_id, msg *m, as_fabric_channel channel);
122int as_fabric_send_list(const cf_node *nodes, uint32_t node_count, msg *m, as_fabric_channel channel);
123int as_fabric_retransmit(cf_node node_id, msg *m, as_fabric_channel channel);
124void as_fabric_register_msg_fn(msg_type type, const msg_template *mt, size_t mt_sz, size_t scratch_sz, as_fabric_msg_fn msg_cb, void *msg_udata);
125void as_fabric_info_peer_endpoints_get(cf_dyn_buf *db);
126bool as_fabric_is_published_endpoint_list(const struct as_endpoint_list_s *list);
127struct as_endpoint_list_s *as_fabric_hb_plugin_get_endpoint_list(struct as_hb_plugin_node_data_s *plugin_data);
128void as_fabric_rate_capture(fabric_rate *rate);
129void as_fabric_dump(bool verbose);
130