Commit f02feab1 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

get the timestamp test working refs[t:1910]

git-svn-id: file:///svn/toku/tokudb@13838 c7de825b-a66e-492c-adef-691d508d4ae1
parent 7e8eab2f
...@@ -61,6 +61,8 @@ int toku_logcursor_create(TOKULOGCURSOR *lc, const char *log_dir) { ...@@ -61,6 +61,8 @@ int toku_logcursor_create(TOKULOGCURSOR *lc, const char *log_dir) {
if ( NULL==cursor->logdir ) if ( NULL==cursor->logdir )
return ENOMEM; return ENOMEM;
strcpy(cursor->logdir, log_dir); strcpy(cursor->logdir, log_dir);
cursor->logfiles = NULL;
cursor->n_logfiles = 0;
r = toku_logger_find_logfiles(cursor->logdir, &(cursor->logfiles), &(cursor->n_logfiles)); r = toku_logger_find_logfiles(cursor->logdir, &(cursor->logfiles), &(cursor->n_logfiles));
if (r!=0) { if (r!=0) {
failresult=r; failresult=r;
...@@ -76,8 +78,10 @@ int toku_logcursor_create(TOKULOGCURSOR *lc, const char *log_dir) { ...@@ -76,8 +78,10 @@ int toku_logcursor_create(TOKULOGCURSOR *lc, const char *log_dir) {
int toku_logcursor_destroy(TOKULOGCURSOR *lc) { int toku_logcursor_destroy(TOKULOGCURSOR *lc) {
int r=0; int r=0;
if ( (*lc)->entry_valid ) if ( (*lc)->entry_valid ) {
toku_log_free_log_entry_resources(&((*lc)->entry)); toku_log_free_log_entry_resources(&((*lc)->entry));
(*lc)->entry_valid = FALSE;
}
r = lc_close_cur_logfile(*lc); r = lc_close_cur_logfile(*lc);
int lf; int lf;
for(lf=0;lf<(*lc)->n_logfiles;lf++) { for(lf=0;lf<(*lc)->n_logfiles;lf++) {
...@@ -92,9 +96,10 @@ int toku_logcursor_destroy(TOKULOGCURSOR *lc) { ...@@ -92,9 +96,10 @@ int toku_logcursor_destroy(TOKULOGCURSOR *lc) {
int toku_logcursor_next(TOKULOGCURSOR lc, struct log_entry **le) { int toku_logcursor_next(TOKULOGCURSOR lc, struct log_entry **le) {
int r=0; int r=0;
if ( lc->entry_valid ) if ( lc->entry_valid ) {
toku_log_free_log_entry_resources(&(lc->entry)); toku_log_free_log_entry_resources(&(lc->entry));
if ( !lc->entry_valid ) { lc->entry_valid = FALSE;
} else if ( !lc->entry_valid ) {
r = toku_logcursor_first(lc, le); r = toku_logcursor_first(lc, le);
return r; return r;
} }
...@@ -121,15 +126,17 @@ int toku_logcursor_next(TOKULOGCURSOR lc, struct log_entry **le) { ...@@ -121,15 +126,17 @@ int toku_logcursor_next(TOKULOGCURSOR lc, struct log_entry **le) {
return r; return r;
} }
} }
lc->entry_valid = TRUE;
*le = &(lc->entry); *le = &(lc->entry);
return r; return r;
} }
int toku_logcursor_prev(TOKULOGCURSOR lc, struct log_entry **le) { int toku_logcursor_prev(TOKULOGCURSOR lc, struct log_entry **le) {
int r=0; int r=0;
if ( lc->entry_valid ) if ( lc->entry_valid ) {
toku_log_free_log_entry_resources(&(lc->entry)); toku_log_free_log_entry_resources(&(lc->entry));
if ( !lc->entry_valid ) { lc->entry_valid = FALSE;
} else if ( !lc->entry_valid ) {
r = toku_logcursor_last(lc, le); r = toku_logcursor_last(lc, le);
return r; return r;
} }
...@@ -156,14 +163,17 @@ int toku_logcursor_prev(TOKULOGCURSOR lc, struct log_entry **le) { ...@@ -156,14 +163,17 @@ int toku_logcursor_prev(TOKULOGCURSOR lc, struct log_entry **le) {
return r; return r;
} }
} }
lc->entry_valid = TRUE;
*le = &(lc->entry); *le = &(lc->entry);
return r; return r;
} }
int toku_logcursor_first(TOKULOGCURSOR lc, struct log_entry **le) { int toku_logcursor_first(TOKULOGCURSOR lc, struct log_entry **le) {
int r=0; int r=0;
if ( lc->entry_valid ) if ( lc->entry_valid ) {
toku_log_free_log_entry_resources(&(lc->entry)); toku_log_free_log_entry_resources(&(lc->entry));
lc->entry_valid = FALSE;
}
// close any but the first log file // close any but the first log file
if ( lc->cur_logfiles_index != 0 ) { if ( lc->cur_logfiles_index != 0 ) {
lc_close_cur_logfile(lc); lc_close_cur_logfile(lc);
...@@ -185,8 +195,10 @@ int toku_logcursor_first(TOKULOGCURSOR lc, struct log_entry **le) { ...@@ -185,8 +195,10 @@ int toku_logcursor_first(TOKULOGCURSOR lc, struct log_entry **le) {
int toku_logcursor_last(TOKULOGCURSOR lc, struct log_entry **le) { int toku_logcursor_last(TOKULOGCURSOR lc, struct log_entry **le) {
int r=0; int r=0;
if ( lc->entry_valid ) if ( lc->entry_valid ) {
toku_log_free_log_entry_resources(&(lc->entry)); toku_log_free_log_entry_resources(&(lc->entry));
lc->entry_valid = FALSE;
}
// close any but last log file // close any but last log file
if ( lc->cur_logfiles_index != lc->n_logfiles-1 ) { if ( lc->cur_logfiles_index != lc->n_logfiles-1 ) {
lc_close_cur_logfile(lc); lc_close_cur_logfile(lc);
......
...@@ -53,12 +53,16 @@ test_main (int argc __attribute__((__unused__)), ...@@ -53,12 +53,16 @@ test_main (int argc __attribute__((__unused__)),
r = toku_logcursor_create(&lc, dname); r = toku_logcursor_create(&lc, dname);
assert(r == 0 && lc != NULL); assert(r == 0 && lc != NULL);
struct log_entry le; struct log_entry *le;
r = toku_logcursor_next(lc, &le); r = toku_logcursor_next(lc, &le);
assert(r == 0 && le.cmd == LT_timestamp); assert(r == 0 && le->cmd == LT_timestamp);
assert(le->u.timestamp.comment.len == 5 && memcmp(le->u.timestamp.comment.data, "hello", 5) == 0);
u_int64_t t = le->u.timestamp.timestamp;
r = toku_logcursor_next(lc, &le); r = toku_logcursor_next(lc, &le);
assert(r == 0 && le.cmd == LT_timestamp); assert(r == 0 && le->cmd == LT_timestamp);
assert(le->u.timestamp.comment.len == 5 && memcmp(le->u.timestamp.comment.data, "world", 5) == 0);
printf("%"PRId64"\n", le->u.timestamp.timestamp - t);
r = toku_logcursor_next(lc, &le); r = toku_logcursor_next(lc, &le);
assert(r != 0); assert(r != 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment