Exemplo n.º 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;
        }
Exemplo n.º 2
0
        private bool DoesTableFitWithNoOverlap(TableFile table, StorageLayer nextLayer)
        {
            var tablesBelow = nextLayer.GetTables();

            var noOverlap = true;
            var firstKey  = table.FirstKey.Span;
            var lastKey   = table.FirstKey.Span;

            foreach (var lowerTable in tablesBelow)
            {
                var compare = firstKey.SequenceCompareTo(lowerTable.LastKey.Span);
                if (compare > 0)
                {
                    continue;
                }
                compare = lastKey.SequenceCompareTo(lowerTable.FirstKey.Span);
                if (compare < 0)
                {
                    continue;
                }
                noOverlap = false;
            }

            return(noOverlap);
        }
Exemplo n.º 3
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
        }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
        private List <TableFile> GetOverlappingTables(TableFile table, StorageLayer nextLayer)
        {
            var tablesBelow = nextLayer.GetTables();
            var firstKey    = table.FirstKey.Span;
            var lastKey     = table.LastKey.Span;

            var overlapped = new List <TableFile>();

            foreach (var lowerTable in tablesBelow)
            {
                var compare = firstKey.SequenceCompareTo(lowerTable.LastKey.Span);
                if (compare > 0)
                {
                    continue;
                }
                compare = lastKey.SequenceCompareTo(lowerTable.FirstKey.Span);
                if (compare < 0)
                {
                    continue;
                }
                overlapped.Add(lowerTable);
            }
            return(overlapped);
        }
Exemplo n.º 6
0
 public TableFileEnumerator(TableFile tableFile)
 {
     _tableFile = tableFile;
 }
Exemplo n.º 7
0
 public TableItemEnumerator(TableFile table)
 {
 }