Skip to content

Conversation

@StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Jul 26, 2024

Why this should be merged

The cache package is currently a bit odd - as there is a metercacher sub-package (similar to the database implementations). But lru is implemented in the top level cache package.

This moves the lru implementations out of the cache package into their own package (to align with the database structure)

How this works

  • Moves code around
  • Deprecates some code
  • Unexports as much code as possible

How this was tested

Existing tests

@StephenButtolph StephenButtolph requested a review from ARR4N July 26, 2024 20:58
@github-actions
Copy link

github-actions bot commented Sep 1, 2024

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes some stutters

Comment on lines -43 to -55

cache.Size = 2

expectedValue3 := &evictable[ids.ID]{id: ids.ID{2}}
returnedValue = cache.Deduplicate(expectedValue3)
require.Equal(expectedValue2, returnedValue)
require.Equal(1, expectedValue1.evicted)
require.Zero(expectedValue2.evicted)

cache.Flush()
require.Equal(1, expectedValue1.evicted)
require.Equal(1, expectedValue2.evicted)
require.Zero(expectedValue3.evicted)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size is no longer mutable.

@StephenButtolph StephenButtolph marked this pull request as ready for review May 1, 2025 01:49
{Size: 2, Func: Eviction},
}

func TestBasic(t *testing.T, cache cache.Cacher[ids.ID, int64]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these renamed? Is this because we felt the cachetest.Test* is stuttering?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@github-project-automation github-project-automation bot moved this to Backlog 🧊 in avalanchego May 1, 2025
@joshua-kim joshua-kim moved this from Backlog 🧊 to In Progress 🏗️ in avalanchego May 1, 2025
@StephenButtolph StephenButtolph requested a review from Copilot May 1, 2025 19:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors cache implementations by moving the LRU cache into its own package and deprecating legacy cache code.

  • Migrates cache.LRU usage to the new lru package API (lru.NewCache and lru.NewSizedCache).
  • Removes legacy cache files and updates corresponding tests.

Reviewed Changes

Copilot reviewed 45 out of 46 changed files in this pull request and generated no comments.

Show a summary per file
File Description
snow/engine/avalanche/bootstrap/queue/state.go Updates cache reference from lru implementations.
snow/engine/avalanche/bootstrap/bootstrapper.go Replaces legacy cache with new lru.NewCache usage.
network/p2p/gossip/gossip.go Converts cache.LRU usage to lru.NewCache in gossip implementation.
network/p2p/acp118/handler_test.go Updates test cache instantiation to lru.NewCache.
database/linkeddb/linkeddb.go Migrates node cache creation to use lru.NewCache.
cache/unique_cache.go Removed unique cache implementation.
cache/metercacher/cache_test.go Refactored tests to use lru.NewCache and lru.NewSizedCache.
cache/lru/sized_cache_test.go Updates sized cache tests with new API and renames test functions.
cache/lru/sized_cache.go Refactors sized cache implementation and naming.
cache/lru/deduplicator_test.go Adapts deduplicator tests to new naming conventions.
cache/lru/deduplicator.go Adds new deduplicator implementation in the lru package.
cache/lru/cache_test.go Introduces tests for the new lru.Cache implementation.
cache/lru/cache.go Implements the new lru.Cache as a replacement for legacy code.
cache/empty.go Adds a clarifying comment to the Empty cache implementation.
cache/cachetest/cacher.go Updates test function names to match the new lru API.
cache/cache.go Removes legacy Deduplicator and Evictable definitions.
Files not reviewed (1)
  • go.mod: Language not supported
Comments suppressed due to low confidence (2)

cache/lru/sized_cache_test.go:4

  • [nitpick] Changing the test package from 'cache_test' to 'lru' may expose unexported identifiers. If white-box testing is not required, consider using 'lru_test' to maintain proper test isolation.
package lru

cache/cachetest/cacher.go:26

  • [nitpick] Ensure that renaming the test function from 'TestBasic' to 'Basic' is consistent with your project's test naming conventions to avoid confusion across the codebase.
{Size: 1, Func: Basic},

Copy link
Contributor

@alarso16 alarso16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@StephenButtolph StephenButtolph added this pull request to the merge queue May 1, 2025
Merged via the queue into master with commit c2ea301 May 1, 2025
24 checks passed
@StephenButtolph StephenButtolph deleted the refactor-cache-implementations branch May 1, 2025 20:45
@github-project-automation github-project-automation bot moved this from In Progress 🏗️ to Done 🎉 in avalanchego May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants