/// <summary> /// 创建初始状态的数据库文件。 /// </summary> /// <param name="fullname">数据库文件据对路径。</param> /// <param name="config">数据库配置信息。</param> private void CreateDB(string fullname, DBConfig config) { FileInfo fileInfo = new FileInfo(fullname); Directory.CreateDirectory(fileInfo.DirectoryName); using (FileStream fs = new FileStream(fullname, FileMode.CreateNew, FileAccess.Write, FileShare.None, Consts.pageSize)) { PageHeaderBlock page = new PageHeaderBlock() { OccupiedBytes = Consts.pageSize, AvailableBytes = 0, }; fs.WriteBlock(page); DBHeaderBlock dbHeader = new DBHeaderBlock() { MaxLevelOfSkipList = config.MaxLevelOfSkipList, ProbabilityOfSkipList = config.ProbabilityOfSkipList, MaxSunkCountInMemory = config.MaxSunkCountInMemory, LockTimeout = config.LockTimeout, ThisPos = fs.Position }; fs.WriteBlock(dbHeader); TableBlock tableHead = new TableBlock() { ThisPos = fs.Position, }; fs.WriteBlock(tableHead); byte[] leftSpace = new byte[Consts.pageSize - fs.Length]; fs.Write(leftSpace, 0, leftSpace.Length); BlockCache.TryRemoveFloatingBlock(page); BlockCache.TryRemoveFloatingBlock(dbHeader); BlockCache.TryRemoveFloatingBlock(tableHead); BlockCache.TryRemoveSunkBlock(page); BlockCache.TryRemoveSunkBlock(dbHeader); BlockCache.TryRemoveSunkBlock(tableHead); } }