From 67530acf1d39a81d83406c638057f1f6cf3322a5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 6 May 2024 16:42:10 +0800 Subject: [PATCH] Update index.py --- plugins/mongodb/index.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index f9272bb36..aa4dad18b 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -1075,7 +1075,7 @@ def replInit(): for x in range(len(nodes)): n = nodes[x] t = {} - t['_id'] = now_time_t+x + t['_id'] = x t['host'] = n['host'] if 'priority' in n: t['priority'] = int(n['priority']) @@ -1098,17 +1098,14 @@ def replInit(): client = mongdbClient() try: - rsStatus = client.admin.command('replSetInitiate',config) + client.admin.command('replSetInitiate',config) except Exception as e: info = str(e).split(',') - + # print(info) if info[0] == 'already initialized': - # tt = client.admin.command('add',{"host":"127.0.0.1:27017"}) - # print(tt) - config['version'] = int(now_time_t) try: - client.admin.command('replSetReconfig',config,force=True) + client.admin.command('replSetReconfig',config,force=True,maxTimeMS=10) except Exception as e: return mw.returnJson(False, str(e)) @@ -1119,6 +1116,12 @@ def replInit(): def replClose(): + d = getConfigData() + if 'replSetName' in d['replication']: + del d['replication']['replSetName'] + setConfig(d) + restart() + ip = getConfIp() port = getConfPort() @@ -1135,26 +1138,14 @@ def replClose(): client = mongdbClient() db = client.admin try: - # {force:True} - # repl_info = client.admin.command('replSetGetStatus') + client.drop_database('local') # print(repl_info) - # repl_info['members'] = [] - # del repl_info['set'] - - # print(repl_info) - rstatus = db.command('replSetReconfig',config,force=True) - - + # rstatus = db.command('replSetReconfig',config,force=True) + restart() except Exception as e: # info = str(e).split(',') return mw.returnJson(False, str(e)) - - d = getConfigData() - if 'replSetName' in d['replication']: - del d['replication']['replSetName'] - setConfig(d) - restart() - + return mw.returnJson(True, '关闭副本同步成功!') def getDbBackupListFunc(dbname=''):