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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "dbstore_mgr.h"
#include <dbstore.h>
#include <dbstore_log.h>
using namespace std;
using namespace rgw::store;
using DB = rgw::store::DB;
struct thr_args {
DB *dbs;
int thr_id;
};
void* process(void *arg)
{
struct thr_args *t_args = (struct thr_args*)arg;
DB *db = t_args->dbs;
int thr_id = t_args->thr_id;
int ret = -1;
cout<<"Entered thread:"<<thr_id<<"\n";
string user1 = "User1";
string bucketa = "rgw";
string objecta1 = "bugfixing";
string objecta2 = "zipper";
string bucketb = "gluster";
string objectb1 = "bugfixing";
string objectb2 = "delegations";
string user2 = "User2";
string bucketc = "qe";
string objectc1 = "rhhi";
string objectc2 = "cns";
DBOpParams params = {};
const DoutPrefixProvider *dpp = db->get_def_dpp();
db->InitializeParams(dpp, ¶ms);
params.op.user.uinfo.display_name = user1;
params.op.user.uinfo.user_id.tenant = "tenant";
params.op.user.uinfo.user_id.id = user1;
params.op.user.uinfo.suspended = 123;
params.op.user.uinfo.max_buckets = 456;
params.op.user.uinfo.placement_tags.push_back("tags1");
params.op.user.uinfo.placement_tags.push_back("tags2");
RGWAccessKey k1("id1", "key1");
RGWAccessKey k2("id2", "key2");
params.op.user.uinfo.access_keys.insert(make_pair("key1", k1));
params.op.user.uinfo.access_keys.insert(make_pair("key2", k2));
ret = db->ProcessOp(dpp, "InsertUser", ¶ms);
cout << "InsertUser return value: " << ret << "\n";
DBOpParams params2 = {};
params.op.user.uinfo.user_id.tenant = "tenant2";
db->InitializeParams(dpp, ¶ms2);
params2.op.user.uinfo.display_name = user1;
ret = db->ProcessOp(dpp, "GetUser", ¶ms2);
cout << "GetUser return value: " << ret << "\n";
cout << "tenant: " << params2.op.user.uinfo.user_id.tenant << "\n";
cout << "suspended: " << (int)params2.op.user.uinfo.suspended << "\n";
list<string>::iterator it = params2.op.user.uinfo.placement_tags.begin();
while (it != params2.op.user.uinfo.placement_tags.end()) {
cout << "list = " << *it << "\n";
it++;
}
map<string, RGWAccessKey>::iterator it2 = params2.op.user.uinfo.access_keys.begin();
while (it2 != params2.op.user.uinfo.access_keys.end()) {
cout << "keys = " << it2->first << "\n";
RGWAccessKey k = it2->second;
cout << "id = " << k.id << ", keys = " << k.key << "\n";
it2++;
}
params.op.bucket.info.bucket.name = bucketa;
db->ProcessOp(dpp, "InsertBucket", ¶ms);
params.op.user.uinfo.display_name = user2;
params.op.user.uinfo.user_id.id = user2;
db->ProcessOp(dpp, "InsertUser", ¶ms);
params.op.bucket.info.bucket.name = bucketb;
db->ProcessOp(dpp, "InsertBucket", ¶ms);
db->ProcessOp(dpp, "GetUser", ¶ms);
db->ProcessOp(dpp, "GetBucket", ¶ms);
db->ListAllUsers(dpp, ¶ms);
db->ListAllBuckets(dpp, ¶ms);
params.op.bucket.info.bucket.name = bucketb;
db->ProcessOp(dpp, "RemoveBucket", ¶ms);
params.op.user.uinfo.user_id.id = user2;
db->ProcessOp(dpp, "RemoveUser", ¶ms);
db->ListAllUsers(dpp, ¶ms);
db->ListAllBuckets(dpp, ¶ms);
cout<<"Exiting thread:"<<thr_id<<"\n";
return 0;
}
int main(int argc, char *argv[])
{
string tenant = "Redhat";
string logfile = "rgw_dbstore_bin.log";
int loglevel = 20;
DBStoreManager *dbsm;
DB *dbs;
int rc = 0, tnum = 0;
void *res;
pthread_attr_t attr;
int num_thr = 2;
pthread_t threads[num_thr];
struct thr_args t_args[num_thr];
cout << "loglevel " << loglevel << "\n";
// format: ./dbstore-bin logfile loglevel
if (argc == 3) {
logfile = argv[1];
loglevel = (atoi)(argv[2]);
cout << "loglevel set to " << loglevel << "\n";
}
vector<const char*> args;
auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
CODE_ENVIRONMENT_DAEMON, CINIT_FLAG_NO_MON_CONFIG, 1);
dbsm = new DBStoreManager(cct.get(), logfile, loglevel);
dbs = dbsm->getDB(tenant, true);
cout<<"No. of threads being created = "<<num_thr<<"\n";
/* Initialize thread creation attributes */
rc = pthread_attr_init(&attr);
if (rc != 0) {
cout<<" error in pthread_attr_init \n";
goto out;
}
for (tnum = 0; tnum < num_thr; tnum++) {
t_args[tnum].dbs = dbs;
t_args[tnum].thr_id = tnum;
rc = pthread_create((pthread_t*)&threads[tnum], &attr, &process,
&t_args[tnum]);
if (rc != 0) {
cout<<" error in pthread_create \n";
goto out;
}
cout<<"Created thread (thread-id:"<<tnum<<")\n";
}
/* Destroy the thread attributes object, since it is no
longer needed */
rc = pthread_attr_destroy(&attr);
if (rc != 0) {
cout<<"error in pthread_attr_destroy \n";
}
/* Now join with each thread, and display its returned value */
for (tnum = 0; tnum < num_thr; tnum++) {
rc = pthread_join(threads[tnum], &res);
if (rc != 0) {
cout<<"error in pthread_join \n";
} else {
cout<<"Joined with thread "<<tnum<<"\n";
}
}
out:
dbsm->destroyAllHandles();
return 0;
}
|