Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 3scale Batcher Policy: replace regex with string operations [PR #1583](https://github.com/3scale/APIcast/pull/1583)
- Proxy/Upstream Connection: setup configuration in init phase - [PR #1602](https://github.com/3scale/APIcast/pull/1602)
- Reduce memory when reloading with large configurations [PR #1608](https://github.com/3scale/APIcast/pull/1608)
- 3scale Batcher Policy: filter by keys to avoid expensive shared dict read [PR #1618](https://github.com/3scale/APIcast/pull/1608)

### Fixed
- Correct FAPI header to `x-fapi-interaction-id` [PR #1557](https://github.com/3scale/APIcast/pull/1557) [THREESCALE-11957](https://issues.redhat.com/browse/THREESCALE-11957)
Expand Down
33 changes: 18 additions & 15 deletions gateway/src/apicast/policy/3scale_batcher/reports_batcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,26 @@ function _M:get_all(service_id)
-- nil for it.
local cached_report_keys = self.storage:get_keys()

local service_prefix = "service_id:" .. service_id .. ","
for _, key in ipairs(cached_report_keys) do
local value = self.storage:get(key)

-- Deletes only happen while holding the lock, but the entry can still be
-- gone, for example if it was evicted. Skip it rather than raising, an
-- error here would leave the lock to expire on its own and would prevent
-- the caller from scheduling the next run.
if value then
local report, err = keys_helper.report_from_key_batched_report(key, value)

if not err then
if value > 0 and report and report.service_id == service_id then
insert(cached_reports, report)
self.storage:delete(key)
if key:find(service_prefix, 1, true) == 1 then
local value = self.storage:get(key)

-- Deletes only happen while holding the lock, but the entry can still be
-- gone, for example if it was evicted. Skip it rather than raising, an
-- error here would leave the lock to expire on its own and would prevent
-- the caller from scheduling the next run.
if value then
local report, err = keys_helper.report_from_key_batched_report(key, value)

if not err then
if value > 0 and report and report.service_id == service_id then
insert(cached_reports, report)
self.storage:delete(key)
end
else
ngx.log(ngx.WARN, 'failed to get report for key ', key, ' err: ', err)
end
else
ngx.log(ngx.WARN, 'failed to get report for key ', key, ' err: ', err)
end
end
end
Expand Down
Loading