Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. from metadatastore.mds import MDS, MDSRO
  2. import metadatastore.conf
  3. from collections import deque
  4. from tqdm import tqdm
  5.  
  6. def main():
  7. old_config = dict(metadatastore.conf.connection_config)
  8. new_config = old_config.copy()
  9.  
  10. new_config['database'] = 'metadatastore_production_v1'
  11.  
  12. old = MDSRO(version=0, config=old_config)
  13. new = MDS(version=1, config=new_config)
  14.  
  15. # Drop all indexes on event collection to speed up insert.
  16. # They will be rebuilt the next time an MDS(RO) object connects.
  17. '''
  18. new._event_col.drop_indexes()
  19. total = old._runstart_col.find().count()
  20. for start in tqdm(old.find_run_starts(), desc='start docs', total=total):
  21. new.insert('start', start)
  22. '''
  23. total = old._runstop_col.find().count()
  24. for stop in tqdm(old.find_run_stops(), desc='stop docs', total=total):
  25. try:
  26. new.insert('stop', stop)
  27. except RuntimeError:
  28. print("error inserting run stop with uid {!r}".format(stop['uid']))
  29. '''
  30. descs = deque()
  31. counts = deque()
  32. total = old._descriptor_col.find().count()
  33. for desc in tqdm(old.find_descriptors(), unit='descriptors', total=total):
  34. d_raw = next(old._descriptor_col.find({'uid': desc['uid']}))
  35. num_events = old._event_col.find({'descriptor_id': d_raw['_id']}).count()
  36. new.insert('descriptor', desc)
  37. descs.append(desc)
  38. counts.append(num_events)
  39.  
  40. total = sum(counts)
  41. with tqdm(total=total, unit='events') as pbar:
  42. for desc, num_events in zip(descs, counts):
  43. if num_events:
  44. # skip empty event stream of bulk insert raises
  45. events = old.get_events_generator(descriptor=desc, convert_arrays=False)
  46. try:
  47. new.bulk_insert_events(descriptor=desc, events=events)
  48. except Exception:
  49. print(desc['uid'])
  50. raise
  51. pbar.update(num_events)
  52. '''
  53. if __name__ == '__main__':
  54. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement