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 (Process): DB writer #8352

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

OjusWiZard
Copy link
Member

@OjusWiZard OjusWiZard commented Aug 2, 2024

Closes #7272

Checklist

  • Seperate DB write process from API process
  • Communication between both the processes
  • Adjust existing code to support this change

@OjusWiZard OjusWiZard force-pushed the feat/db_writer_process branch 4 times, most recently from 92f0da7 to a9f73ca Compare August 6, 2024 11:34
Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 79.15493% with 148 lines in your changes missing coverage. Please review.

Project coverage is 57.75%. Comparing base (55403b6) to head (906423c).
Report is 1 commits behind head on develop.

Files Patch % Lines
rotkehlchen/db/drivers/server.py 59.84% 53 Missing ⚠️
rotkehlchen/db/drivers/client.py 90.17% 3 Missing and 8 partials ⚠️
rotkehlchen/start.py 84.00% 5 Missing and 3 partials ⚠️
rotkehlchen/db/eth2.py 73.33% 2 Missing and 2 partials ⚠️
rotkehlchen/db/evmtx.py 87.50% 3 Missing and 1 partial ⚠️
rotkehlchen/db/dbhandler.py 97.11% 1 Missing and 2 partials ⚠️
frontend/app/src/subprocess-handler.ts 0.00% 2 Missing ⚠️
rotkehlchen/chain/zksync_lite/manager.py 86.66% 1 Missing and 1 partial ⚠️
rotkehlchen/exchanges/bitstamp.py 33.33% 2 Missing ⚠️
rotkehlchen/api/rest.py 88.88% 1 Missing ⚠️
... and 58 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8352       /-   ##
===========================================
- Coverage    59.97%   57.75%   -2.23%     
===========================================
  Files         1755     1755              
  Lines       124891   124809      -82     
  Branches     16729    16279     -450     
===========================================
- Hits         74904    72083    -2821     
- Misses       47539    50249     2710     
- Partials      2448     2477       29     
Flag Coverage Δ
backend 80.85% <79.37%> (-0.21%) ⬇️
frontend_integration 56.77% <ø> ( 0.01%) ⬆️
frontend_unit 31.09% <0.00%> (-5.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

frontend/app/src/subprocess-handler.ts Outdated Show resolved Hide resolved
rotkehlchen/start.py Outdated Show resolved Hide resolved
@OjusWiZard OjusWiZard force-pushed the feat/db_writer_process branch 3 times, most recently from 0850053 to 6bb7716 Compare August 7, 2024 18:21
@OjusWiZard OjusWiZard force-pushed the feat/db_writer_process branch 15 times, most recently from 355ea97 to 0ee5557 Compare August 13, 2024 15:11
@OjusWiZard OjusWiZard changed the title WIP: DB writer process Feat(Process): DB writer Aug 13, 2024
@OjusWiZard OjusWiZard changed the title Feat(Process): DB writer Refactor (Process): DB writer Aug 13, 2024
@OjusWiZard OjusWiZard marked this pull request as ready for review August 13, 2024 15:52
@OjusWiZard OjusWiZard added the ready for peer review Backend PR ready to be reviewed by colleagues label Aug 13, 2024
Comment on lines 2920 to 2923
write_cursor.execute('DELETE FROM zksynclite_transactions WHERE tx_hash=?;', (tx_hash,)) # noqa: E501
concerning_address = cursor.execute(
'SELECT from_address FROM zksynclite_transactions WHERE rowid=?',
(write_cursor.lastrowid,),
).fetchone()
Copy link
Member

Choose a reason for hiding this comment

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

question: here you are using that the writter cursor hasn't commited yet to query for the row id right? I see that this can be error prone if at some point we change the logic. Why not write it like

Suggested change
write_cursor.execute('DELETE FROM zksynclite_transactions WHERE tx_hash=?;', (tx_hash,)) # noqa: E501
concerning_address = cursor.execute(
'SELECT from_address FROM zksynclite_transactions WHERE rowid=?',
(write_cursor.lastrowid,),
).fetchone()
concerning_address = cursor.execute(
'SELECT from_address FROM zksynclite_transactions WHERE tx_hash=?',
(tx_hash,),
).fetchone()
write_cursor.execute('DELETE FROM zksynclite_transactions WHERE tx_hash=?;', (tx_hash,)) # noqa: E501

rotkehlchen/api/rest.py Outdated Show resolved Hide resolved
Comment on lines 2929 to 2931
deleted_event_data = cursor.execute(
'SELECT location_label FROM history_events WHERE rowid=?',
(write_cursor.lastrowid,),
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above, why not interchange the order of the queries? I believe is better for readibility and also can avoid errors in the future

rotkehlchen/balances/manual.py Outdated Show resolved Hide resolved
rotkehlchen/chain/evm/decoding/hop/decoder.py Outdated Show resolved Hide resolved
rotkehlchen/tests/db/test_ranges.py Outdated Show resolved Hide resolved
Comment on lines 474 to 480
with data_updater.user_db.conn.write_ctx() as write_cursor:
write_cursor.execute(
'INSERT INTO rpc_nodes(name, endpoint, owned, active, weight, blockchain) '
'VALUES(?, ?, ?, ?, ?, ?)',
custom_node_tuple,
)
cursor.execute('SELECT COUNT(*) FROM rpc_nodes')
Copy link
Member

Choose a reason for hiding this comment

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

you need to close the cursor before reading to ensure that the other connection can see it right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

with database.user_write() as cursor:
with database.conn.read_ctx() as cursor:
Copy link
Member

Choose a reason for hiding this comment

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

isn't it better in cases like this test to open the read/write cursor that you have?

Copy link
Member Author

Choose a reason for hiding this comment

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

reader can be used like that, but writer has to commit changes

tools/pyinstaller_hooks/hook-zmq.py Outdated Show resolved Hide resolved
rotkehlchen/tests/utils/premium.py Outdated Show resolved Hide resolved
@OjusWiZard OjusWiZard force-pushed the feat/db_writer_process branch 3 times, most recently from 106e6bc to 906423c Compare August 15, 2024 15:31
Comment on lines 2920 to 2923
concerning_address = cursor.execute(
'SELECT from_address FROM zksynclite_transactions WHERE tx_hash=?',
(tx_hash,),
).fetchone()
Copy link
Member

Choose a reason for hiding this comment

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

I believe this introduces a bug since you have a tuple and not an address

rotkehlchen/db/drivers/server.py Outdated Show resolved Hide resolved
rotkehlchen/db/drivers/server.py Outdated Show resolved Hide resolved
rotkehlchen/db/drivers/server.py Show resolved Hide resolved
Comment on lines 86 to 90
for process_type, process_data in manager.processes.items():
process_data.process = Popen(executable ['--process', process_type.value]) # noqa: S603

if (backend_process := manager.processes[ProcessType.API_SERVER].process) is not None:
backend_process.wait()
Copy link
Member

Choose a reason for hiding this comment

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

One thing that I noticed is that you don't check that all the processes are running right? It can happen that the db writter fails to start and you don't check it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for peer review Backend PR ready to be reviewed by colleagues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Database writer process
2 participants