]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/store/dbstore/dbstore_mgr.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rgw / store / dbstore / dbstore_mgr.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <map>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <string>
10 #include <stdio.h>
11 #include <iostream>
12 #include "common/ceph_context.h"
13 #include "common/dbstore.h"
14 #include "sqlite/sqliteDB.h"
15
16 using namespace std;
17 using namespace rgw::store;
18 using DB = rgw::store::DB;
19
20 /* XXX: Should be a dbstore config option */
21 const static string default_tenant = "default_ns";
22
23 using namespace std;
24
25 class DBStoreManager {
26 private:
27 map<string, DB*> DBStoreHandles;
28 DB *default_db = NULL;
29 CephContext *cct;
30
31 public:
32 DBStoreManager(CephContext *_cct): DBStoreHandles() {
33 cct = _cct;
34 default_db = createDB(default_tenant);
35 };
36 DBStoreManager(string logfile, int loglevel): DBStoreHandles() {
37 /* No ceph context. Create one with log args provided */
38 vector<const char*> args;
39 cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
40 CODE_ENVIRONMENT_DAEMON, CINIT_FLAG_NO_MON_CONFIG, 1)->get();
41 cct->_log->set_log_file(logfile);
42 cct->_log->reopen_log_file();
43 cct->_conf->subsys.set_log_level(ceph_subsys_rgw, loglevel);
44 };
45 ~DBStoreManager() { destroyAllHandles(); };
46
47 /* XXX: TBD based on testing
48 * 1) Lock to protect DBStoreHandles map.
49 * 2) Refcount of each DBStore to protect from
50 * being deleted while using it.
51 */
52 DB* getDB () { return default_db; };
53 DB* getDB (string tenant, bool create);
54 DB* createDB (string tenant);
55 void deleteDB (string tenant);
56 void deleteDB (DB* db);
57 void destroyAllHandles();
58 };