Skip to content

Instantly share code, notes, and snippets.

@clayg
Last active May 14, 2020 19:57
Show Gist options
  • Select an option

  • Save clayg/27956ec11c7e65538c9d1c99d60d1613 to your computer and use it in GitHub Desktop.

Select an option

Save clayg/27956ec11c7e65538c9d1c99d60d1613 to your computer and use it in GitHub Desktop.
try and test if reclaim locks up the database
[root@stgss0235 ~]# tail -n 20 *.out
==> orig.out <==
('delete', 1589476453, 968)
('reclaim', 1589476456.4089239, 3.372346878051758)
('delete', 1589476456, 957)
('delete', 1589476459, 546)
('reclaim', 1589476459.7816048, 2.8547749519348145)
('delete', 1589476460, 392)
('reclaim', 1589476462.6364882, 2.8673436641693115)
('delete', 1589476462, 915)
('reclaim', 1589476465.5039353, 3.133700132369995)
('delete', 1589476465, 922)
('delete', 1589476468, 909)
('reclaim', 1589476468.637761, 3.2264034748077393)
('delete', 1589476469, 408)
('delete', 1589476471, 192)
('reclaim', 1589476471.8642952, 3.2684409618377686)
('delete', 1589476472, 733)
('reclaim', 1589476475.1328425, 3.267815351486206)
('delete', 1589476475, 905)
Shutting down...
==> patched.out <==
('delete', 1589480056, 939)
('reclaim', 1589480056.0111036, 2.9567580223083496)
('delete', 1589480058, 91)
('delete', 1589480059, 834)
('reclaim', 1589480058.9680324, 3.3185110092163086)
('delete', 1589480062, 923)
('reclaim', 1589480062.2872758, 3.002448320388794)
('delete', 1589480065, 918)
('reclaim', 1589480065.2898066, 2.974573850631714)
('delete', 1589480068, 910)
('reclaim', 1589480068.2645268, 2.9191181659698486)
('delete', 1589480071, 919)
('reclaim', 1589480071.1837482, 3.16150164604187)
('delete', 1589480074, 906)
('reclaim', 1589480074.3453355, 3.23030948638916)
('reclaim', 1589480077.5758595, 3.3760225772857666)
('delete', 1589480077, 965)
('delete', 1589480080, 266)
Shutting down...
#!/usr/bin/env python3
import sys
import time
from argparse import ArgumentParser
from multiprocessing import Process, Queue
from queue import Empty
parser = ArgumentParser()
parser.add_argument('dbpath', help='path to the database to use/create')
parser.add_argument('--run-time', default=10.0, type=float,
help='seconds to run')
parser.add_argument('--reclaim-age', default=2 * 7 * 24 * 60 * 60, type=float,
help='seconds before reaping')
def do_reclaim(args, results_q, stop_q):
from swift.common.db import DatabaseConnectionError
from swift.container.backend import ContainerBroker
while True:
try:
stop = stop_q.get_nowait()
except Empty:
pass
else:
if stop != 'STOP':
raise ValueError('wtf is %r' % (stop,))
return
start = time.time()
reclaim_age = start - args.reclaim_age
try:
ContainerBroker(args.dbpath).reclaim(reclaim_age, reclaim_age)
except DatabaseConnectionError:
print('waiting for broker...')
time.sleep(1)
continue
delta_t = time.time() - start
results_q.put(('reclaim', start, delta_t))
def do_delete(args, results_q, stop_q):
from swift.common.db import DatabaseConnectionError
from swift.common.utils import Timestamp
from swift.container.backend import ContainerBroker
last_start = int(Timestamp.now())
last_count = 0
while True:
ts = Timestamp.now()
try:
broker = ContainerBroker(args.dbpath)
broker.delete_object('object-%s' % ts.internal, ts.internal)
except DatabaseConnectionError:
broker = ContainerBroker(args.dbpath, account='a', container='c')
broker.initialize(Timestamp.now().internal, 0)
broker.delete_object('object-%s' % ts.internal, ts.internal)
last_count += 1
this_window = int(time.time())
if this_window != last_start:
# send stats and reset
results_q.put(('delete', last_start, last_count))
last_start = this_window
last_count = 0
try:
stop = stop_q.get_nowait()
except Empty:
pass
else:
if stop != 'STOP':
raise ValueError('wtf is %r' % (stop,))
return
def main():
args = parser.parse_args()
results_q = Queue()
stop_q = Queue()
reclaim_p = Process(target=do_reclaim, args=(args, results_q, stop_q))
delete_p = Process(target=do_delete, args=(args, results_q, stop_q))
procs = [reclaim_p, delete_p]
for p in procs:
p.start()
try:
stop = time.time() + args.run_time
while time.time() < stop:
try:
stats = results_q.get(timeout=1)
except Empty:
continue
print(stats)
finally:
print('\nShutting down...')
for p in procs:
stop_q.put('STOP')
for p in procs:
p.join()
while True:
try:
results_q.get_nowait()
except Empty:
break
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment