fix(sync): use nanosecond precision for bindings version to ensure uniqueness

Use UnixNano for version field while keeping Unix seconds for updated_at
timestamp. This ensures version changes are detected even when multiple
syncs occur within the same second.
This commit is contained in:
zenfun
2025-12-26 11:20:53 +08:00
parent c83fe03892
commit 3d39c591fd
2 changed files with 65 additions and 5 deletions

View File

@@ -651,7 +651,9 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
snap routing.BindingSnapshot
}
snaps := make(map[string]*routing.BindingSnapshot)
now := time.Now().Unix()
now := time.Now()
nowUnix := now.Unix()
version := now.UnixNano()
for _, b := range bindings {
if strings.TrimSpace(b.Status) != "" && strings.TrimSpace(b.Status) != "active" {
@@ -677,7 +679,7 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
Namespace: ns,
PublicModel: pm,
Status: "active",
UpdatedAt: now,
UpdatedAt: nowUnix,
}
snaps[key] = snap
}
@@ -699,7 +701,6 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
candidate.Error = "no_provider"
}
nowUnix := time.Now().Unix()
for _, k := range keys {
if k.status != "" && k.status != "active" {
continue
@@ -729,8 +730,8 @@ func (s *SyncService) writeBindingsSnapshot(ctx context.Context, pipe redis.Pipe
}
meta := map[string]string{
"version": fmt.Sprintf("%d", now),
"updated_at": fmt.Sprintf("%d", now),
"version": fmt.Sprintf("%d", version),
"updated_at": fmt.Sprintf("%d", nowUnix),
"source": "cp_builtin",
}
if err := pipe.HSet(ctx, "meta:bindings_meta", meta).Err(); err != nil {