Fix issue with delete only transactions

This commit is contained in:
Jonas Borgström 2012-11-30 22:43:38 +01:00
parent 177569d87b
commit 938901d7aa
1 changed files with 22 additions and 2 deletions

View File

@ -216,7 +216,9 @@ class Store(object):
segment, _ = self.index[id] segment, _ = self.index[id]
self.segments[segment] -= 1 self.segments[segment] -= 1
self.compact.add(segment) self.compact.add(segment)
self.compact.add(self.io.write_delete(id)) segment = self.io.write_delete(id)
self.segments.setdefault(segment, 0)
self.compact.add(segment)
except KeyError: except KeyError:
pass pass
segment, offset = self.io.write_put(id, data) segment, offset = self.io.write_put(id, data)
@ -232,7 +234,9 @@ class Store(object):
segment, offset = self.index.pop(id) segment, offset = self.index.pop(id)
self.segments[segment] -= 1 self.segments[segment] -= 1
self.compact.add(segment) self.compact.add(segment)
self.compact.add(self.io.write_delete(id)) segment = self.io.write_delete(id)
self.compact.add(segment)
self.segments.setdefault(segment, 0)
except KeyError: except KeyError:
raise self.DoesNotExist raise self.DoesNotExist
@ -466,6 +470,22 @@ class StoreTestCase(unittest.TestCase):
self.store.rollback() self.store.rollback()
self.assertEqual(self.store.get('00000000000000000000000000000000'), 'foo') self.assertEqual(self.store.get('00000000000000000000000000000000'), 'foo')
def test_single_kind_transactions(self):
# put
self.store.put('00000000000000000000000000000000', 'foo')
self.store.commit()
self.store.close()
# replace
self.store = self.open()
self.store.put('00000000000000000000000000000000', 'bar')
self.store.commit()
self.store.close()
# delete
self.store = self.open()
self.store.delete('00000000000000000000000000000000')
self.store.commit()
def suite(): def suite():
return unittest.TestLoader().loadTestsFromTestCase(StoreTestCase) return unittest.TestLoader().loadTestsFromTestCase(StoreTestCase)