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

Remove convert old states code #3767

Merged
merged 1 commit into from
Mar 22, 2017
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
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.