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

fix: checkptr error under -race option #73

Merged
merged 7 commits into from
Jan 6, 2023
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/axw/gocov v1.1.0
github.com/blugelabs/bluge v0.2.2
github.com/blugelabs/bluge_segment_api v0.2.0
github.com/boltdb/bolt v1.3.1
github.com/gin-gonic/gin v1.8.2
github.com/mgechev/revive v1.2.4
github.com/stretchr/testify v1.8.1
Expand Down Expand Up @@ -58,6 +57,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.4.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -211,6 +213,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
3 changes: 2 additions & 1 deletion internal/meta/metadata/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package metadata
import (
json "encoding/json"
"github.com/tatris-io/tatris/internal/meta/metadata/storage"
"github.com/tatris-io/tatris/internal/meta/metadata/storage/boltdb"
"github.com/tatris-io/tatris/internal/protocol"
)

var metaStore storage.MetaStore

func init() {
metaStore, _ = storage.Open()
metaStore, _ = boltdb.Open()
}

func Create(idx *protocol.Index) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
// Copyright 2022 Tatris Project Authors. Licensed under Apache-2.0.

// Package storage is about how to implement persistent storage of metadata
package storage
// Package boltdb describes an implementation of boltdb-based metadata storage
package boltdb

import (
"bytes"
"errors"
"github.com/tatris-io/tatris/internal/meta/metadata/storage"
"go.etcd.io/bbolt"
"time"

"github.com/boltdb/bolt"
)

const (
BoltMetaPath = "/tmp/tatris/_meta.bolt"
)

type BoltMetaStore struct {
db *bolt.DB
db *bbolt.DB
}

func Open() (*BoltMetaStore, error) {
// Open the data file in your current directory.
func Open() (storage.MetaStore, error) {
// Open the data file.
// It will be created if it doesn't exist.
db, err := bolt.Open(BoltMetaPath, 0600, &bolt.Options{Timeout: 1 * time.Second})
db, err := bbolt.Open(BoltMetaPath, 0600, &bbolt.Options{Timeout: 1 * time.Second})
if err != nil {
return nil, err
}
return &BoltMetaStore{db}, nil
}

func Close(store *BoltMetaStore) error {
func (store *BoltMetaStore) Close() error {
return store.db.Close()
}

func (store *BoltMetaStore) Get(path string) ([]byte, error) {
var result []byte
bkt, key := splitPath(path)
err := store.db.View(func(tx *bolt.Tx) error {
err := store.db.View(func(tx *bbolt.Tx) error {
bucket := tx.Bucket(bkt)
if bucket == nil {
return errors.New("bucket not found: " + string(bkt))
Expand All @@ -53,7 +53,7 @@ func (store *BoltMetaStore) Get(path string) ([]byte, error) {

func (store *BoltMetaStore) Set(path string, val []byte) error {
bkt, key := splitPath(path)
return store.db.Update(func(tx *bolt.Tx) error {
return store.db.Update(func(tx *bbolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(bkt)
if err != nil {
return err
Expand All @@ -64,7 +64,7 @@ func (store *BoltMetaStore) Set(path string, val []byte) error {

func (store *BoltMetaStore) Delete(path string) error {
bkt, key := splitPath(path)
return store.db.Update(func(tx *bolt.Tx) error {
return store.db.Update(func(tx *bbolt.Tx) error {
bucket := tx.Bucket(bkt)
if bucket != nil {
return bucket.Delete(key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2022 Tatris Project Authors. Licensed under Apache-2.0.

package storage
package boltdb

import (
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 2 additions & 0 deletions internal/meta/metadata/storage/metastore.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright 2022 Tatris Project Authors. Licensed under Apache-2.0.

// Package storage is about the physical storage of metadata
package storage

type MetaStore interface {
Set(string, []byte) error
Get(string) ([]byte, error)
Delete(string) error
Close() error
}