def afterCompletion(self, transaction): tdata = get() if not tdata.registered: return es = tdata.es if es.mode == DISABLE_MODE: tdata.reset() return success = transaction.status == Status.COMMITTED query = FilteredQuery(MatchAllQuery(), TermFilter('transaction_id', tdata.tid)) conn = es.conn # NEED to refresh here otherwise we'll have inconsistencies conn.refresh() try: docs = conn.search(query, es.catalogsid, es.trns_catalogtype, sort='order:desc') docs.count() # force executing except ElasticSearchException: # XXX uh oh, nasty, we have a problem. Let's log it. warn("Error trying to abort transaction: %s" %( traceback.format_exc())) tdata.reset() return for doc in docs: conn.delete(es.catalogsid, es.trns_catalogtype, doc.get_id()) if not success: if doc.action == Actions.add: # if it was an add action, remove delete conn.delete(es.catalogsid, es.catalogtype, doc.uid) elif doc.action in (Actions.modify, Actions.delete): # if it was a modify or delete, restore the doc restored_doc = loads(doc.data) conn.index(restored_doc, es.catalogsid, es.catalogtype, doc.uid) # NEED to refresh here otherwise we'll have inconsistencies conn.refresh() tdata.reset()
def afterCompletion(self, transaction): tdata = get() if not tdata.registered: return es = tdata.es if es.mode == DISABLE_MODE: tdata.reset() return success = transaction.status == Status.COMMITTED query = FilteredQuery(MatchAllQuery(), TermFilter("transaction_id", tdata.tid)) conn = es.conn # NEED to refresh here otherwise we'll have inconsistencies conn.refresh() try: docs = conn.search(query, es.catalogsid, es.trns_catalogtype, sort="order:desc") docs.count() # force executing except ElasticSearchException: # XXX uh oh, nasty, we have a problem. Let's log it. warn("Error trying to abort transaction: %s" % (traceback.format_exc())) tdata.reset() return for doc in docs: conn.delete(es.catalogsid, es.trns_catalogtype, doc.get_id()) if not success: if doc.action == Actions.add: # if it was an add action, remove delete conn.delete(es.catalogsid, es.catalogtype, doc.uid) elif doc.action in (Actions.modify, Actions.delete): # if it was a modify or delete, restore the doc restored_doc = loads(doc.data) conn.index(restored_doc, es.catalogsid, es.catalogtype, doc.uid) # NEED to refresh here otherwise we'll have inconsistencies conn.refresh() tdata.reset()
def data(self): if self._data is None: self._data = loads(self._raw_data) return self._data