feat(redis): add shard-aware key schema, Lua scripts, and atomic ops

Implements the kmsvc: key schema (inflight, pending/watermark keyed by
shard+partition, vis_index, dedup, fifo_lock, queue meta, shard map) plus
the atomic reap/ack Lua scripts used for safe multi-replica redelivery
and DLQ routing.
This commit is contained in:
riotpiaole
2026-06-21 17:05:38 -07:00
parent b704d401a1
commit a04c76a684
12 changed files with 927 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
// Package redis implements the key schemas and atomic Lua scripts from
// design.md §4/§5, shared by the queue-operator and the message-plane service.
package redis
import "fmt"
func InFlightKey(queue, receiptHandle string) string {
return fmt.Sprintf("kmsvc:inflight:%s:%s", queue, receiptHandle)
}
func PendingKey(queue, shardID string, partition int32) string {
return fmt.Sprintf("kmsvc:pending:%s:%s:%d", queue, shardID, partition)
}
func WatermarkKey(queue, shardID string, partition int32) string {
return fmt.Sprintf("kmsvc:watermark:%s:%s:%d", queue, shardID, partition)
}
func VisIndexKey(queue string) string {
return fmt.Sprintf("kmsvc:vis_index:%s", queue)
}
func DedupKey(queue, groupID, dedupID string) string {
return fmt.Sprintf("kmsvc:dedup:%s:%s:%s", queue, groupID, dedupID)
}
func FIFOLockKey(queue, groupID string) string {
return fmt.Sprintf("kmsvc:fifo_lock:%s:%s", queue, groupID)
}
func QueueMetaKey(queue string) string {
return fmt.Sprintf("kmsvc:queue:%s", queue)
}
func ShardMapKey(queue string) string {
return fmt.Sprintf("kmsvc:shardmap:%s", queue)
}
func ShardMapChannel(queue string) string {
return fmt.Sprintf("kmsvc:shardmap_invalidate:%s", queue)
}
func QueueMetaChannel(queue string) string {
return fmt.Sprintf("kmsvc:queuemeta_invalidate:%s", queue)
}
func RedeliverKey(queue string) string {
return fmt.Sprintf("kmsvc:redeliver:%s", queue)
}
func QueueLockKey(queue string) string {
return fmt.Sprintf("kmsvc:queue_lock:%s", queue)
}