Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

syncjobs: use rcache.FIFOList#46676

Merged
keegancsmith merged 6 commits intomainfrom
sync-job-records-fifolist
Jan 20, 2023
Merged

syncjobs: use rcache.FIFOList#46676
keegancsmith merged 6 commits intomainfrom
sync-job-records-fifolist

Conversation

@bobheadxi
Copy link
Member

@bobheadxi bobheadxi commented Jan 19, 2023

Migrates syncjobs to use the new rcache.FIFOList - this allows us to avoid scanning all Redis keys to find relevant records.

The experimental setting authz.syncJobsRecordsTTL has been changed to authz.syncJobsRecordsLimit - records are no longer retained based on age, but based on this size cap. The setting is clearly marked as experimental and is not advertised, so I think this is fine to change.

For simplicity, a hard cap of 500 is placed on reads, so that the reader does not need to implement conf watching.

Addresses https://github.com/sourcegraph/sourcegraph/pull/44387/files#r1080897926

Test plan

Test coverage, and a quick manual test via sg start and some dev-private config

image

@cla-bot cla-bot bot added the cla-signed label Jan 19, 2023
Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

nice! Looking forward to approving this :)

For simplicity, a hard cap of 500 is placed on reads, so that the reader does not need to implement conf watching.

elegant :D

Given most uses of FIFOList have this pattern I wonder if the constructor should take a getter for MaxSize. Would simplify code in a few places.

@bobheadxi bobheadxi marked this pull request as ready for review January 19, 2023 18:55
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Jan 19, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff 02c985e...85fc2b3.

Notify File(s)
@unknwon enterprise/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go
enterprise/cmd/frontend/internal/authz/resolvers/resolver.go
enterprise/cmd/frontend/internal/authz/resolvers/resolver_test.go
enterprise/internal/authz/syncjobs/mocks_test.go
enterprise/internal/authz/syncjobs/records_reader.go
enterprise/internal/authz/syncjobs/records_reader_test.go
enterprise/internal/authz/syncjobs/records_store.go
enterprise/internal/authz/syncjobs/records_store_test.go

@bobheadxi
Copy link
Member Author

Was considering how this will tie in with https://github.com/sourcegraph/sourcegraph/issues/46078, since I just noticed that work has begun in earnest on DB-backed permissions sync - this query and cache was created to make it possible to validate that every authz provider configured has started permissions syncing successfully as part of prep work for https://github.com/sourcegraph/customer/issues/1525, so that we can offer guarantees of successful migration.

Looking at the newly introduced backgroundJobs query, and the format of the perms sync jobs, I think we can eventually get away with dropping this functionality entirely and just using backgroundJobs, at the cost of losing some granularity on per-provider statuses, but maybe it doesn't really matter that much.

It looks like the DB-backed sync might still be a few releases away, so I ended up deciding it's worthwhile to get this updated for now and deprecate/remove it later - the query is marked as experimental so I don't believe there's much issue in getting rid of it eventually.

cc @mrnugget @sashaostrikov

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

Thanks!!

r.cache = rcache.NewWithTTL(syncJobsRecordsPrefix, ttlSeconds)
r.logger.Debug("enabled records store cache", log.Int("ttlSeconds", ttlSeconds))
// Setting cache size to 0 disables it
r.cache.SetMaxSize(recordsLimit)
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure how FIFOList behaves with a negative size. It likely needs to be updated (will be a tiny update) to special case that. Alternatively here if < 0 you make the number 0

Copy link
Member

Choose a reason for hiding this comment

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

I did the former here https://github.com/sourcegraph/sourcegraph/pull/46702

I might land this for ya since I am now basing some other work of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!

@mrnugget
Copy link
Contributor

Was considering how this will tie in with https://github.com/sourcegraph/sourcegraph/issues/46078 [...]

@bobheadxi Work is in progress and @thenamankumar and @sashaostrikov are making great progress. It's not "a few releases" away, I'd say. But Naman can probably say more to when he expects to remove your Redis-based solution.

@keegancsmith keegancsmith merged commit 471793d into main Jan 20, 2023
@keegancsmith keegancsmith deleted the sync-job-records-fifolist branch January 20, 2023 10:57
@0xnmn
Copy link
Contributor

0xnmn commented Jan 20, 2023

@bobheadxi, we are targeting to release DB backed perms syncer, thoroughly tested along with a new permissions sync job API by the end of Feb.

March release will definitely have it, and if things go well, we can release it in the Feb release itself.

@bobheadxi
Copy link
Member Author

Happy to work with y'all on its removal - feel free to cc me on anything!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants