예제 #1
0
BlockInfo* BufferManager::GetFileBlock(string db_name, string tb_name, int file_type, int block_num)
{
	fhandle_->IncreaseAge();
	FileInfo *file = fhandle_->GetFileInfo(db_name, tb_name, file_type);

	if (file)
	{
		BlockInfo *blo = fhandle_->GetBlockInfo(file, block_num);
		if (blo)
			return blo;
		else /* new block */
		{
			BlockInfo *bp = GetUsableBlock();
			bp->set_block_num(block_num);
			bp->SetFile(file);
			bp->ReadInfo(path_);
			fhandle_->AddBlockInfo(bp);
			return bp;
		}
	}
	else
	{
		BlockInfo *bp = GetUsableBlock();
		bp->set_block_num(block_num);
		FileInfo *fp = new FileInfo(db_name,file_type,tb_name, 0 , 0, NULL, NULL);
		fhandle_->AddFileInfo(fp);
		bp->SetFile(fp);
		bp->ReadInfo(path_);
		fhandle_->AddBlockInfo(bp);
		return bp;
	}
	return 0;
}