#! /usr/bin/python

# Clear Pathena database.

# Provided only for use by Client.  This was turned into a separate
# script to make erasure a clean transaction.

import os, sys

base = os.path.expandvars('$PATHENA')
for dir in ('lib',):
    sys.path.insert(0, os.path.join(base, dir))

from db_operations import *

main_log_file = \
    open(os.path.join(log_dir, indexing_log_name), 'a')

print >> main_log_file, ''
emit_log_entry(main_log_file, '>>>>> Clearing Pathena database...')

do_query_effect("delete from file_descriptors")
# Truncating tables doesn't work; seems to be locking behavior.

update_summary_stats()
refreshTsearchStats()
do_query_effect('COMMIT')

vacuumDatabase()

emit_log_entry(main_log_file, '<<<<< ...database fully cleared.')
main_log_file.close()

### consider adding timeout and recovery
