diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/rgw/driver/dbstore/dbstore_main.cc | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/rgw/driver/dbstore/dbstore_main.cc')
-rw-r--r-- | src/rgw/driver/dbstore/dbstore_main.cc | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/src/rgw/driver/dbstore/dbstore_main.cc b/src/rgw/driver/dbstore/dbstore_main.cc new file mode 100644 index 000000000..4fff38ced --- /dev/null +++ b/src/rgw/driver/dbstore/dbstore_main.cc @@ -0,0 +1,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; +} |