Example #1
0
        /// Cook a cookie for use
        ///
        /// \param result  ref to memory cell that receives cookie if status is
        ///                success
        ///
        /// \note this call should be a pretty rare because it actually does
        ///       lookup for an entry in database
        Status cook(const Slice &name, Cookie &cookie)
        {
            Status s;
            assert( !name.empty() );

            std::string v;
            s = meta.Get(name, v);
            if (s.ok())
            {
                if (Cookie::corrupted(v))
                { return Status::Corruption("Invalid sandwich mapping entry"); }
                cookie = v;
                return s;
            }
            else if (s.IsNotFound())
            {
                Cookie nextCookie;
                s = seq.Next(nextCookie);
                if (s.ok() && nextCookie == 0) s = seq.Next(nextCookie); // skip meta part
                if (s.ok()) s = meta.Put(name, nextCookie);
                if (s.ok()) cookie = nextCookie;
                return s;
            }
            else
            { return s; }
        }