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

hyperspace: event index v1=>v2 speed up migration. #10276

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

raulk
Copy link
Member

@raulk raulk commented Feb 15, 2023

This fixes the slow event index v1=>v2 migration by:

  • Adding temporary indices on the value and the event_id.
  • Matching on value, event_id, and key when updating entries.

It also warns and moves on when we fail to update an entry.

Speed on Macbook M1 Max

~5 seconds to migrate 230k entries from an event database that has accumulated events since genesis over various network versions.

2023-02-15T13:03:40.585Z	WARN	event_index	filter/index.go:495	[migration v1=>v2] processing values
2023-02-15T13:03:40.597Z	WARN	event_index	filter/index.go:538	[migration v1=>v2] processed values	{"count": 500}
2023-02-15T13:03:40.607Z	WARN	event_index	filter/index.go:538	[migration v1=>v2] processed values	{"count": 1000}
2023-02-15T13:03:40.618Z	WARN	event_index	filter/index.go:538	[migration v1=>v2] processed values	{"count": 1500}
2023-02-15T13:03:40.629Z	WARN	event_index	filter/index.go:538	[migration v1=>v2] processed values	{"count": 2000}
...
2023-02-15T13:03:45.547Z	WARN	event_index	filter/index.go:538	[migration v1=>v2] processed values	{"count": 238000}
2023-02-15T13:03:45.554Z	WARN	event_index	filter/index.go:543	[migration v1=>v2] processed all values	{"count": 238310}
2023-02-15T13:03:45.565Z	WARN	event_index	filter/index.go:561	[migration v1=>v2] schema version updated to v2
2023-02-15T13:03:45.626Z	WARN	event_index	filter/index.go:567	[migration v1=>v2] transaction committed; ALL DONE

Tests

After loosening the event filter limits:

curl --location --request POST 'localhost:1234/rpc/v1' \
      --header 'Content-Type: application/json' \
      --data-raw '{
  "jsonrpc":"2.0",
  "method":"eth_getLogs",
  "params":[ { "fromBlock": "0x124F8" } ],
  "id":1
  }'

{"jsonrpc":"2.0","result":[{"address":"0xa526253ae512a6ce7586dc602e50a71b3fc2f56b","data":"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b333434353435732e66696c000000000000000000000000000000000000000000","topics":["0xb7d29e911041e8d9b843369e890bcb72c9388692ba48b65ac54e7214c4c348f7","0x48e403c93f2fbf2c5c7c3a878a737d6aee2204963fe68dded825eae37ac1dea6"],"removed":false,"logIndex":"0x6","transactionIndex":"0x0","transactionHash":"0xf6433e1880e7b756aa1bcba2b4c3caeeb87a10bd87c3df0a90635b6589e899a7","blockHash":"0x0bcc8988ec3d08e61847ad48147b044facd637b3b813460270d931722fadf91f","blockNumber":"0x12511"},{"address":"0xc5c9fba1b420f4ad6d0662d08306551391c857bb","data":"0x0000000000000000000000008d5335accb417436c299f903d594f82ae3329f88","topics":["0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82","0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2","0x3584ed15a91a84cde77798dfceea2e247e03b1adfa5ed0151d008c493e2dfca7"],"removed":false,"logIndex":"0x5","transactionIndex":"0x0","transactionHash":"0xf6433e1880e7b756aa1bcba2b4c3caeeb87a10bd87c3df0a90635b6589e899a7","blockHash":"0x0bcc8988ec3d08e61847ad48147b044facd637b3b813460270d931722fadf91f","blockNumber":"0x12511"},{"address":"0xc5c9fba1b420f4ad6d0662d08306551391c857bb","data":"0x000000000000000000000000a526253ae512a6ce7586dc602e50a71b3fc2f56b","topics":["0x335721b01866dc23fbee8b6b2c7b1e14d6f05c28cd35a2c934239f94095602a0","0x6a02c28edda64fa23c420e5bcb29fb33ba73714d8fca1f01d5f74ba189f08d5d"],"removed":false,"logIndex":"0x2","transactionIndex":"0x0","transactionHash":"0xf6433e1880e7b756aa1bcba2b4c3caeeb87a10bd87c3df0a90635b6589e899a7","blockHash":"0x0bcc8988ec3d08e61847ad48147b044facd637b3b813460270d931722fadf91f","blockNumber":"0x12511"},{"address":"0xc5c9fba1b420f4ad6d0662d08306551391c857bb","data":"0x0000000000000000000000008d5335accb417436c299f903d594f82ae3329f88","topics":["0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82","0x78f6b1389af563cc5c91f234ea46b055e49658d8b999eeb9e0baef7dbbc93fdb","0xe5ab962b4999d8b0ab65167ad4bf98c9758b6b18f13a46a45a5a93029125a8be"],"removed":false,"logIndex":"0x1","transactionIndex":"0x0","transactionHash":"0xf6433e1880e7b756aa1bcba2b4c3caeeb87a10bd87c3df0a90635b6589e899a7","blockHash":"0x0bcc8988ec3d08e61847ad48147b044facd637b3b813460270d931722fadf91f","blockNumber":"0x12511"},{"address":"0xc9cf92750d731c5b278af0873302a8b58be17bea","data":"0x00000000000000000000000025cb30acd1786e49177429318f26959681f9aabd000000000000000000000000c9cf92750d731c5b278af0873302a8b58be17bea0000000000000000000000000000000000000000000000000000000000000000"...

SQL checks

sqlite> select count(*) from event_entry where key in ('t1', 't2', 't3', 't4') and length(value) != 32;
0
sqlite> select count(*) from event_entry where key not in ('t1', 't2', 't3', 't4', 'd');
0

@raulk raulk requested a review from a team as a code owner February 15, 2023 11:29
@raulk raulk closed this Feb 15, 2023
@raulk raulk deleted the raulk/fix-slow-migration branch February 15, 2023 11:53
@raulk raulk reopened this Feb 15, 2023
@raulk raulk force-pushed the raulk/fix-slow-migration branch 2 times, most recently from 6c5ae67 to 068e885 Compare February 15, 2023 12:59
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.

1 participant