Skip to content

Commit 53b1ef7

Browse files
authored
Modernize code (#1)
1 parent e505f9c commit 53b1ef7

18 files changed

Lines changed: 404 additions & 341 deletions

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
go:
11+
uses: bsm/misc/.github/workflows/test-go.yml@main

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
default: vet test
2-
3-
vet:
4-
go vet ./...
1+
default: test
52

63
test:
74
go test ./...
85

9-
.PHONY: vet test
6+
bench:
7+
go test ./... -run=NONE -bench=. -benchmem
8+
9+
lint:
10+
golangci-lint run
1011

11-
# go get -u github.com/davelondon/rebecca/cmd/becca
1212
README.md: README.md.tpl
1313
becca -package github.com/bsm/sntable

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# SNTable
22

3-
[![GoDoc](https://godoc.org/github.com/bsm/sntable?status.svg)](https://godoc.org/github.com/bsm/sntable)
4-
[![Build Status](https://travis-ci.org/bsm/sntable.png?branch=master)](https://travis-ci.org/bsm/sntable)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/bsm/sntable.svg)](https://pkg.go.dev/github.com/bsm/sntable)
4+
[![Test](https://github.com/bsm/sntable/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/sntable/actions/workflows/test.yml)
55
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66

77
Custom [SSTable](https://www.igvita.com/2012/02/06/sstable-and-log-structured-storage-leveldb/) implementation
88
for [Go](https://golang.org). Instead of arbitrary bytes strings, this implementation assumes numeric 8-byte (`uint64`)
9-
keys.
9+
keys. Blocks can be stored uncompressed or compressed with [Snappy](https://github.com/klauspost/compress) (default)
10+
or [Zstandard](https://github.com/klauspost/compress).
1011

1112
## Examples
1213

@@ -16,7 +17,6 @@ keys.
1617
package main
1718

1819
import (
19-
"io/ioutil"
2020
"log"
2121
"os"
2222

@@ -25,7 +25,7 @@ import (
2525

2626
func main() {
2727
// create a file
28-
f, err := ioutil.TempFile("", "sntable-example")
28+
f, err := os.CreateTemp("", "sntable-example")
2929
if err != nil {
3030
log.Fatalln(err)
3131
}
@@ -56,7 +56,6 @@ func main() {
5656
package main
5757

5858
import (
59-
"io/ioutil"
6059
"log"
6160
"os"
6261

README.md.tpl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# SNTable
22

3-
[![GoDoc](https://godoc.org/github.com/bsm/sntable?status.svg)](https://godoc.org/github.com/bsm/sntable)
4-
[![Build Status](https://travis-ci.org/bsm/sntable.png?branch=master)](https://travis-ci.org/bsm/sntable)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/bsm/sntable.svg)](https://pkg.go.dev/github.com/bsm/sntable)
4+
[![Test](https://github.com/bsm/sntable/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/sntable/actions/workflows/test.yml)
55
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66

77
Custom [SSTable](https://www.igvita.com/2012/02/06/sstable-and-log-structured-storage-leveldb/) implementation
88
for [Go](https://golang.org). Instead of arbitrary bytes strings, this implementation assumes numeric 8-byte (`uint64`)
9-
keys.
9+
keys. Blocks can be stored uncompressed or compressed with [Snappy](https://github.com/klauspost/compress) (default)
10+
or [Zstandard](https://github.com/klauspost/compress).
1011

1112
## Examples
1213

@@ -16,7 +17,6 @@ keys.
1617
package main
1718
1819
import (
19-
"io/ioutil"
2020
"log"
2121
"os"
2222
@@ -33,7 +33,6 @@ func main() {{ "ExampleWriter" | code }}
3333
package main
3434
3535
import (
36-
"io/ioutil"
3736
"log"
3837
"os"
3938

bench/go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
module github.com/bsm/sntable/bench
22

3-
go 1.12
3+
go 1.26
44

55
replace github.com/bsm/sntable => ../
66

77
require (
88
github.com/bsm/sntable v0.1.1
99
github.com/golang/leveldb v0.0.0-20170107010102-259d9253d719
1010
github.com/syndtr/goleveldb v1.0.0
11+
)
12+
13+
require (
14+
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
15+
github.com/klauspost/compress v1.19.0 // indirect
1116
golang.org/x/net v0.0.0-20190607181551-461777fb6f67 // indirect
1217
golang.org/x/sys v0.0.0-20190610081024-1e42afee0f76 // indirect
1318
)

bench/go.sum

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,35 @@
1-
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
21
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
32
github.com/golang/leveldb v0.0.0-20170107010102-259d9253d719 h1:yahFtfWlyALYDkXw2ETowZqG4vi8hiE0yOEBOkpaXl0=
43
github.com/golang/leveldb v0.0.0-20170107010102-259d9253d719/go.mod h1:etEpE0xVqxA0N3WNUa5wic5HCNSsQvYm+PFNmOnx2iU=
54
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6-
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
7-
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
85
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
96
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
10-
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
11-
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
127
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
138
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
14-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
15-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
16-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
17-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
18-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
9+
github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ=
10+
github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
1911
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
12+
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
2013
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
21-
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
22-
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
14+
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
2315
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
24-
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
25-
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
2616
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
2717
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
2818
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2919
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
30-
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
3120
golang.org/x/net v0.0.0-20190607181551-461777fb6f67 h1:rJJxsykSlULwd2P2+pg/rtnwN2FrWp4IuCxOSyS0V00=
3221
golang.org/x/net v0.0.0-20190607181551-461777fb6f67/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3322
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3423
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3524
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
36-
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3725
golang.org/x/sys v0.0.0-20190610081024-1e42afee0f76 h1:QSmW7Q3mFdAGjtAd0byXmFJ55inUydyZ4WQmiuItAIQ=
3826
golang.org/x/sys v0.0.0-20190610081024-1e42afee0f76/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
27+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
3928
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
40-
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
41-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
42-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
4329
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
44-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
45-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4630
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
4731
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
4832
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
4933
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
34+
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
5035
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
51-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
52-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

doc.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,50 @@
22
Package sntable contains a custom SSTable implementation which,
33
instead of arbitrary bytes strings, assumes 8-byte numeric keys.
44
5-
Data Structure Documentation
5+
# Data Structure Documentation
66
7-
Store
7+
# Store
88
99
A store contains a series of data blocks followed by an index and
1010
a store footer.
1111
12-
Store layout:
13-
+---------+---------+---------+-------------+--------------+
14-
| block 1 | ... | block n | block index | store footer |
15-
+---------+---------+---------+-------------+--------------+
12+
Store layout:
13+
+---------+---------+---------+-------------+--------------+
14+
| block 1 | ... | block n | block index | store footer |
15+
+---------+---------+---------+-------------+--------------+
1616
17-
Block index:
18-
+----------------------------+--------------------+----------------------------------+--------------------------+--------+
19-
| last cell block 1 (varint) | offset 2 (varint) | last cell block 2 (varint,delta) | offset 2 (varint,delta) | ... |
20-
+----------------------------+--------------------+----------------------------------+--------------------------+--------+
17+
Block index:
18+
+----------------------------+--------------------+----------------------------------+--------------------------+--------+
19+
| last cell block 1 (varint) | offset 2 (varint) | last cell block 2 (varint,delta) | offset 2 (varint,delta) | ... |
20+
+----------------------------+--------------------+----------------------------------+--------------------------+--------+
2121
22-
Store footer:
23-
+------------------------+------------------+
24-
| index offset (8 bytes) | magic (8 bytes) |
25-
+------------------------+------------------+
22+
Store footer:
23+
+------------------------+------------------+
24+
| index offset (8 bytes) | magic (8 bytes) |
25+
+------------------------+------------------+
2626
27-
Block
27+
# Block
2828
2929
A block comprises of a series of sections, followed by a section
3030
index and a single-byte compression type indicator.
3131
32-
Block layout:
33-
+-----------+---------+-----------+---------------+---------------------------+
34-
| section 1 | ... | section n | section index | compression type (1-byte) |
35-
+-----------+---------+-----------+---------------+---------------------------+
32+
Block layout:
33+
+-----------+---------+-----------+---------------+---------------------------+
34+
| section 1 | ... | section n | section index | compression type (1-byte) |
35+
+-----------+---------+-----------+---------------+---------------------------+
3636
37-
Section index:
38-
+----------------------------+-------+----------------------------+-------------------------------+
39-
| section offset 2 (4 bytes) | ... | section offset n (4 bytes) | number of sections (4 bytes) |
40-
+----------------------------+-------+----------------------------+-------------------------------+
37+
Section index:
38+
+----------------------------+-------+----------------------------+-------------------------------+
39+
| section offset 2 (4 bytes) | ... | section offset n (4 bytes) | number of sections (4 bytes) |
40+
+----------------------------+-------+----------------------------+-------------------------------+
4141
42-
Section
42+
# Section
4343
4444
A section is a series of key/value pairs where the first key is stored as a full uint64 while subsequent keys
4545
are delta encoded.
4646
47-
+----------------+----------------------+------------------+----------------------+----------------------+------------------+-------+
48-
| key 1 (varint) | value len 1 (varint) | value 1 (varlen) | key 2 (varint,delta) | value len 2 (varint) | value 2 (varlen) | ... |
49-
+----------------+----------------------+------------------+----------------------+----------------------+------------------+-------+
47+
+----------------+----------------------+------------------+----------------------+----------------------+------------------+-------+
48+
| key 1 (varint) | value len 1 (varint) | value 1 (varlen) | key 2 (varint,delta) | value len 2 (varint) | value 2 (varlen) | ... |
49+
+----------------+----------------------+------------------+----------------------+----------------------+------------------+-------+
5050
*/
5151
package sntable

example_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sntable_test
22

33
import (
4-
"io/ioutil"
54
"log"
65
"os"
76

@@ -10,11 +9,11 @@ import (
109

1110
func ExampleWriter() {
1211
// create a file
13-
f, err := ioutil.TempFile("", "sntable-example")
12+
f, err := os.CreateTemp("", "sntable-example")
1413
if err != nil {
1514
log.Fatalln(err)
1615
}
17-
defer f.Close()
16+
defer func() { _ = f.Close() }()
1817

1918
// wrap writer around file, append (neglecting errors for demo purposes)
2019
w := sntable.NewWriter(f, nil)
@@ -39,7 +38,7 @@ func ExampleReader() {
3938
if err != nil {
4039
log.Fatalln(err)
4140
}
42-
defer f.Close()
41+
defer func() { _ = f.Close() }()
4342

4443
// get file size
4544
fs, err := f.Stat()

go.mod

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
module github.com/bsm/sntable
22

3-
go 1.12
3+
go 1.26
44

5-
require (
6-
github.com/golang/snappy v0.0.1
7-
github.com/onsi/ginkgo v1.10.3
8-
github.com/onsi/gomega v1.7.1
9-
)
5+
require github.com/klauspost/compress v1.19.0

0 commit comments

Comments
 (0)