Skip to content

Commit

Permalink
Merge pull request #879 from iotaledger/develop
Browse files Browse the repository at this point in the history
Merge v0.3.4 changes to master
  • Loading branch information
capossele authored Dec 11, 2020
2 parents e197de7 + 1ce4633 commit 65349e3
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.3.4 - 2020-12-11
* Revert Pebble to Badger.
* **Breaking**: bumps network and database versions

# v0.3.3 - 2020-12-10
* Fix sync issue.
* Fix pkger issue.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/beevik/ntp v0.3.0
github.com/cockroachdb/pebble v0.0.0-20201130172119-f19faf8529d6
github.com/dgraph-io/badger/v2 v2.0.3
github.com/drand/drand v1.1.1
github.com/drand/kyber v1.1.2
github.com/gin-gonic/gin v1.6.3
Expand Down
98 changes: 98 additions & 0 deletions packages/database/badgerdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package database

import (
"fmt"
"os"
"runtime"

"github.com/dgraph-io/badger/v2"
"github.com/dgraph-io/badger/v2/options"
"github.com/iotaledger/hive.go/kvstore"
badgerstore "github.com/iotaledger/hive.go/kvstore/badger"
)

const valueLogGCDiscardRatio = 0.1

type badgerDB struct {
*badger.DB
}

// NewDB returns a new persisting DB object.
func NewDB(dirname string) (DB, error) {
// assure that the directory exists
err := createDir(dirname)
if err != nil {
return nil, fmt.Errorf("could not create DB directory: %w", err)
}

opts := badger.DefaultOptions(dirname)

opts.Logger = nil
opts.SyncWrites = false
opts.TableLoadingMode = options.MemoryMap
opts.ValueLogLoadingMode = options.MemoryMap
opts.CompactL0OnClose = false
opts.KeepL0InMemory = false
opts.VerifyValueChecksum = false
opts.ZSTDCompressionLevel = 1
opts.Compression = options.None
opts.MaxCacheSize = 50000000
opts.EventLogging = false

if runtime.GOOS == "windows" {
opts = opts.WithTruncate(true)
}

db, err := badger.Open(opts)
if err != nil {
return nil, fmt.Errorf("could not open DB: %w", err)
}

return &badgerDB{DB: db}, nil
}

func (db *badgerDB) NewStore() kvstore.KVStore {
return badgerstore.New(db.DB)
}

// Close closes a DB. It's crucial to call it to ensure all the pending updates make their way to disk.
func (db *badgerDB) Close() error {
return db.DB.Close()
}

func (db *badgerDB) RequiresGC() bool {
return true
}

func (db *badgerDB) GC() error {
err := db.RunValueLogGC(valueLogGCDiscardRatio)
if err != nil {
return err
}
// trigger the go garbage collector to release the used memory
runtime.GC()
return nil
}

// Returns whether the given file or directory exists.
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return true, err
}

func createDir(dirname string) error {
exists, err := exists(dirname)
if err != nil {
return err
}
if !exists {
return os.Mkdir(dirname, 0700)
}
return nil
}
107 changes: 0 additions & 107 deletions packages/database/pebbledb.go

This file was deleted.

8 changes: 4 additions & 4 deletions packages/tangle/tangle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestTangle_MissingMessages(t *testing.T) {
attachDelay = 5 * time.Millisecond
)

// create pebble store
pebbleDB, err := testutil.PebbleDB(t)
// create badger store
badgerDB, err := testutil.BadgerDB(t)
require.NoError(t, err)

// map to keep track of the tips
Expand All @@ -106,7 +106,7 @@ func TestTangle_MissingMessages(t *testing.T) {

// setup the message factory
msgFactory := NewMessageFactory(
pebbleDB,
badgerDB,
[]byte("sequenceKey"),
identity.GenerateLocalIdentity(),
TipSelectorFunc(func(count int) []MessageID {
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestTangle_MissingMessages(t *testing.T) {
}

// create the tangle
tangle := New(pebbleDB)
tangle := New(badgerDB)
defer tangle.Shutdown()
require.NoError(t, tangle.Prune())

Expand Down
2 changes: 1 addition & 1 deletion plugins/autopeering/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const (

func init() {
flag.StringSlice(CfgEntryNodes, []string{"[email protected]:15626", "5EDH4uY78EA6wrBkHHAVBWBMDt7EcksRq6pjzipoW15B@entrynode.alphanet.tanglebay.org:14656"}, "list of trusted entry nodes for auto peering")
flag.Int(CfgNetworkVersion, 11, "autopeering network version")
flag.Int(CfgNetworkVersion, 12, "autopeering network version")
}
2 changes: 1 addition & 1 deletion plugins/banner/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
once sync.Once

// AppVersion version number
AppVersion = "v0.3.3"
AppVersion = "v0.3.4"
// SimplifiedAppVersion is the version number without commit hash
SimplifiedAppVersion = simplifiedVersion(AppVersion)
)
Expand Down
2 changes: 1 addition & 1 deletion plugins/database/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
const (
// DBVersion defines the version of the database schema this version of GoShimmer supports.
// Every time there's a breaking change regarding the stored data, this version flag should be adjusted.
DBVersion = 13
DBVersion = 14
)

var (
Expand Down

0 comments on commit 65349e3

Please sign in to comment.