1. 打开ulog文件
1308308 1308309 1308310 1308311 1308312 1308313 1308314 1308315 1308316 1308317 1308318 1308319 1308320 1308321 1308322 1308323 1308324 1308325 1308326 1308327 1308328 1308329 1308330 1308331 1308332 1308333 1308334 1308335 1308336 1308337 1308338 1308339 1308340 1308341 1308342 1308343 1308344 1308345 1308346 1308347 1308348 1308349 1308350 1308351 1308352 1308353 1308354 1308355 1308356 1308357 1308358 1308359 |
/* Create a log reader object. */ TCULRD *tculrdnew(TCULOG *ulog, uint64_t ts){ assert(ulog); if(!ulog->base) return NULL; if(pthread_rwlock_rdlock(&ulog->rwlck) != 0) return NULL; TCLIST *names = tcreaddir(ulog->base); if(!names){ pthread_rwlock_unlock(&ulog->rwlck); return NULL; } int ln = tclistnum(names); int max = 0; for(int i = 0; i < ln; i++){ const char *name = tclistval2(names, i); if(!tcstrbwm(name, TCULSUFFIX)) continue; int id = tcatoi(name); char *path = tcsprintf("%s/%08d%s", ulog->base, id, TCULSUFFIX); struct stat sbuf; if(stat(path, &sbuf) == 0 && S_ISREG(sbuf.st_mode) && id > max) max = id; tcfree(path); } tclistdel(names); if(max < 1) max = 1; uint64_t bts = (ts > TCULTMDEVALW * 1000000) ? ts - TCULTMDEVALW * 1000000 : 0; int num = 0; for(int i = max; i > 0; i--){ char *path = tcsprintf("%s/%08d%s", ulog->base, i, TCULSUFFIX); int fd = open(path, O_RDONLY, 00644); tcfree(path); if(fd == -1) break; int rsiz = sizeof(uint8_t) + sizeof(uint64_t); unsigned char buf[rsiz]; uint64_t fts = INT64_MAX; if(tcread(fd, buf, rsiz)){ memcpy(&fts, buf + sizeof(uint8_t), sizeof(ts)); fts = TTNTOHLL(fts); } close(fd); num = i; if(bts >= fts) break; } if(num < 1) num = 1; TCULRD *urld = tcmalloc(sizeof(*urld)); urld->ulog = ulog; urld->ts = ts; urld->num = num; urld->fd = -1; urld->rbuf = tcmalloc(TTIOBUFSIZ); urld->rsiz = TTIOBUFSIZ; pthread_rwlock_unlock(&ulog->rwlck); return urld; } |
2. 读取ulog …