提交 c9cd5fce 编写于 作者: H Hongze Cheng

more TDB

上级 f77d33dc
......@@ -87,17 +87,20 @@ int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv) {
pDb->dbname[dbNameLen] = '\0';
// open pPgFile or get from the env
pPgFile = NULL;
snprintf(dbfname, 128, "%s/%s", tdbEnvGetRootDir(pEnv), fname);
fileExist = (tdbCheckFileAccess(fname, TDB_F_OK) == 0);
if (fileExist) {
// TODO
} else {
tdbGnrtFileID(dbfname, fileid, false);
pPgFile = tdbEnvGetPageFile(pEnv, fileid);
}
if (pPgFile == NULL) {
ret = pgFileOpen(&pPgFile, dbfname, pEnv);
if (ret != 0) {
// TODO: handle error
return -1;
}
// Create and open the page file
}
#if 0
......
......@@ -47,6 +47,7 @@ int tdbEnvCreate(TENV **ppEnv, const char *rootDir) {
pEnv->cacheSize = TDB_DEFAULT_CACHE_SIZE;
memcpy(pEnv->rootDir, rootDir, slen);
pEnv->rootDir[slen] = '\0';
TD_DLIST_INIT(&(pEnv->dbList));
TD_DLIST_INIT(&(pEnv->pgfList));
......
......@@ -20,38 +20,35 @@ static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData);
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv) {
SPgFile * pPgFile;
SPgCache *pPgCache;
size_t fnameLen;
*ppPgFile = NULL;
pPgFile = (SPgFile *)calloc(1, sizeof(*pPgFile));
// create the handle
fnameLen = strlen(fname);
pPgFile = (SPgFile *)calloc(1, sizeof(*pPgFile) + fnameLen + 1);
if (pPgFile == NULL) {
return -1;
}
pPgFile->fd = -1;
pPgFile->fname = strdup(fname);
if (pPgFile->fname == NULL) {
pgFileClose(pPgFile);
return -1;
}
ASSERT(pEnv != NULL);
pPgFile->pPgCache = pPgCache;
// pPgFile->pgSize = ; (TODO)
// init the handle
pPgFile->pEnv = pEnv;
pPgFile->fname = (char *)(&(pPgFile[1]));
memcpy(pPgFile->fname, fname, fnameLen);
pPgFile->fname[fnameLen] = '\0';
pPgFile->fd = -1;
pPgFile->fd = open(fname, O_RDWR, 0755);
pPgFile->fd = open(fname, O_CREAT | O_RDWR, 0755);
if (pPgFile->fd < 0) {
pgFileClose(pPgFile);
// TODO: handle error
return -1;
}
if (tdbGnrtFileID(fname, pPgFile->fileid, false) < 0) {
pgFileClose(pPgFile);
return -1;
}
tdbGnrtFileID(fname, pPgFile->fileid, false);
// TODO: get file size
pPgFile->pgFileSize = 0;
/* TODO */
*ppPgFile = pPgFile;
return 0;
......@@ -75,6 +72,7 @@ SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno) {
SPage * pPage;
pgid_t pgid;
#if 0
pPgCache = pPgFile->pPgCache;
pPage = NULL;
memcpy(pgid.fileid, pPgFile->fileid, TDB_FILE_ID_LEN);
......@@ -94,6 +92,7 @@ SPage *pgFileFetch(SPgFile *pPgFile, pgno_t pgno) {
return pPage;
}
}
#endif
return pPage;
}
......@@ -114,6 +113,8 @@ static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) {
uint8_t *pTData;
size_t szToRead;
#if 0
// pgSize = ; (TODO)
pTData = pData;
szToRead = pgSize;
......@@ -132,6 +133,7 @@ static int pgFileRead(SPgFile *pPgFile, pgno_t pgno, uint8_t *pData) {
szToRead -= rsize;
pTData += rsize;
}
#endif
return 0;
}
\ No newline at end of file
......@@ -33,13 +33,11 @@ typedef struct __attribute__((__packed__)) {
TDB_STATIC_ASSERT(sizeof(SPgFileHdr) == TDB_PG_FILE_HDR_SIZE, "Page file header size if not 128");
struct SPgFile {
char * fname; // backend file name
uint8_t fileid[TDB_FILE_ID_LEN]; // file id
SPgCache *pPgCache; // page cache underline
pgsz_t pgSize;
int fd;
pgno_t pgFileSize;
TDB * pDb; // For a SPgFile for multiple databases, this is the <dbname, pgno> mapping DB.
TENV * pEnv; // env containing this page file
char * fname; // backend file name
uint8_t fileid[TDB_FILE_ID_LEN]; // file id
int fd;
// TDB * pDb; // For a SPgFile for multiple databases, this is the <dbname, pgno> mapping DB.
};
int pgFileOpen(SPgFile **ppPgFile, const char *fname, TENV *pEnv);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册