-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request moby#28996 from Microsoft/jjh/sqlite-remove-windows
Windows: Factor out sqlite
- Loading branch information
Showing
15 changed files
with
95 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package daemon | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/docker/docker/container" | ||
"github.com/docker/docker/pkg/graphdb" | ||
) | ||
|
||
// migrateLegacySqliteLinks migrates sqlite links to use links from HostConfig | ||
// when sqlite links were used, hostConfig.Links was set to nil | ||
func (daemon *Daemon) migrateLegacySqliteLinks(db *graphdb.Database, container *container.Container) error { | ||
// if links is populated (or an empty slice), then this isn't using sqlite links and can be skipped | ||
if container.HostConfig == nil || container.HostConfig.Links != nil { | ||
return nil | ||
} | ||
|
||
logrus.Debugf("migrating legacy sqlite link info for container: %s", container.ID) | ||
|
||
fullName := container.Name | ||
if fullName[0] != '/' { | ||
fullName = "/" + fullName | ||
} | ||
|
||
// don't use a nil slice, this ensures that the check above will skip once the migration has completed | ||
links := []string{} | ||
children, err := db.Children(fullName, 0) | ||
if err != nil { | ||
if !strings.Contains(err.Error(), "Cannot find child for") { | ||
return err | ||
} | ||
// else continue... it's ok if we didn't find any children, it'll just be nil and we can continue the migration | ||
} | ||
|
||
for _, child := range children { | ||
c, err := daemon.GetContainer(child.Entity.ID()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
links = append(links, c.Name+":"+child.Edge.Name) | ||
} | ||
|
||
container.HostConfig.Links = links | ||
return container.WriteHostConfig() | ||
} | ||
|
||
// sqliteMigration performs the link graph DB migration. | ||
func (daemon *Daemon) sqliteMigration(containers map[string]*container.Container) error { | ||
// migrate any legacy links from sqlite | ||
linkdbFile := filepath.Join(daemon.root, "linkgraph.db") | ||
var ( | ||
legacyLinkDB *graphdb.Database | ||
err error | ||
) | ||
|
||
legacyLinkDB, err = graphdb.NewSqliteConn(linkdbFile) | ||
if err != nil { | ||
return fmt.Errorf("error connecting to legacy link graph DB %s, container links may be lost: %v", linkdbFile, err) | ||
} | ||
defer legacyLinkDB.Close() | ||
|
||
for _, c := range containers { | ||
if err := daemon.migrateLegacySqliteLinks(legacyLinkDB, c); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build !linux | ||
|
||
package daemon | ||
|
||
import "github.com/docker/docker/container" | ||
|
||
// sqliteMigration performs the link graph DB migration. No-op on platforms other than Linux | ||
func (daemon *Daemon) sqliteMigration(_ map[string]*container.Container) error { | ||
return nil | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// +build !cgo !linux | ||
|
||
package graphdb |
File renamed without changes.