-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Initialize test schema versions #10790
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
Open
stephanos
wants to merge
14
commits into
main
Choose a base branch
from
stephanos/server-startup-hosts-custom-persistence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−50
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
671fdfe
Allow static hosts for requested services
stephanos c618b0c
Relax startup checks for custom server options
stephanos d34f44d
Initialize test schema versions
stephanos af9e792
Keep schema validation in startup checks
stephanos fdbdf4b
Avoid panic in test schema setup
stephanos e01a658
Avoid panic in schema version setup
stephanos 91c5ab6
Remove static host startup change
stephanos e079cf6
Simplify test schema version setup
stephanos b1308d1
Update test_sql_persistence.go
stephanos 20395a0
Update test_sql_persistence.go
stephanos 908112c
Update test.go
stephanos 6fb30a4
Update test.go
stephanos 3b335ed
Update test.go
stephanos 02bd1a6
Unexport test schema version setup
stephanos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ func (s *TestCluster) SetupTestDatabase() { | |
| } | ||
| s.LoadSchema(path.Join(schemaDir, "temporal", "schema.sql")) | ||
| s.LoadSchema(path.Join(schemaDir, "visibility", "schema.sql")) | ||
| s.loadSchemaVersion() | ||
| } | ||
|
|
||
| // Config returns the persistence config for connecting to this test cluster | ||
|
|
@@ -111,26 +112,9 @@ func (s *TestCluster) CreateDatabase() { | |
| cfg2.DatabaseName = "" | ||
| } | ||
|
|
||
| var db sqlplugin.AdminDB | ||
| var err error | ||
| err = backoff.ThrottleRetry( | ||
| func() error { | ||
| db, err = NewSQLAdminDB(sqlplugin.DbKindUnknown, &cfg2, resolver.NewNoopResolver(), log.NewTestLogger(), metrics.NoopMetricsHandler) | ||
| return err | ||
| }, | ||
| backoff.NewExponentialRetryPolicy(time.Second).WithExpirationInterval(time.Minute), | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer func() { | ||
| err := db.Close() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| }() | ||
| err = db.CreateDatabase(s.cfg.DatabaseName) | ||
| db := s.newAdminDB(sqlplugin.DbKindUnknown, &cfg2) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new helper |
||
| defer s.closeAdminDB(db) | ||
| err := db.CreateDatabase(s.cfg.DatabaseName) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
@@ -154,18 +138,9 @@ func (s *TestCluster) DropDatabase() { | |
|
|
||
| // NOTE need to connect with empty name to drop the database | ||
| cfg2.DatabaseName = "" | ||
| db, err := NewSQLAdminDB(sqlplugin.DbKindUnknown, &cfg2, resolver.NewNoopResolver(), log.NewTestLogger(), metrics.NoopMetricsHandler) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer func() { | ||
| err := db.Close() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| }() | ||
| err = db.DropDatabase(s.cfg.DatabaseName) | ||
| if err != nil { | ||
| db := s.newAdminDB(sqlplugin.DbKindUnknown, &cfg2) | ||
| defer s.closeAdminDB(db) | ||
| if err := db.DropDatabase(s.cfg.DatabaseName); err != nil { | ||
| panic(err) | ||
| } | ||
| s.logger.Info("dropped database", tag.String("database", s.cfg.DatabaseName)) | ||
|
|
@@ -183,24 +158,8 @@ func (s *TestCluster) LoadSchema(schemaFile string) { | |
| ) | ||
| } | ||
|
|
||
| var db sqlplugin.AdminDB | ||
| err = backoff.ThrottleRetry( | ||
| func() error { | ||
| db, err = NewSQLAdminDB(sqlplugin.DbKindUnknown, &s.cfg, resolver.NewNoopResolver(), log.NewTestLogger(), metrics.NoopMetricsHandler) | ||
| return err | ||
| }, | ||
| backoff.NewExponentialRetryPolicy(time.Second).WithExpirationInterval(time.Minute), | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer func() { | ||
| err := db.Close() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| }() | ||
| db := s.newAdminDB(sqlplugin.DbKindUnknown, &s.cfg) | ||
| defer s.closeAdminDB(db) | ||
|
|
||
| if rewriter, ok := db.(sqlplugin.SchemaStatementRewriter); ok { | ||
| statements = rewriter.RewriteSchemaStatements(statements) | ||
|
|
@@ -220,3 +179,43 @@ func (s *TestCluster) LoadSchema(schemaFile string) { | |
| } | ||
| s.logger.Info("loaded schema") | ||
| } | ||
|
|
||
| func (s *TestCluster) loadSchemaVersion() { | ||
| db := s.newAdminDB(sqlplugin.DbKindMain, &s.cfg) | ||
| defer s.closeAdminDB(db) | ||
|
|
||
| expectedVersion := db.ExpectedVersion() | ||
| if err := db.CreateSchemaVersionTables(); err != nil { | ||
| s.logger.Fatal("CreateSchemaVersionTables", tag.Error(err)) | ||
| } | ||
| if err := db.UpdateSchemaVersion(s.cfg.DatabaseName, expectedVersion, expectedVersion); err != nil { | ||
| s.logger.Fatal("UpdateSchemaVersion", tag.Error(err)) | ||
| } | ||
| if err := db.WriteSchemaUpdateLog("0", expectedVersion, "", "initial version"); err != nil { | ||
| s.logger.Fatal("WriteSchemaUpdateLog", tag.Error(err)) | ||
| } | ||
| s.logger.Info("loaded schema version", tag.String("version", expectedVersion)) | ||
| } | ||
|
|
||
| func (s *TestCluster) newAdminDB(kind sqlplugin.DbKind, cfg *config.SQL) sqlplugin.AdminDB { | ||
| var db sqlplugin.AdminDB | ||
| var err error | ||
| err = backoff.ThrottleRetry( | ||
| func() error { | ||
| db, err = NewSQLAdminDB(kind, cfg, resolver.NewNoopResolver(), log.NewTestLogger(), metrics.NoopMetricsHandler) | ||
| return err | ||
| }, | ||
| backoff.NewExponentialRetryPolicy(time.Second).WithExpirationInterval(time.Minute), | ||
| nil, | ||
| ) | ||
| if err != nil { | ||
| s.logger.Fatal("NewSQLAdminDB", tag.Error(err)) | ||
| } | ||
| return db | ||
| } | ||
|
|
||
| func (s *TestCluster) closeAdminDB(db sqlplugin.AdminDB) { | ||
| if err := db.Close(); err != nil { | ||
| s.logger.Fatal("Close schema DB", tag.Error(err)) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ these are defined in
temporal/tools/cassandra/cqlclient.gobut there's no precedence for re-use there so we copy them here; the SQL variants do the same