Skip to content

A2-2: Implement AnnounceKey and QueryKeyOwnership in coordinator #140

Closed

Description

@scttfrdmn

Context

The AnnounceKey and QueryKeyOwnership methods on DistributedCoordinator (added as stubs in A1-2) need real implementations. These are the foundation of peer-to-peer cache warming: nodes announce when they cache an object, and other nodes query ownership before going to S3.

What to implement

In internal/distributed/coordinator.go (or a new cache_announce.go):

Add to Coordinator:

announcements   map[string][]types.KeyAnnouncement  // key → list of holders
announcementsMu sync.RWMutex

Implement AnnounceKey(ctx, ann types.KeyAnnouncement) error:

  1. Store announcement in local announcements map (append/replace by NodeID)
  2. Broadcast a MessageTypeCacheAnnounce gossip message to all alive peers
  3. Start a background TTL eviction goroutine (default 5 minutes) if not already running

Add recordAnnouncement(ann types.KeyAnnouncement) as the internal method called both locally and by the gossip handler.

Implement QueryKeyOwnership(ctx, key string) ([]types.KeyAnnouncement, error):

  • Acquire announcementsMu.RLock()
  • Return a copy of announcements[key] (empty slice, not nil, if not found)

In internal/distributed/gossip.go:
Add MessageTypeCacheAnnounce MessageType = "cache_announce" to the message type constants. Handle it in handleIncomingMessage by calling gp.cluster.coordinator.(*Coordinator).recordAnnouncement(ann).

Acceptance criteria

  • AnnounceKey broadcasts to peers and stores locally
  • QueryKeyOwnership returns local announcements (no network call — local map only)
  • TTL eviction removes stale announcements after 5 minutes (configurable)
  • Goroutine safety: go test -race ./internal/distributed/... passes
  • Integration test: node A calls AnnounceKey, node B (connected via loopback UDP) calls QueryKeyOwnership for same key, gets node A's entry

Sequencing

Depends on A1-2 (interface) and A2-1 (coordinator wired into FUSE). Must land before A2-3 and A2-4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedeffort: largepriority: criticaltype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions