mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Windows: Factor out sqlite
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
9c2f1669a0
commit
3f6127b173
15 changed files with 95 additions and 78 deletions
|
@ -40,7 +40,6 @@ import (
|
||||||
"github.com/docker/docker/libcontainerd"
|
"github.com/docker/docker/libcontainerd"
|
||||||
"github.com/docker/docker/migrate/v1"
|
"github.com/docker/docker/migrate/v1"
|
||||||
"github.com/docker/docker/pkg/fileutils"
|
"github.com/docker/docker/pkg/fileutils"
|
||||||
"github.com/docker/docker/pkg/graphdb"
|
|
||||||
"github.com/docker/docker/pkg/idtools"
|
"github.com/docker/docker/pkg/idtools"
|
||||||
"github.com/docker/docker/pkg/plugingetter"
|
"github.com/docker/docker/pkg/plugingetter"
|
||||||
"github.com/docker/docker/pkg/progress"
|
"github.com/docker/docker/pkg/progress"
|
||||||
|
@ -158,7 +157,6 @@ func (daemon *Daemon) restore() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var migrateLegacyLinks bool
|
|
||||||
removeContainers := make(map[string]*container.Container)
|
removeContainers := make(map[string]*container.Container)
|
||||||
restartContainers := make(map[*container.Container]chan struct{})
|
restartContainers := make(map[*container.Container]chan struct{})
|
||||||
activeSandboxes := make(map[string]interface{})
|
activeSandboxes := make(map[string]interface{})
|
||||||
|
@ -190,6 +188,8 @@ func (daemon *Daemon) restore() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var migrateLegacyLinks bool // Not relevant on Windows
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var mapLock sync.Mutex
|
var mapLock sync.Mutex
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
|
@ -265,24 +265,15 @@ func (daemon *Daemon) restore() error {
|
||||||
return fmt.Errorf("Error initializing network controller: %v", err)
|
return fmt.Errorf("Error initializing network controller: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// migrate any legacy links from sqlite
|
// Perform migration of legacy sqlite links (no-op on Windows)
|
||||||
linkdbFile := filepath.Join(daemon.root, "linkgraph.db")
|
|
||||||
var legacyLinkDB *graphdb.Database
|
|
||||||
if migrateLegacyLinks {
|
if migrateLegacyLinks {
|
||||||
legacyLinkDB, err = graphdb.NewSqliteConn(linkdbFile)
|
if err := daemon.sqliteMigration(containers); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return fmt.Errorf("error connecting to legacy link graph DB %s, container links may be lost: %v", linkdbFile, err)
|
|
||||||
}
|
}
|
||||||
defer legacyLinkDB.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that all the containers are registered, register the links
|
// Now that all the containers are registered, register the links
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
if migrateLegacyLinks {
|
|
||||||
if err := daemon.migrateLegacySqliteLinks(legacyLinkDB, c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := daemon.registerLinks(c, c.HostConfig); err != nil {
|
if err := daemon.registerLinks(c, c.HostConfig); err != nil {
|
||||||
logrus.Errorf("failed to register link for container %s: %v", c.ID, err)
|
logrus.Errorf("failed to register link for container %s: %v", c.ID, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/pkg/graphdb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// linkIndex stores link relationships between containers, including their specified alias
|
// linkIndex stores link relationships between containers, including their specified alias
|
||||||
|
@ -88,41 +85,3 @@ func (l *linkIndex) delete(container *container.Container) {
|
||||||
delete(l.childIdx, container)
|
delete(l.childIdx, container)
|
||||||
l.mu.Unlock()
|
l.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
|
||||||
}
|
|
||||||
|
|
72
daemon/links_linux.go
Normal file
72
daemon/links_linux.go
Normal file
|
@ -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
|
||||||
|
}
|
10
daemon/links_notlinux.go
Normal file
10
daemon/links_notlinux.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
package graphdb
|
package graphdb
|
||||||
|
|
||||||
import "database/sql"
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3" // registers sqlite
|
||||||
|
)
|
||||||
|
|
||||||
// NewSqliteConn opens a connection to a sqlite
|
// NewSqliteConn opens a connection to a sqlite
|
||||||
// database.
|
// database.
|
|
@ -1,7 +0,0 @@
|
||||||
// +build cgo,!windows
|
|
||||||
|
|
||||||
package graphdb
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "github.com/mattn/go-sqlite3" // registers sqlite
|
|
||||||
)
|
|
|
@ -1,7 +0,0 @@
|
||||||
// +build cgo,windows
|
|
||||||
|
|
||||||
package graphdb
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "github.com/mattn/go-sqlite3" // registers sqlite
|
|
||||||
)
|
|
|
@ -1,8 +0,0 @@
|
||||||
// +build !cgo
|
|
||||||
|
|
||||||
package graphdb
|
|
||||||
|
|
||||||
// NewSqliteConn return a new sqlite connection.
|
|
||||||
func NewSqliteConn(root string) (*Database, error) {
|
|
||||||
panic("Not implemented")
|
|
||||||
}
|
|
3
pkg/graphdb/unsupported.go
Normal file
3
pkg/graphdb/unsupported.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// +build !cgo !linux
|
||||||
|
|
||||||
|
package graphdb
|
Loading…
Add table
Reference in a new issue