Skip to content

Commit

Permalink
Merge branch 'dev' into version-bump-v1.10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jul 17, 2023
2 parents 9ff6157 + 7ac713d commit b57e152
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
28 changes: 7 additions & 21 deletions x/merkledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ type merkleDB struct {
metadataDB database.Database

// If a value is nil, the corresponding key isn't in the trie.
// Note that a call to Put may cause a node to be evicted
// from the cache, which will call [OnEviction].
// A non-nil error returned from Put is considered fatal.
nodeCache onEvictCache[path, *node]
onEvictionErr utils.Atomic[error]
evictionBatchSize int
Expand Down Expand Up @@ -566,7 +569,6 @@ func (db *merkleDB) GetChangeProof(
return i.Compare(j) < 0
})

// TODO: sync.pool these buffers
result.KeyChanges = make([]KeyChange, 0, len(changedKeys))

for _, key := range changedKeys {
Expand Down Expand Up @@ -924,7 +926,7 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e
db.root = rootChange.after

for key, nodeChange := range changes.nodes {
if err := db.putNodeInCache(key, nodeChange.after); err != nil {
if err := db.nodeCache.Put(key, nodeChange.after); err != nil {
return err
}
}
Expand Down Expand Up @@ -1234,7 +1236,7 @@ func (db *merkleDB) getNode(key path) (*node, error) {
return db.root, nil
}

if n, isCached := db.getNodeInCache(key); isCached {
if n, isCached := db.nodeCache.Get(key); isCached {
db.metrics.DBNodeCacheHit()
if n == nil {
return nil, database.ErrNotFound
Expand All @@ -1248,7 +1250,7 @@ func (db *merkleDB) getNode(key path) (*node, error) {
if err != nil {
if err == database.ErrNotFound {
// Cache the miss.
if err := db.putNodeInCache(key, nil); err != nil {
if err := db.nodeCache.Put(key, nil); err != nil {
return nil, err
}
}
Expand All @@ -1260,7 +1262,7 @@ func (db *merkleDB) getNode(key path) (*node, error) {
return nil, err
}

err = db.putNodeInCache(key, node)
err = db.nodeCache.Put(key, node)
return node, err
}

Expand Down Expand Up @@ -1341,19 +1343,3 @@ func (db *merkleDB) prepareRangeProofView(start []byte, proof *RangeProof) (*tri
}
return view, nil
}

// Non-nil error is fatal -- [db] will close.
func (db *merkleDB) putNodeInCache(key path, n *node) error {
// TODO Cache metrics
// Note that this may cause a node to be evicted from the cache,
// which will call [OnEviction].
return db.nodeCache.Put(key, n)
}

func (db *merkleDB) getNodeInCache(key path) (*node, bool) {
// TODO Cache metrics
if node, ok := db.nodeCache.Get(key); ok {
return node, true
}
return nil, false
}
5 changes: 0 additions & 5 deletions x/sync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type workItem struct {
localRootID ids.ID
}

// TODO danlaine look into using a sync.Pool for workItems
func newWorkItem(localRootID ids.ID, start, end []byte, priority priority) *workItem {
return &workItem{
localRootID: localRootID,
Expand Down Expand Up @@ -190,10 +189,6 @@ func (m *Manager) sync(ctx context.Context) {
default:
m.processingWorkItems++
work := m.unprocessedWork.GetWork()
// TODO danlaine: We won't release [m.workLock] until
// we've started a goroutine for each available work item.
// We can't apply proofs we receive until we release [m.workLock].
// Is this OK? Is it possible we end up with too many goroutines?
go m.doWork(ctx, work)
}
}
Expand Down
10 changes: 0 additions & 10 deletions x/sync/network_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,6 @@ func (c *networkClient) Disconnected(_ context.Context, nodeID ids.NodeID) error
return nil
}

// Shutdown disconnects all peers
func (c *networkClient) Shutdown() {
c.lock.Lock()
defer c.lock.Unlock()

// reset peers
// TODO danlaine: should we call [Disconnected] on each peer?
c.peers = newPeerTracker(c.log)
}

func (c *networkClient) TrackBandwidth(nodeID ids.NodeID, bandwidth float64) {
c.lock.Lock()
defer c.lock.Unlock()
Expand Down

0 comments on commit b57e152

Please sign in to comment.