publication_transaction.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. namespace sunrise::state::build_data::runtime::persistence {
  3. struct Context;
  4. /** Cannot-fail call that drops one target domain after a save failure. */
  5. using Rollback = void() noexcept;
  6. /** Orders one catalog replace against the complete-cache save boundary. */
  7. class Transaction final {
  8. public:
  9. /** Takes the persistence lock unless a saved cache already freezes all domains. */
  10. Transaction() noexcept;
  11. /** Releases a held publish lock when the caller exits before finishing. */
  12. ~Transaction();
  13. Transaction(const Transaction&) = delete;
  14. Transaction& operator=(const Transaction&) = delete;
  15. Transaction(Transaction&&) = delete;
  16. Transaction& operator=(Transaction&&) = delete;
  17. /** @return True when a catalog replace is allowed under the held State lock. */
  18. [[nodiscard]] bool active() const noexcept;
  19. /**
  20. * Finishes one replace, and drops its target when the first cache write fails.
  21. * Dropping clears the target. It never restores what was published before.
  22. * @param published True when the domain passed validation and replaced its catalog.
  23. * @param rollback Drops the target domain while the publish lock is held.
  24. * @return True when the publish works and any complete cache is on disk.
  25. */
  26. [[nodiscard]] bool finish(bool published, Rollback& rollback) noexcept;
  27. private:
  28. Context* state_{};
  29. bool active_{};
  30. };
  31. } // namespace sunrise::state::build_data::runtime::persistence