Skip to content

Architecture: SMV003 implementation leaks into service layer #25

@drmingdrmer

Description

@drmingdrmer

Summary

The service layer directly imports and uses version-specific state machine implementation (SMV003), creating tight coupling between layers.

Location

crates/service/src/store/meta_raft_state_machine/mod.rs:27-29

use databend_meta_raft_store::sm_v003::SMV003;
use databend_meta_raft_store::sm_v003::SnapshotStoreV004;
use databend_meta_raft_store::sm_v003::WriteEntry;

Problem

The service layer is tightly coupled to a specific storage version (sm_v003). This makes it difficult to:

  • Swap out storage implementations for testing
  • Upgrade to new storage versions without changing service code
  • Test service logic independently of storage

Impact

  • Upgrading storage versions requires changes across multiple crates
  • Unit testing service logic requires the full storage stack
  • Abstraction boundaries are violated

Suggested Fix

Create a trait abstraction in raft-store that hides version-specific details:

// In raft-store
pub trait StateMachineStorage: Send + Sync {
    async fn apply(&self, entry: WriteEntry) -> Result<()>;
    async fn snapshot(&self) -> Result<Snapshot>;
    // ... other operations
}

// SMV003 implements this trait
impl StateMachineStorage for SMV003 { ... }

// Service uses the trait, not the concrete type
pub struct MetaRaftStateMachine<S: StateMachineStorage> {
    storage: S,
}

Priority

P2 - Architecture improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions