Commit 1be01401 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

Addresses #1510 Added callback to toku_checkpoint(), primarily intended for use in testing.

git-svn-id: file:///svn/toku/tokudb@11286 c7de825b-a66e-492c-adef-691d508d4ae1
parent 36440b0c
......@@ -201,7 +201,7 @@ checkpoint_thread (void *cachetable_v)
char *error_string;
CACHETABLE ct = cachetable_v;
printf("%s:%d Checkpointing\n", __FILE__, __LINE__);
int r = toku_checkpoint(ct, ct->logger, &error_string);
int r = toku_checkpoint(ct, ct->logger, &error_string, NULL, NULL);
if (r) {
if (error_string) {
fprintf(stderr, "%s:%d Got error %d while doing: %s\n", __FILE__, __LINE__, r, error_string);
......
......@@ -161,7 +161,7 @@ void toku_checkpoint_destroy(void) {
// Take a checkpoint of all currently open dictionaries
int
toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string) {
toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string, void (*callback_f)(void*), void * extra) {
int r;
assert(initialized);
......@@ -173,7 +173,10 @@ toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string) {
multi_operation_checkpoint_unlock();
ydb_unlock();
if (r==0) {
if (callback_f)
callback_f(extra); // callback is called with checkpoint_safe_lock still held
r = toku_cachetable_end_checkpoint(ct, logger, error_string);
}
......
......@@ -47,4 +47,6 @@ void toku_checkpoint_init(void (*ydb_lock_callback)(void), void (*ydb_unlock_cal
void toku_checkpoint_destroy(void);
// Take a checkpoint of all currently open dictionaries
int toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string);
// Callback is called during checkpoint procedure while checkpoint_safe lock is still held.
// Callback is primarily intended for use in testing.
int toku_checkpoint(CACHETABLE ct, TOKULOGGER logger, char **error_string, void (*callback_f)(void*), void * extra);
......@@ -74,8 +74,7 @@ do_update (void *UU(ignore))
static void*
do_checkpoint (void *UU(v))
{
// TODO: #1510 Replace with real checkpoint function
int r = toku_checkpoint(ct, NULL, NULL);
int r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
return 0;
}
......@@ -124,16 +123,14 @@ static void checkpoint_pending(void) {
//printf("E43\n");
n_flush = n_write_me = n_keep_me = n_fetch = 0; expect_value = 43;
//TODO: #1510 Replace with real checkpoint call
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
assert(n_flush == N && n_write_me == N && n_keep_me == N);
// a subsequent checkpoint should cause no flushes, or writes since all of the items are clean
n_flush = n_write_me = n_keep_me = n_fetch = 0;
//TODO: #1510 Replace with real checkpoint call
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
assert(n_flush == 0 && n_write_me == 0 && n_keep_me == 0);
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
......@@ -27,6 +28,14 @@ static int fetch(CACHEFILE cf, CACHEKEY key, u_int32_t fullhash, void **value, l
return 0;
}
static int callback_was_called = 0;
static void checkpoint_callback(void * extra) {
int * x = (int*) extra;
(*x)++;
if (verbose) printf("checkpoint_callback called %d (should be 1-16)\n", *x);
}
// put n items into the cachetable, maybe mark them dirty, do a checkpoint, and
// verify that all of the items have been written and are clean.
......@@ -68,8 +77,9 @@ static void cachetable_checkpoint_test(int n, enum cachetable_dirty dirty) {
// all items should be kept in the cachetable
n_flush = n_write_me = n_keep_me = n_fetch = 0;
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, checkpoint_callback, &callback_was_called);
assert(r == 0);
assert(callback_was_called != 0);
assert(n_flush == n && n_write_me == n && n_keep_me == n);
// after the checkpoint, all of the items should be clean
......@@ -98,7 +108,7 @@ static void cachetable_checkpoint_test(int n, enum cachetable_dirty dirty) {
n_flush = n_write_me = n_keep_me = n_fetch = 0;
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
assert(n_flush == 0 && n_write_me == 0 && n_keep_me == 0);
......
......@@ -79,7 +79,7 @@ static void cachetable_prefetch_checkpoint_test(int n, enum cachetable_dirty dir
// all items should be kept in the cachetable
n_flush = n_write_me = n_keep_me = n_fetch = 0;
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
assert(n_flush == n && n_write_me == n && n_keep_me == n);
......@@ -108,7 +108,7 @@ static void cachetable_prefetch_checkpoint_test(int n, enum cachetable_dirty dir
// a subsequent checkpoint should cause no flushes, or writes since all of the items are clean
n_flush = n_write_me = n_keep_me = n_fetch = 0;
r = toku_checkpoint(ct, NULL, NULL);
r = toku_checkpoint(ct, NULL, NULL, NULL, NULL);
assert(r == 0);
assert(n_flush == 0 && n_write_me == 0 && n_keep_me == 0);
......
......@@ -696,7 +696,7 @@ static int toku_env_set_verbose(DB_ENV * env, u_int32_t which, int onoff) {
static int toku_env_txn_checkpoint(DB_ENV * env, u_int32_t kbyte __attribute__((__unused__)), u_int32_t min __attribute__((__unused__)), u_int32_t flags __attribute__((__unused__))) {
char *error_string = NULL;
int r = toku_checkpoint(env->i->cachetable, env->i->logger, &error_string);
int r = toku_checkpoint(env->i->cachetable, env->i->logger, &error_string, NULL, NULL);
if (r) {
env->i->is_panicked = r; // Panicking the whole environment may be overkill, but I'm not sure what else to do.
env->i->panic_string = error_string;
......
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