Пример #1
0
        public void WriteChunk(int ChunkId, int FileId)
        {
            Logger.Debug($"M: MARK CHUNK {ChunkId} AS WRITTEN BY {FileId}");
            Chunk Chunk = GetChunkByIdInternal(ChunkId);

            Chunk.SetWritten();
            if (EmptyChunks.ContainsKey(Chunk.Id))
            {
                EmptyChunks.Remove(Chunk.Id);
            }
            if (EmptyChunksStart.ContainsKey(Chunk.Start))
            {
                EmptyChunksStart.Remove(Chunk.Start);
            }
            if (EmptyChunksLength.ContainsKey(Chunk.Length))
            {
                EmptyChunksLength.Remove(Chunk.Length);
            }
            if (!(WrittenChunks.ContainsKey(Chunk.Id)))
            {
                WrittenChunks.Add(Chunk.Id, Chunk);
            }
            if (!(FileId == 0))
            {
                if (!(Files.ContainsKey(FileId)))
                {
                    throw new FileNotFoundException($"File {FileId} not found in Metadata");
                }
                Files[FileId].AddChunk(ChunkId);
            }
        }
Пример #2
0
 public int GetChunkLength(int ChunkId)
 {
     if (EmptyChunks.ContainsKey(ChunkId))
     {
         return(EmptyChunks[ChunkId].Length);
     }
     if (WrittenChunks.ContainsKey(ChunkId))
     {
         return(WrittenChunks[ChunkId].Length);
     }
     throw new ChunkNotFoundException($"Chunk {ChunkId} not found in Metadata");
 }
Пример #3
0
 private Chunk GetChunkByIdInternal(int ChunkId)
 {
     Logger.Debug($"M: GET CHUNK BY ID");
     if (EmptyChunks.ContainsKey(ChunkId))
     {
         return(EmptyChunks[ChunkId]);
     }
     if (WrittenChunks.ContainsKey(ChunkId))
     {
         return(WrittenChunks[ChunkId]);
     }
     throw new ChunkNotFoundException($"Chunk {ChunkId} not found in Metadata");
 }
Пример #4
0
 private void RemoveChunk(Chunk Chunk)
 {
     if (WrittenChunks.ContainsKey(Chunk.Id))
     {
         WrittenChunks.Remove(Chunk.Id);
     }
     if (EmptyChunks.ContainsKey(Chunk.Id))
     {
         EmptyChunks.Remove(Chunk.Id);
     }
     if (EmptyChunksStart.ContainsKey(Chunk.Start))
     {
         EmptyChunksStart.Remove(Chunk.Start);
     }
     if (EmptyChunksLength.ContainsKey(Chunk.Length))
     {
         EmptyChunksLength.Remove(Chunk.Length);
     }
 }
Пример #5
0
        public void MarkChunkAsEmpty(int ChunkId, int FileId)
        {
            Logger.Debug($"M: MARK CHUNK {ChunkId} AS NOT WRITTEN BY {FileId}");
            Chunk Chunk = GetChunkByIdInternal(ChunkId);

            Chunk.SetNotWritten();
            if (!(Files.ContainsKey(FileId)))
            {
                throw new FileNotFoundException($"File {FileId} not found in Metadata");
            }
            Files[FileId].DeleteChunk(ChunkId);
            if (!(Chunk.IsWritten()))
            {
                if (WrittenChunks.ContainsKey(Chunk.Id))
                {
                    WrittenChunks.Remove(Chunk.Id);
                }
                try
                {
                    Chunk PreChunk = GetChunkBeforIfEmpty(Chunk);
                    Chunk = CombineChunks(PreChunk, Chunk);
                }
                catch (ChunkNotFoundException)
                {
                }
                try
                {
                    Chunk AfterChunk = GetChunkAfterIfEmpty(Chunk);
                    Chunk = CombineChunks(Chunk, AfterChunk);
                }
                catch (ChunkNotFoundException)
                {
                }
                if (!(EmptyChunks.ContainsKey(Chunk.Id)))
                {
                    EmptyChunks.Add(Chunk.Id, Chunk);
                    EmptyChunksStart.Add(Chunk.Start, Chunk);
                    EmptyChunksLength.Add(Chunk.Length, Chunk);
                }
            }
        }