private BlobLocation AddBlob(BackupSetReference backupset, HashBlobPair blob, List <byte[]>?blockreferences, bool shallow = false) { // We navigate down // Where we will put the blob data if we dont already have it stored BlobLocation posblocation; if (shallow) { posblocation = new BlobLocation(blockreferences); } else { if (blockreferences == null) { if (blob.Block == null) { throw new Exception("Block can only be null in multirefernce blob"); } posblocation = new BlobLocation(null, "", blob.Block.Length); } else { posblocation = new BlobLocation(blockreferences); } } // Where the data is already stored if it exists (BlobLocation bloc, bool datastored)? existingblocstored; lock (this) { // Have we already stored this? existingblocstored = AddHash(blob.Hash, posblocation); } if (existingblocstored == null) // ExistBloc == null means posbloc was just added { if (!shallow) { if (blockreferences == null) { if (blob.Block == null) { throw new Exception("Block can only be null in multirefernce blob"); } (posblocation.EncryptedHash, posblocation.RelativeFilePath) = WriteBlob(blob.Hash, blob.Block); } } else { posblocation.RelativeFilePath = ""; posblocation.EncryptedHash = blob.Hash; } // Dont change reference counts until finalization // IncrementReferenceCountNoRecurse(backupset, posblocation, blob.Hash, 1); return(posblocation); } else // Existbloc already stored at dst { (BlobLocation existingbloc, bool datastored) = existingblocstored.Value; // Is the data not already stored in the blobstore (are all references shallow thus far)? if (existingbloc.BlockHashes == null) { if (!datastored) { // Data is not already stored // Dont save if we are writing a bloblistcache if (!backupset.BlobListCache) { // If we are saving to a cache and the bloblist cache indicates the destination has the data // Then dont store, Else save //BackupSetReference blobListCacheReference = backupset with { BlobListCache = true }; if (!(backupset.Cache && existingbloc.GetBSetReferenceCount(backupset).HasValue)) { if (blob.Block == null) { throw new Exception("Block can only be null in multirefernce blob"); } (existingbloc.EncryptedHash, existingbloc.RelativeFilePath) = WriteBlob(blob.Hash, blob.Block); } } } } // Dont change reference counts until finalization // IncrementReferenceCountNoRecurse(backupset, existingbloc, blob.Hash, 1); return(existingbloc); } }
/// <summary> /// Add a single blob to blobstore. /// </summary> /// <param name="blob"></param> /// <param name="type"></param> /// <returns>The BlobLocation the blob is saved to.</returns> private BlobLocation AddBlob(BackupSetReference backupset, HashBlobPair blob) { return(AddBlob(backupset, blob, null)); }
private BlobLocation AddBlob(string backupset, HashBlobPair blob, List <byte[]> blockreferences, bool shallow = false) { // We navigate down // Where we will put the blob data if we dont already have it stored BlobLocation posblocation; if (shallow) { posblocation = new BlobLocation(blockreferences); } else { if (blockreferences == null) { posblocation = new BlobLocation(null, "", blob.Block.Length); } else { posblocation = new BlobLocation(blockreferences); } } // Where the data is already stored if it exists (BlobLocation bloc, bool datastored)? existingblocstored; lock (this) { // Have we already stored this? existingblocstored = AddHash(blob.Hash, posblocation); } if (existingblocstored == null) // ExistBloc == null means posbloc was just added { if (!shallow) { if (blockreferences == null) { (posblocation.EncryptedHash, posblocation.RelativeFilePath) = WriteBlob(blob.Hash, blob.Block); } } else { posblocation.RelativeFilePath = ""; posblocation.EncryptedHash = blob.Hash; } // Dont change reference counts until finalization // IncrementReferenceCountNoRecurse(backupset, posblocation, blob.Hash, 1); return(posblocation); } else // Existbloc already stored at dst { (BlobLocation existingbloc, bool datastored) = existingblocstored.Value; // Is the data not already stored in the blobstore (are all references shallow thus far)? if (existingbloc.BlockHashes == null) { if (!datastored) { // Data is not already stored // Dont save if we are writing a bloblistcache if (!backupset.EndsWith(Core.BlobListCacheSuffix)) { // If we are saving to a cache and the bloblist cache indicates the destination has the data // Then dont store, Else save if (!(backupset.EndsWith(Core.CacheSuffix) && existingbloc.BSetReferenceCounts.ContainsKey(backupset.Substring(0, backupset.Length - Core.CacheSuffix.Length) + Core.BlobListCacheSuffix))) { (existingbloc.EncryptedHash, existingbloc.RelativeFilePath) = WriteBlob(blob.Hash, blob.Block); } } } } // Dont change reference counts until finalization // IncrementReferenceCountNoRecurse(backupset, existingbloc, blob.Hash, 1); return(existingbloc); } }
private BlobLocation AddMultiBlobReferenceBlob(string backupset, byte[] hash, List <byte[]> hashlist) { HashBlobPair referenceblob = new HashBlobPair(hash, null); return(AddBlob(backupset, referenceblob, hashlist)); }
/// <summary> /// Add a single blob to blobstore. /// </summary> /// <param name="blob"></param> /// <param name="type"></param> /// <returns>The BlobLocation the blob is saved to.</returns> private BlobLocation AddBlob(string backupset, HashBlobPair blob) { return(AddBlob(backupset, blob, null)); }