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

Support to mysql databases #165

Merged
merged 60 commits into from
Jan 31, 2022
Merged

Support to mysql databases #165

merged 60 commits into from
Jan 31, 2022

Conversation

cphyc
Copy link
Contributor

@cphyc cphyc commented Jan 14, 2022

This brings back support to non-sqlite databases.
Notably, this allows to run the database on one server with the data on another.

TODO:

  • rename environment variables to TANGOS_

Mysql and co: accept connect_timeout keyword
sqlite: accepts timeout keyword
@@ -10,11 +10,11 @@ class Creator(Base):
__tablename__ = 'creators'

id = Column(Integer, primary_key=True)
command_line = Column(String)
command_line = Column(String(128))
Copy link
Contributor Author

@cphyc cphyc Jan 14, 2022

Choose a reason for hiding this comment

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

I am not sure about this, in particular the command_line may be longer than 128 character. Should it be a Text instead?
Note that this change is necessary for MySQL/MariaDB databases.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I suppose it should be Text. In sqlite I think TEXT and VARCHAR are identical so this change should not cause any problems

@cphyc cphyc marked this pull request as ready for review January 14, 2022 13:06
cwd = Column(String)
host = Column(String(128))
username = Column(String(128))
cwd = Column(String(128))
Copy link
Member

Choose a reason for hiding this comment

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

This perhaps should also be Text

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting to turn host and username to Text fields as well?

@@ -18,7 +18,7 @@ class Simulation(Base):
# __table_args__ = {'useexisting': True}

id = Column(Integer, primary_key=True)
basename = Column(String)
basename = Column(String(128))
Copy link
Member

Choose a reason for hiding this comment

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

Text here too

@@ -111,7 +111,7 @@ class SimulationProperty(Base):
data_float = Column(Float)
data_int = Column(Integer)
data_time = Column(DateTime)
data_string = Column(String)
data_string = Column(String(128))
Copy link
Member

Choose a reason for hiding this comment

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

Text here too

@@ -14,7 +14,7 @@ class TimeStep(Base):
__tablename__ = 'timesteps'

id = Column(Integer, primary_key=True)
extension = Column(String)
extension = Column(String(128))
Copy link
Member

Choose a reason for hiding this comment

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

Text here too

@cphyc cphyc marked this pull request as draft January 17, 2022 15:57
MySQL does not support ForeignKeys in temporary tables,
so here we disable it if the table
creation failed.

Note that the table will be deleted when
the current context is left.
@cphyc cphyc marked this pull request as ready for review January 17, 2022 17:42
@cphyc cphyc marked this pull request as draft January 17, 2022 17:42
@cphyc cphyc changed the title Bring back support to mysql/mariadb/... Support to mysql databases Jan 19, 2022
apontzen and others added 11 commits January 19, 2022 12:15
Refactor argmax logic into a generic function
The ambiguous order is probably what is causing intermittent failures of
 * test_live_calculation_link_syntax.test_missing_link
 * test_live_calculation_link_syntax.test_multi_calculation_link_returned_halo_is_usable
 with MySQL running on Github actions
* clarify inheritance path for Halo, BH, Tracker etc, to make clear that many relationships do not overlap
* explicitly flag a few remaining relationships that overlap
@apontzen apontzen mentioned this pull request Jan 22, 2022
apontzen and others added 4 commits January 26, 2022 21:09
Use the LONGBLOB type in MySQL to store up to 2**32 (4GiB) bytes instead of up to 2**16 (65kb)
Only TANGOS_DB_CONNECTION should be used by users.
@cphyc cphyc marked this pull request as ready for review January 28, 2022 13:21
…entation

The proper argmax implementation is needed within relation_finding to make it work with MySQL
(and probably other databases), but uses a large join which can hit performance (~10x degredation
for complicated searches)

The performance on e.g. large tree searches is now similar (though still a few percent worse than)
the older, buggy code
engine = create_engine(db_url)
with engine.connect() as conn:
conn.execute("COMMIT")
# Do not substitute user-supplied database names here.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand this comment, what's it saying?

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 think this is a leftover from a previous version, I'm going to delete it.

@@ -103,6 +106,7 @@ def test_link_returned_halo_is_usable():

def test_multi_calculation_link_returned_halo_is_usable():
all_links = db.get_timestep("sim/ts1").calculate_all('link(testlink)')
print("returned -->",all_links[0][0])
Copy link
Member

Choose a reason for hiding this comment

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

print statement to be removed

@apontzen
Copy link
Member

I fixed a performance issue and have left two ultra-minor comments above - as soon as they are done I think this is good to merge. Hooray!

@apontzen apontzen merged commit d4c6507 into pynbody:master Jan 31, 2022
@cphyc cphyc deleted the support-mysql branch January 31, 2022 15:27
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.

None yet

2 participants