Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take advantage of LMDB append optimization #1912

Merged
merged 10 commits into from
Oct 22, 2020
7 changes: 4 additions & 3 deletions synapse/lib/lmdbslab.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ async def puts(self, name, items, reqid=None):

for item in items:

self.slab.put(abrv + s_common.int64en(offs), s_msgpack.en(item), db=self.qdata)
putv = self.slab.put(abrv + s_common.int64en(offs), s_msgpack.en(item), db=self.qdata)
assert putv, 'Put failed'

self.sizes.inc(name, 1)
offs = self.offsets.inc(name, 1)
Expand Down Expand Up @@ -1421,9 +1422,9 @@ def pop(self, lkey, db=None):
def delete(self, lkey, val=None, db=None):
return self._xact_action(self.delete, lmdb.Transaction.delete, lkey, val, db=db)

def put(self, lkey, lval, dupdata=False, overwrite=True, db=None):
def put(self, lkey, lval, dupdata=False, overwrite=True, append=False, db=None):
return self._xact_action(self.put, lmdb.Transaction.put, lkey, lval, dupdata=dupdata, overwrite=overwrite,
db=db)
append=append, db=db)

def replace(self, lkey, lval, db=None):
'''
Expand Down
7 changes: 5 additions & 2 deletions synapse/lib/slabseqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def add(self, item, indx=None):
return indx

indx = self.indx
self.slab.put(s_common.int64en(indx), s_msgpack.en(item), db=self.db)
retn = self.slab.put(s_common.int64en(indx), s_msgpack.en(item), append=True, db=self.db)
assert retn, "Not adding the largest index"

self.indx += 1

Expand Down Expand Up @@ -89,9 +90,11 @@ def save(self, items):

rows.append((lkey, byts))

self.slab.putmulti(rows, append=True, db=self.db)
retn = self.slab.putmulti(rows, append=True, db=self.db)
took = s_common.now() - tick

assert retn, "Not adding the largest indices"

origindx = self.indx
self.indx = indx

Expand Down
5 changes: 4 additions & 1 deletion synapse/tests/test_lib_lmdbslab.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ async def test_lmdbslab_base(self):

slab.put(b'\x00\x01', b'hehe', db=baz)
slab.put(b'\xff', b'haha', db=baz)
slab.put(b'\xff\xff', b'hoho', db=baz)

slab.put(b'\xff\xff', b'hoho', append=True, db=baz) # Should succeed
slab.put(b'\xaa\xff', b'hoho', append=True, db=baz) # Should fail (not the last key)

self.true(slab.dirty)

Expand All @@ -151,6 +153,7 @@ async def test_lmdbslab_base(self):
self.false(slab.prefexists(b'\x02', db=baz))
self.true(slab.prefexists(b'\xff\xff', db=baz))
self.false(slab.prefexists(b'\xff\xff', db=foo))
self.false(slab.prefexists(b'\xaa\xff', db=baz))

self.true(slab.rangeexists(b'\x00', b'\x01', db=baz))
self.true(slab.rangeexists(b'\x00\x00', b'\x00\x04', db=baz))
Expand Down