-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
145ef2d
to
1bbbfe8
Compare
@@ -176,6 +168,32 @@ func (r *Registrar) loadAndConvertOldState(f *os.File) bool { | |||
return true | |||
} | |||
|
|||
func convertOldStates(oldStates map[string]file.State) []file.State { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
1bbbfe8
to
f402b69
Compare
jenkins, retest it |
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.
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". |
…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.
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.