00001
00002
00003
00004
00005
00006
00007
00008 #ifndef PAGEFILE_MANAGER_H_
00009 #define PAGEFILE_MANAGER_H_
00010
00011 #include "Common.h"
00012 #include <list>
00013
00014 class FileHandle;
00015
00019 class PageBlock {
00020 private:
00021 friend class PageFileManager;
00022
00023 PageBlock();
00024 ~PageBlock();
00025
00026 void clear();
00027 bool isConsistent();
00028 int pin();
00029 int unpin();
00030
00031 bool isFree_;
00032 int pinCount_;
00033 bool isDirty_;
00034 FileHandle* fileHandle_;
00035 int pageNo_;
00036 long epoch_;
00037 char data_[PF_PAGE_SIZE];
00038 ulong guard_;
00039
00040 static const ulong GUARD_VALUE = ULONG_MAX;
00041 };
00042
00043
00044
00045
00066 class PageFileManager {
00067 public:
00076 ReturnCode createFile(const char *fileName);
00077
00088 ReturnCode removeFile(const char *fileName);
00089
00102 ReturnCode openFile(const char *fileName, FileHandle **fileHandle);
00103
00115 ReturnCode closeFile(FileHandle *fileHandle);
00116
00127 ReturnCode allocateBlock(char **buffer);
00128
00139 ReturnCode disposeBlock(char *buffer);
00140
00153 ReturnCode lookupBlock(FileHandle* fileHandle, int pageNo, char** data);
00154
00167 ReturnCode setBlockDirty(FileHandle* fileHandle, int pageNo, bool isDirty);
00168
00181 ReturnCode getBlockDirty(FileHandle* fileHandle, int pageNo, bool *isDirty);
00182
00196 ReturnCode allocateBlock(FileHandle* fileHandle, int pageNo, char** data);
00197
00210 ReturnCode disposeBlock(FileHandle* fileHandle, int pageNo);
00211
00224 ReturnCode unpinBlock(FileHandle* fileHandle, int pageNo);
00225
00239 ReturnCode getDirtyPageNumber(FileHandle* fileHandle, int* pageNo);
00240
00253 ReturnCode getPinCount(FileHandle* fileHandle, int pageNo, int* pinCount);
00254
00260 static PageFileManager* getInstance();
00261
00262 private:
00269 PageFileManager();
00270
00278 ~PageFileManager();
00279
00280 long nextEpoch();
00281 PageBlock* getPageBlock(char* data);
00282 PageBlock* getPageBlock(FileHandle* fileHandle, int pageNo);
00283 void disposePageBlock(PageBlock* pageBlock);
00284 void setPageBlock(PageBlock* pageBlock, FileHandle* fileHandle, int pageNo,
00285 char** data);
00286 bool hasPinnedPage(FileHandle* fileHandle);
00287
00288 std::list<FileHandle*> openFileList_;
00289 PageBlock pageBlocks_[PF_BUFFER_SIZE];
00290 long nEpoch_;
00291 };
00292
00293 #endif