Ledger 是一个 Roblox 数据存储库,用无锁的验证折叠取代会话锁,通过用户定义的操作和归约函数在所有服务器上达成一致状态。

Stars

5

7 天增长

暂无数据

Fork 数

0

开放 Issue

0

开源协议

MIT

最近更新

2026-07-27

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它完全消除了会话锁,提供更强的一致性保证(无效状态不可达),没有锁等待时间、租约到期问题或旁路通信,同时支持跨服务器写入、原子事务和自动恢复。

适合谁使用

  • 管理玩家数据的 Roblox 游戏开发者
  • 需要无锁、强一致性数据存储的服务器工程师
  • 构建涉及交易、余额或物品系统的多人游戏团队
  • 厌倦会话锁复杂性和崩溃恢复问题的开发者

典型使用场景

  • 跨服务器的玩家物品和虚拟货币管理
  • 带原子两阶段提交的跨服物品交易
  • 存储在共享实体存储中的部落或公会数据
  • 离线玩家赠款和一次性奖励分发

项目优势

  • 无锁验证折叠使无效状态不可达,而不仅仅是拒绝
  • 通过构造幂等:每个操作都有唯一 ID,防止重复应用
  • 跨服务器写入(Edit、Transfer、Tx)可作用于任何在线或离线玩家
  • 原子事务,支持最多四个键的无锁两阶段提交

使用前须知

  • 需要纪律:变更必须表达为命名操作和归约函数
  • 主要针对 Roblox 环境(Luau、DataStore),不可移植
  • 对不熟悉事件溯源或折叠模式的开发者学习曲线陡峭

README 快速开始

Ledger

Player data as a ledger, not a document.

What is this?

A datastore library for Roblox with no session locks. You never write state. You write down the change you want, a function you own decides whether it is legal, and state is what falls out of replaying those changes.

local Store = Ledger.New({
	Name = "PlayerData",
	Default = { Gold = 100, Items = {} },
	Reducer = function(State, Op)
		if Op.Kind == "SpendGold" then
			if Op.Amount > State.Gold then
				return nil -- refused, on every server, forever
			end
			local Next = table.clone(State)
			Next.Gold -= Op.Amount
			return Next
		end
		return nil
	end,
})

Store:Load(Player)
Store:Expect(Player):Apply("SpendGold", { Amount = 25 })

Two servers spend the same 100 gold, both writes land, the fold accepts one and refuses the other. Every server agrees, every time.

A session lock serializes writers. A validating fold makes the invalid state unreachable, which is a stronger guarantee that also costs nothing when a server crashes: no lease to wait out, no locked player join stall, no side channel to touch someone offline or on another server. What you pay instead is discipline. Changes are ops with names, and a reducer validates them.

Features

  • Lock-free validating fold. Invalid state is unreachable, not rejected after the fact, and every server computes the same result without a lock.
  • Apply for gameplay, Commit for side effects. Apply is an instant local call. Commit is durable and tells you whether your op won, so exactly one server lands a one time grant.
  • Cross-server writes. Edit, Transfer and Tx work on any player, online here, elsewhere, or offline.
  • Entity stores. Keys = "String" gives you clans, listings, world records: shared state no single server owns.
  • Transfers. One balance moved through an escrow, deduped by id, self healing after a crash. Name the transfer and a retry is safe.
  • Atomic transactions. Lock-free two phase commit across two to four keys, which may span two stores. Both sides move or neither does, and a stale one aborts itself within a minute.
  • Migrations with rolling deploy safety. Versioned shape upgrades, a hard guard against old servers folding new formats down, and a `Compat

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

leifstout
leifstout GitHub avatar

dataServiceTyped

DataServiceTyped provides persistent, auto-replicated, and observable typed player data management for Roblox Luau.

Luau
75