Exemplo n.º 1
0
        /// <summary>
        /// Decrement the reference count of a chunk by its key.  If the reference count reaches zero, the chunk is deleted.
        /// </summary>
        /// <param name="chunkKey">Chunk key.</param>
        /// <returns>Boolean indicating if the chunk should be garbage collected.</returns>
        public override bool DecrementChunkRefcount(string chunkKey)
        {
            if (String.IsNullOrEmpty(chunkKey))
            {
                throw new ArgumentNullException(nameof(chunkKey));
            }

            chunkKey = DedupeCommon.SanitizeString(chunkKey);

            DedupeChunk chunk = GetChunkMetadata(chunkKey);

            if (chunk == null)
            {
                return(false);
            }

            chunk.RefCount = chunk.RefCount - 1;
            if (chunk.RefCount < 1)
            {
                _ORM.Delete <DedupeChunk>(chunk);
                return(true);
            }
            else
            {
                _ORM.Update <DedupeChunk>(chunk);
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Increment reference count for a chunk by its key.  If the chunk does not exist, it is created.
        /// </summary>
        /// <param name="chunkKey">Chunk key.</param>
        /// <param name="length">The chunk length, used when creating the chunk.</param>
        public override void IncrementChunkRefcount(string chunkKey, int length)
        {
            if (String.IsNullOrEmpty(chunkKey))
            {
                throw new ArgumentNullException(nameof(chunkKey));
            }

            chunkKey = DedupeCommon.SanitizeString(chunkKey);

            lock (_ChunkLock)
            {
                DedupeChunk chunk = GetChunkMetadata(chunkKey);

                if (chunk != null)
                {
                    chunk.RefCount = chunk.RefCount + 1;
                    _ORM.Update <DedupeChunk>(chunk);
                }
                else
                {
                    chunk = new DedupeChunk(chunkKey, length, 1);
                    _ORM.Insert <DedupeChunk>(chunk);
                }
            }
        }
Exemplo n.º 3
0
 static void WriteChunk(DedupeChunk data)
 {
     using (var fs = new FileStream(
                _ChunkDir + data.Key,
                FileMode.Create,
                FileAccess.Write,
                FileShare.None,
                0x1000,
                FileOptions.WriteThrough))
     {
         fs.Write(data.Data, 0, data.Data.Length);
     }
 }
Exemplo n.º 4
0
 static void WriteChunk(DedupeChunk data)
 {
     // File.WriteAllBytes("Chunks\\" + data.Key, data.Value);
     using (var fs = new FileStream(
                "Chunks\\" + data.Key,
                FileMode.Create,
                FileAccess.Write,
                FileShare.None,
                0x1000,
                FileOptions.WriteThrough))
     {
         fs.Write(data.Data, 0, data.Data.Length);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieve metadata for a given chunk by its key.
        /// </summary>
        /// <param name="chunkKey">Chunk key.</param>
        /// <returns>Chunk metadata.</returns>
        public override DedupeChunk GetChunkMetadata(string chunkKey)
        {
            if (String.IsNullOrEmpty(chunkKey))
            {
                throw new ArgumentNullException(nameof(chunkKey));
            }

            chunkKey = DedupeCommon.SanitizeString(chunkKey);

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <DedupeChunk>(nameof(DedupeChunk.Key)),
                DbOperators.Equals,
                chunkKey);

            DedupeChunk ret = _ORM.SelectFirst <DedupeChunk>(e);

            return(ret);
        }
Exemplo n.º 6
0
 // Called during store operations, consider using FileStream with FileOptions.WriteThrough to ensure crash consistency
 static void WriteChunk(DedupeChunk data)
 {
     File.WriteAllBytes("Chunks\\" + data.Key, data.Data);
 }