Skip to content

Commit

Permalink
Remove convert old states code
Browse files Browse the repository at this point in the history
Filebeat 1.x had a different registry format from 5.x. So a conversion of the format happened. This code is now removed for 6.0 as the upgrade path to 6.0 is from 5.0.

The code caused some issues in the past so it is better to not have it in anymore.
  • Loading branch information
ruflin committed Mar 22, 2017
1 parent 3bcebf6 commit 91fa70d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 324 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]

*Filebeat*
- Always use absolute path for event and registry. This can lead to issues when relative paths were used before. {pull}3328[3328]
- Remove code to convert states from 1.x. {pull}3767[3767]

*Heartbeat*

Expand Down
88 changes: 0 additions & 88 deletions filebeat/registrar/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"path/filepath"
"sync"

"time"

cfg "github.com/elastic/beats/filebeat/config"
"github.com/elastic/beats/filebeat/input"
"github.com/elastic/beats/filebeat/input/file"
Expand Down Expand Up @@ -105,12 +103,6 @@ func (r *Registrar) loadStates() error {

logp.Info("Loading registrar data from %s", r.registryFile)

// DEPRECATED: This should be removed in 6.0
oldStates := r.loadAndConvertOldState(f)
if oldStates {
return nil
}

decoder := json.NewDecoder(f)
states := []file.State{}
err = decoder.Decode(&states)
Expand All @@ -125,60 +117,6 @@ func (r *Registrar) loadStates() error {
return nil
}

// loadAndConvertOldState loads the old state file and converts it to the new state
// This is designed so it can be easily removed in later versions
func (r *Registrar) loadAndConvertOldState(f *os.File) bool {
// Make sure file reader is reset afterwards
defer f.Seek(0, 0)

stat, err := f.Stat()
if err != nil {
logp.Err("Error getting stat for old state: %+v", err)
return false
}

// Empty state does not have to be transformed ({} + newline)
if stat.Size() <= 4 {
return false
}

// Check if already new state format
decoder := json.NewDecoder(f)
newState := []file.State{}
err = decoder.Decode(&newState)
// No error means registry is already in new format
if err == nil {
return false
}

// Reset file offset
f.Seek(0, 0)
oldStates := map[string]file.State{}
err = decoder.Decode(&oldStates)
if err != nil {
logp.Err("Error decoding old state: %+v", err)
return false
}

// No old states found -> probably already new format
if oldStates == nil {
return false
}

// Convert old states to new states
logp.Info("Old registry states found: %v", len(oldStates))
states := convertOldStates(oldStates)
states = resetStates(states)
r.states.SetStates(states)

// Rewrite registry in new format
r.writeRegistry()

logp.Info("Old states converted to new states and written to registrar: %v", len(oldStates))

return true
}

// resetStates sets all states to finished and disable TTL on restart
// For all states covered by a prospector, TTL will be overwritten with the prospector value
func resetStates(states []file.State) []file.State {
Expand All @@ -192,32 +130,6 @@ func resetStates(states []file.State) []file.State {
return states
}

func convertOldStates(oldStates map[string]file.State) []file.State {
// Convert old states to new states
states := []file.State{}
for _, state := range oldStates {
// Makes timestamp time of migration, as this is the best guess
state.Timestamp = time.Now()

// Check for duplicates
dupe := false
for i, other := range states {
if state.FileStateOS.IsSame(other.FileStateOS) {
dupe = true
if state.Offset > other.Offset {
// replace other
states[i] = state
break
}
}
}
if !dupe {
states = append(states, state)
}
}
return states
}

func (r *Registrar) Start() error {

// Load the previous log file locations now, for use in prospector
Expand Down
58 changes: 0 additions & 58 deletions filebeat/registrar/registrar_test.go

This file was deleted.

178 changes: 0 additions & 178 deletions filebeat/tests/system/test_migration.py

This file was deleted.

0 comments on commit 91fa70d

Please sign in to comment.