Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
sds-keyval
Commits
dba88b73
Commit
dba88b73
authored
May 03, 2018
by
Matthieu Dorier
Browse files
added path argument to sdskv_provider_add_database
parent
11c4288c
Changes
12
Hide whitespace changes
Inline
Side-by-side
include/sdskv-server.h
View file @
dba88b73
...
...
@@ -39,10 +39,13 @@ int sdskv_provider_register(
sdskv_provider_t
*
provider
);
/**
* Makes the provider start managing a database.
* Makes the provider start managing a database. The database will
* be created if it does not exist. Otherwise, the provider will start
* to manage the existing database.
*
* @param[in] provider provider
* @param[in] db_name name of the database
* @param[in] db_path path where the persistent files of the db should be
* @param[in] db_type type of database
* @param[in] comp_fn comparison function for the database
* @param[out] db_id resulting id identifying the database
...
...
@@ -52,6 +55,7 @@ int sdskv_provider_register(
int
sdskv_provider_add_database
(
sdskv_provider_t
provider
,
const
char
*
db_name
,
const
char
*
db_path
,
sdskv_db_type_t
db_type
,
sdskv_compare_fn
comp_fn
,
sdskv_database_id_t
*
sb_id
);
...
...
src/datastore/berkeleydb_datastore.cc
View file @
dba88b73
...
...
@@ -27,15 +27,11 @@ BerkeleyDBDataStore::~BerkeleyDBDataStore() {
delete
_dbenv
;
};
void
BerkeleyDBDataStore
::
createDatabase
(
std
::
string
db_name
)
{
void
BerkeleyDBDataStore
::
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
db_path
)
{
int
status
=
0
;
// db_name assumed to include the full path (e.g. /var/data/db.dat)
boost
::
filesystem
::
path
path
(
db_name
);
std
::
string
basepath
=
path
.
parent_path
().
string
();
std
::
string
dbname
=
path
.
filename
().
string
();
if
(
!
basepath
.
empty
())
{
boost
::
filesystem
::
create_directories
(
basepath
);
if
(
!
db_path
.
empty
())
{
boost
::
filesystem
::
create_directories
(
db_path
);
}
// initialize the environment
...
...
@@ -80,7 +76,7 @@ void BerkeleyDBDataStore::createDatabase(std::string db_name) {
}
else
{
_dbenv
->
set_lk_detect
(
DB_LOCK_MINWRITE
);
_dbenv
->
open
(
base
path
.
c_str
(),
flags
,
0644
);
_dbenv
->
open
(
db_
path
.
c_str
(),
flags
,
0644
);
}
}
catch
(
DbException
&
e
)
{
...
...
@@ -114,7 +110,7 @@ void BerkeleyDBDataStore::createDatabase(std::string db_name) {
}
else
{
status
=
_dbm
->
open
(
NULL
,
// txn pointer
dbname
.
c_str
(),
// file name
db
_
name
.
c_str
(),
// file name
NULL
,
// logical DB name
DB_BTREE
,
// DB type (e.g. BTREE, HASH)
flags
,
...
...
src/datastore/berkeleydb_datastore.h
View file @
dba88b73
...
...
@@ -27,7 +27,7 @@ class BerkeleyDBDataStore : public AbstractDataStore {
BerkeleyDBDataStore
();
BerkeleyDBDataStore
(
Duplicates
duplicates
,
bool
eraseOnGet
,
bool
debug
);
virtual
~
BerkeleyDBDataStore
();
virtual
void
createDatabase
(
std
::
string
db_name
);
virtual
void
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
);
virtual
bool
put
(
const
ds_bulk_t
&
key
,
const
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
std
::
vector
<
ds_bulk_t
>
&
data
);
...
...
src/datastore/bwtree_datastore.cc
View file @
dba88b73
...
...
@@ -25,7 +25,7 @@ BwTreeDataStore::~BwTreeDataStore() {
#endif
};
void
BwTreeDataStore
::
createDatabase
(
std
::
string
db_name
)
{
void
BwTreeDataStore
::
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
)
{
_tree
=
new
BwTree
<
ds_bulk_t
,
ds_bulk_t
,
ds_bulk_less
,
ds_bulk_equal
,
ds_bulk_hash
,
ds_bulk_equal
,
ds_bulk_hash
>
();
...
...
src/datastore/bwtree_datastore.h
View file @
dba88b73
...
...
@@ -14,7 +14,7 @@ public:
BwTreeDataStore
();
BwTreeDataStore
(
Duplicates
duplicates
,
bool
eraseOnGet
,
bool
debug
);
virtual
~
BwTreeDataStore
();
virtual
void
createDatabase
(
std
::
string
db_name
);
virtual
void
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
);
virtual
bool
put
(
const
ds_bulk_t
&
key
,
const
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
std
::
vector
<
ds_bulk_t
>
&
data
);
...
...
src/datastore/datastore.h
View file @
dba88b73
...
...
@@ -19,7 +19,7 @@ public:
AbstractDataStore
();
AbstractDataStore
(
Duplicates
duplicates
,
bool
eraseOnGet
,
bool
debug
);
virtual
~
AbstractDataStore
();
virtual
void
createDatabase
(
std
::
string
db_name
)
=
0
;
virtual
void
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
)
=
0
;
virtual
bool
put
(
const
ds_bulk_t
&
key
,
const
ds_bulk_t
&
data
)
=
0
;
virtual
bool
get
(
const
ds_bulk_t
&
key
,
ds_bulk_t
&
data
)
=
0
;
virtual
bool
get
(
const
ds_bulk_t
&
key
,
std
::
vector
<
ds_bulk_t
>
&
data
)
=
0
;
...
...
src/datastore/datastore_factory.h
View file @
dba88b73
...
...
@@ -25,36 +25,40 @@
class
datastore_factory
{
static
AbstractDataStore
*
create_map_datastore
(
const
std
::
string
&
name
)
{
static
AbstractDataStore
*
create_map_datastore
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
auto
db
=
new
MapDataStore
();
db
->
createDatabase
(
name
);
db
->
createDatabase
(
name
,
path
);
return
db
;
}
static
AbstractDataStore
*
create_bwtree_datastore
(
const
std
::
string
&
name
)
{
static
AbstractDataStore
*
create_bwtree_datastore
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
#ifdef USE_BWTREE
auto
db
=
new
BwTreeDataStore
();
db
->
createDatabase
(
name
);
db
->
createDatabase
(
name
,
path
);
return
db
;
#else
return
nullptr
;
#endif
}
static
AbstractDataStore
*
create_berkeleydb_datastore
(
const
std
::
string
&
name
)
{
static
AbstractDataStore
*
create_berkeleydb_datastore
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
#ifdef USE_BDB
auto
db
=
new
BerkeleyDBDataStore
();
db
->
createDatabase
(
name
);
db
->
createDatabase
(
name
,
path
);
return
db
;
#else
return
nullptr
;
#endif
}
static
AbstractDataStore
*
create_leveldb_datastore
(
const
std
::
string
&
name
)
{
static
AbstractDataStore
*
create_leveldb_datastore
(
const
std
::
string
&
name
,
const
std
::
string
&
path
)
{
#ifdef USE_LEVELDB
auto
db
=
new
LevelDBDataStore
();
db
->
createDatabase
(
name
);
db
->
createDatabase
(
name
,
path
);
return
db
;
#else
return
nullptr
;
...
...
@@ -64,20 +68,26 @@ class datastore_factory {
public:
#ifdef SDSKV
static
AbstractDataStore
*
create_datastore
(
sdskv_db_type_t
type
,
const
std
::
string
&
name
)
static
AbstractDataStore
*
create_datastore
(
sdskv_db_type_t
type
,
const
std
::
string
&
name
,
const
std
::
string
&
path
)
#else
static
AbstractDataStore
*
create_datastore
(
kv_db_type_t
type
,
const
std
::
string
&
name
=
"db"
)
static
AbstractDataStore
*
create_datastore
(
kv_db_type_t
type
,
const
std
::
string
&
name
=
"db"
,
const
std
::
string
&
path
=
"db"
)
#endif
{
switch
(
type
)
{
case
KVDB_MAP
:
return
create_map_datastore
(
name
);
return
create_map_datastore
(
name
,
path
);
case
KVDB_BWTREE
:
return
create_bwtree_datastore
(
name
);
return
create_bwtree_datastore
(
name
,
path
);
case
KVDB_LEVELDB
:
return
create_leveldb_datastore
(
name
);
return
create_leveldb_datastore
(
name
,
path
);
case
KVDB_BERKELEYDB
:
return
create_berkeleydb_datastore
(
name
);
return
create_berkeleydb_datastore
(
name
,
path
);
}
return
nullptr
;
};
...
...
src/datastore/leveldb_datastore.cc
View file @
dba88b73
...
...
@@ -33,19 +33,19 @@ LevelDBDataStore::~LevelDBDataStore() {
//leveldb::Env::Shutdown(); // Riak version only
};
void
LevelDBDataStore
::
createDatabase
(
std
::
string
db_name
)
{
void
LevelDBDataStore
::
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
db_path
)
{
leveldb
::
Options
options
;
leveldb
::
Status
status
;
// db_name assumed to include the full path (e.g. /var/data/db.dat)
boost
::
filesystem
::
path
p
(
db_name
);
std
::
string
basepath
=
p
.
parent_path
().
string
();
if
(
!
basepath
.
empty
())
{
boost
::
filesystem
::
create_directories
(
basepath
);
if
(
!
db_path
.
empty
())
{
boost
::
filesystem
::
create_directories
(
db_path
);
}
options
.
comparator
=
&
_keycmp
;
options
.
create_if_missing
=
true
;
status
=
leveldb
::
DB
::
Open
(
options
,
db_name
,
&
_dbm
);
std
::
string
fullname
=
db_path
;
if
(
!
fullname
.
empty
())
fullname
+=
std
::
string
(
"/"
);
fullname
+=
db_name
;
status
=
leveldb
::
DB
::
Open
(
options
,
fullname
,
&
_dbm
);
if
(
!
status
.
ok
())
{
// error
...
...
src/datastore/leveldb_datastore.h
View file @
dba88b73
...
...
@@ -39,7 +39,7 @@ class LevelDBDataStore : public AbstractDataStore {
LevelDBDataStore
();
LevelDBDataStore
(
Duplicates
duplicates
,
bool
eraseOnGet
,
bool
debug
);
virtual
~
LevelDBDataStore
();
virtual
void
createDatabase
(
std
::
string
db_name
);
virtual
void
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
);
virtual
bool
put
(
const
ds_bulk_t
&
key
,
const
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
ds_bulk_t
&
data
);
virtual
bool
get
(
const
ds_bulk_t
&
key
,
std
::
vector
<
ds_bulk_t
>
&
data
);
...
...
src/datastore/map_datastore.h
View file @
dba88b73
...
...
@@ -35,7 +35,7 @@ class MapDataStore : public AbstractDataStore {
~
MapDataStore
()
=
default
;
virtual
void
createDatabase
(
std
::
string
db_name
)
{
virtual
void
createDatabase
(
const
std
::
string
&
db_name
,
const
std
::
string
&
path
)
{
_map
.
clear
();
}
...
...
src/sdskv-server-daemon.c
View file @
dba88b73
...
...
@@ -181,7 +181,9 @@ int main(int argc, char **argv)
sdskv_database_id_t
db_id
;
ret
=
sdskv_provider_add_database
(
provider
,
opts
.
db_names
[
i
],
opts
.
db_types
[
i
],
SDSKV_COMPARE_DEFAULT
,
opts
.
db_names
[
i
],
opts
.
db_names
[
i
],
// use the name as path
opts
.
db_types
[
i
],
SDSKV_COMPARE_DEFAULT
,
&
db_id
);
if
(
ret
!=
0
)
...
...
@@ -211,8 +213,10 @@ int main(int argc, char **argv)
for
(
i
=
0
;
i
<
opts
.
num_db
;
i
++
)
{
sdskv_database_id_t
db_id
;
ret
=
sdskv_provider_add_database
(
provider
,
opts
.
db_names
[
i
],
opts
.
db_types
[
i
],
ret
=
sdskv_provider_add_database
(
provider
,
opts
.
db_names
[
i
],
opts
.
db_names
[
i
],
// use the name as path
opts
.
db_types
[
i
],
SDSKV_COMPARE_DEFAULT
,
&
db_id
);
...
...
src/sdskv-server.cc
View file @
dba88b73
...
...
@@ -106,11 +106,13 @@ extern "C" int sdskv_provider_register(
extern
"C"
int
sdskv_provider_add_database
(
sdskv_provider_t
provider
,
const
char
*
db_name
,
const
char
*
db_path
,
sdskv_db_type_t
db_type
,
sdskv_compare_fn
comp_fn
,
sdskv_database_id_t
*
db_id
)
{
auto
db
=
datastore_factory
::
create_datastore
(
db_type
,
std
::
string
(
db_name
));
auto
db
=
datastore_factory
::
create_datastore
(
db_type
,
std
::
string
(
db_name
),
std
::
string
(
db_path
));
if
(
db
==
nullptr
)
return
SDSKV_ERR_DB_CREATE
;
db
->
set_comparison_function
(
comp_fn
);
sdskv_database_id_t
id
=
(
sdskv_database_id_t
)(
db
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment