示例#1
0
        public static string CreateUniqueDirectoryLoadBalanced()
        {
            string str = BlockBlobDataManager.blobDataDirectories[BlockBlobDataManager.CurrentBlobCount / 500 % (int)BlockBlobDataManager.blobDataDirectories.Length];

            Directory.CreateDirectory(str);
            return(BlockBlobDataManager.CreateUniqueDirectory(str));
        }
示例#2
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();
            }
        }
示例#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
        public static void DefragmentBlobFiles(object source, ElapsedEventArgs e)
        {
            string str;
            string str1;

            try
            {
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    IQueryable <BlockBlobMetaInfo> blocksData =
                        from b in dbContext.BlocksData
                        group b by new { AccountName = b.AccountName, BlobName = b.BlobName, ContainerName = b.ContainerName, DirectoryPath = b.BlockBlob.DirectoryPath } into blobBlocks
                                                   select new BlockBlobMetaInfo(blobBlocks.Key.AccountName, blobBlocks.Key.ContainerName, blobBlocks.Key.BlobName, blobBlocks.Key.DirectoryPath)
                    {
                        BlobSize = blobBlocks.Sum <BlockData>((BlockData x) => x.Length.GetValueOrDefault((long)0))
                    };
                    foreach (BlockBlobMetaInfo blocksDatum in blocksData)
                    {
                        BlockBlobDataManager.GetDataFiles(blocksDatum, out str, out str1);
                        IStringDataEventStream infoDebug = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                        object[] blobName = new object[] { blocksDatum.BlobName, blocksDatum.ContainerName, blocksDatum.BlobDirectory, str, str1, blocksDatum.BlobSize };
                        infoDebug.Log("BlockBlob: DefragmentBlobFiles BlobInfo Name {0}, ContainerName {1}, Directory {2}, ROFile {3}, RWFile {4}, Size{5}", blobName);
                        long     length   = (long)0;
                        FileInfo fileInfo = null;
                        if (!string.IsNullOrEmpty(str))
                        {
                            fileInfo = new FileInfo(str);
                        }
                        FileInfo fileInfo1 = null;
                        if (!string.IsNullOrEmpty(str1))
                        {
                            fileInfo1 = new FileInfo(str1);
                        }
                        if (fileInfo1 != null && fileInfo1.Exists)
                        {
                            IStringDataEventStream stringDataEventStream = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                            object[] objArray = new object[] { fileInfo1.Length };
                            stringDataEventStream.Log("BlockBlob: DefragmentBlobFiles RWFileLength {0}", objArray);
                            length += fileInfo1.Length;
                        }
                        if (fileInfo != null && fileInfo.Exists)
                        {
                            IStringDataEventStream infoDebug1 = Logger <INormalAndDebugLogger> .Instance.InfoDebug;
                            object[] length1 = new object[] { fileInfo.Length };
                            infoDebug1.Log("BlockBlob: DefragmentBlobFiles ROFileLength {0}", length1);
                            length += fileInfo.Length;
                        }
                        if ((double)length <= (double)blocksDatum.BlobSize * 2)
                        {
                            continue;
                        }
                        Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: DefragmentBlobFiles FileSize {0}", new object[] { length });

                        string key = blocksDatum.GetKey();
                        lock (BlockBlobGarbageCollector.defragLock)
                        {
                            if (!BlockBlobGarbageCollector.toDefragmentDict.ContainsKey(key))
                            {
                                BlockBlobGarbageCollector.toDefragmentDict.Add(key, blocksDatum);
                                BlockBlobGarbageCollector.defragWorkItems.Enqueue(blocksDatum);
                                Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: DefragmentBlobFiles QueuedWork");

                                Monitor.Pulse(BlockBlobGarbageCollector.defragLock);
                            }
                        }
                    }
                }
                if (BlockBlobGarbageCollector.shouldInitializeWorkers)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(BlockBlobGarbageCollector.DoDefragmentBlobWork));
                    }
                    BlockBlobGarbageCollector.shouldInitializeWorkers = false;
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: DefragmentBlobFiles Exception {0}", new object[] { exception.StackTrace });
            }
            BlockBlobGarbageCollector.defragmentTimer.Interval = BlockBlobGarbageCollector.GetTimerIntervalOrDefault(false);
            BlockBlobGarbageCollector.defragmentTimer.Start();
        }
示例#9
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);
            }
        }
示例#10
0
        public static void DeleteOrphanedFiles(object source, ElapsedEventArgs e)
        {
            try
            {
                try
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        BlockBlobDataManager.CurrentBlobCount = dbContext.Blobs.OfType <BlockBlob>().Count <BlockBlob>();
                        if (dbContext.Blobs.Any <Blob>((Blob blob) => blob is BlockBlob || blob is PageBlob))
                        {
                            DateTime         utcNow   = DateTime.UtcNow;
                            DateTime         dateTime = utcNow.Subtract(TimeSpan.FromMinutes(20));
                            HashSet <string> strs1    = new HashSet <string>((
                                                                                 from topDir in BlockBlobDataManager.BlobDataTopLevelDirectories
                                                                                 where Directory.Exists(topDir)
                                                                                 select topDir).SelectMany <string, string>((string topDir) => {
                                IEnumerable <string> strs;
                                try
                                {
                                    strs =
                                        from dir in Directory.EnumerateDirectories(topDir)
                                        where Directory.GetCreationTimeUtc(dir) < dateTime
                                        select dir;
                                }
                                catch (Exception exception)
                                {
                                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: Listing Directories under {0} failed. Exception: {1}", new object[] { topDir, exception.ToString() });
                                    strs = Enumerable.Empty <string>();
                                }
                                return(strs);
                            }), StringComparer.InvariantCultureIgnoreCase);
                            IQueryable <string> strs2 =
                                from blob in dbContext.Blobs.OfType <BlockBlob>()
                                select blob.DirectoryPath;
                            strs1.ExceptWith(strs2);
                            foreach (string str in strs1)
                            {
                                try
                                {
                                    Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("BlockBlob: Deleting Directory {0}", new object[] { str });

                                    Directory.Delete(str, true);
                                    BlockBlobDataManager.RemoveEntryIfExists(str);
                                }
                                catch (Exception exception2)
                                {
                                    Exception exception1 = exception2;
                                    Logger <INormalAndDebugLogger> .Instance.Error.Log("DeleteOrphanedFiles: Unable to delete directory {0} with Exception {1}", new object[] { str, exception1 });
                                }
                            }
                            HashSet <string> strs3 = new HashSet <string>(
                                from dir in Directory.EnumerateFiles(DevelopmentStorageDbDataContext.PageBlobRoot)
                                where Directory.GetCreationTimeUtc(dir) < dateTime
                                select dir, StringComparer.InvariantCultureIgnoreCase);
                            IQueryable <string> strs4 =
                                from blob in dbContext.Blobs.OfType <PageBlob>()
                                where blob.FileName != null
                                select blob.FileName into fileName
                                select DbPageBlobObject.GetFilePath(fileName);

                            strs3.ExceptWith(strs4);
                            foreach (string str1 in strs3)
                            {
                                try
                                {
                                    string filePath = DbPageBlobObject.GetFilePath(str1);
                                    Logger <INormalAndDebugLogger> .Instance.InfoDebug.Log("PageBlob: Deleting File {0}", new object[] { filePath });

                                    File.Delete(filePath);
                                }
                                catch (Exception exception4)
                                {
                                    Exception exception3 = exception4;
                                    Logger <INormalAndDebugLogger> .Instance.Error.Log("DeleteOrphanedFiles: Unable to delete page blob files with Exception {0}", new object[] { exception3 });
                                }
                            }
                        }
                    }
                }
                catch (Exception exception6)
                {
                    Exception exception5 = exception6;
                    Logger <INormalAndDebugLogger> .Instance.Error.Log("BlockBlob: DeleteOrphanedFiles: Exception {0}", new object[] { exception5 });
                }
            }
            finally
            {
                BlockBlobGarbageCollector.gcTimer.Interval = BlockBlobGarbageCollector.GetTimerIntervalOrDefault(true);
                BlockBlobGarbageCollector.gcTimer.Start();
            }
        }
示例#11
0
        private IEnumerator <IAsyncResult> PutBlockImpl(byte[] blockIdentifier, long contentLength, Stream inputStream, byte[] contentMD5, bool isLargeBlockBlobRequest, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer = null;
            BlockBlob    blockBlob   = null;
            IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                long num;
                long num1;
                StorageStampHelpers.ValidatePutBlockArguments(this, blockIdentifier, contentLength, contentMD5, condition, true);
                string str = null;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    blobContainer = base.LoadContainer(dbContext);
                    blockBlob     = base.TryLoadBlockBlob(dbContext, out str);
                    if (blockBlob == null)
                    {
                        lock (DbListBlobObject.SynchronizePutBlock)
                        {
                            blockBlob = base.TryLoadBlockBlob(dbContext, out str);
                            if (blockBlob == null)
                            {
                                if (string.IsNullOrEmpty(str))
                                {
                                    str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced();
                                }
                                using (DevelopmentStorageDbDataContext developmentStorageDbDataContext = DevelopmentStorageDbDataContext.GetDbContext())
                                {
                                    Logger <INormalAndDebugLogger> .Instance.VerboseDebug.Log("PutBlockImpl: Creating record for ({0};{1};{2})", new object[] { this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName });
                                    StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName);
                                    blockBlob = new BlockBlob()
                                    {
                                        AccountName      = this._blob.AccountName,
                                        ContainerName    = this._blob.ContainerName,
                                        BlobName         = this._blob.BlobName,
                                        VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc),
                                        ContentLength    = (long)0,
                                        IsCommitted      = new bool?(false),
                                        HasBlock         = new bool?(true),
                                        DirectoryPath    = str,
                                        GenerationId     = Guid.NewGuid().ToString(),
                                        SnapshotCount    = 0
                                    };
                                    developmentStorageDbDataContext.Blobs.InsertOnSubmit(blockBlob);
                                    developmentStorageDbDataContext.SubmitChanges();
                                }
                            }
                        }
                    }
                    bool flag = false;
                    BlobLeaseInfo blobLeaseInfo = new BlobLeaseInfo(blockBlob, DateTime.UtcNow);
                    DbBlobObject.CheckCopyState(blockBlob);
                    flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, blobLeaseInfo, condition, null, true);
                    byte[] byteArrayFromStream = DbStorageHelper.GetByteArrayFromStream(inputStream, out num, true, isLargeBlockBlobRequest);
                    string file          = BlockBlobDataManager.WriteBytesToFile(new BlockBlobMetaInfo(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, str), byteArrayFromStream, out num1);
                    string hexString     = DbListBlobObject.ToHexString(blockIdentifier);
                    BlockData blockDatum = this.TryLoadUncommittedBlock(dbContext, hexString);
                    if (blockDatum == null)
                    {
                        blockDatum = new BlockData()
                        {
                            AccountName      = this._blob.AccountName,
                            ContainerName    = this._blob.ContainerName,
                            BlobName         = this._blob.BlobName,
                            VersionTimestamp = this._blob.VersionTimestamp,
                            IsCommitted      = false,
                            BlockId          = hexString
                        };
                        dbContext.BlocksData.InsertOnSubmit(blockDatum);
                    }
                    blockDatum.Length      = new long?(num);
                    blockDatum.FilePath    = file;
                    blockDatum.StartOffset = new long?(num1);
                    base.ResetBlobLeaseToAvailable(blockBlob, flag);
                    dbContext.SubmitChanges();
                    blobLeaseInfo.SetBlob(blockBlob, blobLeaseInfo.LeaseInfoValidAt);
                    this.LeaseInfo = blobLeaseInfo;
                }
            }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlock"));

            yield return(asyncResult);

            this._storageManager.AsyncProcessor.EndExecute(asyncResult);
        }
示例#12
0
        private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, byte[][] blockList, BlockSource[] blockSourceList, byte[] contentMD5, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IStringDataEventStream verboseDebug = Logger <INormalAndDebugLogger> .Instance.VerboseDebug;

            object[] objArray = new object[] { contentType, this.ContentLength, serviceMetadata, applicationMetadata, blockList, overwriteOption, condition, base.Timeout };
            verboseDebug.Log("PutBlobImpl.PutBlobImpl({0};{1};{2};{3};{4};{5};{6};{7})", objArray);
            IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        base.LoadContainer(dbContext);
                        string str          = null;
                        BlockBlob blockBlob = base.TryLoadBlockBlob(dbContext, out str);
                        DateTime utcNow     = DateTime.UtcNow;
                        bool flag           = false;
                        if (blockBlob != null)
                        {
                            DbBlobObject.CheckCopyState(blockBlob);
                            flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, new BlobLeaseInfo(blockBlob, utcNow), condition, null, true);
                            if (blockBlob.IsCommitted.Value)
                            {
                                if (overwriteOption == OverwriteOption.CreateNewOnly)
                                {
                                    throw new BlobAlreadyExistsException();
                                }
                            }
                            else if (overwriteOption == OverwriteOption.UpdateExistingOnly && condition != null && !condition.IsIncludingUncommittedBlobs)
                            {
                                throw new ConditionNotMetException();
                            }
                        }
                        else
                        {
                            if (overwriteOption == OverwriteOption.UpdateExistingOnly)
                            {
                                if (condition == null || !condition.LeaseId.HasValue)
                                {
                                    throw new ConditionNotMetException();
                                }
                                throw new LeaseNotPresentException();
                            }
                            StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName);
                            if (string.IsNullOrEmpty(str))
                            {
                                str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced();
                            }
                            blockBlob = new BlockBlob()
                            {
                                AccountName      = this._blob.AccountName,
                                ContainerName    = this._blob.ContainerName,
                                BlobName         = this._blob.BlobName,
                                VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc),
                                IsCommitted      = new bool?(false),
                                DirectoryPath    = str
                            };
                            dbContext.Blobs.InsertOnSubmit(blockBlob);
                        }
                        StorageStampHelpers.ValidatePutBlockListArguments(this, contentLength, applicationMetadata, blockList, blockSourceList, contentMD5, condition, this._blobServiceVersion);
                        blockBlob.ContentType     = contentType ?? "application/octet-stream";
                        blockBlob.ContentMD5      = contentMD5;
                        blockBlob.ServiceMetadata = serviceMetadata;
                        blockBlob.Metadata        = applicationMetadata;
                        blockBlob.HasBlock        = new bool?(true);
                        blockBlob.GenerationId    = Guid.NewGuid().ToString();
                        blockBlob.SnapshotCount   = 0;
                        base.ResetBlobLeaseToAvailable(blockBlob, flag);
                        dbContext.SubmitChanges();
                        DateTime?nullable           = null;
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < (int)blockList.Length; i++)
                        {
                            DbListBlobObject.SerializeCommitBlockListEntry(stringBuilder, blockList[i], (blockSourceList != null ? blockSourceList[i] : BlockSource.Uncommitted));
                        }
                        dbContext.CommitBlockList(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, stringBuilder.ToString(), ref nullable);
                        transactionScope.Complete();
                        blockBlob.LastModificationTime = nullable;
                        this._blob     = blockBlob;
                        this.LeaseInfo = new BlobLeaseInfo(blockBlob, utcNow);
                    }
                }
            }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlob"));

            yield return(asyncResult);

            this._storageManager.AsyncProcessor.EndExecute(asyncResult);
        }
示例#13
0
        private IEnumerator <IAsyncResult> PutBlobImpl(string contentType, long contentLength, byte[] serviceMetadata, byte[] applicationMetadata, Stream inputStream, byte[] contentMD5, bool invokeGeneratePutBlobServiceMetadata, GeneratePutBlobServiceMetadata generatePutBlobServiceMetadata, bool isLargeBlockBlobRequest, ISequenceNumberUpdate sequenceNumberUpdate, OverwriteOption overwriteOption, IBlobObjectCondition condition, AsyncIteratorContext <NoResults> context)
        {
            IAsyncResult asyncResult = this._storageManager.AsyncProcessor.BeginExecute((TimeSpan param0) => {
                long num;
                long num1;
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        base.LoadContainer(dbContext);
                        string str          = null;
                        BlockBlob blockBlob = base.TryLoadBlockBlob(dbContext, out str);
                        DateTime utcNow     = DateTime.UtcNow;
                        bool flag           = false;
                        if (blockBlob != null)
                        {
                            if (blockBlob.IsCommitted.Value && overwriteOption == OverwriteOption.CreateNewOnly)
                            {
                                throw new BlobAlreadyExistsException();
                            }
                            DbBlobObject.CheckCopyState(blockBlob);
                            flag = DbBlobObject.CheckConditionsAndReturnResetRequired(blockBlob, new BlobLeaseInfo(blockBlob, utcNow), condition, null, true);
                            dbContext.ClearUncommittedBlocks(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName);
                            dbContext.Refresh(RefreshMode.KeepChanges, blockBlob);
                        }
                        else
                        {
                            if (overwriteOption == OverwriteOption.UpdateExistingOnly)
                            {
                                if (condition == null || !condition.LeaseId.HasValue)
                                {
                                    throw new ConditionNotMetException();
                                }
                                throw new LeaseNotPresentException();
                            }
                            StorageStampHelpers.CheckBlobName(this._blob.BlobName, this._blob.ContainerName);
                            if (string.IsNullOrEmpty(str))
                            {
                                str = BlockBlobDataManager.CreateUniqueDirectoryLoadBalanced();
                            }
                            blockBlob = new BlockBlob()
                            {
                                AccountName      = this._blob.AccountName,
                                ContainerName    = this._blob.ContainerName,
                                BlobName         = this._blob.BlobName,
                                VersionTimestamp = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc),
                                DirectoryPath    = str
                            };
                            dbContext.Blobs.InsertOnSubmit(blockBlob);
                        }
                        StorageStampHelpers.ValidatePutBlobArguments(this, contentLength, null, applicationMetadata, contentMD5, sequenceNumberUpdate, overwriteOption, condition, true, false);
                        byte[] byteArrayFromStream = DbStorageHelper.GetByteArrayFromStream(inputStream, out num, false, isLargeBlockBlobRequest);
                        string file          = BlockBlobDataManager.WriteBytesToFile(new BlockBlobMetaInfo(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, str), byteArrayFromStream, out num1);
                        Guid guid            = Guid.NewGuid();
                        BlockData blockDatum = new BlockData()
                        {
                            AccountName      = this._blob.AccountName,
                            ContainerName    = this._blob.ContainerName,
                            BlobName         = this._blob.BlobName,
                            VersionTimestamp = this._blob.VersionTimestamp,
                            IsCommitted      = false,
                            BlockId          = DbListBlobObject.ToHexString(guid.ToByteArray()),
                            FilePath         = file,
                            StartOffset      = new long?(num1)
                        };
                        dbContext.BlocksData.InsertOnSubmit(blockDatum);
                        if (invokeGeneratePutBlobServiceMetadata && generatePutBlobServiceMetadata != null)
                        {
                            serviceMetadata = generatePutBlobServiceMetadata();
                        }
                        blockBlob.ContentType              = contentType ?? "application/octet-stream";
                        blockBlob.ContentMD5               = contentMD5;
                        blockBlob.ServiceMetadata          = serviceMetadata;
                        blockBlob.Metadata                 = applicationMetadata;
                        blockBlob.IsCommitted              = new bool?(false);
                        blockBlob.HasBlock                 = new bool?(false);
                        blockBlob.UncommittedBlockIdLength = null;
                        blockBlob.GenerationId             = Guid.NewGuid().ToString();
                        blockBlob.SnapshotCount            = 0;
                        blockDatum.Length       = new long?(num);
                        blockBlob.ContentLength = num;
                        base.ResetBlobLeaseToAvailable(blockBlob, flag);
                        dbContext.SubmitChanges();
                        StringBuilder stringBuilder = new StringBuilder();
                        DbListBlobObject.SerializeCommitBlockListEntry(stringBuilder, guid.ToByteArray(), BlockSource.Uncommitted);
                        DateTime?nullable = null;
                        dbContext.CommitBlockList(this._blob.AccountName, this._blob.ContainerName, this._blob.BlobName, stringBuilder.ToString(), ref nullable);
                        transactionScope.Complete();
                        blockBlob.LastModificationTime = nullable;
                        this._blob     = blockBlob;
                        this.LeaseInfo = new BlobLeaseInfo(blockBlob, utcNow);
                    }
                }
            }, base.Timeout, context.GetResumeCallback(), context.GetResumeState("DbListBlobObject.PutBlobImpl"));

            yield return(asyncResult);

            this._storageManager.AsyncProcessor.EndExecute(asyncResult);
        }
示例#14
0
        public bool PutBlock(string blockId, byte[] data)
        {
            bool     flag;
            bool     flag1    = false;
            DateTime?nullable = this._lastModifiedTime;
            bool     flag2    = false;
            long     num      = (long)0;
            string   file     = null;

            this._currentLength += data.LongLength;
            this._blockIds.Add(blockId);
            try
            {
                for (int i = 0; i < this._maxNumberOfRetries; i++)
                {
                    this._lastModifiedTime = nullable;
                    try
                    {
                        using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                            {
                                this.GetContainer(dbContext);
                                BlockBlob blob = this.GetBlob(dbContext, true) as BlockBlob;
                                if (!flag2)
                                {
                                    file  = BlockBlobDataManager.WriteBytesToFile(new BlockBlobMetaInfo(blob.AccountName, blob.ContainerName, blob.BlobName, blob.DirectoryPath), data, out num);
                                    flag2 = true;
                                }
                                BlockData blockDatum = new BlockData()
                                {
                                    AccountName      = blob.AccountName,
                                    ContainerName    = blob.ContainerName,
                                    BlobName         = blob.BlobName,
                                    VersionTimestamp = blob.VersionTimestamp,
                                    IsCommitted      = false,
                                    BlockId          = blockId,
                                    Length           = new long?(data.LongLength),
                                    FilePath         = file,
                                    StartOffset      = new long?(num)
                                };
                                dbContext.BlocksData.InsertOnSubmit(blockDatum);
                                this.SetCopyStatus(blob);
                                dbContext.SubmitChanges();
                                dbContext.Refresh(RefreshMode.OverwriteCurrentValues, blob);
                                transactionScope.Complete();
                                this._lastModifiedTime = blob.LastModificationTime;
                            }
                        }
                        Logger <IRestProtocolHeadLogger> .Instance.Info.Log("Uploaded Block: {0}", new object[] { blockId });

                        break;
                    }
                    catch (SqlException sqlException)
                    {
                        if (this.ShouldRethrowException(i, sqlException, out flag1))
                        {
                            throw;
                        }
                    }
                }
                if (this._currentLength < this._contentLength)
                {
                    return(true);
                }
                return(this.PutBlockList());
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Logger <IRestProtocolHeadLogger> .Instance.Error.Log("CopyBlob: PutBlock exception {0}", new object[] { exception });

                this.SetCopyFailed(exception, flag1, null);
                flag = false;
            }
            return(flag);
        }