Transport-neutral set reconciliation with invertible sketches
git clone https://github.com/apoloe4/moonreconcile.git
cd moonreconcile| 场景 | 输入 | 处理过程 | 输出 |
|---|---|---|---|
| 边缘缓存与中心索引同步 | 双方缓存对象的稳定 UInt64 ID | 交换快照摘要、恢复差异、拉取缺少对象 | 新增与移除 ID 清单 |
| 备份清单核对 | 本地与远端备份块 ID | 分区清单定位变化、只交换变化分区摘要 | 需要补传或复核的块 ID |
| 离线节点重新连接 | 双方事件/文档版本 ID | 固定快照版本、重试扩大摘要、校验结果 | 同步计划或全量回退建议 |
moon check --deny-warn
moon test --deny-warn
moon run examples/basic
moon run examples/partitioned
moon run examples/capacity
moon run examples/exchangeimport { "apoloe4/moonreconcile" @reconcile }let source = @reconcile.Inventory::from_ids([1UL, 2UL, 3UL], scope=42UL, epoch=7UL)
let target = @reconcile.Inventory::from_ids([2UL, 3UL, 4UL], scope=42UL, epoch=9UL)
let config = @reconcile.Config::new(16)
let wire = target.snapshot(config).encode()
let received = @reconcile.Snapshot::decode(wire, @reconcile.DecodeLimits::new())
match @reconcile.reconcile(source.snapshot(config), received, @reconcile.Policy::new()) {
Ready(plan) => {
let result = source.apply(plan)
assert_eq(result.ids(), target.ids())
}
Retry(next) => { next.width() |> ignore }
FullTransfer(_) => { /* 由应用执行全量 ID 清单交换 */ }
}pub struct BucketOffer {
// private fields
}fn BucketOffer::new(index : Int, layout : Layout, snapshot : Snapshot) -> BucketOffer raise ReconcileErrorpub struct CapacityPlan {
// private fields
}fn CapacityPlan::new(expected_differences : Int, max_wire_bytes? : Int, seed? : UInt64) -> CapacityPlan raise ReconcileErrorfn CapacityPlan::smaller_than_full_ids(self : CapacityPlan, members : Int) -> Bool raise ReconcileErrorpub struct Collector {
// private fields
}fn Collector::accept(self : Collector, source : BucketOffer, target : BucketOffer, policy : Policy) -> Outcome raise ReconcileErrorfn Collector::new(source : Manifest, target : Manifest, max_changes? : Int) -> Collector raise ReconcileErrorpub struct DecodeLimits {
// private fields
}pub struct DecodeReport {
// private fields
}pub struct FrameReader {
// private fields
}pub struct Inventory {
// private fields
}fn Inventory::bucket_offer(self : Inventory, layout : Layout, index : Int, config : Config) -> BucketOffer raise ReconcileErrorfn Inventory::bucket_offers(self : Inventory, layout : Layout, indexes : Array[Int], config : Config, max_cells? : Int) -> Array[BucketOffer] raise ReconcileErrorpub struct Manifest {
// private fields
}fn Manifest::decode(data : Bytes, max_buckets? : Int, max_members? : Int) -> Manifest raise ReconcileErrorpub struct Plan {
// private fields
}pub struct Policy {
// private fields
}pub struct Session {
// private fields
}fn Session::new(source : Snapshot, target_epoch : UInt64, limits : SessionLimits) -> Session raise ReconcileErrorfn Session::receive(self : Session, source : Snapshot, frame : Bytes) -> SessionState raise ReconcileErrorpub struct SessionLimits {
// private fields
}fn SessionLimits::new(max_rounds? : Int, max_bytes? : Int64, max_steps? : Int, max_width? : Int, max_members? : Int) -> SessionLimits raise ReconcileErrorpub struct Sketch {
// private fields
}pub struct Snapshot {
// private fields
}fn Snapshot::from_sorted_ids(ids : Iter[UInt64], config : Config, scope? : UInt64, epoch? : UInt64, max_members? : Int) -> Snapshot raise ReconcileErrorInstall
Download zipTransport-neutral set reconciliation with invertible sketches