Skip to content
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

Removes consul-migrate for 0.6 #1309

Merged
merged 5 commits into from
Oct 15, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 13 additions & 67 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/consul-migrate/migrator"
"github.com/hashicorp/consul/watch"
"github.com/hashicorp/go-checkpoint"
"github.com/hashicorp/go-syslog"
Expand Down Expand Up @@ -165,6 +164,19 @@ func (c *Command) readConfig() *Config {
return nil
}

// Check the data dir for signs of an un-migrated Consul 0.5.x or older
// server. Consul refuses to start if this is present to protect a server
// with existing data from starting on a fresh data set.
if config.Server {
mdbPath := filepath.Join(config.DataDir, "mdb")
if _, err := os.Stat(mdbPath); !os.IsNotExist(err) {
c.Ui.Error(fmt.Sprintf("CRITICAL: Deprecated data folder found at %q!", mdbPath))
c.Ui.Error("Consul will refuse to boot with this directory present.")
c.Ui.Error("See https://consul.io/docs/upgrade-specific.html for more information.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well update that here, too :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is a legit suggestion, too - this is a breaking-ish-change.

return nil
}
}

if config.EncryptKey != "" {
if _, err := config.EncryptBytes(); err != nil {
c.Ui.Error(fmt.Sprintf("Invalid encryption key: %s", err))
Expand Down Expand Up @@ -601,72 +613,6 @@ func (c *Command) Run(args []string) int {
metrics.NewGlobal(metricsConf, inm)
}

// If we are starting a consul 0.5.1+ server for the first time,
// and we have data from a previous Consul version, attempt to
// migrate the data from LMDB to BoltDB using the migrator utility.
if config.Server {
// If the data dir doesn't exist yet (first start), then don't
// attempt to migrate.
if _, err := os.Stat(config.DataDir); os.IsNotExist(err) {
goto AFTER_MIGRATE
}

m, err := migrator.New(config.DataDir)
if err != nil {
c.Ui.Error(err.Error())
return 1
}

// Handle progress info from the migrator utility. This will
// just dump out the current operation and progress every ~5
// percent progress.
doneCh := make(chan struct{})
go func() {
var lastOp string
var lastProgress float64
lastFlush := time.Now()
for {
select {
case update := <-m.ProgressCh:
switch {
case lastOp != update.Op:
lastProgress = update.Progress
lastOp = update.Op
c.Ui.Output(update.Op)
c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress))

case update.Progress-lastProgress >= 5:
fallthrough

case time.Now().Sub(lastFlush) > time.Second:
fallthrough

case update.Progress == 100:
lastFlush = time.Now()
lastProgress = update.Progress
c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress))
}
case <-doneCh:
return
}
}
}()

c.Ui.Output("Starting raft data migration...")
start := time.Now()
migrated, err := m.Migrate()
close(doneCh)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to migrate raft data: %s", err))
return 1
}
if migrated {
duration := time.Now().Sub(start)
c.Ui.Output(fmt.Sprintf("Successfully migrated raft data in %s", duration))
}
}

AFTER_MIGRATE:
// Create the agent
if err := c.setupAgent(config, logOutput, logWriter); err != nil {
return 1
Expand Down
37 changes: 37 additions & 0 deletions command/agent/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -299,3 +300,39 @@ func TestSetupScadaConn(t *testing.T) {
t.Fatalf("should be closed")
}
}

func TestProtectDataDir(t *testing.T) {
dir, err := ioutil.TempDir("", "consul")
if err != nil {
t.Fatalf("err: %v", err)
}
defer os.RemoveAll(dir)

if err := os.MkdirAll(filepath.Join(dir, "mdb"), 0700); err != nil {
t.Fatalf("err: %v", err)
}

cfgFile, err := ioutil.TempFile("", "consul")
if err != nil {
t.Fatalf("err: %v", err)
}
defer os.Remove(cfgFile.Name())

content := fmt.Sprintf(`{"server": true, "data_dir": "%s"}`, dir)
_, err = cfgFile.Write([]byte(content))
if err != nil {
t.Fatalf("err: %v", err)
}

ui := new(cli.MockUi)
cmd := &Command{
Ui: ui,
args: []string{"-config-file=" + cfgFile.Name()},
}
if conf := cmd.readConfig(); conf != nil {
t.Fatalf("should fail")
}
if out := ui.ErrorWriter.String(); !strings.Contains(out, dir) {
t.Fatalf("expected mdb dir error, got: %s", out)
}
}