Beispiel #1
0
        private async Task CloseOffCurrentTable()
        {
            var currentLocation = _metaData.BlockCount * FileConsts.PageSize;

            var filterSize = _metaData.Filter.WriteToPipe(_filePipe);

            _metaData.AddTableEntry(currentLocation, filterSize, TableOfContentsEntryType.Filter);
            currentLocation += filterSize;

            var statsSize = _metaData.WriteStats(_filePipe);

            _metaData.AddTableEntry(currentLocation, statsSize, TableOfContentsEntryType.Statistics);
            currentLocation += statsSize;

            var blockOffsetsSize = _metaData.WriteBlockOffsets(_filePipe);

            _metaData.AddTableEntry(currentLocation, blockOffsetsSize, TableOfContentsEntryType.BlockOffsets);

            _metaData.WriteTOC(_filePipe);

            await _filePipe.FlushAsync();

            await _filePipe.CompleteAsync();

            await _fileStream.DisposeAsync();

            if (_loadNewFiles)
            {
                var tf = new TableFile(_fileName, _blockCache);
                _newTableFiles.Add(tf);
                await tf.LoadAsync();
            }
            _lastTableKeyCount = _metaData.Count;
        }
Beispiel #2
0
        private async Task MoveTableToLowerLevel(SortedStorageLayer sortedStorage, StorageLayer layerBelow, TableFile file)
        {
            var newFilename = layerBelow.GetNextFileName();

            System.IO.File.Copy(file.FileName, newFilename);
            var tableFile = new TableFile(newFilename, _database.BlockCache);
            await tableFile.LoadAsync();

            layerBelow.AddTableFile(tableFile);
            sortedStorage.RemoveTable(file);

            file.Dispose();
            System.IO.File.Delete(file.FileName);

            Console.WriteLine("Moved table down with no merge");
            // Move table down one level
        }
Beispiel #3
0
        private async Task WriteInMemoryTable()
        {
            await foreach (var sl in _channel.Reader.ReadAllAsync())
            {
                try
                {
                    var nextFilename = _storageLayer.GetNextFileName();
                    var fileWriter   = new TableFileWriter(nextFilename);
                    await fileWriter.SaveMemoryTable(sl);

                    var tableFile = new TableFile(fileWriter.FileName, _database.BlockCache);
                    await tableFile.LoadAsync();

                    _storageLayer.AddTableFile(tableFile);
                    _database.RemoveMemoryTable(sl);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error " + ex);
                }
            }
        }