Conversation
src/class_sqlThread.py
Outdated
| Upgrade Db with respect to versions | ||
| """ | ||
|
|
||
| conn, cur = connection_build() |
There was a problem hiding this comment.
here allow to call it optionally with a parameter for in memory database
There was a problem hiding this comment.
pass arguments with DB file name
src/class_sqlThread.py
Outdated
| self.conn = sqlite3.connect(state.appdata + 'messages.dat') | ||
| self.conn.text_factory = str | ||
| self.cur = self.conn.cursor() | ||
| self.conn, self.cur = connection_build() |
There was a problem hiding this comment.
this should be in parent class
There was a problem hiding this comment.
Inherit connection vars from UpgradeDB class
There was a problem hiding this comment.
Moved in to __init__
src/class_sqlThread.py
Outdated
| self.conn.commit() | ||
|
|
||
| settingsversion = 4 | ||
| settingsversion = self.earlier_setting_version(settingsversion) |
There was a problem hiding this comment.
this should be in parent class
src/class_sqlThread.py
Outdated
|
|
||
| # Let us check to see the last time we vaccumed the messages.dat file. | ||
| # If it has been more than a month let's do it now. | ||
| def check_vaccumed(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements, |
src/class_sqlThread.py
Outdated
| helper_sql.sqlReturnQueue.put((self.cur.fetchall(), rowcount)) | ||
| # helper_sql.sqlSubmitQueue.task_done() | ||
|
|
||
| def earlier_setting_version(self, settingsversion): |
There was a problem hiding this comment.
different name, to show it's related to BMConfigParser version rather than sql version
There was a problem hiding this comment.
Change name to upgrade_config_parser_setting_version
src/class_sqlThread.py
Outdated
| self.__flag.set() # Set to True, let the thread stop blocking | ||
|
|
||
| def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements | ||
| def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements, |
There was a problem hiding this comment.
only this should be in this class, the other functionality should be refactored into methods and put into parent.
src/class_sqlThread.py
Outdated
| self.cur.execute(item, parameters) | ||
|
|
||
|
|
||
| class sqlThread(threading.Thread, UpgradeDB): |
There was a problem hiding this comment.
maybe an UpgradeDB object would be an attribute of the sqlThread rarther than sqlThread inheriting it. That way we isolate the DB stuff and can test it without threading, and the thread would need to use the same interfaces as the test.
There was a problem hiding this comment.
Changes done,
Refactored code and kept in Upgrade DB,
0f93137 to
8f544a2
Compare
44654df to
f0044d3
Compare
src/class_sqlThread.py
Outdated
| def __init__(self): | ||
| self._current_level = None | ||
| self.max_level = 11 | ||
| # self.conn, self.cur = connection_build('messages.dat') |
There was a problem hiding this comment.
make another class which overrides this to point to in-memory database, this can then be used for tests. You can call it something like class MockDB(UpgradeDB)
src/class_sqlThread.py
Outdated
|
|
||
| def __init__(self): | ||
| threading.Thread.__init__(self, name="SQL") | ||
| def connection_build(file_name): |
src/class_sqlThread.py
Outdated
|
|
||
| def __get_current_settings_version(self): | ||
| """ | ||
| Upgrade Db with respect to their versions |
src/class_sqlThread.py
Outdated
|
|
||
| def _upgrade_one_level_sql_statement(self, file_name): | ||
| """ | ||
| Execute SQL files and queries |
src/class_sqlThread.py
Outdated
| self.cur.execute(item, parameters) | ||
|
|
||
| helper_startup.updateConfig() | ||
| def embaded_version(self): |
There was a problem hiding this comment.
should be called something like init_database
There was a problem hiding this comment.
Changes are done for that and, but for some query I applied same query script.
There was a problem hiding this comment.
let's call it upgrade_schema_if_old_version
There was a problem hiding this comment.
Changed def name to upgrade_schema_if_old_version
src/class_sqlThread.py
Outdated
| helper_sql.sqlReturnQueue.put((self.cur.fetchall(), rowcount)) | ||
| # helper_sql.sqlSubmitQueue.task_done() | ||
|
|
||
| def earlier_setting_version(self, settingsversion): |
There was a problem hiding this comment.
different name, to show it's related to BMConfigParser version rather than sql version
src/class_sqlThread.py
Outdated
| # If the settings version is equal to 2 or 3 then the | ||
| # sqlThread will modify the pubkeys table and change | ||
| # the settings version to 4. | ||
| settingsversion = BMConfigParser().getint( |
There was a problem hiding this comment.
write getter + setter for this
There was a problem hiding this comment.
Applied setter and getter
src/class_sqlThread.py
Outdated
| # call create_function for encode address | ||
| self.create_function(self.conn) | ||
|
|
||
| self.initiate_database(self.cur, self.conn) |
There was a problem hiding this comment.
Something like this to skip init when running tests:
if not self.instanceof(MockDB):
self.initiate_database()
There was a problem hiding this comment.
managed in earlier logic used in memory for test mocking
|
Your |
src/tests/sql/init_version_5.sql
Outdated
| @@ -0,0 +1,10 @@ | |||
| DROP TABLE objectprocessorqueue; | |||
|
|
|||
| CREATE TABLE IF NOT EXISTS `knownnodes` ( | |||
There was a problem hiding this comment.
Cool (; I haven't seen this used
$ sqlite3 .config/PyBitmessage/messages.dat
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
sqlite> select * from knownnodes;
Error: no such table: knownnodes
There was a problem hiding this comment.
I think the table was deleted in a later version.
There was a problem hiding this comment.
It looks like some weird leftover of deleted code. Since the current upgrade code deletes it, we should keep it, otherwise we'd have to test against ancient versions.
src/tests/sql/init_version_5.sql
Outdated
| @@ -0,0 +1,10 @@ | |||
| DROP TABLE objectprocessorqueue; | |||
There was a problem hiding this comment.
Why drop here, if you are going to create it later?
There was a problem hiding this comment.
you're right, if it's removed and there is an error, it means there is a bug somewhere
src/tests/sql/init_version_7.sql
Outdated
| `payload` blob DEFAULT NULL, | ||
| `integer` integer NOT NULL, | ||
| UNIQUE(hash) ON CONFLICT REPLACE | ||
| ) ; |
There was a problem hiding this comment.
I don't see a difference from the previous version - in the init_version_6.sql
There was a problem hiding this comment.
I haven't reviewed the SQL files yet, I'm focusing on getting the structure of classes and tests right, it's already at like 3rd iteration.
There was a problem hiding this comment.
I looked through the tests and instructed to redesign how they perform setup.
|
@g1itch This PR should among other things separate the SQL execution from threads, so that you can run the tests without launching the SQL thread. There is a lot of work and that's why it's taking long. |
I see. I have no problem with the speed yet. I'm glad to see many line of code deleted in this PR. But I'd prefer to report the strange things, I can see in the code before it got merged. Because I believe we can broke it harder than before. More tests will help to avoid such case. |
|
By the way, the core test suite reports an interesting issue here: https://buildbot.bitmessage.org/#builders/25/builds/1515 |
src/class_sqlThread.py
Outdated
| self.max_level = 11 | ||
| self.conn, self.cur = self.connection_build('messages.dat') | ||
|
|
||
| def connection_build(self, file_name=None): |
There was a problem hiding this comment.
def connection_build(self, file_name='messages.dat'):
There was a problem hiding this comment.
applied changes method name to __connection_build_internal and pass file_name
src/class_sqlThread.py
Outdated
| return self.__get_current_settings_version() | ||
|
|
||
| @sql_schema_version.setter | ||
| def sql_schema_version(self, current_level): |
There was a problem hiding this comment.
instead of current_level use ignore
There was a problem hiding this comment.
removed current_level
src/class_sqlThread.py
Outdated
| item = '''update settings set value=? WHERE key='version';''' | ||
| parameters = (current_level + 1,) | ||
| self.cur.execute(item, parameters) | ||
| self._current_level = self.__get_current_settings_version() |
There was a problem hiding this comment.
variable self.current_level shouldn't be needed
There was a problem hiding this comment.
Now its
def sql_schema_version(self):
"""
Update version with one level
"""
item = '''update settings set value=value+1 WHERE key='version';'''
self.cur.execute(item)
self._current_level = self.__get_current_settings_version()
There was a problem hiding this comment.
Its changed into
self.cur.execute(item, self.__get_current_settings_version() + 1)
Because its not taking value+1
src/class_sqlThread.py
Outdated
| self.cur.execute(item, parameters) | ||
| self.conn.commit() | ||
|
|
||
| settingsversion = 3 |
There was a problem hiding this comment.
separate getter setter for settingsversion
src/class_sqlThread.py
Outdated
| # Redefinition-of-parameters-type-from-tuple-to-str, R0204, line-too-long, E501 | ||
| """Process SQL queries from `.helper_sql.sqlSubmitQueue`""" | ||
| helper_sql.sql_available = True | ||
| self.conn, self.cur = UpgradeDB().conn, UpgradeDB().cur |
There was a problem hiding this comment.
insetad just create one object and save it, like
self.db = UpgradeDB()
and then just reference
self.db.cur.execute(blabla)
There was a problem hiding this comment.
passed while initialise
src/class_sqlThread.py
Outdated
| self.cur.execute('PRAGMA secure_delete = true') | ||
|
|
||
| # call create_function for encode address | ||
| self.create_function(self.conn) |
There was a problem hiding this comment.
self.db.create_function(blabla)
src/class_sqlThread.py
Outdated
| # call create_function for encode address | ||
| self.create_function(self.conn) | ||
|
|
||
| self.initiate_database(self.cur, self.conn) |
There was a problem hiding this comment.
Changed into initialize_schema
src/class_sqlThread.py
Outdated
| # version we are on can stay embedded in the messages.dat file. Let us | ||
| # check to see if the settings table exists yet. | ||
|
|
||
| self.embaded_version() |
There was a problem hiding this comment.
changed to upgrade_schema_if_old_version
79ebee5 to
7240658
Compare
d5296dd to
a55c086
Compare
g1itch
left a comment
There was a problem hiding this comment.
Barely readable ); The tests/sql seems duplicating sql
setup.py
Outdated
| 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', | ||
| 'translations/*.ts', 'translations/*.qm', | ||
| 'images/*.png', 'images/*.ico', 'images/*.icns' | ||
| 'images/*.png', 'images/*.ico', 'images/*.icns', 'sql/*.py', 'sql/*.sql' |
There was a problem hiding this comment.
I don't understand the purpose of this empty sql/__init__.py and especially listing it in the package_data.
There was a problem hiding this comment.
The file was removed, but the reference in setup.py still persists. @cis-muzahid please delete this reference, and also delete the file src/tests/sql/__init__.py, that is also unnecessary.
src/class_sqlThread.py
Outdated
| import sys | ||
| import threading | ||
| import time | ||
| import logging |
src/class_sqlThread.py
Outdated
| class BitmessageDB(object): | ||
| """ | ||
| Upgrade Db with respect to versions | ||
| """ |
src/class_sqlThread.py
Outdated
| """ | ||
| Get current setting Version | ||
| """ | ||
| item = '''SELECT value FROM settings WHERE key='version';''' |
There was a problem hiding this comment.
There was a problem, we found out what it is, will be fixed in next commit.
src/class_sqlThread.py
Outdated
| @property | ||
| def sql_config_settings_version(self): | ||
| """ | ||
| Getter for BmConfigparser |
| "MainWindow", | ||
| 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), | ||
| True))) | ||
| os._exit(0) |
| ' Here is the actual error message thrown by the sqlThread: %s', | ||
| str(item), | ||
| str(repr(parameters)), | ||
| str(err)) |
There was a problem hiding this comment.
These casts seem redundant
There was a problem hiding this comment.
I tend to agree. Something like traceback.format_exc would be better.
src/tests/core.py
Outdated
| queryreturn = sqlExecute("INSERT INTO testtbl VALUES(101);") | ||
| self.assertEqual(queryreturn, 1) | ||
|
|
||
| queryreturn = sqlQuery(''' SELECT * FROM testtbl ''') |
src/tests/core.py
Outdated
| self.delete_address_from_addressbook(address2) | ||
|
|
||
| def test_sqlscripts(self): | ||
| """ Testing sql statements""" |
a55c086 to
b3d6dc4
Compare
g1itch
left a comment
There was a problem hiding this comment.
I see no point in another review since my previous comments are mostly ignored.
src/class_sqlThread.py
Outdated
| parameters = helper_sql.sqlSubmitQueue.get() | ||
| rowcount = 0 | ||
| try: | ||
| self.db.cur.execute(item, parameters) |
There was a problem hiding this comment.
item is a bad name. Use query.
dd64925 to
bb88554
Compare
PeterSurda
left a comment
There was a problem hiding this comment.
There are still a couple of unresolved conversations.
setup.py
Outdated
| 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', | ||
| 'translations/*.ts', 'translations/*.qm', | ||
| 'images/*.png', 'images/*.ico', 'images/*.icns' | ||
| 'images/*.png', 'images/*.ico', 'images/*.icns', 'sql/*.py', 'sql/*.sql' |
There was a problem hiding this comment.
The file was removed, but the reference in setup.py still persists. @cis-muzahid please delete this reference, and also delete the file src/tests/sql/__init__.py, that is also unnecessary.
| "MainWindow", | ||
| 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), | ||
| True))) | ||
| os._exit(0) |
c531e62 to
533df72
Compare
533df72 to
899d28f
Compare
2b89a05 to
d6acbc3
Compare
c953c10 to
de89853
Compare
PeterSurda
left a comment
There was a problem hiding this comment.
The PR shouldn't remove the *.sql files. It should ignore them.
676025a to
f61b1c1
Compare
4267c44 to
a13a37d
Compare
38f7628 to
3720c3f
Compare
Refactor sqlthread and add test cases for setting versions and SQL internal function called create_function