-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
CCIP-1496 Delete expired logs by the block_timestamp #12040
Conversation
I see that you haven't updated any README files. Would it make sense to do so? |
@@ -338,7 +338,7 @@ func (o *DbORM) SelectLogsByBlockRange(start, end int64) ([]Log, error) { | |||
WHERE evm_chain_id = :evm_chain_id | |||
AND block_number >= :start_block | |||
AND block_number <= :end_block | |||
ORDER BY (block_number, log_index, created_at)`, args) | |||
ORDER BY (block_number, log_index)`, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should not be 2 logs with the same log_index, block_number and evm_chain_id
c50cf15
to
f26994c
Compare
@@ -1565,3 +1573,55 @@ func Benchmark_LogsDataWordBetween(b *testing.B) { | |||
assert.Len(b, logs, 1) | |||
} | |||
} | |||
|
|||
func Benchmark_DeleteExpiredLogs(b *testing.B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No big diff
-- block_timestamp
Benchmark_DeleteExpiredLogs
Benchmark_DeleteExpiredLogs-12 13 89827359 ns/op
Benchmark_DeleteExpiredLogs-12 13 96382282 ns/op
Benchmark_DeleteExpiredLogs-12 12 99016438 ns/op
Benchmark_DeleteExpiredLogs-12 12 94013479 ns/op
Benchmark_DeleteExpiredLogs-12 12 93778076 ns/op
-- created_at
pkg: github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller
Benchmark_DeleteExpiredLogs
Benchmark_DeleteExpiredLogs-12 12 89441781 ns/op
Benchmark_DeleteExpiredLogs-12 12 91320372 ns/op
Benchmark_DeleteExpiredLogs-12 12 92141535 ns/op
Benchmark_DeleteExpiredLogs-12 12 93036705 ns/op
Benchmark_DeleteExpiredLogs-12 12 108362344 ns/op
53a5371
to
5c670ed
Compare
@@ -0,0 +1,5 @@ | |||
-- +goose Up | |||
drop index evm.evm_logs_idx_created_at; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This index shouldn't be used anywhere, because there are no more queries that rely on that field. I've also checked index utilization for CCIP to double check
evm.evm_logs_by_timestamp | 21272200 | 3524320643 | 3522526611
evm.logs_pkey | 12636814 | 11596801 | 11596715
evm.idx_evm_logs_ordered_by_block_and_created_at | 4240547 | 20127987563 | 15762720980
evm.evm_logs_idx | 7208398 | 24196816 | 22603336
evm.evm_logs_idx_data_word_one | 0 | 0 | 0
evm.evm_logs_idx_data_word_three | 27315 | 390229380 | 0
evm.evm_logs_idx_data_word_two | 0 | 0 | 0
evm.evm_logs_idx_topic_four | 0 | 0 | 0
evm.evm_logs_idx_topic_three | 0 | 0 | 0
evm.evm_logs_idx_topic_two | 311176 | 104034706 | 17779
evm.evm_logs_idx_created_at | 0 | 0 | 0
evm.evm_logs_idx_tx_hash | 745 | 932 | 922
evm.evm_logs_idx_data_word_four | 0 | 0 | 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube is complaining about the lack of capitalization here, will be cleaner to look at for the future if we address it:
--- drop index evm.evm_logs_idx_created_at;
+++ DROP INDEX evm.evm_logs_idx_created_at;
1311dfd
to
aa20458
Compare
aa20458
to
2de1458
Compare
Post rebase fix Added debug log
2de1458
to
310d5f0
Compare
Quality Gate passedIssues Measures |
Motivation
Delete expired logs should use
block_timestamp
instead ofcreated_at
.created_at
is generated when inserting a block into the database. These values can be completely different for different nodes because of theIn this case,
block_timestamp
is the real value on "when" the block was produced and should be the same for all nodes.This is a very similar case to what was fixed some time ago for the read layer #10743
Additionally, we can get rid of the
created_at
index, because after this change filtering bycreated_at
is not used at all. One index less should save some time during insert/delete operations onevm.logs
table. The only scenario that might be a problem here is running replay from block older than the defined retention. Prune will start removing logs that are just replayed, this won't be a problem when we keep it filtering bycreated_at
No big difference between deleting by
block_timestamp
andcreated_at
. Removing around ~90k logs