Skip to content

perf(groundcontrol): implement in-memory cache for satellite group states - #619

Draft
ahsan-zamil wants to merge 1 commit into
container-registry:mainfrom
ahsan-zamil:fix/gc-group-state-cache
Draft

perf(groundcontrol): implement in-memory cache for satellite group states#619
ahsan-zamil wants to merge 1 commit into
container-registry:mainfrom
ahsan-zamil:fix/gc-group-state-cache

Conversation

@ahsan-zamil

@ahsan-zamil ahsan-zamil commented Aug 12, 2026

Copy link
Copy Markdown

This PR resolves #583 by implementing a thread-safe and nil-safe in-memory cache for satellite group states on the Ground Control Server struct.

Changes:

  1. Added groupStateCache map (map[int32][]string) and a groupStateCacheMu sync.RWMutex to the Server struct.
  2. Checked the cache first in SetSatelliteConfig() and populated it on a cache miss.
  3. Added cache invalidation logic on satellite/group modifications:
    • DeleteSatellite
    • AddSatelliteToGroup
    • RemoveSatelliteFromGroup
    • DeleteGroup (clears the cache)
  4. Added group_cache_test.go verifying cache hits, lazy initialization, and invalidation.

Closes #583

Review in cubic

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ahsan-zamil, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0be474c0-96c3-4276-9ddb-3af77ee5a015

📥 Commits

Reviewing files that changed from the base of the PR and between 341cb42 and 661a0bd.

📒 Files selected for processing (5)
  • internal/groundcontrol/server/config_handlers.go
  • internal/groundcontrol/server/group_cache_test.go
  • internal/groundcontrol/server/group_handlers.go
  • internal/groundcontrol/server/satellite_handlers.go
  • internal/groundcontrol/server/server.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

codacy-production Bot commented Aug 12, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity · 3 duplication

Metric Results
Complexity 9
Duplication 3

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@gitar-bot

gitar-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/groundcontrol/server/config_handlers.go">

<violation number="1" location="internal/groundcontrol/server/config_handlers.go:505">
P1: When a group membership transaction commits while this request fills a cache miss, this write can repopulate the entry after the mutation handler invalidates it. Later `SetSatelliteConfig` calls then reuse the pre-change group list; publish only if a cache-generation check still matches, or synchronize cache fills with invalidation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

}
groupStates = append(groupStates, utils.AssembleGroupState(grp.GroupName))
}
s.setCachedGroupStates(sat.ID, groupStates)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: When a group membership transaction commits while this request fills a cache miss, this write can repopulate the entry after the mutation handler invalidates it. Later SetSatelliteConfig calls then reuse the pre-change group list; publish only if a cache-generation check still matches, or synchronize cache fills with invalidation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/groundcontrol/server/config_handlers.go, line 505:

<comment>When a group membership transaction commits while this request fills a cache miss, this write can repopulate the entry after the mutation handler invalidates it. Later `SetSatelliteConfig` calls then reuse the pre-change group list; publish only if a cache-generation check still matches, or synchronize cache fills with invalidation.</comment>

<file context>
@@ -475,31 +475,34 @@ func (s *Server) SetSatelliteConfig(w http.ResponseWriter, r *http.Request) {
+			}
+			groupStates = append(groupStates, utils.AssembleGroupState(grp.GroupName))
+		}
+		s.setCachedGroupStates(sat.ID, groupStates)
 	}
 
</file context>

…ates

Signed-off-by: Ahsan Zamil <ahsanzamil76@gmail.com>
@ahsan-zamil
ahsan-zamil force-pushed the fix/gc-group-state-cache branch from 6096f78 to 661a0bd Compare August 12, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(groundcontrol): Implement in-memory cache for satellite group states

1 participant