Exemplo n.º 1
0
 private void SetupRegistry(StorageAddress address)
 {
     if (!_intraBlockCache.ContainsKey(address))
     {
         _intraBlockCache[address] = new Stack <int>();
     }
 }
Exemplo n.º 2
0
 private void SetupCache(StorageAddress address)
 {
     if (!_cache.ContainsKey(address))
     {
         _cache[address] = new Stack <int>();
     }
 }
Exemplo n.º 3
0
 private void PushUpdate(StorageAddress address, byte[] value)
 {
     SetupRegistry(address);
     IncrementPosition();
     _intraBlockCache[address].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.Update, address, value);
 }
Exemplo n.º 4
0
 private void PushJustCache(StorageAddress address, byte[] value)
 {
     SetupCache(address);
     IncrementPosition();
     _cache[address].Push(_currentPosition);
     _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value);
 }
Exemplo n.º 5
0
 private void PushToRegistryOnly(StorageAddress address, byte[] value)
 {
     SetupRegistry(address);
     IncrementPosition();
     _intraBlockCache[address].Push(_currentPosition);
     _originalValues[address]   = value;
     _changes[_currentPosition] = new Change(ChangeType.JustCache, address, value);
 }
Exemplo n.º 6
0
        public byte[] GetOriginal(StorageAddress storageAddress)
        {
            if (!_originalValues.ContainsKey(storageAddress))
            {
                throw new InvalidOperationException("Get original should only be called after get within the same caching round");
            }

            return(_originalValues[storageAddress]);
        }
Exemplo n.º 7
0
        private byte[] LoadFromTree(StorageAddress storageAddress)
        {
            StorageTree tree = GetOrCreateStorage(storageAddress.Address);

            Metrics.StorageTreeReads++;
            byte[] value = tree.Get(storageAddress.Index);
            PushToRegistryOnly(storageAddress, value);
            return(value);
        }
Exemplo n.º 8
0
        private byte[] GetThroughCache(StorageAddress storageAddress)
        {
            if (_cache.ContainsKey(storageAddress))
            {
                return(_changes[_cache[storageAddress].Peek()].Value);
            }

            return(GetAndAddToCache(storageAddress));
        }
Exemplo n.º 9
0
        private byte[] GetAndAddToCache(StorageAddress storageAddress)
        {
            //byte[] cached = _storageCache.Get(storageAddress);
            //if (cached != null)
            //{
            //    return cached;
            //}

            StorageTree tree = GetOrCreateStorage(storageAddress.Address);

            Metrics.StorageTreeReads++;
            byte[] value = tree.Get(storageAddress.Index);
            PushJustCache(storageAddress, value);
            //_storageCache.Set(storageAddress, value);
            return(value);
        }
Exemplo n.º 10
0
//        private Dictionary<Address, (int ChangeIndex, StorageTree Storage)> _destructedStorages = new Dictionary<Address, (int, StorageTree)>();

        private byte[] GetCurrentValue(StorageAddress storageAddress)
        {
            if (_intraBlockCache.ContainsKey(storageAddress))
            {
                int lastChangeIndex = _intraBlockCache[storageAddress].Peek();
//                if (_destructedStorages.ContainsKey(storageAddress.Address))
//                {
//                    if (lastChangeIndex < _destructedStorages[storageAddress.Address].ChangeIndex)
//                    {
//                        return new byte[] {0};
//                    }
//                }

                return(_changes[lastChangeIndex].Value);
            }

            return(LoadFromTree(storageAddress));
        }
Exemplo n.º 11
0
 public void Set(StorageAddress storageAddress, byte[] newValue)
 {
     PushUpdate(storageAddress, newValue);
 }
Exemplo n.º 12
0
 public byte[] Get(StorageAddress storageAddress)
 {
     return(GetCurrentValue(storageAddress));
 }
Exemplo n.º 13
0
 public Change(ChangeType changeType, StorageAddress storageAddress, byte[] value)
 {
     StorageAddress = storageAddress;
     Value          = value;
     ChangeType     = changeType;
 }
Exemplo n.º 14
0
 public byte[] Get(StorageAddress storageAddress)
 {
     return(GetThroughCache(storageAddress));
 }