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

Bugfix for shard collisions resulting from attempted _internal import #9576

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions cmd/influxd/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ func (cmd *Command) uploadShardsPortable() error {
if cmd.sourceDatabase == "" || cmd.sourceDatabase == file.Database {
if cmd.backupRetention == "" || cmd.backupRetention == file.Policy {
if cmd.shard == 0 || cmd.shard == file.ShardID {
oldID := file.ShardID
// if newID not found then this shard's metadata was NOT imported
// and should be skipped
newID, ok := cmd.shardIDMap[oldID]
if !ok {
cmd.StdoutLogger.Printf("Meta info not found for shard %d on database %s. Skipping shard file %s", oldID, file.Database, file.FileName)
continue
}
cmd.StdoutLogger.Printf("Restoring shard %d live from backup %s\n", file.ShardID, file.FileName)
f, err := os.Open(filepath.Join(cmd.backupFilesPath, file.FileName))
if err != nil {
Expand All @@ -419,7 +427,7 @@ func (cmd *Command) uploadShardsPortable() error {
targetDB = file.Database
}

if err := cmd.client.UploadShard(file.ShardID, cmd.shardIDMap[file.ShardID], targetDB, cmd.restoreRetention, tr); err != nil {
if err := cmd.client.UploadShard(oldID, newID, targetDB, cmd.restoreRetention, tr); err != nil {
f.Close()
return err
}
Expand Down Expand Up @@ -454,12 +462,20 @@ func (cmd *Command) uploadShardsLegacy() error {
if err != nil {
return err
}

// if newID not found then this shard's metadata was NOT imported
// and should be skipped
newID, ok := cmd.shardIDMap[shardID]
if !ok {
cmd.StdoutLogger.Printf("Meta info not found for shard %d. Skipping shard file %s", shardID, fn)
continue
}
f, err := os.Open(fn)
if err != nil {
return err
}
tr := tar.NewReader(f)
if err := cmd.client.UploadShard(shardID, cmd.shardIDMap[shardID], cmd.destinationDatabase, cmd.restoreRetention, tr); err != nil {
if err := cmd.client.UploadShard(shardID, newID, cmd.destinationDatabase, cmd.restoreRetention, tr); err != nil {
f.Close()
return err
}
Expand Down
13 changes: 13 additions & 0 deletions tests/backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import (

"github.com/influxdata/influxdb/cmd/influxd/backup"
"github.com/influxdata/influxdb/cmd/influxd/restore"
"github.com/influxdata/influxdb/toml"
"strings"
)

func TestServer_BackupAndRestore(t *testing.T) {
config := NewConfig()
config.Data.Engine = "tsm1"
config.BindAddress = freePort()
config.Monitor.StoreEnabled = true
config.Monitor.StoreInterval = toml.Duration(time.Second)

fullBackupDir, _ := ioutil.TempDir("", "backup")
defer os.RemoveAll(fullBackupDir)
Expand Down Expand Up @@ -81,6 +85,15 @@ func TestServer_BackupAndRestore(t *testing.T) {
t.Fatalf("query results wrong:\n\texp: %s\n\tgot: %s", expected, res)
}

for !strings.Contains(res, "_internal") {
res, err = s.Query(`SHOW DATABASES`)
if err != nil {
t.Fatalf("error querying: %s", err.Error())
}
// technically not necessary, but no reason to crush the CPU for polling
time.Sleep(time.Second)
}

// now backup
cmd := backup.NewCommand()
_, port, err := net.SplitHostPort(config.BindAddress)
Expand Down