def flush(self): if self.is_dirty(True): try: with HDFLockingFile(self.file_path, 'a') as f: for k in list(self._dirty): v = getattr(self, k) # log.debug('FLUSH: key=%s v=%s', k, v) if isinstance(v, Dictable): prefix='DICTABLE|{0}:{1}|'.format(v.__module__, v.__class__.__name__) value = prefix + pack(v.dump()) else: value = pack(v) f.attrs[k] = np.array([value]) # Update the hash_value in _hmap self._hmap[k] = utils.hash_any(v) # Remove the key from the _dirty set self._dirty.remove(k) except IOError, ex: if "unable to create file (File accessability: Unable to open file)" in ex.message: log.info('Issue writing to hdf file during master_manager.flush - this is not likely a huge problem: %s', ex.message) else: raise super(BaseManager, self).__setattr__('_is_dirty',False)
def flush(self): if self.is_dirty(True): try: with h5py.File(self.file_path, 'a') as f: for k in list(self._dirty): v = getattr(self, k) # log.debug('FLUSH: key=%s v=%s', k, v) if isinstance(v, Dictable): prefix='DICTABLE|{0}:{1}|'.format(v.__module__, v.__class__.__name__) value = prefix + pack(v.dump()) else: value = pack(v) f.attrs[k] = value # Update the hash_value in _hmap self._hmap[k] = utils.hash_any(v) # Remove the key from the _dirty set self._dirty.remove(k) except IOError, ex: if "unable to create file (File accessability: Unable to open file)" in ex.message: log.info('Issue writing to hdf file during master_manager.flush - this is not likely a huge problem: %s', ex.message) else: raise super(BaseManager, self).__setattr__('_is_dirty',False)
def flush(self, deep=True): if self.is_dirty(deep): try: # package for storage insert_dict = {} for k in list(self._dirty): v = getattr(self, k) log.trace('FLUSH: key=%s v=%s', k, v) if isinstance(v, Dictable): prefix='DICTABLE|{0}:{1}|'.format(v.__module__, v.__class__.__name__) value = prefix + pack(v.dump()) elif k == 'brick_tree': if hasattr(self, 'brick_tree') and isinstance(self.brick_tree, RTreeProxy): val = self.brick_tree.serialize() if val != '': insert_dict['brick_tree'] = val continue elif k == 'parameter_metadata': value = pack_parameter_manager_dict(v) else: value = pack(v) insert_dict[k] = value # Update the hash_value in _hmap self._hmap[k] = hash_any(v) dirty_spans = self.span_collection.get_dirty_spans() if len(dirty_spans) > 0: val = str(self.span_collection) log.trace("Span tuple: %s", val) value = pack(val) insert_dict['span_collection'] = value DBFactory.get_db().insert(self.guid, insert_dict, dirty_spans) for span in dirty_spans: span.is_dirty = False self._dirty.clear() except IOError, ex: if "unable to create file (File accessability: Unable to open file)" in ex.message: log.info('Issue writing to hdf file during master_manager.flush - this is not likely a huge problem: %s', ex.message) else: raise super(DbBackedMetadataManager, self).__setattr__('_is_dirty',False)
def is_dirty(self, force_deep=False): """ Tells if the object has attributes that have changed since the last flush @return: True if the BaseMananager object is dirty and should be flushed """ if not force_deep and len(self._dirty) > 0: # Something new was set, easy-peasy return True else: # Nothing new has been set, need to check hashes self._dirty.difference_update(self._ignore) # Ensure any ignored attrs are gone... for k, v in [(k,v) for k, v in self.__dict__.iteritems() if not k in self._ignore and not k.startswith('_')]: chv = utils.hash_any(v) # log.trace('key=%s: cached hash value=%s current hash value=%s', k, self._hmap[k], chv) if self._hmap[k] != chv: self._dirty.add(k) return len(self._dirty) != 0
def is_dirty(self, force_deep=False): """ Tells if the object has attributes that have changed since the last flush @return: True if the BaseMananager object is dirty and should be flushed """ if not force_deep and self._is_dirty: # Something new was set, easy-peasy return True else: # Nothing new has been set, need to check hashes self._dirty.difference_update(self._ignore) # Ensure any ignored attrs are gone... for k, v in [(k,v) for k, v in self.__dict__.iteritems() if not k in self._ignore and not k.startswith('_')]: chv = utils.hash_any(v) # log.trace('key=%s: cached hash value=%s current hash value=%s', k, self._hmap[k], chv) if self._hmap[k] != chv: self._dirty.add(k) return len(self._dirty) != 0
def __setattr__(self, key, value): super(BaseManager, self).__setattr__(key, value) if not key in self._ignore and not key.startswith('_'): self._hmap[key] = utils.hash_any(value) self._dirty.add(key) super(BaseManager, self).__setattr__('_is_dirty',True)