Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        private Chunk RegisterChunk(int Start, int Length, int Id = 0)
        {
            if (Id == 0)
            {
                Id = GetNewChunkID();
            }
            Chunk NewChunk = new Chunk(Start, Length, 0, Id);

            EmptyChunks.Add(NewChunk.Id, NewChunk);
            EmptyChunksStart.Add(NewChunk.Start, NewChunk);
            EmptyChunksLength.Add(NewChunk.Length, NewChunk);
            return(NewChunk);
        }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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);
                }
            }
        }