提交 7337f759 编写于 作者: 陶建辉(Jeff)'s avatar 陶建辉(Jeff)

add new API walGetWalFile

上级 6b02bd26
...@@ -41,7 +41,7 @@ int walRenew(twal_h); ...@@ -41,7 +41,7 @@ int walRenew(twal_h);
int walWrite(twal_h, SWalHead *); int walWrite(twal_h, SWalHead *);
void walFsync(twal_h); void walFsync(twal_h);
int walRestore(twal_h, void *pVnode, int (*writeFp)(void *ahandle, void *pWalHead)); int walRestore(twal_h, void *pVnode, int (*writeFp)(void *ahandle, void *pWalHead));
int walGetWalFile(twal_h, char *name, int32_t *index); int walGetWalFile(twal_h, char *name, uint32_t *index);
extern int wDebugFlag; extern int wDebugFlag;
......
...@@ -37,7 +37,7 @@ typedef struct { ...@@ -37,7 +37,7 @@ typedef struct {
int fd; int fd;
int level; int level;
int max; // maximum number of wal files int max; // maximum number of wal files
uint64_t id; // increase continuously uint32_t id; // increase continuously
int num; // number of wal files int num; // number of wal files
char path[TSDB_FILENAME_LEN]; char path[TSDB_FILENAME_LEN];
char name[TSDB_FILENAME_LEN]; char name[TSDB_FILENAME_LEN];
...@@ -86,7 +86,7 @@ void walClose(void *handle) { ...@@ -86,7 +86,7 @@ void walClose(void *handle) {
// remove all files in the directory // remove all files in the directory
for (int i=0; i<pWal->num; ++i) { for (int i=0; i<pWal->num; ++i) {
sprintf(pWal->name, "%s/%s%ld", pWal->path, walPrefix, pWal->id-i); sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i);
if (remove(pWal->name) <0) { if (remove(pWal->name) <0) {
wError("wal:%s, failed to remove", pWal->name); wError("wal:%s, failed to remove", pWal->name);
} else { } else {
...@@ -113,7 +113,7 @@ int walRenew(twal_h handle) { ...@@ -113,7 +113,7 @@ int walRenew(twal_h handle) {
pWal->num++; pWal->num++;
sprintf(pWal->name, "%s/%s%ld", pWal->path, walPrefix, pWal->id); sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id);
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (pWal->fd < 0) { if (pWal->fd < 0) {
...@@ -125,7 +125,7 @@ int walRenew(twal_h handle) { ...@@ -125,7 +125,7 @@ int walRenew(twal_h handle) {
if (pWal->num > pWal->max) { if (pWal->num > pWal->max) {
// remove the oldest wal file // remove the oldest wal file
char name[TSDB_FILENAME_LEN]; char name[TSDB_FILENAME_LEN];
sprintf(name, "%s/%s%ld", pWal->path, walPrefix, pWal->id - pWal->max); sprintf(name, "%s/%s%d", pWal->path, walPrefix, pWal->id - pWal->max);
if (remove(name) <0) { if (remove(name) <0) {
wError("wal:%s, failed to remove(%s)", name, strerror(errno)); wError("wal:%s, failed to remove(%s)", name, strerror(errno));
} else { } else {
...@@ -173,7 +173,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) { ...@@ -173,7 +173,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) {
int code = 0; int code = 0;
struct dirent *ent; struct dirent *ent;
int count = 0; int count = 0;
uint64_t maxId = 0, minId = -1, index =0; uint32_t maxId = 0, minId = -1, index =0;
int plen = strlen(walPrefix); int plen = strlen(walPrefix);
char opath[TSDB_FILENAME_LEN]; char opath[TSDB_FILENAME_LEN];
...@@ -185,7 +185,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) { ...@@ -185,7 +185,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) {
DIR *dir = opendir(opath); DIR *dir = opendir(opath);
while ((ent = readdir(dir))!= NULL) { while ((ent = readdir(dir))!= NULL) {
if ( strncmp(ent->d_name, walPrefix, plen) == 0) { if ( strncmp(ent->d_name, walPrefix, plen) == 0) {
index = atoll(ent->d_name + plen); index = atol(ent->d_name + plen);
if (index > maxId) maxId = index; if (index > maxId) maxId = index;
if (index < minId) minId = index; if (index < minId) minId = index;
count++; count++;
...@@ -193,13 +193,13 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) { ...@@ -193,13 +193,13 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) {
} }
if ( count != (maxId-minId+1) ) { if ( count != (maxId-minId+1) ) {
wError("wal:%s, messed up, count:%d max:%ld min:%ld", opath, count, maxId, minId); wError("wal:%s, messed up, count:%d max:%d min:%d", opath, count, maxId, minId);
code = -1; code = -1;
} else { } else {
wTrace("wal:%s, %d files will be restored", opath, count); wTrace("wal:%s, %d files will be restored", opath, count);
for (index = minId; index<=maxId; ++index) { for (index = minId; index<=maxId; ++index) {
sprintf(pWal->name, "%s/old/%s%ld", pWal->path, walPrefix, index); sprintf(pWal->name, "%s/old/%s%d", pWal->path, walPrefix, index);
code = walRestoreWalFile(pWal->name, pVnode, writeFp); code = walRestoreWalFile(pWal->name, pVnode, writeFp);
if (code < 0) break; if (code < 0) break;
} }
...@@ -220,7 +220,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) { ...@@ -220,7 +220,7 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *)) {
return code; return code;
} }
int walGetWalFile(void *handle, char *name, int32_t *index) { int walGetWalFile(void *handle, char *name, uint32_t *index) {
SWal *pWal = (SWal *)handle; SWal *pWal = (SWal *)handle;
int code = 1; int code = 1;
int32_t first = 0; int32_t first = 0;
...@@ -236,7 +236,7 @@ int walGetWalFile(void *handle, char *name, int32_t *index) { ...@@ -236,7 +236,7 @@ int walGetWalFile(void *handle, char *name, int32_t *index) {
if (*index < first && *index > pWal->id) { if (*index < first && *index > pWal->id) {
code = -1; // index out of range code = -1; // index out of range
} else { } else {
sprintf(name, "%s/%s%ld", pWal->path, walPrefix, *index); sprintf(name, "%s/%s%d", pWal->path, walPrefix, *index);
code = (*index == pWal->id) ? 0:1; code = (*index == pWal->id) ? 0:1;
} }
......
...@@ -106,7 +106,7 @@ int main(int argc, char *argv[]) { ...@@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
printf("%d wal files are written\n", total); printf("%d wal files are written\n", total);
int32_t index = 0; uint32_t index = 0;
char name[256]; char name[256];
while (1) { while (1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册