public void UpdateBlock(BlockInfo block) { if (block != null) { try { Trace.TraceInformation("Received update for block {0}", block); AzureBlockStore.Instance.ReceiveBlock(block); } catch (Exception ex) { Trace.TraceError("Error receiving block {0}. Cause: {1}", block, ex); // TODO: Should we drop some/all cached blocks for the same store to force a re-read from blobstore? /* AzureBlockStore.Instance.DropBlock(block.StoreName, block.Offset); if (block.Offset > AzureBlockStore.Instance.BlockSize) { AzureBlockStore.Instance.DropBlock(block.StoreName, block.Offset - AzureBlockStore.Instance.BlockSize); } */ // Rethrow the exception as a service fault so that the sender knows this receiver has a problem. throw; } } }
public void Insert(BlockInfo block) { block.LastAccess = DateTime.UtcNow.Ticks; _cache[MakeKey(block)] = block; //Trace.WriteLine(String.Format("BlockStoreCache: Insert {0} with key {1}", block, MakeKey(block))); if (_cache.Count > _maxBlockCount && !_evictionStarted) { Task.Factory.StartNew(EvictOldBlocks); } if (block.Length == AzureBlockStore.AzureBlockSize) { WriteToDiskCache(block); } }
private static string MakeKey(BlockInfo block) { return MakeKey(block.StoreName, block.Offset); }
private void WriteToDiskCache(BlockInfo block) { // Start a background thread to write the block to the disk Task.Factory.StartNew( () => { try { _diskCache.PutData(MakeKey(block), block.Data); } catch (Exception e) { Trace.TraceWarning("Error writing block to disk cache: {0}", e); } }); }
private static string MakeCacheFileName(BlockInfo block) { return MakeCacheFileName(MakeKey(block)); }