WormDb.Cluster 1.0.2

dotnet add package WormDb.Cluster --version 1.0.2
                    
NuGet\Install-Package WormDb.Cluster -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WormDb.Cluster" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WormDb.Cluster" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="WormDb.Cluster" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WormDb.Cluster --version 1.0.2
                    
#r "nuget: WormDb.Cluster, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WormDb.Cluster@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WormDb.Cluster&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=WormDb.Cluster&version=1.0.2
                    
Install as a Cake Tool

WormDb.Cluster

WormDb 的 gRPC 集群复制模块,实现 Follower → Leader 单向推流复制。

写节点(Follower)先将日志本地落盘,再异步推送到汇聚节点(Leader)归档。支持断线自动重连、补偿推送、背压保护。

功能

特性 说明
Follower → Leader 推流 gRPC 客户端流(Client Streaming),单向复制
本地先行落地 Follower 先写本地 DB 再推流,保证数据不丢
去重(序列号水位) Leader 按 per-follower 序列号去重,避免重复写入
断线自动重连 网络中断后自动重连,未确认条目自动补偿推送
背压保护 Channel 满时返回 false,静默丢弃计数
优雅退出 ShutdownAsync 等待 Channel 排空 + 超时保护
持久化水位 Leader/Follower 水位状态持久化到 JSON 文件,重启可恢复

核心 API

Leader 端

// LeaderNode
int AggregateBatch(PushBatch push);      // 汇聚批次(含去重),返回写入数
void OnFollowerConnected(uint id);        // 跟踪连接
void OnFollowerDisconnected(uint id);
IReadOnlyList<LogEntry> QueryRange(long startNs, long endNs);

// 统计
long TotalReceived / TotalBatches / DuplicateSkipped
int ConnectedFollowers
uint NodeId
ulong GetFollowerWatermark(uint followerId)

Follower 端

// FollowerReplicationClient
bool Write(LogEntry entry);                          // 单条:本地写入 + 推流入队
bool WriteBatch(IReadOnlyList<LogEntry> entries);    // 批量写入(false = 背压)
Task StartAsync();                                    // 启动后台推流循环
Task ShutdownAsync(TimeSpan timeout);                 // 优雅排空 + 关闭
Task RequestReplayAsync(ulong fromSeq);               // 向 Leader 请求回放

// 统计
long SentCount / LastAckSeq / DroppedCount
int PushErrors

gRPC 服务定义

service WormReplication {
    rpc PushEntries (stream PushBatch) returns (PushAck);
    rpc ReplayFrom (ReplayRequest) returns (stream LogEntry);
}

核心组件

职责
LeaderNode Leader 汇聚节点:接收推流、去重、写入归档、连接管理
FollowerReplicationClient Follower 推流客户端:本地写入 + 异步推流、重连、补偿
LeaderReplicationService gRPC 服务端:实现 PushEntriesReplayFrom
LeaderReplicationState Leader 持久化水位:per-follower 去重序列号、统计
FollowerReplicationState Follower 持久化进度:lastAckedSeq、lastAckedTimeNs

数据流

客户端 HTTP 写入
    |
    v
Follower: Write() -> 本地 LogDatabase.Append() -> Channel<T>.TryWrite()
    |
    | gRPC Client Streaming (PushEntries)
    v
Leader: PushEntries() -> LeaderNode.AggregateBatch()
        -> 去重检查(序列号水位) -> db.Append()
        -> 更新持久化水位

依赖


<ProjectReference Include="..\WormDb.Core\WormDb.Core.csproj" />


<PackageReference Include="Google.Protobuf" Version="3.35.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.80.0" />
<PackageReference Include="Grpc.Net.Client" Version="2.80.0" />
<PackageReference Include="Grpc.Tools" Version="2.81.0" PrivateAssets="All" />


<FrameworkReference Include="Microsoft.AspNetCore.App" />

使用

Leader 模式

using WormDb.Cluster;

var leader = new LeaderNode(nodeId: 0, db, stateFile: "./leader-state.json");
var grpcService = new LeaderReplicationService(leader);
// 注册到 gRPC 服务...

Follower 模式

using WormDb.Cluster;

var follower = new FollowerReplicationClient(
    nodeId: 1,
    localDb,
    leaderAddress: "http://localhost:5100",
    stateFile: "./follower-state.json"
);
await follower.StartAsync();

// 写入(本地落盘 + 异步推流)
follower.Write(new LogEntry { ... });

// 优雅退出
await follower.ShutdownAsync(TimeSpan.FromSeconds(10));
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WormDb.Cluster:

Package Downloads
WormDb

WORM (Write Once Read Many) append-only log database engine. Built-in TagIndex inverted index, LZ4 compression, mmap zero-copy reads, Protobuf serialization, gRPC cluster replication, and ASP.NET Core Minimal API. Zero external dependencies, single-binary deployment.

WormDb.Extensions

WORM (Write Once Read Many) append-only log database engine. Built-in TagIndex inverted index, LZ4 compression, mmap zero-copy reads, Protobuf serialization, gRPC cluster replication, and ASP.NET Core Minimal API. Zero external dependencies, single-binary deployment.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 45 6/2/2026
1.0.1 58 6/1/2026