sds-keyval.h 3.92 KB
Newer Older
1
2
#include <mercury.h>
#include <mercury_macros.h>
Rob Latham's avatar
Rob Latham committed
3
4
#include <mercury_proc_string.h>

5
6
7
8
9
10
11
12
13
14
15
16
17
#include <margo.h>
#include <abt.h>
#include <abt-snoozer.h>

#if defined(__cplusplus)
extern "C" {
#endif

#if 0
sdskeyval_put();
sdskeyval_get();
#endif

Rob Latham's avatar
Rob Latham committed
18
19
20
21
typedef int kv_id;

typedef enum {
	KV_INT,
22
	KV_UINT,
Rob Latham's avatar
Rob Latham committed
23
24
	KV_FLOAT,
	KV_DOUBLE,
25
	KV_STRING,
26
	KV_BULK,
Rob Latham's avatar
Rob Latham committed
27
28
} kv_type;

29
30
31
32
33
34
typedef enum {
  KV_ALLOWDUPKEY   = 0x0001,
  KV_IGNOREDUPKEY  = 0x0002,
  KV_ERASEONGETKEY = 0x0004,
} kv_options;

35
36
37
38
39
/* do we need one for server, one for client? */
typedef struct kv_context_s {
	margo_instance_id mid;
	hg_addr_t svr_addr;
	hg_id_t put_id;
40
	hg_id_t bulk_put_id;
41
	hg_id_t get_id;
42
	hg_id_t bulk_get_id;
43
44
	hg_id_t open_id;
	hg_id_t close_id;
45
	hg_id_t bench_id;
46
	hg_id_t shutdown_id;
47
	hg_handle_t put_handle;
48
        hg_handle_t bulk_put_handle; // necessary?
49
	hg_handle_t get_handle;
50
	hg_handle_t bulk_get_handle; // necessary?
51
	hg_handle_t bench_handle;
52
	hg_handle_t shutdown_handle;
Rob Latham's avatar
Rob Latham committed
53
54
55
56
	/* some keyval dodad goes here so the server can discriminate.  Seems
	 * like it should be some universal identifier we can share with other
	 * clients */
	kv_id kv;
57
58
59

} kv_context;

Rob Latham's avatar
Rob Latham committed
60
61
62
/* struggling a bit with types.  We'll need to create one of these for every
 * type? */

63
MERCURY_GEN_PROC(put_in_t,
Rob Latham's avatar
Rob Latham committed
64
65
		((int32_t)(key))\
		((int32_t)(value)) )
David Rich's avatar
David Rich committed
66
MERCURY_GEN_PROC(put_out_t, ((int32_t)(ret)) )
Rob Latham's avatar
Rob Latham committed
67
68
DECLARE_MARGO_RPC_HANDLER(put_handler)

69
MERCURY_GEN_PROC(get_in_t,
Rob Latham's avatar
Rob Latham committed
70
71
		((int32_t)(key)) )
MERCURY_GEN_PROC(get_out_t,
David Rich's avatar
David Rich committed
72
		((int32_t)(value)) ((int32_t)(ret)) )
Rob Latham's avatar
Rob Latham committed
73
74
DECLARE_MARGO_RPC_HANDLER(get_handler)

75
MERCURY_GEN_PROC(open_in_t,
76
77
78
		 ((hg_string_t)(name))		\
		 ((uint32_t) (keytype))		\
		 ((uint32_t) (valtype)))
David Rich's avatar
David Rich committed
79
MERCURY_GEN_PROC(open_out_t, ((int32_t)(ret)))
Rob Latham's avatar
Rob Latham committed
80
DECLARE_MARGO_RPC_HANDLER(open_handler)
81
82

MERCURY_GEN_PROC(close_in_t,
83
84
		 ((int32_t)(x))			\
		 ((int32_t)(y)) )
David Rich's avatar
David Rich committed
85
MERCURY_GEN_PROC(close_out_t, ((int32_t)(ret)) )
Rob Latham's avatar
Rob Latham committed
86
DECLARE_MARGO_RPC_HANDLER(close_handler)
87

88
MERCURY_GEN_PROC(bench_in_t, ((int32_t)(count)) )
Rob Latham's avatar
Rob Latham committed
89
90
91
92
93
94
95
96
97
98
99
100
101

typedef struct {
    size_t nkeys;
    double insert_time;
    double read_time;
    double overhead;
} bench_result;

static inline hg_return_t hg_proc_bench_result( hg_proc_t proc, bench_result *result)
{
    /* TODO: needs a portable encoding */
    return(hg_proc_memcpy(proc, result, sizeof(*result))) ;
}
102

Rob Latham's avatar
Rob Latham committed
103
DECLARE_MARGO_RPC_HANDLER(bench_handler)
Rob Latham's avatar
Rob Latham committed
104
MERCURY_GEN_PROC(bench_out_t, ((bench_result)(result)) )
105

David Rich's avatar
David Rich committed
106
107
108
109
110
// for handling bulk puts/gets (e.g. for ParSplice use case)
MERCURY_GEN_PROC(bulk_put_in_t,
		 ((uint64_t)(key))		\
		 ((uint64_t)(size))		\
		 ((hg_bulk_t)(bulk_handle)) )
David Rich's avatar
David Rich committed
111
MERCURY_GEN_PROC(bulk_put_out_t, ((int32_t)(ret)))
David Rich's avatar
David Rich committed
112
113
114
115
116
117
DECLARE_MARGO_RPC_HANDLER(bulk_put_handler)

MERCURY_GEN_PROC(bulk_get_in_t,
		 ((uint64_t)(key))		\
		 ((uint64_t)(size))		\
		 ((hg_bulk_t)(bulk_handle)) )
David Rich's avatar
David Rich committed
118
119
MERCURY_GEN_PROC(bulk_get_out_t,
		 ((uint64_t)(size))		\
David Rich's avatar
David Rich committed
120
		 ((int32_t)(ret)))
David Rich's avatar
David Rich committed
121
122
DECLARE_MARGO_RPC_HANDLER(bulk_get_handler)

David Rich's avatar
David Rich committed
123

124
kv_context *kv_client_register(const char *addr_str=0);
125
kv_context * kv_server_register(margo_instance_id mid);
126

127
128
DECLARE_MARGO_RPC_HANDLER(shutdown_handler)

David Rich's avatar
David Rich committed
129
130
DECLARE_MARGO_RPC_HANDLER(shutdown_handler)

131
/* both the same: should probably move to common */
132
133
hg_return_t kv_client_deregister(kv_context *context);
hg_return_t kv_server_deregister(kv_context *context);
134

135
/* server-side routine */
136
hg_return_t kv_server_wait_for_shutdown(kv_context *context);
137

Rob Latham's avatar
Rob Latham committed
138
/* client-side routines wrapping up all the RPC stuff  */
David Rich's avatar
David Rich committed
139
hg_return_t kv_client_signal_shutdown(kv_context *context);
140
hg_return_t kv_open(kv_context *context, const char *server, const char *db_name,
David Rich's avatar
David Rich committed
141
		    kv_type keytype, kv_type valtype);
142
hg_return_t kv_put(kv_context *context, void *key, void *value);
David Rich's avatar
David Rich committed
143
hg_return_t kv_bulk_put(kv_context *context, void *key, void *data, uint64_t *data_size);
144
hg_return_t kv_get(kv_context *context, void *key, void *value);
David Rich's avatar
David Rich committed
145
hg_return_t kv_bulk_get(kv_context *context, void *key, void *data, uint64_t *data_size);
146
hg_return_t kv_close(kv_context *context);
Rob Latham's avatar
Rob Latham committed
147
bench_result *kv_benchmark(kv_context *context, int count);
148
149
150
151
152

#if defined(__cplusplus)
}
#endif