Skip to content

Commit

Permalink
Merge branch 'protobuf-1.4-fix' into release-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lni committed Apr 19, 2020
2 parents 415d373 + 3049e09 commit ee03e85
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ notifications:
on_success: never
on_failure: never

before_install:
- go get -u google.golang.org/grpc

script:
- GO111MODULE=on DRAGONBOAT_LOGDB=pebble make travis-ci-test
- GO111MODULE=on go test -tags "dragonboat_pebble_test" -v -coverprofile=coverage.txt -covermode=atomic
Expand Down
21 changes: 14 additions & 7 deletions internal/fileutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"

"github.com/lni/dragonboat/v3/internal/vfs"
)

Expand All @@ -43,6 +41,15 @@ const (
deleteFilename = "DELETED.dragonboat"
)

// Marshaler is the interface for types that can be Marshaled.
type Marshaler interface {
Marshal() ([]byte, error)
}

type Unmarshaler interface {
Unmarshal([]byte) error
}

// DirExist returns whether the specified filesystem entry exists.
func DirExist(name string, fs vfs.IFS) (bool, error) {
if name == "." || name == "/" {
Expand Down Expand Up @@ -152,7 +159,7 @@ func SyncDir(dir string, fs vfs.IFS) (err error) {
}

// MarkDirAsDeleted marks the specified directory as deleted.
func MarkDirAsDeleted(dir string, msg proto.Message, fs vfs.IFS) error {
func MarkDirAsDeleted(dir string, msg Marshaler, fs vfs.IFS) error {
return CreateFlagFile(dir, deleteFilename, msg, fs)
}

Expand All @@ -175,7 +182,7 @@ func getHash(data []byte) []byte {
// CreateFlagFile creates a flag file in the specific location. The flag file
// contains the marshaled data of the specified protobuf message.
func CreateFlagFile(dir string,
filename string, msg proto.Message, fs vfs.IFS) (err error) {
filename string, msg Marshaler, fs vfs.IFS) (err error) {
fp := fs.PathJoin(dir, filename)
f, err := fs.Create(fp)
if err != nil {
Expand All @@ -189,7 +196,7 @@ func CreateFlagFile(dir string,
err = cerr
}
}()
data, err := proto.Marshal(msg)
data, err := msg.Marshal()
if err != nil {
panic(err)
}
Expand All @@ -215,7 +222,7 @@ func CreateFlagFile(dir string,
// location. The data of the flag file will be unmarshaled into the specified
// protobuf message.
func GetFlagFileContent(dir string,
filename string, msg proto.Message, fs vfs.IFS) (err error) {
filename string, msg Unmarshaler, fs vfs.IFS) (err error) {
fp := fs.PathJoin(dir, filename)
f, err := fs.Open(vfs.Clean(fp))
if err != nil {
Expand All @@ -239,7 +246,7 @@ func GetFlagFileContent(dir string,
if !bytes.Equal(h, expectedHash) {
panic("corrupted flag file content")
}
return proto.Unmarshal(buf, msg)
return msg.Unmarshal(buf)
}

// HasFlagFile returns a boolean value indicating whether flag file can be
Expand Down
4 changes: 1 addition & 3 deletions internal/rsm/statemachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"math/rand"
"testing"

"github.com/golang/protobuf/proto"

"github.com/lni/dragonboat/v3/client"
"github.com/lni/dragonboat/v3/config"
"github.com/lni/dragonboat/v3/internal/raft"
Expand Down Expand Up @@ -1259,7 +1257,7 @@ func genTestKVData(k, d string) []byte {
Key: k,
Val: d,
}
data, err := proto.Marshal(&u)
data, err := u.Marshal()
if err != nil {
panic(err)
}
Expand Down
8 changes: 3 additions & 5 deletions internal/server/snapshotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sync"
"syscall"

"github.com/golang/protobuf/proto"

"github.com/lni/dragonboat/v3/internal/fileutil"
"github.com/lni/dragonboat/v3/internal/vfs"
)
Expand Down Expand Up @@ -186,7 +184,7 @@ func (se *SSEnv) MustRemoveTempDir() {
}

// FinalizeSnapshot finalizes the snapshot.
func (se *SSEnv) FinalizeSnapshot(msg proto.Message) error {
func (se *SSEnv) FinalizeSnapshot(msg fileutil.Marshaler) error {
finalizeLock.Lock()
defer finalizeLock.Unlock()
if err := se.createFlagFile(msg); err != nil {
Expand All @@ -209,7 +207,7 @@ func (se *SSEnv) RemoveFinalDir() error {
}

// SaveSSMetadata saves the metadata of the snapshot file.
func (se *SSEnv) SaveSSMetadata(msg proto.Message) error {
func (se *SSEnv) SaveSSMetadata(msg fileutil.Marshaler) error {
err := fileutil.CreateFlagFile(se.tmpDir,
SnapshotMetadataFilename, msg, se.fs)
return err
Expand Down Expand Up @@ -278,7 +276,7 @@ func (se *SSEnv) renameTempDirToFinalDir() error {
return fileutil.SyncDir(se.rootDir, se.fs)
}

func (se *SSEnv) createFlagFile(msg proto.Message) error {
func (se *SSEnv) createFlagFile(msg fileutil.Marshaler) error {
return fileutil.CreateFlagFile(se.tmpDir,
fileutil.SnapshotFlagFilename, msg, se.fs)
}
3 changes: 1 addition & 2 deletions internal/tests/concurrentkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"time"
"unsafe"

"github.com/golang/protobuf/proto"
"github.com/lni/dragonboat/v3/internal/tests/kvpb"
sm "github.com/lni/dragonboat/v3/statemachine"
)
Expand Down Expand Up @@ -89,7 +88,7 @@ func (s *ConcurrentKVTest) Lookup(key interface{}) (interface{}, error) {
func (s *ConcurrentKVTest) Update(ents []sm.Entry) ([]sm.Entry, error) {
for i := 0; i < len(ents); i++ {
dataKv := &kvpb.PBKV{}
err := proto.Unmarshal(ents[i].Cmd, dataKv)
err := dataKv.Unmarshal(ents[i].Cmd)
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/tests/kvtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"
"github.com/lni/dragonboat/v3/internal/tests/kvpb"
sm "github.com/lni/dragonboat/v3/statemachine"
"github.com/lni/goutils/random"
Expand Down Expand Up @@ -153,7 +152,7 @@ func (s *KVTest) Update(data []byte) (sm.Result, error) {
}
generateRandomDelay()
dataKv := s.pbkvPool.Get().(*kvpb.PBKV)
err := proto.Unmarshal(data, dataKv)
err := dataKv.Unmarshal(data)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit ee03e85

Please sign in to comment.