Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
68cede3
Merge pull request #1 from tecbot/master
jmoiron May 21, 2019
40385d7
link lz4 and zstd
jmoiron May 21, 2019
b33948f
add Copy routine to slices to make it easier to do copies of iter key…
jmoiron May 23, 2019
82b9c1d
add lz4 and zstd to static build flags
kenny-house Jun 13, 2019
81c6e3e
Merge pull request #2 from DataDog/kenny.house/lz4-zstd-static
kenny-house Jun 13, 2019
641add3
Adding the missing prefix_same_as_start option
jamesbibby Aug 20, 2019
b0fde3d
Merge pull request #3 from DataDog/bibby/add-prefix-same-as-start-ro
jamesbibby Aug 21, 2019
02e913e
Adding PartialMergeMulti
jamesbibby Sep 10, 2019
b554c6b
fixing the test
jamesbibby Sep 10, 2019
39c1afb
taking a more opinionated approach and just ditching the left right o…
jamesbibby Sep 11, 2019
1384bf7
Update PartialMerge to be PartialMergeMulti
jamesbibby Sep 11, 2019
a3b2f44
New MergeMultiOperator interface
jamesbibby Sep 12, 2019
20539af
Don't embed the MergeOperator in MergeMultiOperator
jamesbibby Sep 12, 2019
c1b2da7
Adding a test for merge multi
jamesbibby Sep 13, 2019
d0110a4
Separate the interfaces
jamesbibby Sep 13, 2019
aeb6dc0
Merge pull request #5 from DataDog/bibby/merge-multi
jamesbibby Sep 13, 2019
d425dd0
Cleanup
jamesbibby Sep 13, 2019
00c2451
remove extra file
jamesbibby Sep 13, 2019
1a753c7
merge upstream updates
jamesbibby Sep 30, 2019
de48daf
Merge branch 'master' of github.com:tecbot/gorocksdb into bibby/merge…
jamesbibby Sep 30, 2019
aa1f449
Merge pull request #6 from DataDog/bibby/merge-upstream
jamesbibby Oct 2, 2019
2fb740c
Avoid segfault when using slicetransform in options
benauthor Oct 16, 2019
a192cce
just delete it
benauthor Oct 17, 2019
36d99af
Merge pull request #7 from DataDog/eb/avoid_transform_segfault
benauthor Oct 17, 2019
25adc89
need to static link dl on linux
jamesbibby Nov 25, 2019
918a5d2
Merge pull request #8 from DataDog/bibby/static-link-dl
jamesbibby Dec 11, 2019
df7aab2
Merge remote-tracking branch 'upstream/master' into kenny.house/merge…
kenny-house Jan 7, 2020
9722c3a
Merge pull request #10 from DataDog/kenny.house/merge-upstream
kenny-house Jan 7, 2020
bc97612
Adding support for setting total_order_seek
dgromov Apr 10, 2020
aa0f725
Merge pull request #11 from DataDog/dmitriy.gromov/total_order_seek
dgromov Apr 13, 2020
8c57e47
Add missing FlushCF method
kenny-house Jun 25, 2020
5b11931
Add test that calls FlushCF method
kenny-house Jul 14, 2020
2f34580
Merge pull request #12 from DataDog/kenny.house/flush-cf-2
kenny-house Jul 14, 2020
0370b26
Add ReadOptions setter for ignore_range_deletions
kenny-house Nov 15, 2020
2f07916
Merge pull request #15 from DataDog/kenny.house/ignore-range-deletions
kenny-house Nov 18, 2020
2585a0c
Change minimum required RocksDB version to 6.16 (#16)
akrylysov May 26, 2021
a822212
[gorocksdb] add functionality to utilize secondary db
dforciea Sep 27, 2021
afe92a8
[gorocks] add unit test for column families flavor of secondary db open
dforciea Sep 27, 2021
ed396ba
[gorocksdb] add SetAtomicFlush function for options
dforciea Sep 29, 2021
3fe6494
Merge pull request #17 from DataDog/dylan.forciea/add-secondary-db-funcs
dforciea Sep 30, 2021
d5bcc94
[gorocks] add a call to open a database with TTL
dforciea Nov 12, 2021
96abbfa
[gorocks] add function call for creating column family with TTL
dforciea Nov 15, 2021
390c04c
Merge pull request #19 from DataDog/dylan.forciea/add-open-db-column-…
dforciea Nov 19, 2021
f381455
Rename the static build tag
scanterog Nov 3, 2021
509e22a
Merge pull request #18 from DataDog/scanterog/build-tag
scanterog Dec 13, 2021
8f7853f
Adds ColumnFamily support in TransactionDB. (#22)
yuanyuanzhao3 Nov 29, 2022
aea66a9
Adds column familiy support to Transaction.
yuanyuanzhao3 Nov 29, 2022
5375896
Merge pull request #23 from DataDog/yuanyuan.zhao/transactiondb-colum…
yuanyuanzhao3 Nov 29, 2022
fdaff39
Add unordered_write option
kenny-house Dec 13, 2022
1164ce9
Implements TransactionDB with WriteBatch.
yuanyuanzhao3 Dec 15, 2022
7aea411
Adds test of WriteBatch with DeleteRangeCF that is not supported.
yuanyuanzhao3 Dec 15, 2022
4867506
Merge pull request #25 from DataDog/yuanyuan.zhao/transactiondb-colum…
yuanyuanzhao3 Dec 15, 2022
114f359
Merge pull request #24 from DataDog/kenny.house/unordered-writes
kenny-house Dec 18, 2022
eaf1035
Create option to dump malloc stats
dforciea Mar 2, 2023
d67207c
Merge pull request #26 from DataDog/dylan.forciea/set-dump-malloc-sta…
dforciea Mar 3, 2023
066237c
Allow usage of GetApproximateMemoryUsageByType with TransactionDB
remicalixte Jun 22, 2023
2753e07
avoid changing public function signature
remicalixte Jun 23, 2023
2c02809
update unit tests
remicalixte Jun 23, 2023
a4d4b5b
better naming
remicalixte Jun 23, 2023
0ac53e5
naming
remicalixte Jun 26, 2023
cfc828d
Merge pull request #27 from DataDog/remicalixte/transactiondb-memory-…
remicalixte Jun 26, 2023
9d9bd73
add option to set bottomost compression
az0977776 Jan 3, 2024
ea6ab6b
fix typo
az0977776 Jan 3, 2024
e62307a
Merge pull request #35 from DataDog/aw/bottommost-compression
az0977776 Jan 3, 2024
3160997
Add SetAllowCompaction method to FIFOCompactionOptions
ounim Mar 21, 2024
c2c0899
Merge pull request #41 from DataDog/dp/AddFIFOSetAllowCompaction
ounim Mar 21, 2024
1ce0640
Revert "Add SetAllowCompaction method to FIFOCompactionOptions"
ounim Mar 22, 2024
30d6130
Move Rocksdb V8 compatible code into a /v8 module (#40)
jamesbibby Apr 10, 2024
5ddc348
[REDRES-1186] add gorocks point lookup options
dforciea Jun 11, 2024
abc1365
Merge pull request #43 from DataDog/dylan.forciea/redres-1186-add-poi…
dforciea Jun 12, 2024
e95f060
[REDRES-820] Add rocks options for compaction
dforciea Jun 24, 2024
767cf31
set period compaction not present in 8.5.4 yet
dforciea Jun 24, 2024
e2bdf74
Add functions for getting base DB
dforciea Jun 25, 2024
7028d12
Add SetOptionsCF call
dforciea Jun 26, 2024
b70dda7
Add missing func
dforciea Jun 26, 2024
a9df074
Add missing include
dforciea Jun 26, 2024
7571dab
More imports
dforciea Jun 26, 2024
3b1c13b
Fix up error handling
dforciea Jun 26, 2024
2a82964
Merge pull request #44 from DataDog/dylan.forciea/redres-820-add-comp…
dforciea Jul 1, 2024
b329552
Merge pull request #42 from DataDog/revert-41-dp/AddFIFOSetAllowCompa…
ounim Feb 11, 2025
d4761d8
expose column family name to GetLiveFilesMetaData
rakovskyp Mar 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Install

You'll need to build [RocksDB](https://github.com/facebook/rocksdb) v5.16+ on your machine.
You'll need to build [RocksDB](https://github.com/facebook/rocksdb) v6.16+ on your machine.

After that, you can install gorocksdb using the following command:

Expand All @@ -14,5 +14,3 @@ After that, you can install gorocksdb using the following command:

Please note that this package might upgrade the required RocksDB version at any moment.
Vendoring is thus highly recommended if you require high stability.

*The [embedded CockroachDB RocksDB](https://github.com/cockroachdb/c-rocksdb) is no longer supported in gorocksdb.*
241 changes: 229 additions & 12 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type Range struct {

// DB is a reusable handle to a RocksDB database on disk, created by Open.
type DB struct {
c *C.rocksdb_t
name string
opts *Options
c *C.rocksdb_t
name string
secondaryPath string
opts *Options
}

// OpenDb opens a database with the specified options.
Expand Down Expand Up @@ -139,6 +140,76 @@ func OpenDbColumnFamilies(
}, cfHandles, nil
}

// OpenDbColumnFamiliesWithTTL opens a database with the specified column families.
func OpenDbColumnFamiliesWithTTL(
opts *Options,
name string,
cfNames []string,
cfOpts []*Options,
cfTtls []int,
) (*DB, []*ColumnFamilyHandle, error) {
numColumnFamilies := len(cfNames)
if numColumnFamilies != len(cfOpts) {
return nil, nil, errors.New("must provide the same number of column family names and options")
}

if numColumnFamilies != len(cfTtls) {
return nil, nil, errors.New("must provide the same number of column family names and ttls")
}

cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))

cNames := make([]*C.char, numColumnFamilies)
for i, s := range cfNames {
cNames[i] = C.CString(s)
}
defer func() {
for _, s := range cNames {
C.free(unsafe.Pointer(s))
}
}()

cOpts := make([]*C.rocksdb_options_t, numColumnFamilies)
for i, o := range cfOpts {
cOpts[i] = o.c
}

cHandles := make([]*C.rocksdb_column_family_handle_t, numColumnFamilies)

cTtls := make([]C.int, numColumnFamilies)
for i, t := range cfTtls {
cTtls[i] = C.int(t)
}

var cErr *C.char
db := C.rocksdb_open_column_families_with_ttl(
opts.c,
cName,
C.int(numColumnFamilies),
&cNames[0],
&cOpts[0],
&cHandles[0],
&cTtls[0],
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, nil, errors.New(C.GoString(cErr))
}

cfHandles := make([]*ColumnFamilyHandle, numColumnFamilies)
for i, c := range cHandles {
cfHandles[i] = NewNativeColumnFamilyHandle(c)
}

return &DB{
name: name,
c: db,
opts: opts,
}, cfHandles, nil
}

// OpenDbForReadOnlyColumnFamilies opens a database with the specified column
// families in read only mode.
func OpenDbForReadOnlyColumnFamilies(
Expand Down Expand Up @@ -201,6 +272,93 @@ func OpenDbForReadOnlyColumnFamilies(
}, cfHandles, nil
}

// OpenDbAsSecondary opens a database with the specified options for secondary usage.
func OpenDbAsSecondary(opts *Options, name string, secondaryPath string) (*DB, error) {
var (
cErr *C.char
cName = C.CString(name)
cSecondaryPath = C.CString(secondaryPath)
)
defer C.free(unsafe.Pointer(cName))
defer C.free(unsafe.Pointer(cSecondaryPath))
db := C.rocksdb_open_as_secondary(opts.c, cName, cSecondaryPath, &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}
return &DB{
name: name,
secondaryPath: secondaryPath,
c: db,
opts: opts,
}, nil
}

// OpenDbAsSecondaryColumnFamilies opens a database with the specified column
// families in secondary mode.
func OpenDbAsSecondaryColumnFamilies(
opts *Options,
name string,
secondaryPath string,
cfNames []string,
cfOpts []*Options,
) (*DB, []*ColumnFamilyHandle, error) {
numColumnFamilies := len(cfNames)
if numColumnFamilies != len(cfOpts) {
return nil, nil, errors.New("must provide the same number of column family names and options")
}

cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))

cSecondaryPath := C.CString(secondaryPath)
defer C.free(unsafe.Pointer(cSecondaryPath))

cNames := make([]*C.char, numColumnFamilies)
for i, s := range cfNames {
cNames[i] = C.CString(s)
}
defer func() {
for _, s := range cNames {
C.free(unsafe.Pointer(s))
}
}()

cOpts := make([]*C.rocksdb_options_t, numColumnFamilies)
for i, o := range cfOpts {
cOpts[i] = o.c
}

cHandles := make([]*C.rocksdb_column_family_handle_t, numColumnFamilies)

var cErr *C.char
db := C.rocksdb_open_as_secondary_column_families(
opts.c,
cName,
cSecondaryPath,
C.int(numColumnFamilies),
&cNames[0],
&cOpts[0],
&cHandles[0],
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, nil, errors.New(C.GoString(cErr))
}

cfHandles := make([]*ColumnFamilyHandle, numColumnFamilies)
for i, c := range cHandles {
cfHandles[i] = NewNativeColumnFamilyHandle(c)
}

return &DB{
name: name,
c: db,
opts: opts,
}, cfHandles, nil
}

// ListColumnFamilies lists the names of the column families in the DB.
func ListColumnFamilies(opts *Options, name string) ([]string, error) {
var (
Expand Down Expand Up @@ -237,6 +395,11 @@ func (db *DB) Name() string {
return db.name
}

// SecondaryPath returns the secondary path of the database, if it is a secondary database instance.
func (db *DB) SecondaryPath() string {
return db.secondaryPath
}

// Get returns the data associated with the key from the database.
func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) {
var (
Expand Down Expand Up @@ -566,6 +729,22 @@ func (db *DB) CreateColumnFamily(opts *Options, name string) (*ColumnFamilyHandl
return NewNativeColumnFamilyHandle(cHandle), nil
}

// CreateColumnFamilyWithTTL creates a new column family with a TTL.
func (db *DB) CreateColumnFamilyWithTTL(opts *Options, name string, ttl int) (*ColumnFamilyHandle, error) {
var (
cErr *C.char
cName = C.CString(name)
cTtl = C.int(ttl)
)
defer C.free(unsafe.Pointer(cName))
cHandle := C.rocksdb_create_column_family_with_ttl(db.c, opts.c, cName, cTtl, &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}
return NewNativeColumnFamilyHandle(cHandle), nil
}

// DropColumnFamily drops a column family.
func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error {
var cErr *C.char
Expand All @@ -582,10 +761,10 @@ func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error {
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
func (db *DB) GetApproximateSizes(ranges []Range) ([]uint64, error) {
sizes := make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
return sizes, nil
}

cStarts := make([]*C.char, len(ranges))
Expand All @@ -606,27 +785,34 @@ func (db *DB) GetApproximateSizes(ranges []Range) []uint64 {
}
}()

var cErr *C.char
C.rocksdb_approximate_sizes(
db.c,
C.int(len(ranges)),
&cStarts[0],
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))
(*C.uint64_t)(&sizes[0]),
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return sizes, errors.New(C.GoString(cErr))
}

return sizes
return sizes, nil
}

// GetApproximateSizesCF returns the approximate number of bytes of file system
// space used by one or more key ranges in the column family.
//
// The keys counted will begin at Range.Start and end on the key before
// Range.Limit.
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []uint64 {
func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) ([]uint64, error) {
sizes := make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
return sizes, nil
}

cStarts := make([]*C.char, len(ranges))
Expand All @@ -647,6 +833,7 @@ func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []ui
}
}()

var cErr *C.char
C.rocksdb_approximate_sizes_cf(
db.c,
cf.c,
Expand All @@ -655,9 +842,14 @@ func (db *DB) GetApproximateSizesCF(cf *ColumnFamilyHandle, ranges []Range) []ui
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))

return sizes
(*C.uint64_t)(&sizes[0]),
&cErr,
)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return sizes, errors.New(C.GoString(cErr))
}
return sizes, nil
}

// SetOptions dynamically changes options through the SetOptions API.
Expand Down Expand Up @@ -752,6 +944,17 @@ func (db *DB) Flush(opts *FlushOptions) error {
return nil
}

// FlushCF triggers a manual flush for the column family.
func (db *DB) FlushCF(cf *ColumnFamilyHandle, opts *FlushOptions) error {
var cErr *C.char
C.rocksdb_flush_cf(db.c, opts.c, cf.c, &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}
return nil
}

// DisableFileDeletions disables file deletions and should be used when backup the database.
func (db *DB) DisableFileDeletions() error {
var cErr *C.char
Expand Down Expand Up @@ -907,6 +1110,20 @@ func (db *DB) Close() {
C.rocksdb_close(db.c)
}

// TryCatchUpWithPrimary will sync a secondary db with the state of the primary
func (db *DB) TryCatchUpWithPrimary() error {
var (
cErr *C.char
)
C.rocksdb_try_catch_up_with_primary(db.c, &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}

return nil
}

// DestroyDb removes a database entirely, removing everything from the
// filesystem.
func DestroyDb(name string, opts *Options) error {
Expand Down
Loading