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

NEOS-1641: Fixes stale DB Connections during Data Sync Workflow #2995

Merged
merged 44 commits into from
Dec 2, 2024

Conversation

nickzelei
Copy link
Member

@nickzelei nickzelei commented Nov 26, 2024

This is a pretty large refactor that does a few things:

  • Consolidates DB Connection Caching into a single connection manager
  • Updates SQL Manager to use ConnectionManager under the hood (part of the connection consolidation)
  • Updates the Data Sync Workflow activities to properly release their connection sessions once they are finished with them
  • Moves the connection reaper out of the Sync activity and into the startup script
  • Centralizes the DB pools for the data sync activity to use a single pool that is shared across all (in-process) activities
  • Updates the backend to use the same connection manager logic but to operate in the auto-close mode once a session is released since everything here is transactional
  • Updates default connection timeout to be 10s and centralizes
  • Updates a bunch of places that hardcoded postgres and pgx to use the module constants

Copy link

linear bot commented Nov 26, 2024

Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
neosync-docs ⬜️ Ignored (Inspect) Visit Preview Dec 2, 2024 7:44pm

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 53.40136% with 274 lines in your changes missing coverage. Please review.

Project coverage is 36.10%. Comparing base (78afd79) to head (4ee4822).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/connection-manager/manager.go 80.76% 31 Missing and 4 partials ⚠️
cli/internal/cmds/neosync/sync/sync.go 0.00% 34 Missing ⚠️
backend/pkg/sqlmanager/sql-manager.go 55.55% 20 Missing ⚠️
...on-manager/pool/providers/sql/sql-pool-provider.go 9.09% 20 Missing ⚠️
worker/internal/cmds/worker/serve/serve.go 0.00% 20 Missing ⚠️
backend/internal/cmds/mgmt/serve/connect/cmd.go 0.00% 16 Missing ⚠️
internal/benthos/benthos-builder/builders/sql.go 12.50% 14 Missing ⚠️
backend/pkg/sqlmanager/sql-connection.go 0.00% 12 Missing ⚠️
...1alpha1/connection-data-service/connection-data.go 57.14% 12 Missing ⚠️
...run-sql-init-table-stmts/init-statement-builder.go 57.14% 12 Missing ⚠️
... and 18 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2995      +/-   ##
==========================================
+ Coverage   35.58%   36.10%   +0.51%     
==========================================
  Files         337      343       +6     
  Lines       39189    39323     +134     
==========================================
+ Hits        13944    14196     +252     
+ Misses      23599    23477     -122     
- Partials     1646     1650       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nickzelei nickzelei added bug Something isn't working Tech Debt Created by Linear-GitHub Sync labels Nov 27, 2024
@nickzelei nickzelei changed the title Nick/neos 1641 investigate postgres stale connections NEOS-1641: Fixes stale DB Connections during Data Sync Workflow Nov 27, 2024
@nickzelei nickzelei marked this pull request as ready for review December 2, 2024 18:16
Copy link
Contributor

@alishakawaguchi alishakawaguchi left a comment

Choose a reason for hiding this comment

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

Very clean! Left a few comments nothing blocking

"public.users": {Columns: []string{"id"}},
}, resp.Msg.TableConstraints)
}
// import (
Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to comment this out?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shoot, I don't think I did. I'll fix them, but we need to replace these with integration tests.


func (c *ConnectionManager[T]) GetConnection(
session SessionInterface,
connection ConnectionInput,
Copy link
Contributor

Choose a reason for hiding this comment

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

might be helpful to have a few debug logs here about when it finds an existing vs when it creates a new one

Copy link
Member Author

Choose a reason for hiding this comment

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

Good callout. I updated the interface to require the logger and filled it out throughout with more messages.
This forced me to pass it down further anyways and replaced a few instances where I was using the global slog.

@@ -1573,31 +1573,32 @@ func (f *fakeEELicense) IsValid() bool {
}

func executeWorkflow(
t *testing.T,
t testing.TB,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -32,6 +34,10 @@ func (r *RedisTestContainer) Setup(ctx context.Context) (*RedisTestContainer, er
"docker.io/redis:7",
redis.WithSnapshotting(10, 1),
redis.WithLogLevel(redis.LogLevelVerbose),
testcontainers.WithWaitStrategy(
wait.ForLog("* Ready to accept connections"),
wait.ForExposedPort(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to have fixed the redis container flakiness.

@nickzelei nickzelei merged commit ca71920 into main Dec 2, 2024
10 checks passed
@nickzelei nickzelei deleted the nick/neos-1641-investigate-postgres-stale-connections branch December 2, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Tech Debt Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants