hatoku_defines.h 3.9 KB
Newer Older
Zardosht Kasheff's avatar
Zardosht Kasheff committed
1 2 3
#ifndef _HATOKU_DEF
#define _HATOKU_DEF

Zardosht Kasheff's avatar
Zardosht Kasheff committed
4
#include "db.h"
Zardosht Kasheff's avatar
Zardosht Kasheff committed
5 6 7
extern "C" {
#include "toku_os.h"
}
Zardosht Kasheff's avatar
Zardosht Kasheff committed
8 9 10 11 12


extern ulong tokudb_debug;


13 14 15 16 17
//
// returns maximum length of dictionary name, such as key-NAME
// NAME_CHAR_LEN is max length of the key name, and have upper bound of 10 for key-
//
#define MAX_DICT_NAME_LEN NAME_CHAR_LEN + 10
Zardosht Kasheff's avatar
Zardosht Kasheff committed
18 19


Zardosht Kasheff's avatar
Zardosht Kasheff committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// QQQ how to tune these?
#define HA_TOKUDB_RANGE_COUNT   100
/* extra rows for estimate_rows_upper_bound() */
#define HA_TOKUDB_EXTRA_ROWS    100

/* Bits for share->status */
#define STATUS_PRIMARY_KEY_INIT 0x1

// tokudb debug tracing
#define TOKUDB_DEBUG_INIT 1
#define TOKUDB_DEBUG_OPEN 2
#define TOKUDB_DEBUG_ENTER 4
#define TOKUDB_DEBUG_RETURN 8
#define TOKUDB_DEBUG_ERROR 16
#define TOKUDB_DEBUG_TXN 32
#define TOKUDB_DEBUG_AUTO_INCREMENT 64
36
#define TOKUDB_DEBUG_LOCK 256
37
#define TOKUDB_DEBUG_LOCKRETRY 512
38
#define TOKUDB_DEBUG_CHECK_KEY 1024
39
#define TOKUDB_DEBUG_HIDE_DDL_LOCK_ERRORS 2048
Zardosht Kasheff's avatar
Zardosht Kasheff committed
40 41 42 43

#define TOKUDB_TRACE(f, ...) \
    printf("%d:%s:%d:" f, my_tid(), __FILE__, __LINE__, ##__VA_ARGS__);

Zardosht Kasheff's avatar
Zardosht Kasheff committed
44 45

inline unsigned int my_tid() {
Zardosht Kasheff's avatar
Zardosht Kasheff committed
46
    return (unsigned int)toku_os_gettid();
Zardosht Kasheff's avatar
Zardosht Kasheff committed
47 48 49 50
}



Zardosht Kasheff's avatar
Zardosht Kasheff committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#define TOKUDB_DBUG_ENTER(f, ...)      \
{ \
    if (tokudb_debug & TOKUDB_DEBUG_ENTER) { \
        TOKUDB_TRACE(f "\n", ##__VA_ARGS__); \
    } \
} \
    DBUG_ENTER(__FUNCTION__);


#define TOKUDB_DBUG_RETURN(r) \
{ \
    int rr = (r); \
    if ((tokudb_debug & TOKUDB_DEBUG_RETURN) || (rr != 0 && (tokudb_debug & TOKUDB_DEBUG_ERROR))) { \
        TOKUDB_TRACE("%s:return %d\n", __FUNCTION__, rr); \
    } \
    DBUG_RETURN(rr); \
}

#define TOKUDB_DBUG_DUMP(s, p, len) \
{ \
    TOKUDB_TRACE("%s:%s", __FUNCTION__, s); \
    uint i;                                                             \
    for (i=0; i<len; i++) {                                             \
        printf("%2.2x", ((uchar*)p)[i]);                                \
    }                                                                   \
    printf("\n");                                                       \
}


Zardosht Kasheff's avatar
Zardosht Kasheff committed
80 81 82
typedef enum {
    hatoku_iso_not_set = 0,
    hatoku_iso_read_uncommitted,
83
    hatoku_iso_read_committed,
84
    hatoku_iso_repeatable_read,
Zardosht Kasheff's avatar
Zardosht Kasheff committed
85 86 87 88 89
    hatoku_iso_serializable
} HA_TOKU_ISO_LEVEL;



90 91 92 93 94
typedef struct st_tokudb_stmt_progress {
    ulonglong inserted;
    ulonglong updated;
    ulonglong deleted;
    ulonglong queried;
95
    bool using_loader;
96 97 98
} tokudb_stmt_progress;


Zardosht Kasheff's avatar
Zardosht Kasheff committed
99 100 101 102
typedef struct st_tokudb_trx_data {
    DB_TXN *all;
    DB_TXN *stmt;
    DB_TXN *sp_level;
103
    DB_TXN *sub_sp_level;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
104
    uint tokudb_lock_count;
105
    tokudb_stmt_progress stmt_progress;
106
    bool checkpoint_lock_taken;
Zardosht Kasheff's avatar
Zardosht Kasheff committed
107 108
} tokudb_trx_data;

109 110 111
extern char *tokudb_data_dir;
extern const char *ha_tokudb_ext;

112 113 114 115 116 117 118
static void reset_stmt_progress (tokudb_stmt_progress* val) {
    val->deleted = 0;
    val->inserted = 0;
    val->updated = 0;
    val->queried = 0;
}

119 120 121 122 123 124 125 126 127 128 129 130 131 132
static int get_name_length(const char *name) {
    int n = 0;
    const char *newname = name;
    n += strlen(newname);
    n += strlen(ha_tokudb_ext);
    return n;
}

//
// returns maximum length of path to a dictionary
//
static int get_max_dict_name_path_length(const char *tablename) {
    int n = 0;
    n += get_name_length(tablename);
133
    n += 1; //for the '-'
134 135 136 137 138 139 140
    n += MAX_DICT_NAME_LEN;
    return n;
}

static void make_name(char *newname, const char *tablename, const char *dictname) {
    const char *newtablename = tablename;
    char *nn = newname;
141 142 143 144 145 146 147 148 149 150
    assert(tablename);
    assert(dictname);
    nn += sprintf(nn, "%s", newtablename);
    nn += sprintf(nn, "-%s", dictname);
}

static inline void commit_txn(DB_TXN* txn, u_int32_t flags) {
    int r;
    r = txn->commit(txn, flags);
    if (r != 0) {
Zardosht Kasheff's avatar
Zardosht Kasheff committed
151
        sql_print_error("tried committing transaction %p and got error code %d", txn, r);
152
    }
153
    assert(r == 0);
154 155
}

156 157 158 159
static inline void abort_txn(DB_TXN* txn) {
    int r;
    r = txn->abort(txn);
    if (r != 0) {
Zardosht Kasheff's avatar
Zardosht Kasheff committed
160
        sql_print_error("tried aborting transaction %p and got error code %d", txn, r);
161 162 163
    }
    assert(r == 0);
}
Zardosht Kasheff's avatar
Zardosht Kasheff committed
164 165


Zardosht Kasheff's avatar
Zardosht Kasheff committed
166
#endif