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

Refactor UsageTracker #831

Merged
merged 3 commits into from
Sep 19, 2023
Merged

Refactor UsageTracker #831

merged 3 commits into from
Sep 19, 2023

Conversation

jkilpatr
Copy link
Member

This simple double ended iterator based design of UsageTracker has served us pretty well for a long time. We would push to the front a new usage hour and pop old ones off the back.

Sadly this format has proven to not be very robust to errors, if for any reason the usage or payments list was to become out of order invalid duplicate data would exist leading to confusing questions about which one to select.

We saw this most recently with payments where the make_payments_v2 change caused duplicate payments and incorrect income data to pollute the databases of many routers. That issue was patched with a duplicate check but in this new structure duplicates of payments in the payment list and duplicates of data usage in the data usage list are simply not possible.

By storing the usage data as a hashmap indexed by unix timestamp we will always retrieve a copy of the usage data for a given hour if we request it and only one version of any hour can exist.

Likewise for payments we've moved to a flat HashSet where the Hash value for the payment struct is the txid, this means that duplicate payments with the same txid can not co-exist in the hashset.

This new more robust format will be consumed by operator tools as well making it easier to manage usage data for many routers in the database there.

@jkilpatr jkilpatr requested review from ptulugu and ch-iara September 15, 2023 20:29
@jkilpatr jkilpatr force-pushed the jkilpatr/usage-tracker-refactor branch from 86fda96 to d0f3582 Compare September 15, 2023 20:32
This simple double ended iterator based design of UsageTracker has
served us pretty well for a long time. We would push to the front a new
usage hour and pop old ones off the back.

Sadly this format has proven to not be very robust to errors, if for any
reason the usage or payments list was to become out of order invalid
duplicate data would exist leading to confusing questions about which
one to select.

We saw this most recently with payments where the make_payments_v2
change caused duplicate payments and incorrect income data to pollute
the databases of many routers. That issue was patched with a duplicate
check but in this new structure duplicates of payments in the payment
list and duplicates of data usage in the data usage list are simply not
possible.

By storing the usage data as a hashmap indexed by unix timestamp we will
always retrieve a copy of the usage data for a given hour if we request
it and only one version of any hour can exist.

Likewise for payments we've moved to a flat HashSet where the Hash value
for the payment struct is the txid, this means that duplicate payments
with the same txid can not co-exist in the hashset.

This new more robust format will be consumed by operator tools as well
making it easier to manage usage data for many routers in the database
there.
@jkilpatr jkilpatr force-pushed the jkilpatr/usage-tracker-refactor branch 2 times, most recently from c7773ba to 468ebf6 Compare September 18, 2023 19:11
This will be helpful in allowing us to show the current live usage of a
router.
@jkilpatr jkilpatr force-pushed the jkilpatr/usage-tracker-refactor branch from 25538f8 to db534d9 Compare September 18, 2023 20:21
@jkilpatr jkilpatr merged commit db534d9 into master Sep 19, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants