-
Notifications
You must be signed in to change notification settings - Fork 391
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
fix: fix PreservedDirDepth not working with polling and wildcard path #1866
Merged
yyuuttaaoo
merged 9 commits into
alibaba:main
from
yyuuttaaoo:fix/preserved_dir_depth_polling
Nov 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
48f1354
fix PreservedDirDepth not working with polling and wildcard path
yyuuttaaoo 3be6377
Add unittest and fix mem leaks
yyuuttaaoo 45efdd6
Merge branch 'main' into fix/preserved_dir_depth_polling
yyuuttaaoo bc4ba21
fix compile
yyuuttaaoo fcdfc67
fix register dir
yyuuttaaoo 92642c2
fix CMakeLists.txt
yyuuttaaoo 250d6d3
remove unwanted logs
yyuuttaaoo df6c7ad
Merge upstream/main into fix/preserved_dir_depth_polling
yyuuttaaoo 642f50c
fix UT
yyuuttaaoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -150,7 +150,7 @@ bool ConfigManager::RegisterHandlersRecursively(const std::string& path, | |
return result; | ||
|
||
if (!config.first->IsDirectoryInBlacklist(path)) | ||
result = EventDispatcher::GetInstance()->RegisterEventHandler(path.c_str(), config, mSharedHandler); | ||
result = EventDispatcher::GetInstance()->RegisterEventHandler(path, config, mSharedHandler); | ||
|
||
if (!result) | ||
return result; | ||
|
@@ -462,7 +462,7 @@ bool ConfigManager::RegisterDirectory(const std::string& source, const std::stri | |
// Match(subdir, *.log) = false. | ||
FileDiscoveryConfig config = FindBestMatch(source, object); | ||
if (config.first && !config.first->IsDirectoryInBlacklist(source)) { | ||
return EventDispatcher::GetInstance()->RegisterEventHandler(source.c_str(), config, mSharedHandler); | ||
return EventDispatcher::GetInstance()->RegisterEventHandler(source, config, mSharedHandler); | ||
} | ||
return false; | ||
} | ||
|
@@ -478,16 +478,7 @@ bool ConfigManager::RegisterHandlersWithinDepth(const std::string& path, | |
LOG_INFO(sLogger, ("ignore path matching host path blacklist", path)); | ||
return false; | ||
} | ||
if (preservedDirDepth <= 0) { | ||
DirCheckPointPtr dirCheckPoint; | ||
if (CheckPointManager::Instance()->GetDirCheckPoint(path, dirCheckPoint)) { | ||
// path had dircheckpoint means it was watched before, so it is valid | ||
const set<string>& subdir = dirCheckPoint.get()->mSubDir; | ||
for (const auto& it : subdir) { | ||
RegisterHandlersWithinDepth(it, config, preservedDirDepth - 1, maxDepth - 1); | ||
} | ||
return true; | ||
} | ||
if (preservedDirDepth < 0) { | ||
fsutil::PathStat statBuf; | ||
if (!fsutil::PathStat::stat(path, statBuf)) { | ||
return true; | ||
|
@@ -513,23 +504,33 @@ bool ConfigManager::RegisterHandlersWithinDepth(const std::string& path, | |
LOG_ERROR(sLogger, ("Open dir error: ", path.c_str())("errno", err)); | ||
return false; | ||
} | ||
if (!(EventDispatcher::GetInstance()->RegisterEventHandler(path.c_str(), config, mSharedHandler))) { | ||
if (!(EventDispatcher::GetInstance()->RegisterEventHandler(path, config, mSharedHandler))) { | ||
// break;// fail early, do not try to register others | ||
return false; | ||
} | ||
if (maxDepth == 0) { | ||
return true; | ||
} | ||
bool result = true; | ||
|
||
if (preservedDirDepth == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. =0时就必须进入checkpoint恢复的注册方式,在此方式下保持PreservedDirDepth=0确保注册成功 |
||
DirCheckPointPtr dirCheckPoint; | ||
if (CheckPointManager::Instance()->GetDirCheckPoint(path, dirCheckPoint)) { | ||
// path had dircheckpoint means it was watched before, so it is valid | ||
const set<string>& subdir = dirCheckPoint.get()->mSubDir; | ||
for (const auto& it : subdir) { | ||
RegisterHandlersWithinDepth(it, config, 0, maxDepth - 1); | ||
} | ||
return true; | ||
} | ||
} | ||
fsutil::Entry ent; | ||
while ((ent = dir.ReadNext())) { | ||
string item = PathJoin(path, ent.Name()); | ||
if (ent.IsDir() && !config.first->IsDirectoryInBlacklist(item)) { | ||
RegisterHandlersWithinDepth(item, config, preservedDirDepth - 1, maxDepth - 1); | ||
} | ||
} | ||
|
||
return result; | ||
return true; | ||
} | ||
|
||
// path not terminated by '/', path already registered | ||
|
@@ -553,7 +554,7 @@ bool ConfigManager::RegisterDescendants(const string& path, const FileDiscoveryC | |
LOG_ERROR(sLogger, ("Open dir error: ", path.c_str())("errno", err)); | ||
return false; | ||
} | ||
if (!EventDispatcher::GetInstance()->RegisterEventHandler(path.c_str(), config, mSharedHandler)) { | ||
if (!EventDispatcher::GetInstance()->RegisterEventHandler(path, config, mSharedHandler)) { | ||
// break;// fail early, do not try to register others | ||
return false; | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
=0和<0需要区分,=0时总是注册baseDir,<0时必须符合不超时的条件