forked from tecbot/gorocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatible with RocksDB v6.16, tecbot#203
- Loading branch information
Showing
10 changed files
with
374 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Continuous integration | ||
|
||
on: [push, pull_request] | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-20.04, ubuntu-18.04, macos-11.0, macos-10.15] | ||
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 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-20.04 | ||
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: v1.38 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// +build rocksdb_6_16 | ||
|
||
package gorocksdb | ||
|
||
// #include <stdlib.h> | ||
// #include "rocksdb/c.h" | ||
import "C" | ||
import ( | ||
"errors" | ||
"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) (sizes []uint64, err error) { | ||
var cErr *C.char | ||
sizes = make([]uint64, len(ranges)) | ||
if len(ranges) == 0 { | ||
return | ||
} | ||
|
||
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]), | ||
&cErr, | ||
) | ||
if cErr != nil { | ||
defer C.rocksdb_free(unsafe.Pointer(cErr)) | ||
err = errors.New(C.GoString(cErr)) | ||
} | ||
|
||
return | ||
} | ||
|
||
// 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) (sizes []uint64, err error) { | ||
var cErr *C.char | ||
sizes = make([]uint64, len(ranges)) | ||
if len(ranges) == 0 { | ||
return | ||
} | ||
|
||
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]), | ||
&cErr, | ||
) | ||
if cErr != nil { | ||
defer C.rocksdb_free(unsafe.Pointer(cErr)) | ||
err = errors.New(C.GoString(cErr)) | ||
} | ||
|
||
return | ||
} |
Oops, something went wrong.