提交 ef084468 编写于 作者: H hzcheng

resolve warning

上级 5ba5fb73
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
extern "C" { extern "C" {
#endif #endif
typedef int32_t file_id_t;
typedef enum { typedef enum {
TSDB_FILE_TYPE_HEAD, // .head file type TSDB_FILE_TYPE_HEAD, // .head file type
TSDB_FILE_TYPE_DATA, // .data file type TSDB_FILE_TYPE_DATA, // .data file type
...@@ -40,19 +38,33 @@ typedef struct { ...@@ -40,19 +38,33 @@ typedef struct {
} SFileInfo; } SFileInfo;
typedef struct { typedef struct {
char * fname; int fd;
SFileInfo fInfo; int64_t size; // total size of the file
} SFILE; int64_t tombSize; // unused file size
} SFile;
// typedef struct { typedef struct {
// int64_t offset; int32_t fileId;
// int64_t skey; SFile fhead;
// int64_t ekey; SFile fdata;
// int16_t numOfBlocks; SFile flast;
// } SDataBlock; } SFileGroup;
// TSDB file handle
typedef struct {
int32_t daysPerFile;
int32_t keep;
int32_t minRowPerFBlock;
int32_t maxRowsPerFBlock;
SFileGroup fGroup[];
} STsdbFileH;
#define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) <= TSDB_FILE_TYPE_META) #define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) <= TSDB_FILE_TYPE_META)
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
int32_t maxRowsPerFBlock);
void tsdbCloseFile(STsdbFileH *pFileH);
char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type); char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -14,9 +14,21 @@ ...@@ -14,9 +14,21 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <dirent.h>
#include "tsdbFile.h" #include "tsdbFile.h"
#include "tglobalcfg.h"
// int64_t tsMsPerDay[] = {
// 86400000L, // TSDB_PRECISION_MILLI
// 86400000000L, // TSDB_PRECISION_MICRO
// 86400000000000L // TSDB_PRECISION_NANO
// };
#define tsdbGetKeyFileId(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
#define tsdbGetMaxNumOfFiles(keep, daysPerFile) ((keep) / (daysPerFile) + 3)
typedef struct { typedef struct {
int64_t offset; int64_t offset;
...@@ -71,6 +83,55 @@ const char *tsdbFileSuffix[] = { ...@@ -71,6 +83,55 @@ const char *tsdbFileSuffix[] = {
".meta" // TSDB_FILE_TYPE_META ".meta" // TSDB_FILE_TYPE_META
}; };
/**
* Initialize the TSDB file handle
*/
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
int32_t maxRowsPerFBlock) {
STsdbFileH *pTsdbFileH =
(STsdbFileH *)calloc(1, sizeof(STsdbFileH) + sizeof(SFileGroup) * tsdbGetMaxNumOfFiles(keep, daysPerFile));
if (pTsdbFileH == NULL) return NULL;
pTsdbFileH->daysPerFile = daysPerFile;
pTsdbFileH->keep = keep;
pTsdbFileH->minRowPerFBlock = minRowsPerFBlock;
pTsdbFileH->maxRowsPerFBlock = maxRowsPerFBlock;
// Open the directory to read information of each file
DIR *dir = opendir(dataDir);
if (dir == NULL) {
free(pTsdbFileH);
return NULL;
}
struct dirent *dp;
char fname[256];
while ((dp = readdir(dir)) != NULL) {
if (strncmp(dp->d_name, ".", 1) == 0 || strncmp(dp->d_name, "..", 2) == 0) continue;
if (true /* check if the file is the .head file */) {
int fileId = 0;
int vgId = 0;
sscanf(dp->d_name, "v%df%d.head", &vgId, &fileId);
// TODO
// Open head file
// Open data file
// Open last file
}
}
return pTsdbFileH;
}
/**
* Closet the file handle
*/
void tsdbCloseFile(STsdbFileH *pFileH) {
// TODO
}
char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type) { char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type) {
if (!IS_VALID_TSDB_FILE_TYPE(type)) return NULL; if (!IS_VALID_TSDB_FILE_TYPE(type)) return NULL;
...@@ -79,4 +140,10 @@ char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type) { ...@@ -79,4 +140,10 @@ char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type) {
sprintf(fileName, "%s/%s%s", dirName, fname, tsdbFileSuffix[type]); sprintf(fileName, "%s/%s%s", dirName, fname, tsdbFileSuffix[type]);
return fileName; return fileName;
}
static void tsdbGetKeyRangeOfFileId(int32_t daysPerFile, int8_t precision, int32_t fileId, TSKEY *minKey,
TSKEY *maxKey) {
*minKey = fileId * daysPerFile * tsMsPerDay[precision];
*maxKey = *minKey + daysPerFile * tsMsPerDay[precision] - 1;
} }
\ No newline at end of file
...@@ -83,7 +83,7 @@ int32_t tsdbInsertMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co ...@@ -83,7 +83,7 @@ int32_t tsdbInsertMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co
} }
// TODO: make below a function to implement // TODO: make below a function to implement
if (fseek(mfh->fd, info.offset, SEEK_CUR) < 0) { if (lseek(mfh->fd, info.offset, SEEK_CUR) < 0) {
return -1; return -1;
} }
...@@ -114,7 +114,7 @@ int32_t tsdbDeleteMetaRecord(SMetaFile *mfh, int64_t uid) { ...@@ -114,7 +114,7 @@ int32_t tsdbDeleteMetaRecord(SMetaFile *mfh, int64_t uid) {
// Remove record from file // Remove record from file
info.offset = -info.offset; info.offset = -info.offset;
if (fseek(mfh->fd, -info.offset, SEEK_CUR) < 0) { if (lseek(mfh->fd, -info.offset, SEEK_CUR) < 0) {
return -1; return -1;
} }
...@@ -149,7 +149,7 @@ int32_t tsdbUpdateMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co ...@@ -149,7 +149,7 @@ int32_t tsdbUpdateMetaRecord(SMetaFile *mfh, int64_t uid, void *cont, int32_t co
mfh->size += contLen; mfh->size += contLen;
} }
if (fseek(mfh->fd, -info.offset, SEEK_CUR) < 0) { if (lseek(mfh->fd, -info.offset, SEEK_CUR) < 0) {
return -1; return -1;
} }
...@@ -212,7 +212,7 @@ static int tsdbRestoreFromMetaFile(char *fname, SMetaFile *mfh) { ...@@ -212,7 +212,7 @@ static int tsdbRestoreFromMetaFile(char *fname, SMetaFile *mfh) {
return -1; return -1;
} }
if (fseek(fd, TSDB_META_FILE_HEADER_SIZE, SEEK_SET) < 0) { if (lseek(fd, TSDB_META_FILE_HEADER_SIZE, SEEK_SET) < 0) {
// TODO: deal with the error // TODO: deal with the error
close(fd); close(fd);
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册