-
Notifications
You must be signed in to change notification settings - Fork 68
Implement upload directory creation and lockfile handling #608
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -295,14 +295,23 @@ def create_project_version(id): | |
| if request.json.get("check_only", False): | ||
| return NoContent, 204 | ||
|
|
||
| upload_dir = None | ||
| try: | ||
| # while processing data, block other uploads | ||
| upload = Upload(project, version, upload_changes, current_user.id) | ||
| db.session.add(upload) | ||
| # Save path as local before any potential rollback expires the ORM instance | ||
| upload_dir = upload.upload_dir | ||
| # Create dir and lockfile BEFORE committing so concurrent is_active() checks | ||
| # always see this upload as active once its DB row is visible to other workers. | ||
| os.makedirs(upload_dir) | ||
| open(upload.lockfile, "w").close() | ||
|
Comment on lines
+305
to
+308
|
||
| # Creating blocking upload can fail, e.g. in case of racing condition | ||
| db.session.commit() | ||
| except IntegrityError: | ||
| db.session.rollback() | ||
| if upload_dir: | ||
| move_to_tmp(upload_dir) | ||
| # check and clean dangling blocking uploads or abort | ||
| for current_upload in project.uploads.all(): | ||
| if current_upload.is_active(): | ||
|
|
@@ -321,16 +330,17 @@ def create_project_version(id): | |
| # Try again after cleanup | ||
| upload = Upload(project, version, upload_changes, current_user.id) | ||
| db.session.add(upload) | ||
| upload_dir = upload.upload_dir | ||
| os.makedirs(upload_dir) | ||
| open(upload.lockfile, "w").close() | ||
| db.session.commit() | ||
|
Comment on lines
332
to
336
|
||
| move_to_tmp(upload.upload_dir) | ||
| except IntegrityError as err: | ||
| db.session.rollback() | ||
| if upload_dir: | ||
| move_to_tmp(upload_dir) | ||
| logging.error(f"Failed to create upload session: {str(err)}") | ||
| return AnotherUploadRunning().response(409) | ||
|
|
||
| # Create transaction folder and lockfile | ||
| os.makedirs(upload.upload_dir) | ||
| open(upload.lockfile, "w").close() | ||
|
|
||
| file_changes, errors = upload.process_chunks(use_shared_chunk_dir=True) | ||
| # files consistency or geodiff related issues, project push would never succeed, whole upload is aborted | ||
| if errors: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.makedirs(upload_dir)and creating the lockfile can raiseOSError/PermissionError/FileExistsError, but thistryonly handlesIntegrityError. If either filesystem call fails, the request will 500 without rolling back the DB session or cleaning up partially created artifacts. Consider catchingOSErroraround the directory/lockfile creation, callingdb.session.rollback(), and moving the directory to tmp (or removing it) before returning anUploadErrorresponse.