Skip to content

Implement persistent cache service #3903

Merged
chlins merged 3 commits intodragonflyoss:mainfrom
BruceAko:main
Apr 2, 2025
Merged

Implement persistent cache service #3903
chlins merged 3 commits intodragonflyoss:mainfrom
BruceAko:main

Conversation

@BruceAko
Copy link
Copy Markdown
Member

@BruceAko BruceAko commented Mar 18, 2025

Add persistent cache API in Dragonfly Manager.

Description

This PR adds new features to manage persistent cache in Dragonfly Manager:

  1. Implementation of Redis-based persistent cache operations:

    • Added GetPersistentCaches method to list multiple persistent cache tasks
    • Added GetPersistentCache method to retrieve a single persistent cache task
    • Added DestroyPersistentCache method to delete a persistent cache task
  2. Enhanced data structures:

    • Completed GetPersistentCacheResponse structure with all necessary task information fields
    • Implemented PersistentCachePeer structure with detailed peer information
    • Added PersistentCachePeerHost structure with comprehensive host information
    • Created PersistentCacheParams for API parameter handling
  3. Technical improvements:

    • Used Scan operation instead of Keys for better Redis performance
    • Improved error handling with clear warning messages
    • Normalized parameter naming for better code consistency
    • Enhanced logging with standardized formats

Related Issue

#3892

Motivation and Context

Persistent cache is an important feature in Dragonfly that allows frequently accessed resources to be cached for extended periods. This PR provides the necessary APIs to manage these persistent caches through the Dragonfly Manager.

The implementation follows the existing patterns in Dragonfly, particularly referencing the scheduler/resource/persistentcache modules for data structure design. By providing these management APIs, users can now view detailed information about persistent cache tasks, including their associated peers and host information, as well as perform management operations.

These changes enable better visibility and control over persistent caches in Dragonfly deployments, which is particularly valuable for environments with high volumes of repeated downloads.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update (if none of the other choices apply)

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@BruceAko BruceAko requested a review from a team as a code owner March 18, 2025 15:49
Comment thread manager/service/persistent_cache.go Fixed
Comment thread manager/service/persistent_cache.go Fixed
Comment thread pkg/redis/redis.go Fixed
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 8.19113% with 538 lines in your changes missing coverage. Please review.

Project coverage is 34.65%. Comparing base (e0bedbd) to head (ae9cb66).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
manager/service/persistent_cache.go 0.00% 506 Missing ⚠️
manager/handlers/persistent_cache.go 56.75% 12 Missing and 4 partials ⚠️
pkg/redis/redis.go 0.00% 10 Missing ⚠️
manager/router/router.go 0.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3903      +/-   ##
==========================================
- Coverage   35.03%   34.65%   -0.39%     
==========================================
  Files         337      339       +2     
  Lines       39373    39959     +586     
==========================================
+ Hits        13796    13847      +51     
- Misses      24670    25201     +531     
- Partials      907      911       +4     
Flag Coverage Δ
unittests 34.65% <8.19%> (-0.39%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
api/manager/docs.go 0.00% <ø> (ø)
manager/handlers/job.go 50.42% <ø> (ø)
manager/service/mocks/service_mock.go 95.67% <100.00%> (+0.15%) ⬆️
manager/service/service.go 0.00% <ø> (ø)
manager/router/router.go 0.00% <0.00%> (ø)
pkg/redis/redis.go 31.42% <0.00%> (-5.24%) ⬇️
manager/handlers/persistent_cache.go 56.75% <56.75%> (ø)
manager/service/persistent_cache.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaius-qi gaius-qi requested a review from Copilot March 31, 2025 09:35
Copy link
Copy Markdown

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 introduces a persistent cache service with new Redis key functions, API endpoints, types, and corresponding service mocks to support persistent cache management.

  • Updates Redis helper functions for key management, including a new extraction function
  • Adds new API routes and handler for retrieving persistent caches
  • Implements new types and service mocks for persistent cache functionality

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/redis/redis.go Updates key formatting and adds a new extraction function
manager/types/persistent_cache.go Introduces types for persistent cache tasks and peers
manager/types/job.go Refactors comment to match updated scheduler cluster IDs
manager/service/service.go Adds the GetPersistentCaches service method
manager/service/mocks/service_mock.go Implements the mock for GetPersistentCaches
manager/router/router.go Adds persistent cache GET route using JWT and RBAC middleware
manager/handlers/persistent_cache.go Implements the handler for retrieving persistent caches
manager/handlers/job.go Updates routing comment for job creation endpoint

Comment thread pkg/redis/redis.go
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
@BruceAko BruceAko changed the title [WIP] Implement persistent cache service Implement persistent cache service Apr 1, 2025
BruceAko added 2 commits April 2, 2025 01:13
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
Copy link
Copy Markdown
Member

@gaius-qi gaius-qi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@chlins chlins left a comment

Choose a reason for hiding this comment

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

lgtm

@chlins chlins merged commit 2f49b73 into dragonflyoss:main Apr 2, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants