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

Dump and restore Stochastic Event Set #1300

Merged
merged 33 commits into from Nov 11, 2013
Merged

Conversation

matley
Copy link
Contributor

@matley matley commented Nov 4, 2013

Addresses https://bugs.launchpad.net/oq-engine/+bug/1247665

Additionally, I have changed the database permissions such that oq_admin is able to create temporary tables (used for the dump/restore workflow).

For a clean diff, #1298 should land first

@micheles
Copy link
Contributor

micheles commented Nov 6, 2013

This branch should be refreshed

@matley
Copy link
Contributor Author

matley commented Nov 6, 2013

Just refreshed

@micheles
Copy link
Contributor

micheles commented Nov 6, 2013

The first thing that I do not like is that now a regular user gets the error:

psycopg2.ProgrammingError: must be superuser to COPY to or from a file
HINT: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone.

It should be possible to avoid that by using psycopg2 copy_expert functionality

@@ -60,7 +59,7 @@ def _tuplestr(tup):
class Copier(object):
"""
Small wrapper around a psycopg2 cursor, which a .copy method
writing directly to .gz files. It remembers the copied filenames,
writing directly to csv files. It remembers the copied filenames,
which are stored in the attribute .filenames.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason why we are not generating .gz files? This makes a lot of difference in terms of disk space occupation. Notice that this tool is intended to be used even for large outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This work is experimental. So, I did not want to add too many feature. I prefer at this moment to let the user zip or not zip the result. however, I see where you are coming from. Therefore, I have added a ticket https://bugs.launchpad.net/oq-engine/+bug/1248584

@matley
Copy link
Contributor Author

matley commented Nov 6, 2013

I have just addressed all the raised issues, including the permission ones (by using copy_expert as you suggested). Could you give it a look again?

@micheles
Copy link
Contributor

micheles commented Nov 7, 2013

There is still something not working:

$ bin/openquake --restore-hazard-calculation /tmp
Traceback (most recent call last):
File "bin/openquake", line 546, in
main()
File "bin/openquake", line 539, in main
connection.connection, args.restore_hazard_calculation)
File "/home/michele/oq-engine/openquake/engine/tools/restore_hazards.py", line 147, in hazard_restore
curs = conn.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'

@micheles
Copy link
Contributor

micheles commented Nov 7, 2013

I get this error:

Traceback (most recent call last):
File "/home/michele/oq-engine/bin/openquake", line 545, in
main()
File "/home/michele/oq-engine/bin/openquake", line 535, in main
dump_hazards.main(*args.dump_hazard_calculation)
File "/home/michele/oq-engine/openquake/engine/tools/dump_hazards.py", line 274, in main
host=host, database=dbname, user=user, password=password, port=port)
File "/usr/lib/python2.7/dist-packages/psycopg2/init.py", line 167, in connect
if port is not None and int(port) > 0:
ValueError: invalid literal for int() with base 10: ''

The fix is to change engine/settings.py and set the port to '5432' instead of ''. How comes it works on your machine?

@micheles
Copy link
Contributor

micheles commented Nov 7, 2013

Then I get another error:
$ oq --restore-hazard-calculation /tmp/
Traceback (most recent call last):
File "/home/michele/oq-engine/bin/openquake", line 545, in
main()
File "/home/michele/oq-engine/bin/openquake", line 538, in main
models.getcursor('admin').connection, args.restore_hazard_calculation)
File "/home/michele/oq-engine/openquake/engine/tools/restore_hazards.py", line 158, in hazard_restore
hc_ids = transfer_data(curs, models.HazardCalculation)
File "/home/michele/oq-engine/openquake/engine/tools/restore_hazards.py", line 63, in transfer_data
"ALTER TABLE %s ADD restore_id INT" % model_table(model))
psycopg2.ProgrammingError: must be owner of relation hazard_calculation

help=("Restore a hazard calculation from a dump. "
"Only SES outputs currently supported"),
metavar=('DUMP_DIR'))

Copy link
Contributor

Choose a reason for hiding this comment

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

After yesterday discussion, I think we should change the names to --save-hazard-calculation and --load-hazard-calculation. Paul and Matteo like those names better. Also restore_hazards.py and dump_hazards.py could be renamed.

@matley
Copy link
Contributor Author

matley commented Nov 7, 2013

I have renamed dump/restore -> save/load. I have added a proper migration script to fix permission problems.

@micheles
Copy link
Contributor

micheles commented Nov 8, 2013

Notice that there is still the issue with the port number in engine/settings.py. Moreover I cannot dump Miriam's computation:

$ bin/openquake --shc 1 /tmp/
Dumping ses (1) in /tmp/
Dumping gmf (2) in /tmp/
Traceback (most recent call last):
File "/home/michele/oq-engine/bin/openquake", line 545, in
main()
File "/home/michele/oq-engine/bin/openquake", line 535, in main
save_hazards.main(*args.save_hazard_calculation)
File "/home/michele/oq-engine/openquake/engine/tools/save_hazards.py", line 276, in main
hc.dump(hazard_calculation_id)
File "/home/michele/oq-engine/openquake/engine/tools/save_hazards.py", line 246, in dump
self.gmf(ids)
File "/home/michele/oq-engine/openquake/engine/tools/save_hazards.py", line 175, in gmf
'hzrdr.gmf.csv', mode='a')
File "/home/michele/oq-engine/openquake/engine/tools/save_hazards.py", line 121, in _copy
self.outdir, filename, mode)
File "/home/michele/oq-engine/openquake/engine/tools/save_hazards.py", line 88, in copy
self._cursor.copy_expert(query, fileobj)
psycopg2.ProgrammingError: syntax error at or near ")"
LINE 1: copy (select * from hzrdr.gmf where output_id in (2)))

You should also refresh the branch from master.

@matley
Copy link
Contributor Author

matley commented Nov 8, 2013

I have just fixed the issue with inputs having ground motion fields. I can't reproduce the problem you are experiencing (the one related to the settings.py). GMFs are currently unsupported, so now we skip processing them and warn the user properly.

@matley
Copy link
Contributor Author

matley commented Nov 8, 2013

Hey Michele, look at the latest commit. I have also added support for gzip.

@micheles
Copy link
Contributor

I have an issue with the ALTER TABLE locking the original tables, but it is not a problem when loading a calculation on an user computer (there is a single user there) and the approach can be revised later on, when this feature will be used in the platform. So LGTM for now.

matley added a commit that referenced this pull request Nov 11, 2013
Dump and restore Stochastic Event Set
@matley matley merged commit e62244f into gem:master Nov 11, 2013
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