diff --git a/kv/kv_interface.go b/kv/kv_interface.go index f44578601..62fce3c97 100644 --- a/kv/kv_interface.go +++ b/kv/kv_interface.go @@ -81,10 +81,11 @@ type DBVerbosityLvl int8 type Label uint8 const ( - ChainDB Label = 0 - TxPoolDB Label = 1 - SentryDB Label = 2 - ConsensusDB Label = 3 + ChainDB Label = 0 + TxPoolDB Label = 1 + SentryDB Label = 2 + ConsensusDB Label = 3 + DownloaderDB Label = 4 ) func (l Label) String() string { @@ -97,6 +98,8 @@ func (l Label) String() string { return "sentry" case ConsensusDB: return "consensus" + case DownloaderDB: + return "downloader" default: return "unknown" } diff --git a/kv/mdbx/kv_mdbx.go b/kv/mdbx/kv_mdbx.go index 8e4c0c0b8..ecca12e2c 100644 --- a/kv/mdbx/kv_mdbx.go +++ b/kv/mdbx/kv_mdbx.go @@ -249,8 +249,7 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) { } if opts.roTxsLimiter == nil { - - opts.roTxsLimiter = make(chan struct{}, runtime.NumCPU()) + opts.roTxsLimiter = make(chan struct{}, runtime.GOMAXPROCS(-1)) } db := &MdbxKV{ opts: opts, diff --git a/kv/memdb/memory_database.go b/kv/memdb/memory_database.go index ce9fb3527..3cb28de75 100644 --- a/kv/memdb/memory_database.go +++ b/kv/memdb/memory_database.go @@ -32,7 +32,9 @@ func New() kv.RwDB { func NewPoolDB() kv.RwDB { return mdbx.NewMDBX(log.New()).InMem().Label(kv.TxPoolDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.TxpoolTablesCfg }).MustOpen() } - +func NewDownloaderDB() kv.RwDB { + return mdbx.NewMDBX(log.New()).InMem().Label(kv.DownloaderDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.DownloaderTablesCfg }).MustOpen() +} func NewSentryDB() kv.RwDB { return mdbx.NewMDBX(log.New()).InMem().Label(kv.SentryDB).WithTablessCfg(func(_ kv.TableCfg) kv.TableCfg { return kv.SentryTablesCfg }).MustOpen() } @@ -51,6 +53,13 @@ func NewTestPoolDB(tb testing.TB) kv.RwDB { return db } +func NewTestDownloaderDB(tb testing.TB) kv.RwDB { + tb.Helper() + db := NewDownloaderDB() + tb.Cleanup(db.Close) + return db +} + func NewTestSentrylDB(tb testing.TB) kv.RwDB { tb.Helper() db := NewPoolDB() diff --git a/kv/tables.go b/kv/tables.go index 116e5e914..c01b56c67 100644 --- a/kv/tables.go +++ b/kv/tables.go @@ -205,9 +205,7 @@ const TrieOfStorage = "TrieStorage" const ( // DatabaseInfo is used to store information about data layout. - DatabaseInfo = "DbInfo" - SnapshotInfo = "SnapshotInfo" - BittorrentInfo = "BittorrentInfo" + DatabaseInfo = "DbInfo" // Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes). HeaderNumber = "HeaderNumber" // header_hash -> num_u64 @@ -326,6 +324,10 @@ const ( BorReceipts = "BorReceipt" BorTxLookup = "BlockBorTransactionLookup" BorSeparate = "BorSeparate" + + // Downloader + BittorrentCompletion = "BittorrentCompletion" + BittorrentInfo = "BittorrentInfo" ) // Keys @@ -387,7 +389,6 @@ var ChaindataTables = []string{ Migrations, LogTopicIndex, LogAddressIndex, - SnapshotInfo, CallTraceSet, CallFromIndex, CallToIndex, @@ -401,7 +402,6 @@ var ChaindataTables = []string{ TrieOfStorage, HashedAccounts, HashedStorage, - BittorrentInfo, HeaderCanonical, Headers, HeaderTD, @@ -429,6 +429,10 @@ var TxPoolTables = []string{ PoolInfo, } var SentryTables = []string{} +var DownloaderTables = []string{ + BittorrentCompletion, + BittorrentInfo, +} // ChaindataDeprecatedTables - list of buckets which can be programmatically deleted - for example after migration var ChaindataDeprecatedTables = []string{ @@ -496,6 +500,7 @@ var ChaindataTablesCfg = TableCfg{ var TxpoolTablesCfg = TableCfg{} var SentryTablesCfg = TableCfg{} +var DownloaderTablesCfg = TableCfg{} func sortBuckets() { sort.SliceStable(ChaindataTables, func(i, j int) bool { @@ -541,4 +546,10 @@ func reinit() { } } + for _, name := range DownloaderTables { + _, ok := DownloaderTablesCfg[name] + if !ok { + DownloaderTablesCfg[name] = TableCfgItem{} + } + } }