Skip to content

Commit

Permalink
NO-ISSUE Adapt rocksdb 6.12.7 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Oct 17, 2020
1 parent c19ec86 commit fc87456
Show file tree
Hide file tree
Showing 67 changed files with 2,723 additions and 1,113 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: go
go:
- 1.13.x
- 1.14.x
- 1.15.x

install:
- go get -u github.com/mattn/goveralls
Expand Down
28 changes: 14 additions & 14 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ func (b *BackupEngine) RestoreDBFromLatestBackup(dbDir, walDir string, ro *Resto
return
}

// // RestoreDBFromBackup restores the backup (identified by its id) to dbDir. walDir
// // is where the write ahead logs are restored to and usually the same as dbDir.
// func (b *BackupEngine) RestoreDBFromBackup(dbDir, walDir string, ro *RestoreOptions, backupID uint32) (err error) {
// cDbDir := C.CString(dbDir)
// cWalDir := C.CString(walDir)

// var cErr *C.char
// C.rocksdb_backup_engine_restore_db_from_backup(b.c, cDbDir, cWalDir, ro.c, C.uint32_t(backupID), &cErr)
// err = fromCError(cErr)

// C.free(unsafe.Pointer(cDbDir))
// C.free(unsafe.Pointer(cWalDir))
// return
// }
// RestoreDBFromBackup restores the backup (identified by its id) to dbDir. walDir
// is where the write ahead logs are restored to and usually the same as dbDir.
func (b *BackupEngine) RestoreDBFromBackup(dbDir, walDir string, ro *RestoreOptions, backupID uint32) (err error) {
cDbDir := C.CString(dbDir)
cWalDir := C.CString(walDir)

var cErr *C.char
C.rocksdb_backup_engine_restore_db_from_backup(b.c, cDbDir, cWalDir, ro.c, C.uint32_t(backupID), &cErr)
err = fromCError(cErr)

C.free(unsafe.Pointer(cDbDir))
C.free(unsafe.Pointer(cWalDir))
return
}

// Close close the backup engine and cleans up state
// The backups already taken remain on storage.
Expand Down
225 changes: 112 additions & 113 deletions backup_test.go
Original file line number Diff line number Diff line change
@@ -1,115 +1,114 @@
package grocksdb

// import (
// "io/ioutil"
// "testing"

// "github.com/facebookgo/ensure"
// "github.com/stretchr/testify/require"
// )

// func TestBackupEngine(t *testing.T) {
// db := newTestDB(t, "TestDBBackup", nil)
// defer db.Close()

// var (
// givenKey = []byte("hello")
// givenVal1 = []byte("")
// givenVal2 = []byte("world1")
// wo = NewDefaultWriteOptions()
// ro = NewDefaultReadOptions()
// )
// defer wo.Destroy()
// defer ro.Destroy()

// // create
// ensure.Nil(t, db.Put(wo, givenKey, givenVal1))

// // retrieve
// v1, err := db.Get(ro, givenKey)
// defer v1.Free()
// ensure.Nil(t, err)
// ensure.DeepEqual(t, v1.Data(), givenVal1)

// // retrieve bytes
// _v1, err := db.GetBytes(ro, givenKey)
// ensure.Nil(t, err)
// ensure.DeepEqual(t, _v1, givenVal1)

// // update
// ensure.Nil(t, db.Put(wo, givenKey, givenVal2))
// v2, err := db.Get(ro, givenKey)
// defer v2.Free()
// ensure.Nil(t, err)
// ensure.DeepEqual(t, v2.Data(), givenVal2)

// // retrieve pinned
// v3, err := db.GetPinned(ro, givenKey)
// defer v3.Destroy()
// ensure.Nil(t, err)
// ensure.DeepEqual(t, v3.Data(), givenVal2)

// engine, err := CreateBackupEngine(db)
// require.Nil(t, err)
// defer engine.Close()

// t.Run("createBackupAndVerify", func(t *testing.T) {
// infos := engine.GetInfo()
// require.Empty(t, infos)

// // create first backup
// require.Nil(t, engine.CreateNewBackup())

// // create second backup
// require.Nil(t, engine.CreateNewBackupFlush(true))

// infos = engine.GetInfo()
// require.Equal(t, 2, len(infos))
// for i := range infos {
// require.Nil(t, engine.VerifyBackup(infos[i].ID))
// require.True(t, infos[i].Size > 0)
// require.True(t, infos[i].NumFiles > 0)
// }
// })

// t.Run("purge", func(t *testing.T) {
// require.Nil(t, engine.PurgeOldBackups(1))

// infos := engine.GetInfo()
// require.Equal(t, 1, len(infos))
// })

// t.Run("restoreFromLatest", func(t *testing.T) {
// dir, err := ioutil.TempDir("", "gorocksdb-restoreFromLatest")
// require.Nil(t, err)

// ro := NewRestoreOptions()
// defer ro.Destroy()
// require.Nil(t, engine.RestoreDBFromLatestBackup(dir, dir, ro))
// require.Nil(t, engine.RestoreDBFromLatestBackup(dir, dir, ro))
// })

// t.Run("restoreFromBackup", func(t *testing.T) {
// infos := engine.GetInfo()
// require.Equal(t, 1, len(infos))

// dir, err := ioutil.TempDir("", "gorocksdb-restoreFromBackup")
// require.Nil(t, err)

// ro := NewRestoreOptions()
// defer ro.Destroy()
// require.Nil(t, engine.RestoreDBFromBackup(dir, dir, ro, infos[0].ID))

// // try to reopen restored db
// backupDB, err := OpenDb(db.opts, dir)
// require.Nil(t, err)

// r := NewDefaultReadOptions()
// defer r.Destroy()

// v3, err := backupDB.GetPinned(r, givenKey)
// defer v3.Destroy()
// ensure.Nil(t, err)
// ensure.DeepEqual(t, v3.Data(), givenVal2)
// })
// }
import (
"io/ioutil"
"testing"

"github.com/stretchr/testify/require"
)

func TestBackupEngine(t *testing.T) {
db := newTestDB(t, "TestDBBackup", nil)
defer db.Close()

var (
givenKey = []byte("hello")
givenVal1 = []byte("")
givenVal2 = []byte("world1")
wo = NewDefaultWriteOptions()
ro = NewDefaultReadOptions()
)
defer wo.Destroy()
defer ro.Destroy()

// create
require.Nil(t, db.Put(wo, givenKey, givenVal1))

// retrieve
v1, err := db.Get(ro, givenKey)
defer v1.Free()
require.Nil(t, err)
require.EqualValues(t, v1.Data(), givenVal1)

// retrieve bytes
_v1, err := db.GetBytes(ro, givenKey)
require.Nil(t, err)
require.EqualValues(t, _v1, givenVal1)

// update
require.Nil(t, db.Put(wo, givenKey, givenVal2))
v2, err := db.Get(ro, givenKey)
defer v2.Free()
require.Nil(t, err)
require.EqualValues(t, v2.Data(), givenVal2)

// retrieve pinned
v3, err := db.GetPinned(ro, givenKey)
defer v3.Destroy()
require.Nil(t, err)
require.EqualValues(t, v3.Data(), givenVal2)

engine, err := CreateBackupEngine(db)
require.Nil(t, err)
defer engine.Close()

t.Run("createBackupAndVerify", func(t *testing.T) {
infos := engine.GetInfo()
require.Empty(t, infos)

// create first backup
require.Nil(t, engine.CreateNewBackup())

// create second backup
require.Nil(t, engine.CreateNewBackupFlush(true))

infos = engine.GetInfo()
require.Equal(t, 2, len(infos))
for i := range infos {
require.Nil(t, engine.VerifyBackup(infos[i].ID))
require.True(t, infos[i].Size > 0)
require.True(t, infos[i].NumFiles > 0)
}
})

t.Run("purge", func(t *testing.T) {
require.Nil(t, engine.PurgeOldBackups(1))

infos := engine.GetInfo()
require.Equal(t, 1, len(infos))
})

t.Run("restoreFromLatest", func(t *testing.T) {
dir, err := ioutil.TempDir("", "gorocksdb-restoreFromLatest")
require.Nil(t, err)

ro := NewRestoreOptions()
defer ro.Destroy()
require.Nil(t, engine.RestoreDBFromLatestBackup(dir, dir, ro))
require.Nil(t, engine.RestoreDBFromLatestBackup(dir, dir, ro))
})

t.Run("restoreFromBackup", func(t *testing.T) {
infos := engine.GetInfo()
require.Equal(t, 1, len(infos))

dir, err := ioutil.TempDir("", "gorocksdb-restoreFromBackup")
require.Nil(t, err)

ro := NewRestoreOptions()
defer ro.Destroy()
require.Nil(t, engine.RestoreDBFromBackup(dir, dir, ro, infos[0].ID))

// try to reopen restored db
backupDB, err := OpenDb(db.opts, dir)
require.Nil(t, err)

r := NewDefaultReadOptions()
defer r.Destroy()

v3, err := backupDB.GetPinned(r, givenKey)
defer v3.Destroy()
require.Nil(t, err)
require.EqualValues(t, v3.Data(), givenVal2)
})
}
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cd $BUILD_PATH && wget https://github.com/facebook/zstd/releases/download/v1.4.5
$CMAKE_REQUIRED_PARAMS -DZSTD_ZLIB_SUPPORT=ON -DZSTD_LZMA_SUPPORT=OFF -DCMAKE_BUILD_TYPE=Release .. && make -j16 install && \
cd $BUILD_PATH && rm -rf *

cd $BUILD_PATH && wget https://github.com/facebook/rocksdb/archive/v6.11.6.tar.gz && tar xzf v6.11.6.tar.gz && cd rocksdb-6.11.6/ && \
cd $BUILD_PATH && wget https://github.com/facebook/rocksdb/archive/v6.12.7.tar.gz && tar xzf v6.12.7.tar.gz && cd rocksdb-6.12.7/ && \
mkdir -p build_place && cd build_place && cmake -DCMAKE_BUILD_TYPE=Release $CMAKE_REQUIRED_PARAMS -DCMAKE_PREFIX_PATH=$INSTALL_PREFIX -DWITH_TESTS=OFF -DWITH_GFLAGS=OFF \
-DWITH_BENCHMARK_TOOLS=OFF -DWITH_TOOLS=OFF -DWITH_MD_LIBRARY=OFF -DWITH_RUNTIME_DEBUG=OFF -DROCKSDB_BUILD_SHARED=OFF -DWITH_SNAPPY=ON -DWITH_LZ4=ON -DWITH_ZLIB=ON \
-DWITH_ZSTD=ON -DWITH_BZ2=OFF -WITH_GFLAGS=OFF .. && make -j16 install/strip && \
Expand Down
Loading

0 comments on commit fc87456

Please sign in to comment.