-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferManager.h
More file actions
58 lines (49 loc) · 1.99 KB
/
BufferManager.h
File metadata and controls
58 lines (49 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// BufferManager.h
// Minisql
// Description: Provide funtions to manage the buffers.
//
// Created by xuyuhao on 14/11/1.
// Copyright (c) 2014年 xuyuhao. All rights reserved.
//
#ifndef __Minisql__BufferManager__
#define __Minisql__BufferManager__
#include "Minisql.h"
#include <stdio.h>
static int replaced_block = -1;
class BufferManager
{
private:
fileNode *fileHead;
fileNode file_pool[MAX_FILE_NUM];
blockNode block_pool[MAX_BLOCK_NUM];
int total_block; // the number of block that have been used, which means the block is in the list.
int total_file; // the number of file that have been used, which means the file is in the list.
void init_block(blockNode & block);
void init_file(fileNode & file);
blockNode* getBlock(fileNode * file,blockNode* position,bool if_pin = false);
void writtenBackToDiskAll();
void writtenBackToDisk(const char* fileName,blockNode* block);
void clean_dirty(blockNode &block);
size_t getUsingSize(blockNode* block);
static const int BLOCK_SIZE = 4096;
public:
BufferManager();
~BufferManager();
void delete_fileNode(const char * fileName);
fileNode* getFile(const char* fileName,bool if_pin = false);
void set_dirty(blockNode & block);
void set_pin(blockNode & block,bool pin);
void set_pin(fileNode & file,bool pin);
void set_usingSize(blockNode & block,size_t usage);
size_t get_usingSize(blockNode & block);
char* get_content(blockNode& block);
static int getBlockSize() //Get the size of the block that others can use.Others cannot use the block head
{
return BLOCK_SIZE - sizeof(size_t);//减去文件头
}
blockNode* getNextBlock(fileNode * file,blockNode* block);
blockNode* getBlockHead(fileNode* file);
blockNode* getBlockByOffset(fileNode* file, int offestNumber);
};
#endif /* defined(__Minisql__BufferManager__) */