diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-01 10:32:48 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-01 10:32:48 +0100 |
| commit | 1c929e46d8e7b14a74f80a21b5f30c9abbee410f (patch) | |
| tree | 9fa41d54696d91ce523a3830640d949e98f31760 /src/ingestor.cpp | |
| parent | ada3ab9f84dfa2df733d48d516476203a361ac63 (diff) | |
| download | webstat-1c929e46d8e7b14a74f80a21b5f30c9abbee410f.tar.bz2 webstat-1c929e46d8e7b14a74f80a21b5f30c9abbee410f.tar.xz webstat-1c929e46d8e7b14a74f80a21b5f30c9abbee410f.zip | |
Limit the number lines stored at once
Limits the number lines inserted per transactions, and the number of
transactions before returning to reading input.
Prevents long running transactions in the case when queued lines has
grown in size.
Diffstat (limited to 'src/ingestor.cpp')
| -rw-r--r-- | src/ingestor.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp index c41454f..04216f8 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -253,14 +253,19 @@ namespace WebStat { void Ingestor::tryIngestQueuedLogLines() { + auto storedEnd = queuedLines.begin(); try { - ingestLogLines(dbpool->get().get(), queuedLines); - queuedLines.clear(); + for (auto batch : + queuedLines | std::views::chunk(settings.maxBatchSize) | std::views::take(settings.maxBatches)) { + ingestLogLines(dbpool->get().get(), batch); + storedEnd = batch.end(); + } } catch (const std::exception & excp) { log(LOG_ERR, "Unhandled exception: %s, clearing known entity list", excp.what()); existingEntities.clear(); } + queuedLines.erase(queuedLines.begin(), storedEnd); } template<typename... T> @@ -285,7 +290,7 @@ namespace WebStat { } void - Ingestor::ingestLogLines(DB::Connection * dbconn, const LineBatch & lines) + Ingestor::ingestLogLines(DB::Connection * dbconn, const LinesView lines) { auto entityIds = std::views::transform([](auto && value) { return std::make_pair(value->hash, *value->id); |
