From 6601bebcfe669ad3dd48ec237a271dd34d7e7aa3 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 21 Feb 2015 18:41:07 -0700 Subject: [PATCH] master: make RIDs unique across restarts --- artiq/frontend/artiq_master.py | 4 ++-- artiq/master/results.py | 31 +++++++++++++++++++++++++++++++ artiq/master/scheduler.py | 4 ++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index d9fe9410b..f2061cb24 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -9,7 +9,7 @@ from artiq.protocols.pc_rpc import Server from artiq.protocols.sync_struct import Publisher from artiq.protocols.file_db import FlatFileDB, SimpleHistory from artiq.master.scheduler import Scheduler -from artiq.master.results import RTResults +from artiq.master.results import RTResults, get_last_rid from artiq.master.repository import Repository from artiq.tools import verbosity_args, init_logger @@ -51,7 +51,7 @@ def main(): def run_cb(rid, run_params): rtr.current_group = run_params["rtr_group"] - scheduler = Scheduler(run_cb) + scheduler = Scheduler(run_cb, get_last_rid() + 1) scheduler.worker.handlers = { "req_device": ddb.request, "req_parameter": pdb.request, diff --git a/artiq/master/results.py b/artiq/master/results.py index 451028d8c..8dc8eaff6 100644 --- a/artiq/master/results.py +++ b/artiq/master/results.py @@ -1,5 +1,6 @@ import os import time +import re import numpy import h5py @@ -16,6 +17,36 @@ def get_hdf5_output(start_time, rid, name): return h5py.File(os.path.join(dirname, filename), "w") +def get_last_rid(): + r = -1 + try: + day_folders = os.listdir("results") + except: + return r + day_folders = filter(lambda x: re.fullmatch('\d\d\d\d-\d\d-\d\d', x), + day_folders) + for df in day_folders: + day_path = os.path.join("results", df) + try: + minute_folders = os.listdir(day_path) + except: + continue + minute_folders = filter(lambda x: re.fullmatch('\d\d-\d\d', x), + minute_folders) + for mf in minute_folders: + minute_path = os.path.join(day_path, mf) + try: + h5files = os.listdir(minute_path) + except: + continue + for x in h5files: + m = re.fullmatch('(\d\d\d\d\d\d\d\d\d)-.*\.h5', x) + rid = int(m.group(1)) + if rid > r: + r = rid + return r + + _type_to_hdf5 = { int: h5py.h5t.STD_I64BE, float: h5py.h5t.IEEE_F64BE diff --git a/artiq/master/scheduler.py b/artiq/master/scheduler.py index 00e67226a..d95f0038c 100644 --- a/artiq/master/scheduler.py +++ b/artiq/master/scheduler.py @@ -6,10 +6,10 @@ from artiq.master.worker import Worker class Scheduler: - def __init__(self, run_cb): + def __init__(self, run_cb, first_rid): self.run_cb = run_cb self.worker = Worker() - self.next_rid = 0 + self.next_rid = first_rid self.queue = Notifier([]) self.queue_modified = asyncio.Event() self.timed = Notifier(dict())