Clean up global variables in safekeeper code #8200
Labels
a/tech_debt
Area: related to tech debt
c/storage/safekeeper
Component: storage: safekeeper
m/good_first_issue
Moment: when doing your first Neon contributions
We have at least several places in the code where global variables are used:
GlobalTimelines::<funcname>
to lookup timelinesstatic TIMELINES_STATE
stores all timelines as a global variablestatic REMOTE_STORAGE
stores config for remote storage (e.g. S3)To resolve the issue, we should replace
GlobalTimelines::
calls withArc<GlobalTimelines>
struct. It will contain the hashmap of all timelines (the same wayTIMELINES_STATE
is working now). It should be passed around to the code that needs access to all timelines, instead of everything relying on global access throughGlobalTimelines
.GlobalTimelines::
callsstatic TIMELINES_STATE
REMOTE_STORAGE
too should be passed around as aArc<RemoteStorage>
. Each task that requires access to remote storage should getArc<RemoteStorage>
as a dependency during initialization.static REMOTE_STORAGE
If some background task requires access to all global state (remote storage, timeline, config), we can bundle them together inside
Arc<SafekeeperApp>
, which is easier to carry around.Also, currently
struct GlobalTimelinesState
contains two fields that are part of the global state:Currently
conf
is required in many places and usually it just copied from global state on demand. The config is loaded once on startup and never changes. This is wasteful, we should replace it withArc<SafeKeeperConf>
and always carryArc<..>
instead ofSafeKeeperConf
.SafeKeeperConf
usages withArc<SafeKeeperConf>
everywhereWhy?
To improve testing, to allow to run more than one safekeeper instance in a single process.
To simplify creating new dependencies without introducing global variables and special getters.
The text was updated successfully, but these errors were encountered: