Esempio n. 1
0
    def unpack(cls, stor, val):
        if val['ver'] != 1:
            raise s_exc.BadStorageVersion(mesg=f"Found version {val['ver']}")  # pragma: no cover
        recs = [ApptRec.unpack(tupl) for tupl in val['recs']]
        appt = cls(stor, val['iden'], val['recur'], val['indx'], val['query'], val['creator'], recs, nexttime=val['nexttime'], view=val.get('view'))
        appt.doc = val.get('doc', '')
        appt.name = val.get('name', '')
        appt.laststarttime = val['laststarttime']
        appt.lastfinishtime = val['lastfinishtime']
        appt.lastresult = val['lastresult']
        appt.enabled = val['enabled']

        return appt
Esempio n. 2
0
    def unpack(cls, val):
        if val['ver'] != 1:
            raise s_exc.BadStorageVersion(
                mesg=f"Found version {val['ver']}")  # pragma: no cover
        recs = [ApptRec.unpack(tupl) for tupl in val['recs']]
        appt = cls(val['iden'], val['recur'], val['indx'], val['query'],
                   val['useriden'], recs, val['nexttime'])
        appt.startcount = val['startcount']
        appt.laststarttime = val['laststarttime']
        appt.lastfinishtime = val['lastfinishtime']
        appt.lastresult = val['lastresult']
        appt.enabled = val['enabled']

        return appt
Esempio n. 3
0
    async def __anit__(self,
                       dirn: str,
                       donexslog: bool = True,
                       map_async=False):

        await s_base.Base.__anit__(self)

        # avoid import cycle
        import synapse.lib.lmdbslab as s_lmdbslab
        import synapse.lib.multislabseqn as s_multislabseqn

        self.dirn = dirn
        self.client = None
        self.started = False
        self.celliden = None
        self.donexslog = donexslog
        self.applylock = asyncio.Lock()

        self._mirrors: List[ChangeDist] = []
        self._nexskids: Dict[str, 'Pusher'] = {}

        # Used to match pending follower write requests with the responses arriving on the log
        self._futures: Dict[str, asyncio.Future] = {}

        path = s_common.genpath(self.dirn, 'slabs', 'nexus.lmdb')
        fresh = not os.path.exists(path)

        logpath = s_common.genpath(self.dirn, 'slabs', 'nexuslog')

        self.map_async = map_async
        self.nexsslab = await s_lmdbslab.Slab.anit(path, map_async=map_async)
        self.nexshot = await self.nexsslab.getHotCount('nexs:indx')

        if fresh:
            self.nexshot.set('version', 2)

        vers = self.nexshot.get('version')

        if vers <= 1:
            await self._migrateV1toV2(path, logpath)
        elif vers != 2:
            raise s_exc.BadStorageVersion(
                mesg=
                f'Got nexus log version {vers}.  Expected 2.  Accidental downgrade?'
            )

        slabopts = {'map_async': map_async}
        self.nexslog = await s_multislabseqn.MultiSlabSeqn.anit(
            logpath, slabopts=slabopts)

        # just in case were previously configured differently
        logindx = self.nexslog.index()
        hotindx = self.nexshot.get('nexs:indx')
        maxindx = max(logindx, hotindx)

        self.nexshot.set('nexs:indx', maxindx)
        self.nexslog.setIndex(maxindx)

        async def fini():

            for futu in self._futures.values():  # pragma: no cover
                futu.cancel()

            await self.nexsslab.fini()
            await self.nexslog.fini()

        self.onfini(fini)