Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Abingcbc committed Jan 7, 2025
1 parent dcd68aa commit 6af14e0
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions core/file_server/EventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,12 +835,11 @@ void EventDispatcher::UnregisterEventHandler(const string& path) {
LOG_INFO(sLogger, ("remove the watcher for dir", path)("wd", wd));
}

void EventDispatcher::StopAllDir(const string& baseDir, const string& configName, const string& containerID) {
void EventDispatcher::StopAllDir(const string& baseDir, const string& containerID) {
LOG_DEBUG(sLogger, ("Stop all sub dir", baseDir));
auto subDirAndHandlers = FindAllSubDirAndHandler(baseDir);
for (auto& subDirAndHandler : subDirAndHandlers) {
Event e(subDirAndHandler.first, "", EVENT_ISDIR | EVENT_CONTAINER_STOPPED, -1, 0);
e.SetConfigName(configName);
e.SetContainerID(containerID);
subDirAndHandler.second->Handle(e);
}
Expand Down
2 changes: 1 addition & 1 deletion core/file_server/EventDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class EventDispatcher {
*
* @param path for whom event handler will be removed.
*/
void StopAllDir(const std::string& baseDir, const std::string& configName, const std::string& containerID);
void StopAllDir(const std::string& baseDir, const std::string& containerID);

EventHandler* GetHandler(const char* path) {
MapType<std::string, int>::Type::iterator itr = mPathWdMap.find(path);
Expand Down
10 changes: 4 additions & 6 deletions core/file_server/event_handler/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,10 @@ void CreateModifyHandler::Handle(const Event& event) {
mCreateHandlerPtr->Handle(event);
} else if (event.IsContainerStopped() && isDir) {
for (auto& pair : mModifyHandlerPtrMap) {
if (pair.second->GetConfigName() == event.GetConfigName()) {
LOG_DEBUG(sLogger,
("Handle container stopped event, config", pair.first)("Source", event.GetSource())(
"Object", event.GetObject())("Dev", event.GetDev())("Inode", event.GetInode()));
pair.second->Handle(event);
}
LOG_DEBUG(sLogger,
("Handle container stopped event, config", pair.first)("Source", event.GetSource())(
"Object", event.GetObject())("Dev", event.GetDev())("Inode", event.GetInode()));
pair.second->Handle(event);
}
} else if (event.IsCreate() || event.IsModify() || event.IsMoveFrom() || event.IsMoveTo() || event.IsDeleted()) {
if (!event.GetConfigName().empty()) {
Expand Down
2 changes: 1 addition & 1 deletion core/file_server/event_handler/LogInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void LogInput::ProcessEvent(EventDispatcher* dispatcher, Event* ev) {
string path = source;
if (object.size() > 0)
path += PATH_SEPARATOR + object;
dispatcher->StopAllDir(path, ev->GetConfigName(), ev->GetContainerID());
dispatcher->StopAllDir(path, ev->GetContainerID());
} else {
EventHandler* handler = dispatcher->GetHandler(source.c_str());
if (handler) {
Expand Down
2 changes: 1 addition & 1 deletion core/unittest/controller/EventDispatcherDirUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class EventDispatcherDirUnittest : public ::testing::Test {
void TestStopAllDir() {
LOG_INFO(sLogger, ("TestStopAllDir() begin", time(NULL)));
std::string baseDir = "/basepath0";
EventDispatcher::GetInstance()->StopAllDir(baseDir, "", "");
EventDispatcher::GetInstance()->StopAllDir(baseDir, "");
for (size_t i = 0; i < 10; ++i) {
if (i < 4) {
APSARA_TEST_EQUAL_FATAL(mHandlers[i].handle_count, 1);
Expand Down
5 changes: 0 additions & 5 deletions core/unittest/event_handler/CreateModifyHandlerUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ void CreateModifyHandlerUnittest::TestHandleContainerStoppedEvent() {
event2.SetConfigName(mConfigName);
createModifyHandler.Handle(event2);
APSARA_TEST_EQUAL_FATAL(pHanlder->handle_count, 2);

Event event3(gRootDir, "", EVENT_ISDIR | EVENT_CONTAINER_STOPPED, 0);
event3.SetConfigName(mConfigName + "_test");
createModifyHandler.Handle(event3);
APSARA_TEST_EQUAL_FATAL(pHanlder->handle_count, 2);
}

std::string CreateModifyHandlerUnittest::gRootDir;
Expand Down

0 comments on commit 6af14e0

Please sign in to comment.