go: sqle: remotesrv: Successfully replicate CREATE DATABASE commands by instantiating new databases on the standby on demand.

This commit is contained in:
Aaron Son
2022-10-05 12:37:39 -07:00
parent 3cbd40c618
commit 995e3818cd
3 changed files with 20 additions and 20 deletions

View File

@@ -59,6 +59,8 @@ type DoltDatabaseProvider interface {
sql.DatabaseProvider
RevisionDatabaseProvider
CreateDatabase(ctx *sql.Context, path string) error
// FileSystem returns the filesystem used by this provider, rooted at the data directory for all databases.
FileSystem() filesys.Filesys
// FileSystemForDatabase returns a filesystem, with the working directory set to the root directory
@@ -109,6 +111,10 @@ func (e emptyRevisionDatabaseProvider) CloneDatabaseFromRemote(ctx *sql.Context,
return nil
}
func (e emptyRevisionDatabaseProvider) CreateDatabase(ctx *sql.Context, dbName string) error {
return nil
}
func (e emptyRevisionDatabaseProvider) RevisionDbState(_ *sql.Context, revDB string) (InitialDbState, error) {
return InitialDbState{}, sql.ErrDatabaseNotFound.New(revDB)
}

View File

@@ -33,7 +33,18 @@ func (s remotesrvStore) Get(path, nbfVerStr string) (remotesrv.RemoteSrvStore, e
sess := dsess.DSessFromSess(s.ctx.Session)
db, err := sess.Provider().Database(s.ctx, path)
if err != nil {
return nil, err
if sql.ErrDatabaseNotFound.Is(err) {
err = sess.Provider().CreateDatabase(s.ctx, path)
if err != nil {
return nil, err
}
db, err = sess.Provider().Database(s.ctx, path)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
sdb, ok := db.(SqlDatabase)
if !ok {

View File

@@ -835,18 +835,9 @@ tests:
error_match: failed to transition from primary to standby gracefully
- exec: "create table vals (i int primary key)"
- exec: "insert into vals values (0)"
- name: primary replicates to standby, fails over, new primary replicates to standby, fails over, new primary has all writes
- name: create new database, primary replicates to standby, fails over, new primary replicates to standby, fails over, new primary has all writes
multi_repos:
- name: server1
repos:
- name: repo1
with_remotes:
- name: standby
url: http://localhost:50052/repo1
- name: repo2
with_remotes:
- name: standby
url: http://localhost:50052/repo2
with_files:
- name: server.yaml
contents: |
@@ -866,15 +857,6 @@ tests:
args: ["--config", "server.yaml"]
port: 3309
- name: server2
repos:
- name: repo1
with_remotes:
- name: standby
url: http://localhost:50051/repo1
- name: repo2
with_remotes:
- name: standby
url: http://localhost:50051/repo2
with_files:
- name: server.yaml
contents: |
@@ -896,6 +878,7 @@ tests:
connections:
- on: server1
queries:
- exec: 'create database repo1'
- exec: 'use repo1'
- exec: 'create table vals (i int primary key)'
- exec: 'insert into vals values (0),(1),(2),(3),(4)'