Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
520d9cef
Commit
520d9cef
authored
Jul 20, 2015
by
Tyler Neely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial column family (broken) stubs.
parent
6ca40b78
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
7 deletions
+141
-7
ffi.rs
src/ffi.rs
+20
-1
lib.rs
src/lib.rs
+2
-0
rocksdb.rs
src/rocksdb.rs
+57
-5
test.rs
test/test.rs
+1
-0
test_column_family.rs
test/test_column_family.rs
+57
-0
test_multithreaded.rs
test/test_multithreaded.rs
+4
-1
No files found.
src/ffi.rs
View file @
520d9cef
...
...
@@ -353,9 +353,28 @@ extern {
name_fn
:
extern
fn
(
*
mut
c_void
)
->
*
const
c_char
)
->
RocksDBComparator
;
pub
fn
rocksdb_comparator_destroy
(
cmp
:
RocksDBComparator
);
// Column Family
pub
fn
rocksdb_open_column_families
(
options
:
RocksDBOptions
,
path
:
*
const
i8
,
num_column_families
:
c_int
,
column_family_names
:
*
const
*
const
i8
,
column_family_options
:
*
const
[
RocksDBOptions
],
column_family_handles
:
*
mut
*
const
RocksDBCFHandle
,
err
:
*
mut
*
const
i8
)
->
RocksDBInstance
;
pub
fn
rocksdb_create_column_family
(
db
:
RocksDBInstance
,
column_family_options
:
RocksDBOptions
,
column_family_name
:
*
const
i8
,
err
:
*
mut
*
const
i8
)
->
RocksDBCFHandle
;
pub
fn
rocksdb_drop_column_family
(
db
:
RocksDBInstance
,
column_family_handle
:
*
const
RocksDBCFHandle
,
err
:
*
mut
*
const
i8
);
pub
fn
rocksdb_column_family_handle_destroy
(
column_family_handle
:
*
mut
*
const
RocksDBCFHandle
);
}
#[allow(dead_code)]
#[test]
fn
internal
()
{
unsafe
{
...
...
src/lib.rs
View file @
520d9cef
...
...
@@ -18,7 +18,9 @@
#
!
[
feature
(
libc
)]
#
!
[
feature
(
unique
)]
#
!
[
feature
(
path_ext
)]
#
!
[
feature
(
convert
)]
#
!
[
feature
(
raw
)]
#
!
[
allow
(
dead_code
)]
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
new_bloom_filter
,
RocksDBCompactionStyle
,
RocksDBComparator
};
...
...
src/rocksdb.rs
View file @
520d9cef
...
...
@@ -23,13 +23,13 @@ use std::path::Path;
use
std
::
ptr
::
Unique
;
use
std
::
slice
;
use
std
::
str
::
from_utf8
;
use
std
::
marker
::
PhantomData
;
use
rocksdb_ffi
;
use
rocksdb_options
::
Options
;
pub
struct
RocksDB
{
inner
:
rocksdb_ffi
::
RocksDBInstance
,
cfs
:
Vec
<
rocksdb_ffi
::
RocksDBCFHandle
>
,
}
unsafe
impl
Send
for
RocksDB
{}
...
...
@@ -184,6 +184,10 @@ impl RocksDB {
}
pub
fn
open
(
opts
:
&
Options
,
path
:
&
str
)
->
Result
<
RocksDB
,
String
>
{
RocksDB
::
open_cf
(
opts
,
path
,
vec!
[])
}
pub
fn
open_cf
(
opts
:
&
Options
,
path
:
&
str
,
mut
cfs
:
Vec
<&
str
>
)
->
Result
<
RocksDB
,
String
>
{
let
cpath
=
match
CString
::
new
(
path
.as_bytes
())
{
Ok
(
c
)
=>
c
,
Err
(
_
)
=>
...
...
@@ -203,18 +207,49 @@ impl RocksDB {
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
let
db
:
rocksdb_ffi
::
RocksDBInstance
;
if
cfs
.len
()
==
0
{
unsafe
{
db
=
rocksdb_ffi
::
rocksdb_open
(
opts
.inner
,
cpath_ptr
,
err_ptr
);
}
}
else
{
let
nfam
=
cfs
.len
();
let
mut
cfnames
:
Vec
<*
const
i8
>
=
vec!
[];
let
mut
cfhandles
:
Vec
<
rocksdb_ffi
::
RocksDBCFHandle
>
=
vec!
[];
let
mut
cfopts
:
Vec
<
rocksdb_ffi
::
RocksDBOptions
>
=
vec!
[];
cfs
.push
(
"default"
);
for
name
in
cfs
{
match
CString
::
new
(
name
.as_bytes
())
{
Ok
(
c
)
=>
{
cfnames
.push
(
c
.as_ptr
());
cfhandles
.push
(
rocksdb_ffi
::
RocksDBCFHandle
(
0
as
*
mut
c_void
));
cfopts
.push
(
Options
::
new
()
.inner
);
},
Err
(
_
)
=>
return
Err
(
"Failed to convert path to CString when opening rocksdb"
.to_string
()),
}
};
unsafe
{
println!
(
"1!"
);
println!
(
"nfam: {}"
,
nfam
);
db
=
rocksdb_ffi
::
rocksdb_open_column_families
(
opts
.inner
,
cpath_ptr
,
nfam
as
libc
::
c_int
,
cfnames
.as_slice
()
.as_ptr
(),
cfopts
.as_slice
(),
cfhandles
.as_ptr
()
as
*
mut
*
const
rocksdb_ffi
::
RocksDBCFHandle
,
err_ptr
);
println!
(
"2!"
);
}
}
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
let
rocksdb_ffi
::
RocksDBInstance
(
db_ptr
)
=
db
;
if
db_ptr
.is_null
()
{
if
db
.
0
.is_null
()
{
return
Err
(
"Could not initialize database."
.to_string
());
}
Ok
(
RocksDB
{
inner
:
db
})
Ok
(
RocksDB
{
inner
:
db
,
cfs
:
vec!
[]
})
}
pub
fn
destroy
(
opts
:
&
Options
,
path
:
&
str
)
->
Result
<
(),
String
>
{
...
...
@@ -300,6 +335,24 @@ impl RocksDB {
}
}
pub
fn
create_cf
(
&
mut
self
,
name
:
&
str
,
opts
:
&
Options
)
->
Result
<
(),
String
>
{
let
cname
=
match
CString
::
new
(
name
.as_bytes
())
{
Ok
(
c
)
=>
c
,
Err
(
_
)
=>
return
Err
(
"Failed to convert path to CString when opening rocksdb"
.to_string
()),
};
let
cname_ptr
=
cname
.as_ptr
();
let
mut
err
:
*
const
i8
=
0
as
*
const
i8
;
let
err_ptr
:
*
mut
*
const
i8
=
&
mut
err
;
unsafe
{
rocksdb_ffi
::
rocksdb_create_column_family
(
self
.inner
,
opts
.inner
,
cname_ptr
,
err_ptr
);
}
if
!
err
.is_null
()
{
return
Err
(
error_message
(
err
));
}
Ok
(())
}
pub
fn
iterator
(
&
self
)
->
DBIterator
{
let
opts
=
ReadOptions
::
new
();
DBIterator
::
new
(
&
self
,
&
opts
)
...
...
@@ -546,7 +599,6 @@ impl <T, E> RocksDBResult<T, E> {
}
}
#[allow(dead_code)]
#[test]
fn
external
()
{
let
path
=
"_rust_rocksdb_externaltest"
;
...
...
test/test.rs
View file @
520d9cef
...
...
@@ -2,3 +2,4 @@ extern crate rocksdb;
mod
test_iterator
;
mod
test_multithreaded
;
mod
test_column_family
;
test/test_column_family.rs
0 → 100644
View file @
520d9cef
/*
Copyright 2014 Tyler Neely
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use
rocksdb
::{
Options
,
RocksDB
,
Writable
,
Direction
};
#[test]
pub
fn
test_column_family
()
{
let
path
=
"_rust_rocksdb_cftest"
;
// should be able to create column families
{
let
mut
db
=
RocksDB
::
open_default
(
path
)
.unwrap
();
let
opts
=
Options
::
new
();
match
db
.create_cf
(
"cf1"
,
&
opts
)
{
Ok
(
_
)
=>
println!
(
"cf1 created successfully"
),
Err
(
e
)
=>
{
panic!
(
"could not create column family: {}"
,
e
);
},
}
}
// should fail to open db without specifying same column families
{
match
RocksDB
::
open_default
(
path
)
{
Ok
(
_
)
=>
panic!
(
"should not have opened DB successfully without specifying column
families"
),
Err
(
e
)
=>
assert
!
(
e
.starts_with
(
"Invalid argument: You have to open all column families."
)),
}
}
// should properly open db when specyfing all column families
{
match
RocksDB
::
open_cf
(
&
Options
::
new
(),
path
,
vec!
[
"cf1"
])
{
Ok
(
_
)
=>
println!
(
"successfully opened db with column family"
),
Err
(
e
)
=>
panic!
(
"failed to open db with column family"
),
}
}
// should be able to write, read, merge, batch, and iterate over a cf
{
}
assert
!
(
RocksDB
::
destroy
(
&
Options
::
new
(),
path
)
.is_ok
());
}
test/test_multithreaded.rs
View file @
520d9cef
...
...
@@ -2,11 +2,12 @@ use rocksdb::{Options, RocksDB, Writable, Direction, RocksDBResult};
use
std
::
thread
::{
self
,
Builder
};
use
std
::
sync
::
Arc
;
const
N
:
usize
=
100
0
_000
;
const
N
:
usize
=
100
_000
;
#[test]
pub
fn
test_multithreaded
()
{
let
path
=
"_rust_rocksdb_multithreadtest"
;
{
let
db
=
RocksDB
::
open_default
(
path
)
.unwrap
();
let
db
=
Arc
::
new
(
db
);
...
...
@@ -45,4 +46,6 @@ pub fn test_multithreaded() {
j1
.join
();
j2
.join
();
j3
.join
();
}
assert
!
(
RocksDB
::
destroy
(
&
Options
::
new
(),
path
)
.is_ok
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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