def getSetOps(self, buid, norm): indx = self.type.indx(norm) if len(indx) > 256: raise s_exc.BadIndxValu(name=self.name, norm=norm, indx=indx) return (('prop:set', (buid, self.name, '', norm, indx, {})), )
def _storPropSet(self, oper): _, (buid, form, prop, valu, indx, info) = oper if indx is not None and len(indx) > MAX_INDEX_LEN: mesg = 'index bytes are too large' raise s_exc.BadIndxValu(mesg=mesg, prop=prop, valu=valu) fenc = form.encode() + b'\x00' penc = prop.encode() + b'\x00' pvpref = fenc + penc univ = info.get('univ') # special case for setting primary property if not prop: assert not univ prop = '*' + form bpkey = buid + prop.encode() cacheval = self.buidcache.get(buid) if cacheval is not None: cacheval[prop] = valu self._storPropSetCommon(buid, penc, bpkey, pvpref, univ, valu, indx)
async def get(self, offs: int) -> Any: ''' Retrieve a single row by offset ''' ridx = self._getRangeIndx(offs) if ridx is None: raise s_exc.BadIndxValu( mesg=f'offs lower than first index {self.firstindx}') async with self._getSeqn(ridx) as seqn: return seqn.get(offs)
async def storPropSet(self, buid, prop, valu): ''' Migration-only function ''' assert self.buidcache.disabled indx = prop.type.indx(valu) if indx is not None and len(indx) > MAX_INDEX_LEN: mesg = 'index bytes are too large' raise s_exc.BadIndxValu(mesg=mesg, prop=prop, valu=valu) univ = prop.utf8name[0] in (46, 35) # leading . or # bpkey = buid + prop.utf8name self._storPropSetCommon(buid, prop.utf8name, bpkey, prop.pref, univ, valu, indx)
async def _storPropSet(self, oper): _, (buid, form, prop, valu, indx, info) = oper if len(indx) > MAX_INDEX_LEN: mesg = 'index bytes are too large' raise s_exc.BadIndxValu(mesg=mesg, prop=prop, valu=valu) fenc = self.encoder[form] penc = self.encoder[prop] univ = info.get('univ') # special case for setting primary property if not prop: prop = '*' + form bpkey = buid + self.utf8[prop] # FIXME: might need to update any cortex buid cache bpval = s_msgpack.en((valu, indx)) pvpref = fenc + penc pvvalu = s_msgpack.en((buid, )) byts = self.layrslab.replace(bpkey, bpval, db=self.bybuid) if byts is not None: oldv, oldi = s_msgpack.un(byts) self.layrslab.delete(pvpref + oldi, pvvalu, db=self.byprop) if univ: unkey = penc + oldi self.layrslab.delete(unkey, pvvalu, db=self.byuniv) self.layrslab.put(pvpref + indx, pvvalu, dupdata=True, db=self.byprop) if univ: self.layrslab.put(penc + indx, pvvalu, dupdata=True, db=self.byuniv)
async def add(self, item: Any, indx=None) -> int: ''' Add a single item to the sequence. ''' advances = True if indx is not None: if indx < self.firstindx: raise s_exc.BadIndxValu( mesg= f'indx lower than first index in sequence {self.firstindx}' ) if indx < self._ranges[-1]: ridx = self._getRangeIndx(indx) assert ridx is not None async with self._getSeqn(ridx) as seqn: seqn.add(item, indx=indx) return indx if indx >= self.indx: self.indx = indx else: advances = False else: indx = self.indx assert self.tailseqn retn = self.tailseqn.add(item, indx=indx) if advances: self.indx += 1 self._wake_waiters() return retn