Skip to content

Commit

Permalink
new functionality to recover from a corrupted node synonymizer file
Browse files Browse the repository at this point in the history
  • Loading branch information
edeutsch committed Jul 27, 2023
1 parent 8cde373 commit b5a1901
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion code/ARAX/ARAXQuery/ARAX_background_tasker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
import time
import psutil
import subprocess
import datetime
import traceback
import pkgutil
Expand Down Expand Up @@ -54,7 +55,6 @@ def run_tasks(self, config):
eprint(f" {modname} ???")
else:
pass
#eprint(f" {modname} x {location}")

while True:

Expand Down Expand Up @@ -86,6 +86,41 @@ def run_tasks(self, config):
n_clients += 1
n_ongoing_queries += n_queries

#### Check in on the NodeSynonymizer database, which sometimes gets corrupted
node_synonymizer_path = os.path.dirname(os.path.abspath(__file__)) + "/../NodeSynonymizer"
files = os.listdir(node_synonymizer_path)
already_printed_header = False
link_counter = 0
file_counter = 0
for file in files:
if file.startswith('node_syn') and file.endswith('.sqlite'):
file_counter += 1
filepath = node_synonymizer_path + "/" + file
fileinfo = '??'
if os.path.islink(filepath):
fileinfo = '(symlink)'
link_counter += 1
else:
fileinfo = os.path.getsize(filepath)
if file_counter != 1 or link_counter != 1:
if not already_printed_header:
eprint("Strange files in NodeSynonymizer directory:")
already_printed_header = True
eprint(f" {fileinfo} {file}")
eprint(f" Deleting file {filepath}")
try:
os.unlink(filepath)
except Exception as error:
eprint(f"ERROR: Unable to delete file with error {error}")

if file_counter != 1 or link_counter != 1:
eprint(f"ERROR: NodeSynonymizer state is weird. Running the database manager")
try:
subprocess.check_call( [ 'python3', node_synonymizer_path + "/../ARAXQuery/ARAX_database_manager.py" ] )
except Exception as error:
eprint(f"ERROR: Attempt to run database manager failed with {error}")


load_tuple = psutil.getloadavg()

eprint(f"{timestamp}: INFO: ARAXBackgroundTasker status: waiting. Current load is {load_tuple}, n_clients={n_clients}, n_ongoing_queries={n_ongoing_queries}")
Expand Down

0 comments on commit b5a1901

Please sign in to comment.