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

Ignore duplicate state entries #2792

Merged
merged 1 commit into from
Oct 18, 2016

Conversation

tsg
Copy link
Contributor

@tsg tsg commented Oct 17, 2016

When upgrading the registry file from 1.x versions, make sure the new state doesn't contain any duplicate inodes, as these will cause an invalid state. Fixes #2784.

@tsg tsg added review Filebeat Filebeat needs_backport PR is waiting to be backported to other branches. labels Oct 17, 2016
@tsg tsg force-pushed the ignore_duplicate_state_entries branch 2 times, most recently from 145ef2d to 1bbbfe8 Compare October 17, 2016 22:06
@@ -176,6 +168,32 @@ func (r *Registrar) loadAndConvertOldState(f *os.File) bool {
return true
}

func convertOldStates(oldStates map[string]file.State) []file.State {
Copy link
Member

Choose a reason for hiding this comment

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

The logic you have looks correct. What do you think about using a map with struct key to do the deduplication?

    states := map[file.StateOS]file.State{}
    for _, state := range oldStates {
        // If there is a duplicate, use the one with the larger offset.
        existingState, found := states[state.FileStateOS]
        if found && existingState.Offset > state.Offset {
            continue
        }

        // Makes timestamp the time of migration, as this is the best guess.
        state.Timestamp = time.Now()
        states[state.FileStateOS] = state
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that would simpler and would work, but bypassing the IsSame() method feels risky for future StateOS implementations (note that the structures is platform specific, so we could see variations).

I'm not really worried about the O(n^2) aspect here, since this is done only once and with an N up to tens of thousands at most.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, that might be brittle and break if there are any changes to StateOS.

When upgrading the registry file from 1.x versions, make sure
the new state doesn't contain any duplicate inodes, as these will cause
an invalid state. Fixes elastic#2784.
@tsg tsg force-pushed the ignore_duplicate_state_entries branch from 1bbbfe8 to f402b69 Compare October 18, 2016 07:21
@tsg
Copy link
Contributor Author

tsg commented Oct 18, 2016

jenkins, retest it

@andrewkroh andrewkroh merged commit 1350664 into elastic:master Oct 18, 2016
tsg added a commit to tsg/beats that referenced this pull request Oct 18, 2016
When upgrading the registry file from 1.x versions, make sure
the new state doesn't contain any duplicate inodes, as these will cause
an invalid state. Fixes elastic#2784.
@tsg tsg removed the needs_backport PR is waiting to be backported to other branches. label Oct 18, 2016
@ruflin
Copy link
Contributor

ruflin commented Oct 18, 2016

LGTM. Thx for the fix. I also don't worry here about the complexity here because it only happens once. And using IsSame should be "future proof".

monicasarbu pushed a commit that referenced this pull request Oct 18, 2016
When upgrading the registry file from 1.x versions, make sure
the new state doesn't contain any duplicate inodes, as these will cause
an invalid state. Fixes #2784.
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…elastic#2797)

When upgrading the registry file from 1.x versions, make sure
the new state doesn't contain any duplicate inodes, as these will cause
an invalid state. Fixes elastic#2784.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants