[Sugar-devel] [PATCH 1/2] Add ds_clean flag to trigger index rebuilds #2095, #2317
Martin Langhoff
martin at laptop.org
Thu Sep 20 12:06:54 EDT 2012
This gives us more complete coverage of cases where ENOSPC or
other errors are hit when creating/updating datastore entries.
Without this patch, using the Journal on ENOSPC sometimes leads
to an "empty" Journal after restart. Datastore entries exist on
disk but are not in the index (Xapian DB).
With this patch, failure to complete create/update/delete forces
an index rebuild on restart.
---
src/carquinyol/datastore.py | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index de79500..6ede341 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -77,12 +77,28 @@ class DataStore(dbus.service.Object):
self._rebuild_index()
return
+ ds_root_path=layoutmanager.get_instance().get_root_path()
+ self._cleanflag = os.path.join(ds_root_path, 'ds_clean')
+
if initiated:
logging.debug('Initiate datastore')
self._index_store.flush()
elif not self._index_store.index_updated:
logging.debug('Index is not up-to-date, will update')
self._update_index()
+ elif not os.path.exists(self._cleanflag):
+ logging.debug('DS state is not clean, will update')
+ self._update_index()
+ self._mark_clean()
+
+
+ def _mark_clean(self):
+ try:
+ f = open(self._cleanflag, 'w')
+ os.fsync(f.fileno())
+ f.close()
+ except Exception:
+ logging.exception("Could not mark the datastore clean")
def _open_layout(self):
"""Open layout manager, check version of data store on disk and
@@ -178,6 +194,7 @@ class DataStore(dbus.service.Object):
self.Created(uid)
self._optimizer.optimize(uid)
logger.debug('created %s', uid)
+ self._mark_clean()
async_cb(uid)
@dbus.service.method(DS_DBUS_INTERFACE,
@@ -190,6 +207,8 @@ class DataStore(dbus.service.Object):
uid = str(uuid.uuid4())
logging.debug('datastore.create %r', uid)
+ os.remove(self._cleanflag)
+
if not props.get('timestamp', ''):
props['timestamp'] = int(time.time())
@@ -232,6 +251,7 @@ class DataStore(dbus.service.Object):
self.Updated(uid)
self._optimizer.optimize(uid)
logger.debug('updated %s', uid)
+ self._mark_clean()
async_cb()
@dbus.service.method(DS_DBUS_INTERFACE,
@@ -243,6 +263,8 @@ class DataStore(dbus.service.Object):
async_cb, async_err_cb):
logging.debug('datastore.update %r', uid)
+ os.remove(self._cleanflag)
+
if not props.get('timestamp', ''):
props['timestamp'] = int(time.time())
@@ -393,6 +415,7 @@ class DataStore(dbus.service.Object):
in_signature='s',
out_signature='')
def delete(self, uid):
+ os.remove(self._cleanflag)
self._optimizer.remove(uid)
self._index_store.delete(uid)
@@ -404,7 +427,7 @@ class DataStore(dbus.service.Object):
self.Deleted(uid)
logger.debug('deleted %s', uid)
-
+ self._mark_clean()
@dbus.service.signal(DS_DBUS_INTERFACE, signature="s")
def Deleted(self, uid):
pass
--
1.7.10.4
More information about the Sugar-devel
mailing list