Skip to content

Commit

Permalink
improved advisory lock related messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Stefou committed Oct 26, 2021
1 parent 9ad85cd commit 53f4c3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion migreat/MiGreat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import random
import time
import yaml
from migreat import __VERSION__

# Log config
logger = logging.getLogger('MiGreat')
Expand Down Expand Up @@ -139,7 +140,6 @@ def cli():

config = mg.config
if config.use_advisory_lock:
logger.info("Acquiring lock")
priv_engine = MiGreat.connect(
config.hostname,
config.port,
Expand All @@ -154,10 +154,13 @@ def cli():
sha_start = hashlib.sha256(config.service_schema.encode('utf8')).digest()[:4]
lock_id = int.from_bytes(sha_start, 'little')
with priv_engine.connect() as lock_conn:
logger.info("Waiting for advisory lock")
# Block until lock is available. This allows init container to wait on all replicas
# until the migration is complete.
lock_conn.execute(text(f"SELECT pg_advisory_lock({lock_id})"))
logger.info("Lock acquired")
mg.upgrade()
logger.info("Releasing lock")
else:
mg.upgrade()

Expand Down Expand Up @@ -230,6 +233,7 @@ def __init__(self, config: Config):
"""
Initializes an instance of MiGreat.
"""
logger.info(f"MiGreat {__VERSION__}")
self.__config = config

@property
Expand Down
1 change: 1 addition & 0 deletions migreat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__VERSION__ = '0.1.10'
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
here = Path(__file__).parent
long_description = (here / "README.md").read_text()

with open("./migreat/__init__.py") as ver_file:
version = ver_file.read().strip().split('=')[1].strip()[1:-1]

# Load the requirements file in here to avoid duplication
with open("./requirements.txt", "r") as req_file:
requirements = [r for r in req_file.readlines() if r.strip()]

setup(
name='MiGreat-cli',
version='0.1.9',
version=version,
packages=find_packages(),
author='Hashibuto',
author_email='[email protected]',
Expand Down

0 comments on commit 53f4c3a

Please sign in to comment.