Skip to content

Commit

Permalink
Merge pull request #1 from 0chain/fix/integrate_latest_rocksb6.20+
Browse files Browse the repository at this point in the history
Fix/integrate latest rocksb6.20+
  • Loading branch information
kushthedude authored Jan 26, 2022
2 parents 8752a94 + 9721107 commit 31547a9
Show file tree
Hide file tree
Showing 29 changed files with 820 additions and 98 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
dist: xenial
language: go
go:
- 1.11
- 1.12.x
- 1.13.x
- tip

before_install:
Expand Down
29 changes: 23 additions & 6 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func OpenBackupEngine(opts *Options, path string) (*BackupEngine, error) {

be := C.rocksdb_backup_engine_open(opts.c, cpath, &cErr)
if cErr != nil {
defer C.free(unsafe.Pointer(cErr))
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}
return &BackupEngine{
Expand All @@ -104,19 +104,25 @@ func (b *BackupEngine) UnsafeGetBackupEngine() unsafe.Pointer {
return unsafe.Pointer(b.c)
}

// CreateNewBackup takes a new backup from db.
func (b *BackupEngine) CreateNewBackup(db *DB) error {
// CreateNewBackupFlush takes a new backup from db. If flush is set to true,
// it flushes the WAL before taking the backup.
func (b *BackupEngine) CreateNewBackupFlush(db *DB, flush bool) error {
var cErr *C.char

C.rocksdb_backup_engine_create_new_backup(b.c, db.c, &cErr)
C.rocksdb_backup_engine_create_new_backup_flush(b.c, db.c, boolToChar(flush), &cErr)
if cErr != nil {
defer C.free(unsafe.Pointer(cErr))
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}

return nil
}

// CreateNewBackup takes a new backup from db.
func (b *BackupEngine) CreateNewBackup(db *DB) error {
return b.CreateNewBackupFlush(db, false)
}

// GetInfo gets an object that gives information about
// the backups that have already been taken
func (b *BackupEngine) GetInfo() *BackupEngineInfo {
Expand All @@ -138,7 +144,18 @@ func (b *BackupEngine) RestoreDBFromLatestBackup(dbDir, walDir string, ro *Resto

C.rocksdb_backup_engine_restore_db_from_latest_backup(b.c, cDbDir, cWalDir, ro.c, &cErr)
if cErr != nil {
defer C.free(unsafe.Pointer(cErr))
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}
return nil
}

// PurgeOldBackups deletes all backups older than the latest 'n' backups
func (b *BackupEngine) PurgeOldBackups(n uint32) error {
var cErr *C.char
C.rocksdb_backup_engine_purge_old_backups(b.c, C.uint32_t(n), &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Cache struct {
}

// NewLRUCache creates a new LRU Cache object with the capacity given.
func NewLRUCache(capacity int) *Cache {
func NewLRUCache(capacity uint64) *Cache {
return NewNativeCache(C.rocksdb_cache_create_lru(C.size_t(capacity)))
}

Expand All @@ -19,13 +19,13 @@ func NewNativeCache(c *C.rocksdb_cache_t) *Cache {
}

// GetUsage returns the Cache memory usage.
func (c *Cache) GetUsage() int {
return int(C.rocksdb_cache_get_usage(c.c))
func (c *Cache) GetUsage() uint64 {
return uint64(C.rocksdb_cache_get_usage(c.c))
}

// GetPinnedUsage returns the Cache pinned memory usage.
func (c *Cache) GetPinnedUsage() int {
return int(C.rocksdb_cache_get_pinned_usage(c.c))
func (c *Cache) GetPinnedUsage() uint64 {
return uint64(C.rocksdb_cache_get_pinned_usage(c.c))
}

// Destroy deallocates the Cache object.
Expand Down
2 changes: 1 addition & 1 deletion checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (checkpoint *Checkpoint) CreateCheckpoint(checkpoint_dir string, log_size_f

C.rocksdb_checkpoint_create(checkpoint.c, cDir, C.uint64_t(log_size_for_flush), &cErr)
if cErr != nil {
defer C.free(unsafe.Pointer(cErr))
defer C.rocksdb_free(unsafe.Pointer(cErr))
return errors.New(C.GoString(cErr))
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion checkpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gorocksdb

import (
"github.com/facebookgo/ensure"
"io/ioutil"
"os"
"testing"

"github.com/facebookgo/ensure"
)

func TestCheckpoint(t *testing.T) {
Expand Down
Loading

0 comments on commit 31547a9

Please sign in to comment.