From db5c31030d3276ff03720c404c1cc8645f0312df Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 9 Jun 2022 16:23:35 -0400 Subject: [PATCH] Migrate DB on start If python2 db format detected, use python2 to dump to text, then python3 to restore to get the python3 native version --- confluent_server/bin/confluentdbutil | 1 + .../confluent/config/configmanager.py | 2 ++ confluent_server/confluent/main.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/confluent_server/bin/confluentdbutil b/confluent_server/bin/confluentdbutil index 0f3148e7..25a5acf8 100755 --- a/confluent_server/bin/confluentdbutil +++ b/confluent_server/bin/confluentdbutil @@ -69,6 +69,7 @@ if args[0] == 'restore': if options.interactivepassword: password = getpass.getpass('Enter password to restore backup: ') try: + cfm.init(True) cfm.statelessmode = True cfm.restore_db_from_directory(dumpdir, password) cfm.statelessmode = False diff --git a/confluent_server/confluent/config/configmanager.py b/confluent_server/confluent/config/configmanager.py index f1a4192e..68a8c94a 100644 --- a/confluent_server/confluent/config/configmanager.py +++ b/confluent_server/confluent/config/configmanager.py @@ -565,6 +565,8 @@ def _load_dict_from_dbm(dpath, tdb): currdict[tks] = cPickle.loads(dbe[tk]) # nosec tk = dbe.nextkey(tk) except dbm.error: + if os.path.exists(tdb): + raise return diff --git a/confluent_server/confluent/main.py b/confluent_server/confluent/main.py index 5f35b2c8..2d26df8d 100644 --- a/confluent_server/confluent/main.py +++ b/confluent_server/confluent/main.py @@ -29,6 +29,10 @@ import atexit import confluent.auth as auth import confluent.config.conf as conf import confluent.config.configmanager as configmanager +try: + import anydbm as dbm +except ModuleNotFoundError: + import dbm import confluent.consoleserver as consoleserver import confluent.core as confluentcore import confluent.httpapi as httpapi @@ -62,8 +66,10 @@ import os import glob import signal import socket +import subprocess import time import traceback +import tempfile import uuid @@ -232,8 +238,20 @@ def sanity_check(): assure_ownership('/etc/confluent/srvcert.pem') +def migrate_db(): + tdir = tempfile.mkdtemp() + subprocess.check_call(['python2', '/opt/confluent/bin/confluentdbutil', 'dump', '-u', tdir]) + subprocess.check_call(['python3', '/opt/confluent/bin/confluentdbutil', 'restore', '-u', tdir]) + subprocess.check_call(['rm', '-rf', tdir]) + configmanager.init() + + def run(args): setlimits() + try: + configmanager.ConfigManager(None) + except dbm.error: + migrate_db() try: signal.signal(signal.SIGUSR1, dumptrace) except AttributeError: