Skip to content

Commit a4fe5a9

Browse files
authored
Merge pull request #51 from lutraconsulting/fix-failing-push-finish
Fix failing push finish
2 parents 9b488b2 + fc89483 commit a4fe5a9

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

mergin/client_push.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ def push_project_async(mc, directory):
133133
total_size = 0
134134
# prepare file chunks for upload
135135
for file in upload_files:
136-
# do checkpoint to push changes from wal file to gpkg if there is no diff
137-
if "diff" not in file and mp.is_versioned_file(file["path"]):
138-
do_sqlite_checkpoint(mp.fpath(file["path"]))
139-
file["checksum"] = generate_checksum(mp.fpath(file["path"]))
140136
file['location'] = mp.fpath_meta(file['diff']['path']) if 'diff' in file else mp.fpath(file['path'])
141137

142138
for chunk_index, chunk_id in enumerate(file["chunks"]):
@@ -210,16 +206,17 @@ def push_project_finalize(job):
210206
resp = job.mc.post("/v1/project/push/finish/%s" % job.transaction_id)
211207
job.server_resp = json.load(resp)
212208
except ClientError as err:
213-
job.mc.post("/v1/project/push/cancel/%s" % job.transaction_id)
214209
# server returns various error messages with filename or something generic
215210
# it would be better if it returned list of failed files (and reasons) whenever possible
216-
return {'error': str(err)}
217-
218-
if 'error' in job.server_resp:
219-
#TODO would be good to get some detailed info from server so user could decide what to do with it
220-
# e.g. diff conflicts, basefiles issues, or any other failure
221-
job.mp.log.error("push failed. server response: " + job.server_resp['error'])
222-
raise ClientError(job.server_resp['error'])
211+
job.mp.log.error("--- push finish failed! " + str(err))
212+
213+
# if push finish fails, the transaction is not killed, so we
214+
# need to cancel it so it does not block further uploads
215+
job.mp.log.info("canceling the pending transaction...")
216+
resp_cancel = job.mc.post("/v1/project/push/cancel/%s" % job.transaction_id)
217+
server_resp_cancel = json.load(resp_cancel)
218+
job.mp.log.info("cancel response: " + str(server_resp_cancel))
219+
raise err
223220

224221
job.mp.metadata = {
225222
'name': job.project_path,

mergin/merginproject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def get_push_changes(self):
289289
changes = self.compare_file_sets(self.metadata['files'], self.inspect_files())
290290
# do checkpoint to push changes from wal file to gpkg
291291
for file in changes['added'] + changes['updated']:
292-
size, checksum = do_sqlite_checkpoint(self.fpath(file["path"]))
292+
size, checksum = do_sqlite_checkpoint(self.fpath(file["path"]), self.log)
293293
if size and checksum:
294294
file["size"] = size
295295
file["checksum"] = checksum

mergin/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,33 @@ def int_version(version):
6969
return int(version.lstrip('v')) if re.match(r'v\d', version) else None
7070

7171

72-
def do_sqlite_checkpoint(path):
72+
def do_sqlite_checkpoint(path, log=None):
7373
"""
7474
Function to do checkpoint over the geopackage file which was not able to do diff file.
7575
7676
:param path: file's absolute path on disk
7777
:type path: str
78+
:param log: optional reference to a logger
79+
:type log: logging.Logger
7880
:returns: new size and checksum of file after checkpoint
7981
:rtype: int, str
8082
"""
8183
new_size = None
8284
new_checksum = None
8385
if ".gpkg" in path and os.path.exists(f'{path}-wal'):
86+
if log:
87+
log.info("checkpoint - going to add it in " + path)
8488
conn = sqlite3.connect(path)
8589
cursor = conn.cursor()
8690
cursor.execute("PRAGMA wal_checkpoint=FULL")
91+
if log:
92+
log.info("checkpoint - return value: " + str(cursor.fetchone()))
8793
cursor.execute("VACUUM")
8894
conn.commit()
8995
conn.close()
9096
new_size = os.path.getsize(path)
9197
new_checksum = generate_checksum(path)
98+
if log:
99+
log.info("checkpoint - new size {} checksum {}".format(new_size, new_checksum))
92100

93101
return new_size, new_checksum

0 commit comments

Comments
 (0)