-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…3960) * Check if file has disappeared sooner in Log reader (#13907) * Adding comment about EOF and removing redundant logic * Adding debug logging when close_remove and close_renamed situations are reached * Check file stats related errors before adding to buffer * Reordering checks to be same as before * Add CHANGELOG entry * Fixing issue # in CHANGELOG entry * Move CloseInactive and truncate checks back to being after EOF check * Don't perform stat call for CloseRemoved/CloseRenamed unless those settings are enabled * Better comments / function godoc * Renaming method to be more descriptive * Fixing up CHANGELOG * Fix CHANGELOG * Fixed compile error * [WIP] Trying to check if file is removed * Adding Removed() to Source interface * Initialize procGetFileInformationByHandleEx * Adding missed import
- Loading branch information
1 parent
945fd70
commit e28e5c2
Showing
7 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build !windows | ||
|
||
package log | ||
|
||
import "os" | ||
|
||
// isRemoved checks wheter the file held by f is removed. | ||
func isRemoved(f *os.File) bool { | ||
_, err := os.Stat(f.Name()) | ||
return err != nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package log | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"unsafe" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
var ( | ||
modkernel32 = windows.NewLazySystemDLL("kernel32.dll") | ||
|
||
procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx") | ||
) | ||
|
||
// isRemoved checks whether the file held by f is removed. | ||
// On Windows isRemoved reads the DeletePending flags using the GetFileInformationByHandleEx. | ||
// A file is not removed/unlinked as long as at least one process still own a | ||
// file handle. A delete file is only marked as deleted, and file attributes | ||
// can still be read. Only opening a file marked with 'DeletePending' will | ||
// fail. | ||
func isRemoved(f *os.File) bool { | ||
hdl := f.Fd() | ||
if hdl == uintptr(syscall.InvalidHandle) { | ||
return false | ||
} | ||
|
||
info := struct { | ||
AllocationSize int64 | ||
EndOfFile int64 | ||
NumberOfLinks int32 | ||
DeletePending bool | ||
Directory bool | ||
}{} | ||
infoSz := unsafe.Sizeof(info) | ||
|
||
const class = 1 // FileStandardInfo | ||
r1, _, _ := syscall.Syscall6( | ||
procGetFileInformationByHandleEx.Addr(), 4, uintptr(hdl), class, uintptr(unsafe.Pointer(&info)), infoSz, 0, 0) | ||
if r1 == 0 { | ||
return true // assume file is removed if syscall errors | ||
} | ||
return info.DeletePending | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters