Beispiel #1
0
        public string WriteMulti(Dictionary <ulong, ClockValues> values)
        {
            WriteWalEntry entry = new WriteWalEntry()
            {
                Values = values
            };
            var err = writeToLog(entry);

            if (err != null)
            {
                Interlocked.Increment(ref stats.WriteErr);
            }
            else
            {
                Interlocked.Increment(ref stats.WriteOK);
            }
            return(err);
        }
Beispiel #2
0
        public bool Next()
        {
            int nReadOK = 0;

            // read the type and the length of the entry
            byte[] lv = new byte[5];
            try
            {
                nReadOK += stream.Read(lv, 0, 5);
                if (nReadOK == 0)
                {
                    return(false);
                }
            }
            catch (EndOfStreamException ex)
            {
                err = ex.Message;
                return(false);
            }
            catch (Exception ex)
            {
                err = ex.Message;
                // We return true here because we want the client code to call read which
                // will return the this error to be handled.
                return(true);
            }
            byte entryType = lv[0];
            int  length    = BitConverter.ToInt32(lv, 1);

            byte[] b = ArrayPool <byte> .Shared.Rent(length);;//? b := *(getBuf(int(length)))
            try
            {
                nReadOK += stream.Read(b, 0, length);
            }
            catch (Exception ex)
            {
                err = ex.Message;
                return(true);
            }
            IWalEntry newentry = null;

            switch (entryType)
            {
            case Constants.WriteWALEntryType:
                newentry = new WriteWalEntry();
                break;

            case Constants.DeleteWALEntryType:
                newentry = new DeleteWalEntry();
                break;

            case Constants.DeleteRangeWALEntryType:
                newentry = new DeleteRangeWalEntry();
                break;

            default:
                err = string.Format("unknown wal entry type: {0}", entryType);
                return(true);
            }
            byte[] data = SnappyPI.SnappyCodec.Uncompress(b, 0, length);
            ArrayPool <byte> .Shared.Return(b);

            err = newentry.UnmarshalBinary(data, 0, data.Length);
            if (err == null)
            {
                // Read and decode of this entry was successful.
                n += nReadOK;
            }
            entry = newentry;
            return(true);
        }