-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyperput.c
121 lines (106 loc) · 3.49 KB
/
hyperput.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdio.h>
#include <string.h>
#include <hyperclient.h>
const char* coordinator = "127.0.0.1";
uint16_t coordinator_port = 1987;
void hyperput(){
/* create the hyperdex client */
char* space = "datafile1";
char* description = "space datafile1 key offset attributes data";
enum hyperclient_returncode retcode, loop_retcode;
int64_t ret, loop_ret;
struct hyperclient* client = NULL;
client = hyperclient_create(coordinator, coordinator_port);
/* make sure the client is OK */
if (!client) {
fprintf(stderr, "Cannot create hyperdex client.\n");
return;
}
/* remove the old space */
retcode = 0;
retcode = hyperclient_rm_space(client, space);
if (retcode == HYPERCLIENT_SUCCESS)
{
printf("Code: %d, removed old space successfully.\n", retcode);
}else{
fprintf(stderr, "Code %d, failed to remove the old space.\n", retcode);
}
/* add a space */
retcode = 0;
retcode = hyperclient_add_space(client, description);
if (retcode == HYPERCLIENT_SUCCESS) {
printf("Code: %d, created space successfully.\n", retcode);
} else {
fprintf(stderr, "Code %d, failed to create space.\n", retcode);
if (retcode != HYPERCLIENT_DUPLICATE) {
retcode = hyperclient_rm_space(client, space);
hyperclient_destroy(client);
return;
}
}
/* LOOP
*
* In each iteration, we create a key-value pair and put it into
* the key-value store. The value is an attribute
*/
//uint32_t shift = 1024;
uint32_t range = 4*32*1024; //32*1024*1024*np;
size_t request_size = 64; //64*1024
uint64_t offset;
char* key = malloc(64);
size_t key_size;
struct hyperclient_attribute* attribute = malloc(sizeof(struct hyperclient_attribute));
if (attribute) {
attribute->attr = "data";
attribute->value_sz = request_size;
attribute->datatype = HYPERDATATYPE_STRING;
}
char* buf;// = NULL;
offset = 0;
int index = 1;
while (offset < range ) {
/* prepare the key */
memset(key, 0, 64);
sprintf(key, "%ld", offset); /* we use offset as key */
key_size = (size_t)strlen(key);
printf("Key: %s\n", key);
/* prepare the attribute */
buf = (char *) malloc(request_size);
memset(buf, 0, request_size);
if ( (index%2) == 0 ) {
memset(buf, 'b', request_size-1);
} else {
memset(buf, 'a', request_size-1);
}
++index;
attribute->value = buf;
ret = 0; loop_ret = 0;
retcode = 0; loop_retcode = 0;
ret = hyperclient_put(
client, space,
key, key_size,
attribute, 1,
&retcode);
while (loop_ret < ret) {
loop_ret = hyperclient_loop(
client, 5000, &loop_retcode);
}
free(buf);
printf("Ret: %ld\tRetCode: %d\tRet2: %ld\tRetCode2: %d\n", ret, retcode, loop_ret, loop_retcode);
if (loop_retcode == HYPERCLIENT_SUCCESS) {
printf("Put data: %d\n", (int)request_size);
offset += request_size;
} else {
fprintf(stderr, "Code %d: Failed to put data in.\n", loop_retcode);
break;
}
}
/* clean up */
free(key);
free(attribute);
/*Destroy the client at the end.*/
hyperclient_destroy(client);
}
int main(int argc, char* args[]) {
hyperput();
}