Exemplo n.º 1
0
        /// <summary>
        /// Commits the provided transaction
        /// </summary>
        public void CommitTransaction(ref TransactionToken token)
        {
            AssertionFailedException.Assert(token.State == StateOpen);
            token.State = StateCommitted;

            MemoryStream buffer = token.Object as MemoryStream;

            if (buffer == null)
            {
                return; // nothing to commit
            }
            byte[] bytes = buffer.GetBuffer();
            Crc32  crc   = new Crc32();

            crc.Add(bytes, 4, (int)buffer.Position - 4);
            PrimitiveSerializer.Int32.WriteTo(crc.Value, buffer);

            int len = (int)buffer.Position;

            PrimitiveSerializer.Int32.WriteTo((0xee << 24) + len, buffer);
            buffer.Position = 0;
            PrimitiveSerializer.Int32.WriteTo((0xbb << 24) + len, buffer);
            bytes = buffer.GetBuffer();

            WriteBytes(bytes, 0, len + 4);
        }
Exemplo n.º 2
0
        private void Write(ref TransactionToken token, OperationCode operation, TKey key, TValue value)
        {
            AssertionFailedException.Assert(token.State == StateOpen);
            MemoryStream buffer = token.Object as MemoryStream;

            if (buffer == null)
            {
                token.Object = buffer = new MemoryStream();
                PrimitiveSerializer.Int32.WriteTo(0, buffer);
                PrimitiveSerializer.Int32.WriteTo(unchecked ((int)token.Handle), buffer);
                PrimitiveSerializer.Int16.WriteTo(0, buffer);
            }

            PrimitiveSerializer.Int16.WriteTo((short)operation, buffer);
            _options.KeySerializer.WriteTo(key, buffer);
            if (operation != OperationCode.Remove)
            {
                _options.ValueSerializer.WriteTo(value, buffer);
            }

            //Increment the operation counter at offset 8
            long pos = buffer.Position;

            buffer.Position = 8;
            short count = PrimitiveSerializer.Int16.ReadFrom(buffer);

            buffer.Position = 8;
            PrimitiveSerializer.Int16.WriteTo(++count, buffer);

            buffer.Position = pos;
        }
Exemplo n.º 3
0
 public void RemoveValue(TKey key)
 {
     if (_cache.Options.LogFile != null)
     {
         if (!_hasLogToken)
         {
             _logToken = _cache.Options.LogFile.BeginTransaction();
         }
         _hasLogToken = true;
         _cache.Options.LogFile.RemoveValue(ref _logToken, key);
     }
 }
Exemplo n.º 4
0
 public void UpdateValue(TKey key, TValue value)
 {
     if (_cache.Options.LogFile != null)
     {
         if (!_hasLogToken)
         {
             _logToken = _cache.Options.LogFile.BeginTransaction();
         }
         _hasLogToken = true;
         _cache.Options.LogFile.UpdateValue(ref _logToken, key, value);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Abandons the provided transaction
        /// </summary>
        public void RollbackTransaction(ref TransactionToken token)
        {
            if (token.State == StateRolledback)
            {
                return;
            }

            AssertionFailedException.Assert(token.State == StateOpen);
            token.State = StateRolledback;
            MemoryStream buffer = token.Object as MemoryStream;

            if (buffer != null)
            {
                buffer.Dispose();
            }
            token.Object = null;
            token.Handle = 0;
        }
Exemplo n.º 6
0
 /// <summary> The provided key/value pair was removed in the provided transaction </summary>
 public void RemoveValue(ref TransactionToken token, TKey key)
 {
     Write(ref token, OperationCode.Remove, key, default(TValue));
 }
Exemplo n.º 7
0
 /// <summary> The provided key/value pair was updated in the provided transaction </summary>
 public void UpdateValue(ref TransactionToken token, TKey key, TValue value)
 {
     Write(ref token, OperationCode.Update, key, value);
 }
Exemplo n.º 8
0
 /// <summary> The provided key/value pair was added in the provided transaction </summary>
 public void AddValue(ref TransactionToken token, TKey key, TValue value)
 {
     Write(ref token, OperationCode.Add, key, value);
 }
Exemplo n.º 9
0
 public NodeTransaction(NodeCacheBase cache)
 {
     _cache       = cache;
     _hasLogToken = false;
     _logToken    = new TransactionToken();
 }