Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: safe database initialisation and schema migration during startup #2734

Merged
merged 1 commit into from
Nov 25, 2022

Conversation

atzoum
Copy link
Contributor

@atzoum atzoum commented Nov 24, 2022

Description

When running in embedded mode (core & warehouse) and using separate database instances for core & warehouse data, it is possible that one database's unavailability panic may cause the other database's schema migration to become dirty (corrupted) due to the asynchronous nature of the two components' startup sequence.

To eliminate this, we are now initialising both databases sequentially and stop the process gracefully in case of an error. Database initialisation for reach component happens only if the component needs to be started.

Other improvements:

  • removed a handful of panics for supporting graceful termination on failure scenarios
  • refactored the apphandlers package to remove global variables
  • introduced tests for some exceptional runner & apphandler scenarios

Notion Ticket

Link

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Base: 46.63% // Head: 46.79% // Increases project coverage by +0.15% 🎉

Coverage data is based on head (2d32146) compared to base (88f1ec1).
Patch coverage: 49.44% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2734      +/-   ##
==========================================
+ Coverage   46.63%   46.79%   +0.15%     
==========================================
  Files         297      297              
  Lines       48696    48830     +134     
==========================================
+ Hits        22711    22850     +139     
+ Misses      24557    24527      -30     
- Partials     1428     1453      +25     
Impacted Files Coverage Δ
jobsdb/jobsdb_utils.go 78.06% <0.00%> (-0.51%) ⬇️
jobsdb/readonly_jobsdb.go 33.97% <25.00%> (-0.83%) ⬇️
services/db/embeddedRecovery.go 45.71% <30.00%> (-10.96%) ⬇️
services/db/nullRecovery.go 48.27% <30.00%> (+48.27%) ⬆️
services/validators/envValidator.go 51.16% <38.20%> (-8.95%) ⬇️
app/apphandlers/gatewayAppHandler.go 14.56% <40.54%> (+14.56%) ⬆️
app/apphandlers/processorAppHandler.go 12.07% <40.98%> (+5.30%) ⬆️
warehouse/warehouse.go 10.03% <42.85%> (+0.57%) ⬆️
app/apphandlers/setup.go 67.74% <62.85%> (-11.21%) ⬇️
app/apphandlers/embeddedAppHandler.go 79.91% <69.23%> (-3.59%) ⬇️
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@atzoum atzoum force-pushed the refactor.safeStartup branch 2 times, most recently from 3b7a7d6 to 1b81a06 Compare November 24, 2022 14:24
@atzoum atzoum force-pushed the refactor.safeStartup branch 2 times, most recently from 6bacfbc to b473414 Compare November 24, 2022 16:06
@atzoum atzoum force-pushed the refactor.safeStartup branch from b473414 to 2d32146 Compare November 25, 2022 07:09
@atzoum atzoum requested review from lvrach and achettyiitr November 25, 2022 07:09
App app.App
VersionHandler func(w http.ResponseWriter, r *http.Request)
// embeddedApp is the type for embedded type implementation
type embeddedApp struct {
Copy link
Collaborator

@fracasula fracasula Nov 25, 2022

Choose a reason for hiding this comment

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

Nice job with unexporting these types 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants