Make checkpointing atomic
Update Engine currently has a bug where if it the process is interrupted
during checkpointing, we are unable to resume progress from where we
were previously. This is because prefs are reset at the beginning of
checkpointing and then slowly updated during checkpointing, if
update_engine is interrupted during this stage, it loses its state. This
change allows us to update the prefs non-destructively and then
atomically replace the old prefs with the new ones.
Test: m update_engine. update_device.py tested resume ota
Change-Id: I3a7edf7498be9cde5c6f34e3cb259a7853f4f443
diff --git a/common/prefs_interface.h b/common/prefs_interface.h
index 69ccf68..d56435f 100644
--- a/common/prefs_interface.h
+++ b/common/prefs_interface.h
@@ -105,6 +105,17 @@
virtual void RemoveObserver(std::string_view key,
ObserverInterface* observer) = 0;
+ // create tmp_prefs to write to during checkpointing. Flush will replace prefs
+ // with tmp_prefs
+ virtual bool StartTransaction() = 0;
+
+ // cancel any pending transaction by deleting tmp_prefs
+ virtual bool CancelTransaction() = 0;
+
+ // swap prefs with tmp_prefs checkpointing will use new tmp prefs to resume
+ // updates, otherwise we fall back on old prefs
+ virtual bool SubmitTransaction() = 0;
+
protected:
// Key separator used to create sub key and get file names,
static const char kKeySeparator = '/';