Skip to content

Commit

Permalink
chore: address shutdown event listener logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pcnc committed Nov 20, 2023
1 parent 786cd0d commit a03b5fe
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions docker/all-in-one/shutdown_event_listener.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/python3

# This script is used to make sure the latest LSN checkpoint is persisted remotely
# before the container is stopped. It is triggered by the shutdown event listener
# or every 60 seconds, whichever comes first.
# before the container is stopped. It is triggered every 60 seconds, whichever comes first.
# The script will ship the latest LSN checkpoint to the remote storage if:
# - the latest LSN checkpoint is different from the previous, already shipped, one
# - the latest LSN checkpoint is not 0/0 as to avoid shipping empty checkpoints
Expand Down Expand Up @@ -39,20 +38,18 @@ def main():
write_stderr(data)

if headers['eventname'] == 'TICK_60':
if os.path.getmtime(checkpointFile) < time.time() - 60 * LSN_CHECKPOINT_SHIP_INTERVAL:
break

previousLSN = ''
with open(checkpointFilePrevious) as f:
previousLSN = f.read()

# If the current LSN is different from the previous one, persist it remotely
with open(checkpointFile) as f:
currentLSN = f.read()
if currentLSN != '0/0' and currentLSN != previousLSN:
subprocess.run(["/usr/bin/admin-mgr", "lsn-checkpoint-push"])
with open(previousLSN, 'w') as f:
f.write(checkpointFilePrevious)
if os.path.getmtime(checkpointFilePrevious) < time.time() - 60 * LSN_CHECKPOINT_SHIP_INTERVAL:
previousLSN = ''
with open(checkpointFilePrevious) as f:
previousLSN = f.read()

# If the current LSN is different from the previous one, persist it remotely
with open(checkpointFile) as f:
currentLSN = f.read()
if currentLSN != '0/0' and currentLSN != previousLSN:
subprocess.run(["/usr/bin/admin-mgr", "lsn-checkpoint-push"])
with open(checkpointFilePrevious, 'w') as f:
f.write(currentLSN)

write_stdout('RESULT 2\nOK')

Expand Down

0 comments on commit a03b5fe

Please sign in to comment.