Пример #1
0
        public static void ResetReadOnlyFileToNull(BlockBlobMetaInfo blobInfo)
        {
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo);

            devStoreBlockBlobFileParameter.AccessReadWriteLock.EnterReadLock();
            try
            {
                try
                {
                    File.Delete(devStoreBlockBlobFileParameter.ReadOnlyFile);
                    devStoreBlockBlobFileParameter.ReadOnlyFile = null;
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: ResetReadOnlyFileToNull Exception {0}", new object[] { exception.StackTrace });

                    throw;
                }
            }
            finally
            {
                devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitReadLock();
            }
        }
Пример #2
0
 private static void RemoveWorkFromProcessingDictionary(BlockBlobMetaInfo info)
 {
     lock (BlockBlobGarbageCollector.defragLock)
     {
         string key = info.GetKey();
         BlockBlobGarbageCollector.toDefragmentDict.Remove(key);
     }
 }
Пример #3
0
        public static void GetDataFiles(BlockBlobMetaInfo blobInfo, out string readOnlyFile, out string readWriteFile)
        {
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo);

            devStoreBlockBlobFileParameter.AccessReadWriteLock.EnterReadLock();
            readWriteFile = devStoreBlockBlobFileParameter.ReadWriteFile;
            readOnlyFile  = devStoreBlockBlobFileParameter.ReadOnlyFile;
            devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitReadLock();
        }
Пример #4
0
        public static string MakeBlobDataCopy(BlockBlobMetaInfo blobInfo)
        {
            string str;
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo);

            try
            {
                try
                {
                    devStoreBlockBlobFileParameter.AccessReadWriteLock.EnterWriteLock();
                    string   str1  = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced();
                    string[] files = Directory.GetFiles(devStoreBlockBlobFileParameter.DirectoryName);
                    string   str2  = null;
                    IStringDataEventStream infoDebug = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                    object[] directoryName           = new object[] { devStoreBlockBlobFileParameter.DirectoryName, str1 };
                    infoDebug.Log("BlockBlob: MakeBlobDataCopy SrcDir {0} -> DestDir {1}", directoryName);
                    if (files != null && (int)files.Length > 0)
                    {
                        string[] strArrays = files;
                        for (int i = 0; i < (int)strArrays.Length; i++)
                        {
                            string str3 = strArrays[i];
                            string str4 = Path.Combine(str1, Path.GetFileName(str3));
                            if (string.Compare(str3, devStoreBlockBlobFileParameter.ReadWriteFile, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                str2 = str4;
                            }
                            else
                            {
                                Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: MakeBlobDataCopy SrcFile {0} -> DestFile {1}", new object[] { str3, str4 });

                                File.Copy(str3, str4);
                            }
                        }
                        IStringDataEventStream stringDataEventStream = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                        object[] readWriteFile = new object[] { devStoreBlockBlobFileParameter.ReadWriteFile, str2 };
                        stringDataEventStream.Log("BlockBlob: MakeBlobDataCopy RW FILE SrcFile {0} -> DestFile {1}", readWriteFile);
                        File.Copy(devStoreBlockBlobFileParameter.ReadWriteFile, str2);
                    }
                    str = str1;
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: MakeBlobDataCopy failed. Exception:{0}", new object[] { exception.StackTrace });

                    throw;
                }
            }
            finally
            {
                devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitWriteLock();
            }
            return(str);
        }
Пример #5
0
        private static DevStoreBlockBlobFileParameters AddInfoIfNotExists(BlockBlobMetaInfo blobInfo)
        {
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter;
            string key = blobInfo.GetKey();

            if (!BlockBlobDataManager.blobInfoMap.TryGetValue(key, out devStoreBlockBlobFileParameter))
            {
                lock (BlockBlobDataManager.blobInfoMap)
                {
                    if (!BlockBlobDataManager.blobInfoMap.TryGetValue(key, out devStoreBlockBlobFileParameter))
                    {
                        devStoreBlockBlobFileParameter = new DevStoreBlockBlobFileParameters();
                        BlockBlobDataManager.InitializeBlockBlobFileAttributes(blobInfo.BlobDirectory, devStoreBlockBlobFileParameter);
                        BlockBlobDataManager.blobInfoMap.Add(key, devStoreBlockBlobFileParameter);
                    }
                }
            }
            return(devStoreBlockBlobFileParameter);
        }
Пример #6
0
        public static bool SealCurrentWriteFile(BlockBlobMetaInfo blobInfo, int timeoutInMillis)
        {
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo);
            bool flag = false;

            if (devStoreBlockBlobFileParameter.AccessReadWriteLock.TryEnterWriteLock(timeoutInMillis))
            {
                try
                {
                    BlockBlobDataManager.InitializeNewReadWriteFile(devStoreBlockBlobFileParameter);
                    flag = true;
                }
                finally
                {
                    devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitWriteLock();
                }
            }
            return(flag);
        }
Пример #7
0
        public static string WriteBytesToFile(BlockBlobMetaInfo blobInfo, byte[] content, out long startIndex)
        {
            string str;
            DevStoreBlockBlobFileParameters devStoreBlockBlobFileParameter = BlockBlobDataManager.AddInfoIfNotExists(blobInfo);
            IStringDataEventStream          infoDebug = Logger <INormalAndDebugLogger> .Instance.InfoDebug;

            object[] blobDirectory = new object[] { blobInfo.BlobDirectory, content.LongLength, blobInfo.ContainerName, blobInfo.BlobName };
            infoDebug.Log("BlockBlob: WriteBytesToFile! Directory {0}, contentLen {1} ,containerName {2}, blobName {3}", blobDirectory);
            try
            {
                try
                {
                    devStoreBlockBlobFileParameter.AccessReadWriteLock.EnterReadLock();
                    string readWriteFile = devStoreBlockBlobFileParameter.ReadWriteFile;
                    long   num           = Interlocked.Add(ref devStoreBlockBlobFileParameter.LastAllottedChunkEnd, content.LongLength);
                    startIndex = num - content.LongLength;
                    IStringDataEventStream stringDataEventStream = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                    object[] objArray = new object[] { startIndex, num };
                    stringDataEventStream.Log("BlockBlob: WriteBytesToFile oldIndex {0} , newIndex {1}", objArray);
                    using (FileStream fileStream = new FileStream(readWriteFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                    {
                        fileStream.Seek(startIndex, SeekOrigin.Begin);
                        fileStream.Write(content, 0, (int)content.Length);
                    }
                    str = readWriteFile;
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: WriteBytesToFile Exception: {0}", new object[] { exception.StackTrace });

                    throw;
                }
            }
            finally
            {
                devStoreBlockBlobFileParameter.AccessReadWriteLock.ExitReadLock();
            }
            return(str);
        }
Пример #8
0
        private static void DoDefragmentBlobWork(object info)
        {
            string str;
            bool   flag;
            long   num;
            string str1;

            while (true)
            {
                BlockBlobMetaInfo blockBlobMetaInfo = null;
                lock (BlockBlobGarbageCollector.defragLock)
                {
                    if (BlockBlobGarbageCollector.defragWorkItems.Count == 0)
                    {
                        Monitor.Wait(BlockBlobGarbageCollector.defragLock);
                    }
                    blockBlobMetaInfo = BlockBlobGarbageCollector.defragWorkItems.Dequeue();
                }
                IStringDataEventStream infoDebug = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                object[] objArray = new object[] { blockBlobMetaInfo.ToString() };
                infoDebug.Log("BlockBlob: DoDefragmentBlobWork WorkItem! {0}", objArray);
                try
                {
                    BlockBlobDataManager.GetDataFiles(blockBlobMetaInfo, out str1, out str);
                    Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: DoDefragmentBlobWork readOnlyFile {0}, readWriteFile {1}", new object[] { str1, str });

                    if (string.IsNullOrEmpty(str1))
                    {
                        BlockBlobDataManager.SealCurrentWriteFile(blockBlobMetaInfo, -1);
                    }
                    BlockBlobDataManager.GetDataFiles(blockBlobMetaInfo, out str1, out str);
                    Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: DoDefragmentBlobWork NEW readOnlyFile {0}, readWriteFile {1}", new object[] { str1, str });
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: DoDefragmentBlobWork Exception {0}", new object[] { exception.StackTrace });

                    BlockBlobGarbageCollector.RemoveWorkFromProcessingDictionary(blockBlobMetaInfo);
                    continue;
                }
                int num1 = 0;
                do
                {
Label0:
                    if (num1 >= 5)
                    {
                        break;
                    }
                    flag = true;
                    int maxItemsToSync = BlockBlobGarbageCollector.GetMaxItemsToSync();
                    try
                    {
                        using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                        {
                            IQueryable <BlockData> blockDatas = (
                                from b in dbContext.BlocksData
                                where (b.ContainerName == blockBlobMetaInfo.ContainerName) && (b.BlobName == blockBlobMetaInfo.BlobName) && (b.FilePath == str1)
                                select b).Take <BlockData>(maxItemsToSync);
                            foreach (BlockData nullable in blockDatas)
                            {
                                flag = false;
                                byte[] numArray = null;
                                using (FileStream fileStream = new FileStream(str1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                {
                                    fileStream.Seek(nullable.StartOffset.Value, SeekOrigin.Begin);
                                    numArray = new byte[checked ((IntPtr)nullable.Length.Value)];
                                    fileStream.Read(numArray, 0, (int)numArray.Length);
                                }
                                string file = BlockBlobDataManager.WriteBytesToFile(blockBlobMetaInfo, numArray, out num);
                                nullable.FilePath    = file;
                                nullable.StartOffset = new long?(num);
                            }
                            dbContext.SubmitChanges(ConflictMode.ContinueOnConflict);
                        }
                    }
                    catch (Exception exception3)
                    {
                        Exception exception2 = exception3;
                        num1++;
                        IStringDataEventStream error = Logger <INormalAndDebugLogger> .Instance.Error;
                        object[] stackTrace          = new object[] { exception2.StackTrace, num1 };
                        error.Log("BlockBlob: DoDefragmentBlobWork Exception {0}, Attempt {1}", stackTrace);
                        goto Label0;
                    }
                }while (!flag);
                if (num1 < 5)
                {
                    try
                    {
                        BlockBlobDataManager.ResetReadOnlyFileToNull(blockBlobMetaInfo);
                    }
                    catch (Exception exception5)
                    {
                        Exception exception4 = exception5;
                        Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: DoDefragmentBlobWork Exception while setting up rofile to null {0} ", new object[] { exception4.StackTrace });
                    }
                }
                BlockBlobGarbageCollector.RemoveWorkFromProcessingDictionary(blockBlobMetaInfo);
            }
        }