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: move exit info related functions to smaller responsibility module #1503

Merged
merged 21 commits into from
May 22, 2020

Conversation

boolafish
Copy link
Contributor

@boolafish boolafish commented May 11, 2020

📋 ref https://github.com/omisego/new-tx-type-poc/issues/9

Overview

Move exit_info related DB access to PaymentExitInfo module instead. The motivation is to make the code easier to scale when we are adding new tx types. We will write new PaymentV2ExitInfo for example when we extend to payment v2.

First step to break the big DB module into smaller pieces!

Changes

  • Moving functions around from OMG.DB to OMG.DB.Models.PaymentExitInfo
  • expose get and get_all_by_type from OMG.DB for the db models module to call and simplify the code.
  • remove unused type param from decode_value and decode_values method of RocksDB.Core.

Question

Can we remove one of OMG.DBTest and OMG.RocksDBTest ? They are testing same thing now?

Testing

  • Move existing tests around
  • Add new tests for get/2, 3 and get_all_by_type/1, 2

@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch from dce58bb to 2e681aa Compare May 11, 2020 08:39
@coveralls
Copy link

coveralls commented May 11, 2020

Coverage Status

Coverage increased (+0.07%) to 78.211% when pulling 18583fc on boolafish/exit_info_db_with_tx_type_awareness into 5024988 on master.

@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch 2 times, most recently from 5a8c49e to 2156ff2 Compare May 12, 2020 10:41
spent_blknum: 2,
block_hashes: 2,
child_top_block_number: 1
child_top_block_number: 1,
get_single_value: 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not add get/3 and get_all_by_type/2 as optional as it is used in the implementation of PaymentExitInfo

@boolafish boolafish marked this pull request as ready for review May 12, 2020 10:42
@boolafish boolafish requested review from pnowosie and T-Dnzt May 12, 2020 10:42
@boolafish boolafish marked this pull request as draft May 12, 2020 10:49
@boolafish boolafish marked this pull request as ready for review May 13, 2020 03:01
@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch from 455cf87 to 9d23ad3 Compare May 13, 2020 03:01
@boolafish boolafish requested a review from InoMurko May 13, 2020 03:02
@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch from 9d23ad3 to e5aac6e Compare May 14, 2020 05:10
Copy link

@T-Dnzt T-Dnzt left a comment

Choose a reason for hiding this comment

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

Approving with a comment on some logs not being moved to the new functions :)

apps/omg_db/lib/omg_db/rocks_db.ex Show resolved Hide resolved
apps/omg_db/lib/omg_db/rocks_db.ex Show resolved Hide resolved
Copy link
Contributor

@pnowosie pnowosie left a comment

Choose a reason for hiding this comment

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

Wait, I didn't understand what we're trying to fix here...

apps/omg_db/lib/db.ex Show resolved Hide resolved
apps/omg_db/lib/db.ex Show resolved Hide resolved
apps/omg_db/lib/omg_db/rocksdb/server.ex Outdated Show resolved Hide resolved
@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch 2 times, most recently from 9f58834 to 6180a5e Compare May 20, 2020 05:03
apps/omg_db/lib/db.ex Show resolved Hide resolved
apps/omg_db/lib/omg_db/models/payment_exit_info.ex Outdated Show resolved Hide resolved
@boolafish
Copy link
Contributor Author

boolafish commented May 20, 2020

In a meeting/sync-up with @T-Dnzt and @pnowosie we decide to go with generic functions in DB/server exposing timeout as parameter for the model modules to fine-tune themselves. I will update the PR with that :)


def exit_infos(utxo_pos_list, server_name \\ @server_name)
when is_list(utxo_pos_list) do
DB.get(:exit_info, utxo_pos_list, @ten_seconds, server_name)
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 am not 100% sure on the data size yet. 10 sec might be premature large?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it optional in DB.get with 5 seconds (default GenServer call's timeout)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay. To introduce multiple optional args, I have to use opts \\ [] instead of timeout \\ 5000, server \\ @server_name to allow optional args combination in timeout and server. (unless there is better way of doing this?)

@boolafish boolafish requested review from pnowosie and T-Dnzt May 21, 2020 08:33
This is generic DB function that can get the specific data of a specific type.
If it is a single value data, use get_single_value/1 instead.
"""
def get(type, specific_keys, timeout), do: driver().get(type, specific_keys, timeout)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we want to name this get_multi instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 yes, be specific!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename the function to batch_get

@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch from 25996de to e0c44ea Compare May 21, 2020 10:10
Copy link
Contributor

@pnowosie pnowosie 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! (just minors left)


def exit_infos(utxo_pos_list, server_name \\ @server_name)
when is_list(utxo_pos_list) do
DB.get(:exit_info, utxo_pos_list, @ten_seconds, server_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it optional in DB.get with 5 seconds (default GenServer call's timeout)

This is generic DB function that can get the specific data of a specific type.
If it is a single value data, use get_single_value/1 instead.
"""
def get(type, specific_keys, timeout), do: driver().get(type, specific_keys, timeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 yes, be specific!

@boolafish boolafish force-pushed the boolafish/exit_info_db_with_tx_type_awareness branch from c761fc5 to 6593d83 Compare May 22, 2020 06:21
@boolafish boolafish merged commit dd5f33d into master May 22, 2020
@boolafish boolafish deleted the boolafish/exit_info_db_with_tx_type_awareness branch May 22, 2020 08:49
@unnawut unnawut added the chore Technical work that does not affect service behaviour label Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Technical work that does not affect service behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants