-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #879 from iotaledger/develop
Merge v0.3.4 changes to master
- Loading branch information
Showing
8 changed files
with
110 additions
and
115 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
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,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 | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -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") | ||
} |
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