-
-
Notifications
You must be signed in to change notification settings - Fork 729
go/store: fix push latency growth for git-backed remotes #10597
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
Changes from all commits
11d9d0c
75380a8
66c9930
c923d9f
b3b9192
67f9187
57fd4b4
8077ce2
411d2d3
68fccc0
942bc24
0f55ff4
a6a847d
272d08e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,11 @@ type DoltDatabaseProvider struct { | |
| droppedDatabaseManager *droppedDatabaseManager | ||
| overrides sql.EngineOverrides | ||
|
|
||
| // remoteDbs caches remote DoltDB instances by URL so that repeated push calls | ||
| // to the same remote reuse the store (and its already-opened table chunk sources) | ||
| // instead of re-opening every table file from the blobstore each time. | ||
| remoteDbs map[string]*doltdb.DoltDB | ||
|
|
||
| defaultBranch string | ||
| dbFactoryUrl string | ||
| DropDatabaseHooks []DropDatabaseHook | ||
|
|
@@ -181,6 +186,7 @@ func NewDoltDatabaseProviderWithDatabases(defaultBranch string, fs filesys.Files | |
| isStandby: new(bool), | ||
| droppedDatabaseManager: newDroppedDatabaseManager(fs), | ||
| overrides: overrides, | ||
| remoteDbs: make(map[string]*doltdb.DoltDB), | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -294,6 +300,20 @@ func (p *DoltDatabaseProvider) Close() { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // Close cached remote databases. | ||
| var remoteDbs []*doltdb.DoltDB | ||
| func() { | ||
| p.mu.RLock() | ||
| defer p.mu.RUnlock() | ||
| remoteDbs = make([]*doltdb.DoltDB, 0, len(p.remoteDbs)) | ||
| for _, rdb := range p.remoteDbs { | ||
| remoteDbs = append(remoteDbs, rdb) | ||
| } | ||
| }() | ||
| for _, rdb := range remoteDbs { | ||
| _ = rdb.Close() | ||
| } | ||
| } | ||
|
|
||
| // Installs an InitDatabaseHook which configures new databases--those | ||
|
|
@@ -539,7 +559,43 @@ func (p *DoltDatabaseProvider) GetRemoteDB(ctx context.Context, format *types.No | |
| } | ||
|
|
||
| if withCaching { | ||
| return r.GetRemoteDB(ctx, format, dialer) | ||
| // Only cache git-backed remote DBs. Other remote types (file://, aws, etc.) | ||
| // register their underlying NBS in a global singleton cache that is closed | ||
| // separately by CloseAllLocalDatabases(). Caching those here would cause a | ||
| // double-close panic on process exit. | ||
| isGitRemote := strings.HasPrefix(strings.ToLower(r.Url), "git+") | ||
| if isGitRemote { | ||
| cached := func() *doltdb.DoltDB { | ||
| p.mu.RLock() | ||
| defer p.mu.RUnlock() | ||
| return p.remoteDbs[r.Url] | ||
| }() | ||
| if cached != nil { | ||
| return cached, nil | ||
| } | ||
| } | ||
|
|
||
| remoteDB, err := r.GetRemoteDB(ctx, format, dialer) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if isGitRemote { | ||
| cached := func() *doltdb.DoltDB { | ||
| p.mu.Lock() | ||
| defer p.mu.Unlock() | ||
| if existing, ok := p.remoteDbs[r.Url]; ok { | ||
| return existing | ||
| } | ||
| p.remoteDbs[r.Url] = remoteDB | ||
| return nil | ||
| }() | ||
| if cached != nil { | ||
| _ = remoteDB.Close() | ||
| return cached, nil | ||
| } | ||
| } | ||
| return remoteDB, nil | ||
|
Comment on lines
+566
to
+598
|
||
| } | ||
| return r.GetRemoteDBWithoutCaching(ctx, format, dialer) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.