Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RocksDB v6.16 or later #210

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Continuous integration

on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: [1.16.x, 1.15.x, 1.14.x, 1.13.x]
name: Go ${{ matrix.go }} tests @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo apt-get update
sudo apt-get install -yq librocksdb-dev

- name: Install MacOS dependencies
if: startsWith(matrix.os, 'macos-')
run: |
brew update
brew install rocksdb

- name: Install Golang ${{ matrix.go }}
id: install-golang
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go version

- name: Checkout code
uses: actions/checkout@v2

- name: Cache Golang modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Test v5
if: startsWith(matrix.os, 'ubuntu-')
run: go test -v

- name: Test v6.16 or later
if: startsWith(matrix.os, 'macos-')
run: go test -v -tags rocksdb_6_16

golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -yq librocksdb-dev
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
vendor
56 changes: 56 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 20m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# skip-dirs:
# - ^test.*

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: readonly

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# skip-files:
# - ".*\\.my\\.go$"
# - lib/bad.go

# all available settings of specific linters
linters-settings:
govet:
enable:
- nilness
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
# locale: US
ignore-words:
- rela # This is for elf.SHT_RELA
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
dist: xenial
language: go
go:
- 1.12.x
- 1.13.x
- 1.14.x
- 1.15.x
- 1.16.x
- tip

before_install:
Expand All @@ -24,10 +26,10 @@ install:
- sudo cp --preserve=links ./librocksdb.* /usr/lib/
- sudo cp -r ./include/rocksdb/ /usr/include/
- popd
- go get -t ./...
- go get -t -tags rocksdb_6_16 ./...

script:
- go test -v ./
- go test -v -tags rocksdb_6_16 ./

notifications:
email:
Expand Down
2 changes: 1 addition & 1 deletion checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestCheckpoint(t *testing.T) {
opts := NewDefaultOptions()
opts.SetCreateIfMissing(true)
dbCheck, err = OpenDb(opts, dir)
defer dbCheck.Close()
ensure.Nil(t, err)
defer dbCheck.Close()

// test keys
var value *Slice
Expand Down
83 changes: 0 additions & 83 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,89 +577,6 @@ func (db *DB) DropColumnFamily(c *ColumnFamilyHandle) error {
return nil
}

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

cStarts := make([]*C.char, len(ranges))
cLimits := make([]*C.char, len(ranges))
cStartLens := make([]C.size_t, len(ranges))
cLimitLens := make([]C.size_t, len(ranges))
for i, r := range ranges {
cStarts[i] = (*C.char)(C.CBytes(r.Start))
cStartLens[i] = C.size_t(len(r.Start))
cLimits[i] = (*C.char)(C.CBytes(r.Limit))
cLimitLens[i] = C.size_t(len(r.Limit))
}

defer func() {
for i := range ranges {
C.free(unsafe.Pointer(cStarts[i]))
C.free(unsafe.Pointer(cLimits[i]))
}
}()

C.rocksdb_approximate_sizes(
db.c,
C.int(len(ranges)),
&cStarts[0],
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))

return sizes
}

// 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 {
sizes := make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
}

cStarts := make([]*C.char, len(ranges))
cLimits := make([]*C.char, len(ranges))
cStartLens := make([]C.size_t, len(ranges))
cLimitLens := make([]C.size_t, len(ranges))
for i, r := range ranges {
cStarts[i] = (*C.char)(C.CBytes(r.Start))
cStartLens[i] = C.size_t(len(r.Start))
cLimits[i] = (*C.char)(C.CBytes(r.Limit))
cLimitLens[i] = C.size_t(len(r.Limit))
}

defer func() {
for i := range ranges {
C.free(unsafe.Pointer(cStarts[i]))
C.free(unsafe.Pointer(cLimits[i]))
}
}()

C.rocksdb_approximate_sizes_cf(
db.c,
cf.c,
C.int(len(ranges)),
&cStarts[0],
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))

return sizes
}

// SetOptions dynamically changes options through the SetOptions API.
func (db *DB) SetOptions(keys, values []string) error {
num_keys := len(keys)
Expand Down
91 changes: 91 additions & 0 deletions db_6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// +build !rocksdb_6_16

package gorocksdb

// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"
import "unsafe"

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

cStarts := make([]*C.char, len(ranges))
cLimits := make([]*C.char, len(ranges))
cStartLens := make([]C.size_t, len(ranges))
cLimitLens := make([]C.size_t, len(ranges))
for i, r := range ranges {
cStarts[i] = (*C.char)(C.CBytes(r.Start))
cStartLens[i] = C.size_t(len(r.Start))
cLimits[i] = (*C.char)(C.CBytes(r.Limit))
cLimitLens[i] = C.size_t(len(r.Limit))
}

defer func() {
for i := range ranges {
C.free(unsafe.Pointer(cStarts[i]))
C.free(unsafe.Pointer(cLimits[i]))
}
}()

C.rocksdb_approximate_sizes(
db.c,
C.int(len(ranges)),
&cStarts[0],
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))

return sizes
}

// 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 {
sizes := make([]uint64, len(ranges))
if len(ranges) == 0 {
return sizes
}

cStarts := make([]*C.char, len(ranges))
cLimits := make([]*C.char, len(ranges))
cStartLens := make([]C.size_t, len(ranges))
cLimitLens := make([]C.size_t, len(ranges))
for i, r := range ranges {
cStarts[i] = (*C.char)(C.CBytes(r.Start))
cStartLens[i] = C.size_t(len(r.Start))
cLimits[i] = (*C.char)(C.CBytes(r.Limit))
cLimitLens[i] = C.size_t(len(r.Limit))
}

defer func() {
for i := range ranges {
C.free(unsafe.Pointer(cStarts[i]))
C.free(unsafe.Pointer(cLimits[i]))
}
}()

C.rocksdb_approximate_sizes_cf(
db.c,
cf.c,
C.int(len(ranges)),
&cStarts[0],
&cStartLens[0],
&cLimits[0],
&cLimitLens[0],
(*C.uint64_t)(&sizes[0]))

return sizes
}
Loading