~marienz/storm/recover-from-failed-flush

« back to all changes in this revision

Viewing changes to storm/store.py

  • Committer: Marien Zwart
  • Date: 2010-10-07 18:27:55 UTC
  • Revision ID: marien.zwart@gmail.com-20101007182755-qdvcsn0o10l4r0sg
Deal with flushes failing better (still needs tests!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
485
485
                else:
486
486
                    raise OrderLoopError("Can't flush due to ordering loop")
487
487
                del sorted_dirty[i]
488
 
                self._dirty.pop(obj_info, None)
489
 
                self._flush_one(obj_info)
 
488
                # We have to do this before actually flushing: if we
 
489
                # do it afterwards we break the case where flushing
 
490
                # rendered the object dirty again (via the "flushed"
 
491
                # hook).
 
492
                dirty = self._dirty.pop(obj_info, None)
 
493
                try:
 
494
                    self._flush_one(obj_info)
 
495
                except:
 
496
                    # If our flush failed the object is still dirty.
 
497
                    self._dirty[obj_info] = dirty
 
498
                    raise
490
499
 
491
500
        self._order.clear()
492
501
 
496
505
    def _flush_one(self, obj_info):
497
506
        cls_info = obj_info.cls_info
498
507
 
499
 
        pending = obj_info.pop("pending", None)
 
508
        pending = obj_info.get("pending", None)
500
509
 
501
510
        if pending is PENDING_REMOVE:
502
511
            expr = Delete(compare_columns(cls_info.primary_key,
549
558
 
550
559
                self._add_to_alive(obj_info)
551
560
 
 
561
        obj_info.pop("pending", None)
 
562
 
552
563
        self._run_hook(obj_info, "__storm_flushed__")
553
564
 
554
565
        obj_info.event.emit("flushed")