@@ -266,6 +266,7 @@ void LogFileReader::DumpMetaToMem(bool checkConfigFlag, int32_t idxInReaderArray
266266 ToString (mLogFileOp .IsOpen ())));
267267 }
268268 CheckPoint* checkPointPtr = new CheckPoint (mHostLogPath ,
269+ mResolvedHostLogPath ,
269270 mLastFilePos ,
270271 mLastFileSignatureSize ,
271272 mLastFileSignatureHash ,
@@ -321,6 +322,7 @@ void LogFileReader::InitReader(bool tailExisted, FileReadPolicy policy, uint32_t
321322 mLastFileSignatureHash = checkPointPtr->mSignatureHash ;
322323 mLastFileSignatureSize = checkPointPtr->mSignatureSize ;
323324 mRealLogPath = checkPointPtr->mRealFileName ;
325+ mResolvedHostLogPath = checkPointPtr->mResolvedFileName ;
324326 mLastEventTime = checkPointPtr->mLastUpdateTime ;
325327 if (checkPointPtr->mContainerID == mContainerID ) {
326328 mContainerStopped = checkPointPtr->mContainerStopped ;
@@ -1112,6 +1114,7 @@ bool LogFileReader::UpdateFilePtr() {
11121114 OnOpenFileError ();
11131115 } else if (CheckDevInode ()) {
11141116 GloablFileDescriptorManager::GetInstance ()->OnFileOpen (this );
1117+ ResolveHostLogPath ();
11151118 LOG_INFO (sLogger ,
11161119 (" open file succeeded, project" , GetProject ())(" logstore" , GetLogstore ())(
11171120 " config" , GetConfigName ())(" log reader queue name" , mHostLogPath )(
@@ -1151,6 +1154,7 @@ bool LogFileReader::UpdateFilePtr() {
11511154 // the mHostLogPath's dev inode equal to mDevInode, so real log path is mHostLogPath
11521155 mRealLogPath = mHostLogPath ;
11531156 GloablFileDescriptorManager::GetInstance ()->OnFileOpen (this );
1157+ ResolveHostLogPath ();
11541158 LOG_INFO (
11551159 sLogger ,
11561160 (" open file succeeded, project" , GetProject ())(" logstore" , GetLogstore ())(" config" , GetConfigName ())(
@@ -1308,7 +1312,7 @@ bool LogFileReader::CheckFileSignatureAndOffset(bool isOpenOnUpdate) {
13081312
13091313 // If file size is 0 and filename is changed, we cannot judge if the inode is reused by signature,
13101314 // so we just recreate the reader to avoid filename mismatch
1311- if (mLastFileSignatureSize == 0 && mRealLogPath != mHostLogPath ) {
1315+ if (mLastFileSignatureSize == 0 && mRealLogPath != mResolvedHostLogPath ) {
13121316 return false ;
13131317 }
13141318 fsutil::PathStat ps;
@@ -2497,6 +2501,27 @@ bool LogFileReader::UpdateContainerInfo() {
24972501 return false ;
24982502}
24992503
2504+ void LogFileReader::ResolveHostLogPath () {
2505+ if (!mResolvedHostLogPath .empty ()) {
2506+ return ;
2507+ }
2508+ if (mSymbolicLinkFlag ) {
2509+ mResolvedHostLogPath = mHostLogPath ;
2510+ return ;
2511+ }
2512+ if (mLogFileOp .IsOpen ()) {
2513+ mResolvedHostLogPath = mLogFileOp .GetFilePath ();
2514+ } else {
2515+ mResolvedHostLogPath = mHostLogPath ;
2516+ }
2517+ if (mResolvedHostLogPath != mHostLogPath ) {
2518+ LOG_INFO (sLogger ,
2519+ (" open file" , " symbolic link exists in absolute path" )(" host log path" , mHostLogPath )(
2520+ " resolved host log path" ,
2521+ mResolvedHostLogPath )(" dev" , ToString (mDevInode .dev ))(" inode" , ToString (mDevInode .inode )));
2522+ }
2523+ }
2524+
25002525#ifdef APSARA_UNIT_TEST_MAIN
25012526void LogFileReader::UpdateReaderManual () {
25022527 if (mLogFileOp .IsOpen ()) {
@@ -2505,6 +2530,7 @@ void LogFileReader::UpdateReaderManual() {
25052530 mLogFileOp .Open (mHostLogPath .c_str ());
25062531 mDevInode = GetFileDevInode (mHostLogPath );
25072532 mRealLogPath = mHostLogPath ;
2533+ ResolveHostLogPath ();
25082534}
25092535#endif
25102536
0 commit comments