Skip to content

Commit 58e4863

Browse files
authored
Fix external log stream init timestamp (#318)
1 parent bdbbb30 commit 58e4863

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/Storages/ExternalStream/Log/FileLog.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <Storages/IStorage.h>
1010
#include <Storages/SelectQueryInfo.h>
1111
#include <Storages/Streaming/storageUtil.h>
12+
#include <Common/logger_useful.h>
1213

1314
#include <boost/algorithm/string.hpp>
1415
#include <re2/re2.h>
15-
#include <Poco/Logger.h>
1616

1717
namespace DB
1818
{
@@ -148,6 +148,15 @@ FileLogSource::FileContainer FileLog::searchForCandidates()
148148
candidates.erase(candidates.begin());
149149
}
150150

151+
LOG_INFO(
152+
log,
153+
"Using {} regexes: {} to search log_dir={} with start_timestamp={}, found {} candidates",
154+
file_regexes.size(),
155+
settings->log_files.value,
156+
settings->log_dir.value,
157+
start_timestamp,
158+
candidates.size());
159+
151160
if (!candidates.empty())
152161
/// Update start timestamp for next scan
153162
start_timestamp = candidates.rbegin()->first;

src/Storages/ExternalStream/Log/FileLog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "FileLogSource.h"
3+
#include <Storages/ExternalStream/Log/FileLogSource.h>
44

55
#include <Storages/ExternalStream/ExternalStreamSettings.h>
66
#include <Storages/ExternalStream/StorageExternalStreamImpl.h>
@@ -55,7 +55,7 @@ class FileLog final : public StorageExternalStreamImpl
5555
std::unique_ptr<re2::RE2> timestamp_regex;
5656
std::unique_ptr<re2::RE2> linebreaker_regex;
5757

58-
Int64 start_timestamp;
58+
Int64 start_timestamp = 0;
5959

6060
Poco::Logger * log;
6161
};

src/Storages/ExternalStream/Log/FileLogSource.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "FileLogSource.h"
2-
#include "FileLog.h"
3-
#include "fileLastModifiedTime.h"
1+
#include <Storages/ExternalStream/Log/FileLog.h>
2+
#include <Storages/ExternalStream/Log/FileLogSource.h>
3+
#include <Storages/ExternalStream/Log/fileLastModifiedTime.h>
44

55
#include <Storages/ExternalStream/BreakLines.h>
66
#include <base/ClockUtils.h>
@@ -15,10 +15,10 @@ namespace DB
1515
{
1616
namespace ErrorCodes
1717
{
18-
extern const int FILE_DOESNT_EXIST;
19-
extern const int CANNOT_OPEN_FILE;
20-
extern const int CANNOT_FSTAT;
21-
extern const int CANNOT_READ_FROM_FILE_DESCRIPTOR;
18+
extern const int FILE_DOESNT_EXIST;
19+
extern const int CANNOT_OPEN_FILE;
20+
extern const int CANNOT_FSTAT;
21+
extern const int CANNOT_READ_FROM_FILE_DESCRIPTOR;
2222
}
2323

2424
FileLogSource::FileLogSource(
@@ -75,7 +75,6 @@ Chunk FileLogSource::generate()
7575
if (buffer.empty())
7676
buffer.resize(4 * 1024 * 1024);
7777

78-
7978
if (!handleCurrentFile())
8079
return head_chunk.clone();
8180
}
@@ -183,6 +182,8 @@ void FileLogSource::checkNewFiles()
183182
}
184183

185184
auto new_files{file_log->searchForCandidates()};
185+
last_check = MonotonicMilliseconds::now();
186+
186187
if (new_files.empty())
187188
{
188189
/// FIXME, notification

0 commit comments

Comments
 (0)