Skip to content
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

feat: cache incomplete line in memory to avoid repeat read from disk #1142

Merged
merged 9 commits into from Sep 22, 2023

Conversation

yyuuttaaoo
Copy link
Collaborator

@yyuuttaaoo yyuuttaaoo commented Sep 20, 2023

活跃的磁盘缓存会被容器记入内存占用。ilogtail原来重复读取一个位置的行为会将缓存标记活跃,从而使被采集的容器内存上涨,该补丁应该可以大幅减缓这一现象。

TEST:

  1. 重新启动
  2. 配置热加载
  3. 日志轮转
  4. GBK编码日志
  5. 日志通过\n line生成,行尾回车下次补齐
  6. 不补齐行位\n,等超时采集
  7. kill -9后恢复行为

core/reader/LogFileReader.h Show resolved Hide resolved
@@ -371,7 +374,8 @@ void LogFileReader::adjustParametersByRangeCheckpoints() {
return lhs->data.read_offset() < rhs->data.read_offset();
});
auto& firstCpt = uncommittedCheckpoints.front()->data;
mLastReadPos = mLastFilePos = firstCpt.read_offset();
mLastFilePos = firstCpt.read_offset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExactlyOnce是否有测试保证?

core/reader/LogFileReader.h Outdated Show resolved Hide resolved
core/reader/LogFileReader.cpp Show resolved Hide resolved
APSARA_TEST_FALSE_FATAL(moreData);
APSARA_TEST_EQUAL_FATAL(0UL, reader2.mCache.size());
reader1.DumpMetaToMem(false);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

配置变更场景模拟下用例,在checkpoint中,恢复后继续能够读取,保证数据连续性

reader.ReadGBK(logBuffer, fileSize, moreData);
APSARA_TEST_TRUE_FATAL(moreData);
std::string expectedPart(expectedContent.get());
expectedPart.resize(expectedPart.rfind("iLogtail") - 1);
APSARA_TEST_STREQ_FATAL(expectedPart.c_str(), logBuffer.rawBuffer.data());
// second read
APSARA_TEST_GE_FATAL(reader.mCache.size(), 0UL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第一次读有缓存,第二次读续上这种是不是没有用例?

@yyuuttaaoo yyuuttaaoo merged commit 42df83e into alibaba:main Sep 22, 2023
20 checks passed
@yyuuttaaoo yyuuttaaoo deleted the feature/no_repeat_read branch September 22, 2023 08:05
@yyuuttaaoo yyuuttaaoo added the enhancement Feature enhancement label Sep 26, 2023
@yyuuttaaoo yyuuttaaoo added this to the v1.8 milestone Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants