Skip to content

Add DataStorage interface and implementations#4458

Merged
yrobla merged 2 commits intomainfrom
issue-4420-v2
Apr 1, 2026
Merged

Add DataStorage interface and implementations#4458
yrobla merged 2 commits intomainfrom
issue-4420-v2

Conversation

@yrobla
Copy link
Copy Markdown
Contributor

@yrobla yrobla commented Mar 31, 2026

Summary

Introduce DataStorage, a key-value metadata store separate from the existing Session-based Storage interface. Unlike Storage, DataStorage never round-trips live session objects — it stores only serialisable map[string]string metadata.

This separation avoids the type-assertion bug where a Redis round-trip deserialises a MultiSession as a plain *StreamableSession, losing all backend connections and routing state.

Two implementations are provided:

  • LocalSessionDataStorage: in-memory sync.Map with TTL-based eviction and a background cleanup goroutine.
  • RedisSessionDataStorage: Redis/Valkey-backed with sliding-window TTL via GETEX on every Load, and atomic SET NX for StoreIfAbsent.

Both pass a shared contract test suite covering Store/Load round-trips, upsert, nil metadata, empty-ID errors, Exists (without TTL refresh), StoreIfAbsent atomicity, Delete idempotency, and TTL behaviour.

Fixes #4220

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Changes

File Change

Does this introduce a user-facing change?

Special notes for reviewers

Introduce DataStorage, a key-value metadata store separate from the
existing Session-based Storage interface. Unlike Storage, DataStorage
never round-trips live session objects — it stores only serialisable
map[string]string metadata.

This separation avoids the type-assertion bug where a Redis round-trip
deserialises a MultiSession as a plain *StreamableSession, losing all
backend connections and routing state.

Two implementations are provided:
- LocalSessionDataStorage: in-memory sync.Map with TTL-based eviction
  and a background cleanup goroutine.
- RedisSessionDataStorage: Redis/Valkey-backed with sliding-window TTL
  via GETEX on every Load, and atomic SET NX for StoreIfAbsent.

Both pass a shared contract test suite covering Store/Load round-trips,
upsert, nil metadata, empty-ID errors, Exists (without TTL refresh),
StoreIfAbsent atomicity, Delete idempotency, and TTL behaviour.

Related-to: #4420
@yrobla yrobla requested a review from Copilot March 31, 2026 11:16
@github-actions github-actions bot added the size/L Large PR: 600-999 lines changed label Mar 31, 2026
Copy link
Copy Markdown
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

Introduces a new DataStorage abstraction for storing session metadata only (map[string]string) to avoid round-tripping live session objects through Redis and the associated type-loss/deserialization issues.

Changes:

  • Added DataStorage interface with Store/Load/Exists/StoreIfAbsent/Delete/Close semantics.
  • Implemented LocalSessionDataStorage (in-memory sync.Map with TTL eviction via background cleanup goroutine).
  • Implemented RedisSessionDataStorage (JSON-encoded metadata with sliding TTL via GETEX, atomic create via SET NX) plus a shared contract test suite for both implementations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
pkg/transport/session/session_data_storage.go Defines the DataStorage interface and provides the local constructor.
pkg/transport/session/session_data_storage_local.go Adds in-memory metadata storage with TTL-based eviction and cleanup goroutine.
pkg/transport/session/session_data_storage_redis.go Adds Redis/Valkey-backed metadata storage with sliding TTL and atomic create.
pkg/transport/session/session_data_storage_test.go Adds contract tests and TTL/behavior tests for both implementations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 74.85030% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.68%. Comparing base (9824210) to head (ee7f535).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
...kg/transport/session/session_data_storage_redis.go 55.55% 21 Missing and 7 partials ⚠️
...kg/transport/session/session_data_storage_local.go 87.80% 6 Missing and 4 partials ⚠️
pkg/transport/session/session_data_storage.go 75.00% 1 Missing and 1 partial ⚠️
pkg/transport/session/storage_redis.go 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4458      +/-   ##
==========================================
+ Coverage   69.54%   69.68%   +0.13%     
==========================================
  Files         486      493       +7     
  Lines       50026    50452     +426     
==========================================
+ Hits        34791    35156     +365     
- Misses      12554    12602      +48     
- Partials     2681     2694      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Mar 31, 2026
@yrobla yrobla requested a review from Copilot March 31, 2026 13:16
Copy link
Copy Markdown
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Mar 31, 2026
@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Mar 31, 2026
@yrobla yrobla requested a review from Copilot March 31, 2026 13:32
Copy link
Copy Markdown
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Mar 31, 2026
Copy link
Copy Markdown
Contributor

@jerm-dro jerm-dro left a comment

Choose a reason for hiding this comment

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

Clean implementation — the interface is well-motivated and both implementations are solid with thorough shared contract tests. Two suggestions inline on naming and interface surface area. Feel free to address them in a stacked PR.

@yrobla yrobla merged commit 1bcf16b into main Apr 1, 2026
79 of 81 checks passed
@yrobla yrobla deleted the issue-4420-v2 branch April 1, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write unit tests for horizontal scaling operator behaviors (THV-0047)

5 participants