Skip to content

Refactor sqlthread #1760

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

Closed
wants to merge 8 commits into from
Closed

Conversation

cis-muzahid
Copy link
Contributor

@cis-muzahid cis-muzahid commented May 5, 2021

No description provided.

Copy link
Member

@PeterSurda PeterSurda left a comment

Choose a reason for hiding this comment

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

Too big, can't review. Needs to be split. Separate code quality, support functions, and the individual levels.

stdeb.cfg Outdated
@@ -1,7 +1,7 @@
[DEFAULT]
Package: pybitmessage
Section: net
Build-Depends: dh-python, libssl-dev, python-all-dev, python-setuptools
Build-Depends: dh-python, libssl-dev, python-all-dev, python-setuptools, python-six
Copy link
Member

Choose a reason for hiding this comment

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

this should be a separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is 16a1177 merged from v0.6.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it fine now?

@@ -29,6 +25,8 @@
except ImportError:
get_plugin = None

# pylint: disable=too-many-branches,too-many-statements

Copy link
Member

Choose a reason for hiding this comment

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

is this a code quality only change? Then it should go into a separate PR.

@cis-muzahid cis-muzahid force-pushed the refactor_sqlthread branch 3 times, most recently from 2d9ad93 to 359553b Compare June 3, 2021 15:27
@PeterSurda
Copy link
Member

The upgrade design is too complicated. There is no need for a separate function per level.

@cis-muzahid cis-muzahid force-pushed the refactor_sqlthread branch from ad37a9e to 0097965 Compare June 8, 2021 08:25
self.upgrade_one_level(l)
self.run_migrations(l)

def upgrade_schema_data_level(self, level):
Copy link
Member

Choose a reason for hiding this comment

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

```def increment_settings_version``

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

method = getattr(self, method_name, lambda: "Invalid version")
return method()

def run_migrations(self, file_name):
Copy link
Member

Choose a reason for hiding this comment

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

def _upgrade_one_level_sql_statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.current_level = None
self.max_level = 11

def get_current_level(self):
Copy link
Member

Choose a reason for hiding this comment

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

def __get_current_settings_version
Maybe this can't be private, that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.cur.execute(item, parameters)
return int(self.cur.fetchall()[0][0])

def upgrade_one_level(self, level):
Copy link
Member

Choose a reason for hiding this comment

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

def _upgrade_one_level_method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -102,11 +189,20 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
settingsversion = BMConfigParser().getint(
'bitmessagesettings', 'settingsversion')

# Process SQL queries first20bytesofencryptedmessage in table inventory
Copy link
Member

Choose a reason for hiding this comment

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

this section can probably be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

item = '''update settings set value=? WHERE key='version';'''
parameters = (2,)
self.cur.execute(item, parameters)

# People running earlier versions of PyBitmessage do not have the
Copy link
Member

Choose a reason for hiding this comment

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

lines 201-227 can be made into a separate method

Copy link
Member

Choose a reason for hiding this comment

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

lines 227-292 can be split into 2 or 3 methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, please check the method name.


# Test versions
upgrade_db = UpgradeDB()
upgrade_db._upgrade_one_level_sql_statement(int(version))
Copy link
Member

Choose a reason for hiding this comment

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

# pylint: disable=protected-access

@cis-muzahid cis-muzahid force-pushed the refactor_sqlthread branch 2 times, most recently from f335968 to 560c2ba Compare June 10, 2021 16:24
@cis-muzahid cis-muzahid marked this pull request as ready for review June 11, 2021 11:11
@PeterSurda
Copy link
Member

  • rebase
  • make the versions into properties
  • rename versioning into something else, inside the methods you can use version, as a decorator perhaps sql_schema_upgrade
  • delete obsolete stuff
  • I haven't thoroughly reviewed tests but for starters they are probably ok
  • rename the version 1 init/test to version 3. I checked the original source and it may break things if you're upgrading from version 1. If you just rename it to 3, then it would only break if we stopped the upgrade at version 2, which isn't a practical problem. You just need to make sure version 2 and 3 tests still succeeds.

Copy link
Member

@PeterSurda PeterSurda left a comment

Choose a reason for hiding this comment

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

Please make the requested changes.

return None

# Migrate Db with level
method_name = 'upgrade_schema_data_' + str(level)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this defined anywhere, so delete this method.

item = '''update settings set value=? WHERE key='version';'''
parameters = (level + 1,)
self.cur.execute(item, parameters)

Copy link
Member

Choose a reason for hiding this comment

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

this should be more transparent. For example, you can use a @property decorator for properties sql_schema_version and configparser_schema_version and use these instead calling the methods directly. And setter can enforce a +1 irrespective of what you pass as an argument.

@PeterSurda
Copy link
Member

It is certainly an improvement but still work left to do.

@g1itch g1itch marked this pull request as draft June 30, 2021 16:35
@cis-muzahid
Copy link
Contributor Author

Closing because having changes in #1794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants