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

[AUD-223] Set a TTL for latest block in redis #1269

Merged
merged 9 commits into from
Mar 11, 2021

Conversation

dmanjunath
Copy link
Contributor

@dmanjunath dmanjunath commented Mar 2, 2021

Description

This PR sets a TTL for the latest block number and hash redis objects. More details in linear, but what was happening is if our indexing task takes a long time to finish, the latest block number and hash objects in redis become outdated since no other indexing tasks come up and update them. For example, if an indexing task takes 90 seconds to complete, that's 90/5=18 blocks that the discovery node would be behind at a 5 second/block rate. However, for those 90 seconds, the block diff in health check would show 0 because no other indexing task came up and wrote updated values to the cache.

This PR expires the cache value at the indexing interval of 5 seconds and if health checks doesn't see those redis keys, it sets them only if they don't exist with the same TTL. If a new indexing task starts up, it will override the values each time.

Tests

I slowed indexing locally to 60 seconds and hit health check to set the keys in redis. Notice the "HEALTH CHECK DEBUG" messages for cache misses and observe the health_check hits in between with no logs.

{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:36,880", "method": "GET", "path": "/tracks", "status": 200, "duration": 25, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 10, "level": "DEBUG", "msg": "Making request. Method: eth_getBlockByNumber", "timestamp": "2021-03-02 16:42:39,044"}
{"levelno": 10, "level": "DEBUG", "msg": "Making request HTTP. URI: http://audius_ganache_cli:8545, Method: eth_getBlockByNumber", "timestamp": "2021-03-02 16:42:39,046"}
{"levelno": 10, "level": "DEBUG", "msg": "Starting new HTTP connection (1): audius_ganache_cli:8545", "timestamp": "2021-03-02 16:42:39,062"}
{"levelno": 10, "level": "DEBUG", "msg": "http://audius_ganache_cli:8545 \"POST / HTTP/1.1\" 200 None", "timestamp": "2021-03-02 16:42:39,103"}
{"levelno": 10, "level": "DEBUG", "msg": "Getting response HTTP. URI: http://audius_ganache_cli:8545, Method: eth_getBlockByNumber, Response: {'id': 0, 'jsonrpc': '2.0', 'result': {'number': '0x1f', 'hash': '0xdd5d00b9af983a073242eb8250c23840be978eba03a180122d7559c23e807d6e', 'parentHash': '0x879ed61fd518ee456236d913a888331062005986874e837daf05c624113967e7', 'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'nonce': '0x0000000000000000', 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', 'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'transactionsRoot': '0x81a0a735769227fa100fc76762ec54ead217d146ebc24eceb0b99ee20efe5d35', 'stateRoot': '0xd1915d8610d6f94f041205cf4a16a937367c40f5237aa8b08fc485dcf0b14955', 'receiptsRoot': '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', 'miner': '0x0000000000000000000000000000000000000000', 'difficulty': '0x0', 'totalDifficulty': '0x0', 'extraData': '0x', 'size': '0x3e8', 'gasLimit': '0x7a1200', 'gasUsed': '0x5208', 'timestamp': '0x60386468', 'transactions': [{'hash': '0xd42028f5299cbe20f17aa9a6a107a2e910c170dcabee50a3a67b8e9480019d1e', 'nonce': '0x1e', 'blockHash': '0xdd5d00b9af983a073242eb8250c23840be978eba03a180122d7559c23e807d6e', 'blockNumber': '0x1f', 'transactionIndex': '0x0', 'from': '0xd7bed82b01ccfc56032f9e77a7c891a62ea1f754', 'to': '0xbe718f98a5b5a473186eb6e30888f26e72be0b66', 'value': '0xde0b6b3a7640000', 'gas': '0x15f90', 'gasPrice': '0x4a817c800', 'input': '0x', 'v': '0x25', 'r': '0x3b8db42cf9b6ed76a2bfeb559c0510993b7e0f05e5879d32c9e56dcd8628192c', 's': '0x7d09c8e7e8144b826f259561fcb50c6a52b6f4a96dca71293deee81b8c330dfe'}], 'uncles': []}}", "timestamp": "2021-03-02 16:42:39,105"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: redis cache miss health 31", "timestamp": "2021-03-02 16:42:39,109"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: setting values for latest_block_num 31", "timestamp": "2021-03-02 16:42:39,111"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: finished setting values for latest_block_num 31", "timestamp": "2021-03-02 16:42:39,114"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:39,126", "method": "GET", "path": "/health_check", "status": 200, "duration": 90, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:40,026", "method": "GET", "path": "/notifications", "status": 200, "duration": 54, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "min_block_number=31"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:40,078", "method": "GET", "path": "/tracks", "status": 200, "duration": 36, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - miss API_V1_ROUTE:unpopulated-playlist:/playlists:", "timestamp": "2021-03-02 16:42:40,087"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:40,116", "method": "GET", "path": "/playlists", "status": 200, "duration": 30, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:40,197", "method": "GET", "path": "/users", "status": 200, "duration": 75, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit API_V1_ROUTE:/v1/full/tracks/trending:time=['week', 'week']", "timestamp": "2021-03-02 16:42:40,228"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit generated-trending:week:", "timestamp": "2021-03-02 16:42:40,229"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:40,278", "method": "GET", "path": "/v1/full/tracks/trending", "status": 200, "duration": 57, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "time=week&time=week&limit=10"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:41,208", "method": "GET", "path": "/health_check", "status": 200, "duration": 5, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:41,355", "method": "GET", "path": "/favicon.ico", "status": 404, "duration": 1, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:42,601", "method": "GET", "path": "/health_check", "status": 200, "duration": 5, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:42,738", "method": "GET", "path": "/favicon.ico", "status": 404, "duration": 0, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,399", "method": "GET", "path": "/notifications", "status": 200, "duration": 90, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "min_block_number=31"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,458", "method": "GET", "path": "/tracks", "status": 200, "duration": 39, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit API_V1_ROUTE:unpopulated-playlist:/playlists:", "timestamp": "2021-03-02 16:42:43,468"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,511", "method": "GET", "path": "/playlists", "status": 200, "duration": 43, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,601", "method": "GET", "path": "/users", "status": 200, "duration": 82, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit API_V1_ROUTE:/v1/full/tracks/trending:time=['week', 'week']", "timestamp": "2021-03-02 16:42:43,610"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit generated-trending:week:", "timestamp": "2021-03-02 16:42:43,611"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,648", "method": "GET", "path": "/v1/full/tracks/trending", "status": 200, "duration": 39, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "time=week&time=week&limit=10"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,664", "method": "GET", "path": "/health_check", "status": 200, "duration": 14, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:43,794", "method": "GET", "path": "/favicon.ico", "status": 404, "duration": 1, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 10, "level": "DEBUG", "msg": "Making request. Method: eth_getBlockByNumber", "timestamp": "2021-03-02 16:42:44,791"}
{"levelno": 10, "level": "DEBUG", "msg": "Making request HTTP. URI: http://audius_ganache_cli:8545, Method: eth_getBlockByNumber", "timestamp": "2021-03-02 16:42:44,792"}
{"levelno": 10, "level": "DEBUG", "msg": "Resetting dropped connection: audius_ganache_cli", "timestamp": "2021-03-02 16:42:44,800"}
{"levelno": 10, "level": "DEBUG", "msg": "http://audius_ganache_cli:8545 \"POST / HTTP/1.1\" 200 None", "timestamp": "2021-03-02 16:42:44,821"}
{"levelno": 10, "level": "DEBUG", "msg": "Getting response HTTP. URI: http://audius_ganache_cli:8545, Method: eth_getBlockByNumber, Response: {'id': 0, 'jsonrpc': '2.0', 'result': {'number': '0x1f', 'hash': '0xdd5d00b9af983a073242eb8250c23840be978eba03a180122d7559c23e807d6e', 'parentHash': '0x879ed61fd518ee456236d913a888331062005986874e837daf05c624113967e7', 'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000', 'nonce': '0x0000000000000000', 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', 'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'transactionsRoot': '0x81a0a735769227fa100fc76762ec54ead217d146ebc24eceb0b99ee20efe5d35', 'stateRoot': '0xd1915d8610d6f94f041205cf4a16a937367c40f5237aa8b08fc485dcf0b14955', 'receiptsRoot': '0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2', 'miner': '0x0000000000000000000000000000000000000000', 'difficulty': '0x0', 'totalDifficulty': '0x0', 'extraData': '0x', 'size': '0x3e8', 'gasLimit': '0x7a1200', 'gasUsed': '0x5208', 'timestamp': '0x60386468', 'transactions': [{'hash': '0xd42028f5299cbe20f17aa9a6a107a2e910c170dcabee50a3a67b8e9480019d1e', 'nonce': '0x1e', 'blockHash': '0xdd5d00b9af983a073242eb8250c23840be978eba03a180122d7559c23e807d6e', 'blockNumber': '0x1f', 'transactionIndex': '0x0', 'from': '0xd7bed82b01ccfc56032f9e77a7c891a62ea1f754', 'to': '0xbe718f98a5b5a473186eb6e30888f26e72be0b66', 'value': '0xde0b6b3a7640000', 'gas': '0x15f90', 'gasPrice': '0x4a817c800', 'input': '0x', 'v': '0x25', 'r': '0x3b8db42cf9b6ed76a2bfeb559c0510993b7e0f05e5879d32c9e56dcd8628192c', 's': '0x7d09c8e7e8144b826f259561fcb50c6a52b6f4a96dca71293deee81b8c330dfe'}], 'uncles': []}}", "timestamp": "2021-03-02 16:42:44,823"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: redis cache miss health 31", "timestamp": "2021-03-02 16:42:44,829"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: setting values for latest_block_num 31", "timestamp": "2021-03-02 16:42:44,831"}
{"levelno": 20, "level": "INFO", "msg": "HEALTH CHECK DEBUG: finished setting values for latest_block_num 31", "timestamp": "2021-03-02 16:42:44,833"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:44,838", "method": "GET", "path": "/health_check", "status": 200, "duration": 57, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:45,067", "method": "GET", "path": "/favicon.ico", "status": 404, "duration": 0, "ip": "71.246.246.90", "host": "34.237.76.89", "params": ""}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:46,734", "method": "GET", "path": "/notifications", "status": 200, "duration": 63, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "min_block_number=31"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:46,767", "method": "GET", "path": "/tracks", "status": 200, "duration": 24, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit API_V1_ROUTE:unpopulated-playlist:/playlists:", "timestamp": "2021-03-02 16:42:46,775"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:46,798", "method": "GET", "path": "/playlists", "status": 200, "duration": 24, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "handle flask request", "timestamp": "2021-03-02 16:42:46,839", "method": "GET", "path": "/users", "status": 200, "duration": 33, "ip": "192.168.64.26", "host": "audius-disc-prov_web-server_1", "params": "limit=0&offset=0"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit API_V1_ROUTE:/v1/full/tracks/trending:time=['week', 'week']", "timestamp": "2021-03-02 16:42:46,850"}
{"levelno": 20, "level": "INFO", "msg": "Redis Cache - hit generated-trending:week:", "timestamp": "2021-03-02 16:42:46,851"}

❗ Reminder 💡❗:
If this PR touches a critical flow (such as Indexing, Uploads, Gateway or the Filesystem), make sure to add the requires-special-attention label. Add relevant labels as necessary.

@dmanjunath dmanjunath changed the title Set a TTL for latest block in redis [AUD-223] Set a TTL for latest block in redis Mar 3, 2021
@dmanjunath dmanjunath marked this pull request as ready for review March 3, 2021 17:20
Copy link
Contributor

@hareeshnagaraj hareeshnagaraj left a comment

Choose a reason for hiding this comment

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

Does this now need a fallback to web3?

response_dictionary['latest_chain_block'] = (int(latest_chain_block) if latest_chain_block else None)

If there is none, we will end up with none as latest_chain_block in the case we have an expired redis value. is that acceptable?

@dmanjunath
Copy link
Contributor Author

dmanjunath commented Mar 3, 2021

Does this now need a fallback to web3?

response_dictionary['latest_chain_block'] = (int(latest_chain_block) if latest_chain_block else None)

If there is none, we will end up with none as latest_chain_block in the case we have an expired redis value. is that acceptable?

We should change this too. good find. i can make a wrapper around this logic like attempt to get from redis or fallback to web3 so it can be consumed by health check and the api helpers

Copy link
Contributor

@SidSethi SidSethi left a comment

Choose a reason for hiding this comment

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

looks good to me aside from hareehs's comment, good find on this. will leave approval to hareesh

discovery-provider/default_config.ini Outdated Show resolved Hide resolved
@@ -126,6 +128,12 @@ def get_health(args, use_redis_cache=True):
latest_block_num = latest_block.number
latest_block_hash = latest_block.hash.hex()

if use_redis_cache:
Copy link
Contributor

Choose a reason for hiding this comment

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

there is already an if use_redis_cache: above on line 115, why not put these at the bottom of that block?

# if we had attempted to use redis cache and the values weren't there, set the values now
# ex sets expiration time and nx only sets if key doesn't exist in redis
redis.set(latest_block_redis_key, latest_block_num, ex=default_indexing_interval_seconds, nx=True)
redis.set(latest_block_hash_redis_key, latest_block_hash, ex=default_indexing_interval_seconds, nx=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth wrapping these in a try-except? wouldn't want to fail the health check due to a redis.set call failure

up to you

@hareeshnagaraj
Copy link
Contributor

hareeshnagaraj commented Mar 3, 2021

Does this now need a fallback to web3?

response_dictionary['latest_chain_block'] = (int(latest_chain_block) if latest_chain_block else None)

If there is none, we will end up with none as latest_chain_block in the case we have an expired redis value. is that acceptable?

We should change this too. good find. i can make a wrapper around this logic like attempt to get from redis or fallback to web3 so it can be consumed by health check and the api helpers

@SidSethi brought this up but we should probably also set this value in monitors.py since having it cached is not actually relevant to indexing. We can literally set 'latestChainBlock' there as well with a separate redis key. If you recall we initially had this caching to avoid web3 calls in health check so another redundancy layer might be beneficial

@dmanjunath
Copy link
Contributor Author

Does this now need a fallback to web3?

response_dictionary['latest_chain_block'] = (int(latest_chain_block) if latest_chain_block else None)

If there is none, we will end up with none as latest_chain_block in the case we have an expired redis value. is that acceptable?

We should change this too. good find. i can make a wrapper around this logic like attempt to get from redis or fallback to web3 so it can be consumed by health check and the api helpers

@SidSethi brought this up but we should probably also set this value in monitors.py since having it cached is not actually relevant to indexing. We can literally set 'latestChainBlock' there as well with a separate redis key. If you recall we initially had this caching to avoid web3 calls in health check so another redundancy layer might be beneficial

so there's no monitor to track latest chain block or block diff. should i add that to the monitors and plumb it everywhere?

the goal for this pr was to fix the cached web3 calls, not to benefit indexing in any way

if use_redis_cache:
# get latest blockchain state from redis cache, or fallback to chain if None
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little worried about this change causing health check to be significantly slower some of the time (since we're manually clearing the key). The client's heavily depend on health check being as fast as possible for selection.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should have sep. keys for health vs. indexing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is actually never used in indexing. the reason we added these keys was only for health check

as for health check latency, it's possible that an uncached value could cause the time to spike, but the tradeoff to weigh here is latency vs correctness. one tradeoff i'm willing to make is increase the ttl of this to 2x+1 of the indexing window so like 11 seconds. that way we should be no more than 3 blocks apart from chain in terms of accuracy but if indexing hasn't fired off and set the new value in redis, we'll get an accurate block diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also i'm down to benchmark on a prod node to see what the latency effects are

Copy link
Member

Choose a reason for hiding this comment

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

gotcha. i kinda see more value in the monitoring method that was suggested-- have this done independently of the health check behind the scenes make the most sense to me. we could make the calculation happen every 5s still or something. im ok to ship this now if you think the benefit from this correctness outways the potential incurred cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think the benefits here are more higher level. accurate health checks are nice, but the result system wide is what i was going for. like certain discovery nodes have a tendency to oscillate from like 0 to 20 blocks behind and back to 0. effectively this represents like 90 seconds of falling behind and then catching up, which i think this may also contribute to content nodes timing out in the middlewares. however if the true block diff is exposed, when we make requests through libs (or cnode via libs) to the discovery node, if the block diff is accurate, _makeRequest in the libs discovery service be much quicker and more accurate to move to run discovery reselection and move to another node

Copy link
Member

Choose a reason for hiding this comment

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

yeah, while i do think it would be better totally async from the health check, this makes a lot of sense. if your hunch that this will help the middleware situation is correct, we should def ship this asap

redis.set(latest_block_redis_key, latest_block_from_chain.number)
redis.set(latest_block_hash_redis_key, latest_block_from_chain.hash.hex())
# these keys have a TTL which is the indexing interval
redis.set(latest_block_redis_key, latest_block_from_chain.number, ex=default_indexing_interval_seconds)
Copy link
Member

Choose a reason for hiding this comment

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

is there a possible race cond. between the celery task actually running at default_indexing_interval_seconds and this getting expired at default_indexing_interval_seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since this is not used anywhere for indexing related tasks i'm not super worried. indexing actually does a web3 get latest call before each task anyway. plus this is set while the health check override is setnx so it'll prefer the health check set value and it won't override

Copy link
Contributor

Choose a reason for hiding this comment

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

i was going to suggest we make this last exactly 1s longer or something funky like that but based on the above idt its a big deal

Copy link
Contributor

@hareeshnagaraj hareeshnagaraj left a comment

Choose a reason for hiding this comment

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

LGTM, I think if we want to add this to monitors we'd have to increase that frequency quite a bit from 60s so this is a better option

@dmanjunath dmanjunath merged commit ba56bec into master Mar 11, 2021
@dmanjunath dmanjunath deleted the dm-indexing-latest-block-ttl branch March 11, 2021 14:31
dmanjunath added a commit that referenced this pull request Mar 11, 2021
* Set a TTL for latest block in redis

* Move this variable definition

* Rename env var to include units with _sec

* Refactor this logic into itss own function

* lint

* lint

* Cleanup
@AudiusProject AudiusProject deleted a comment from linear bot Sep 11, 2023
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.

None yet

4 participants