summaryrefslogtreecommitdiff
path: root/storage/tokudb/ft-index/toku_include
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-09-09 11:32:39 +0200
committerSergei Golubchik <sergii@pisem.net>2013-09-09 11:32:39 +0200
commit905c9815f799226dd95524aa5cf14402eea7c31b (patch)
tree4513be38c9e0e2c5927148d000cc7212f9a21ceb /storage/tokudb/ft-index/toku_include
parent9b933e3be9854a6b41c3915e594d63225104d973 (diff)
parenta52b3259f6903fd92ac7d8c250c15d219e227355 (diff)
downloadmariadb-git-905c9815f799226dd95524aa5cf14402eea7c31b.tar.gz
merge with git://github.com/Tokutek/ft-index.git up to tokudb-7.0.4
Diffstat (limited to 'storage/tokudb/ft-index/toku_include')
-rw-r--r--storage/tokudb/ft-index/toku_include/CMakeLists.txt15
-rw-r--r--storage/tokudb/ft-index/toku_include/memory.h226
-rw-r--r--storage/tokudb/ft-index/toku_include/old-db.h275
-rw-r--r--storage/tokudb/ft-index/toku_include/rdtsc.h126
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_assert.h196
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_config.h.in67
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_htod.h172
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_list.h182
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_os.h185
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_portability.h433
-rw-r--r--storage/tokudb/ft-index/toku_include/toku_race_tools.h141
11 files changed, 2018 insertions, 0 deletions
diff --git a/storage/tokudb/ft-index/toku_include/CMakeLists.txt b/storage/tokudb/ft-index/toku_include/CMakeLists.txt
new file mode 100644
index 00000000000..6ae304f8df3
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/CMakeLists.txt
@@ -0,0 +1,15 @@
+configure_file(toku_config.h.in toku_config.h)
+add_custom_target(generate_config_h DEPENDS
+ "${CMAKE_CURRENT_BINARY_DIR}/toku_config.h")
+
+# detect when we are being built as a subproject
+if (NOT DEFINED MYSQL_PROJECT_NAME_DOCSTRING)
+ install(
+ FILES toku_list.h toku_os.h
+ DESTINATION include
+ )
+ install(
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/toku_config.h"
+ DESTINATION include
+ )
+endif () \ No newline at end of file
diff --git a/storage/tokudb/ft-index/toku_include/memory.h b/storage/tokudb/ft-index/toku_include/memory.h
new file mode 100644
index 00000000000..2e1bfab4e7b
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/memory.h
@@ -0,0 +1,226 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+#ifndef MEMORY_H
+#define MEMORY_H
+
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+
+#include <stdlib.h>
+#include <toku_portability.h>
+
+
+/* Tokutek memory allocation functions and macros.
+ * These are functions for malloc and free */
+
+int toku_memory_startup(void) __attribute__((constructor));
+void toku_memory_shutdown(void) __attribute__((destructor));
+
+/* Generally: errno is set to 0 or a value to indicate problems. */
+
+// Everything should call toku_malloc() instead of malloc(), and toku_calloc() instead of calloc()
+// That way the tests can can, e.g., replace the malloc function using toku_set_func_malloc().
+void *toku_calloc(size_t nmemb, size_t size) __attribute__((__visibility__("default")));
+void *toku_xcalloc(size_t nmemb, size_t size) __attribute__((__visibility__("default")));
+void *toku_malloc(size_t size) __attribute__((__visibility__("default")));
+void *toku_malloc_aligned(size_t alignment, size_t size) __attribute__((__visibility__("default")));
+
+// xmalloc aborts instead of return NULL if we run out of memory
+void *toku_xmalloc(size_t size) __attribute__((__visibility__("default")));
+void *toku_xrealloc(void*, size_t size) __attribute__((__visibility__("default")));
+void *toku_xmalloc_aligned(size_t alignment, size_t size) __attribute__((__visibility__("default")));
+// Effect: Perform a os_malloc_aligned(size) with the additional property that the returned pointer is a multiple of ALIGNMENT.
+// Fail with a resource_assert if the allocation fails (don't return an error code).
+// If the alloc_aligned function has been set then call it instead.
+// Requires: alignment is a power of two.
+
+void toku_free(void*) __attribute__((__visibility__("default")));
+void *toku_realloc(void *, size_t size) __attribute__((__visibility__("default")));
+void *toku_realloc_aligned(size_t alignment, void *p, size_t size) __attribute__((__visibility__("default")));
+// Effect: Perform a os_realloc_aligned(alignment, p, size) which has the additional property that the returned pointer is a multiple of ALIGNMENT.
+// If the malloc_aligned function has been set then call it instead.
+// Requires: alignment is a power of two.
+
+size_t toku_malloc_usable_size(void *p) __attribute__((__visibility__("default")));
+
+/* MALLOC is a macro that helps avoid a common error:
+ * Suppose I write
+ * struct foo *x = malloc(sizeof(struct foo));
+ * That works fine. But if I change it to this, I've probably made an mistake:
+ * struct foo *x = malloc(sizeof(struct bar));
+ * It can get worse, since one might have something like
+ * struct foo *x = malloc(sizeof(struct foo *))
+ * which looks reasonable, but it allocoates enough to hold a pointer instead of the amount needed for the struct.
+ * So instead, write
+ * struct foo *MALLOC(x);
+ * and you cannot go wrong.
+ */
+#define MALLOC(v) CAST_FROM_VOIDP(v, toku_malloc(sizeof(*v)))
+/* MALLOC_N is like calloc(Except no 0ing of data): It makes an array. Write
+ * int *MALLOC_N(5,x);
+ * to make an array of 5 integers.
+ */
+#define MALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_malloc((n)*sizeof(*v)))
+#define MALLOC_N_ALIGNED(align, n, v) CAST_FROM_VOIDP(v, toku_malloc_aligned((align), (n)*sizeof(*v)))
+
+
+//CALLOC_N is like calloc with auto-figuring out size of members
+#define CALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_calloc((n), sizeof(*v)))
+
+#define CALLOC(v) CALLOC_N(1,v)
+
+#define REALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_realloc(v, (n)*sizeof(*v)))
+#define REALLOC_N_ALIGNED(align, n,v) CAST_FROM_VOIDP(v, toku_realloc_aligned((align), v, (n)*sizeof(*v)))
+
+// XMALLOC macros are like MALLOC except they abort if the operation fails
+#define XMALLOC(v) CAST_FROM_VOIDP(v, toku_xmalloc(sizeof(*v)))
+#define XMALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_xmalloc((n)*sizeof(*v)))
+#define XCALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_xcalloc((n), (sizeof(*v))))
+#define XCALLOC(v) XCALLOC_N(1,(v))
+#define XREALLOC(v,s) CAST_FROM_VOIDP(v, toku_xrealloc(v, s))
+#define XREALLOC_N(n,v) CAST_FROM_VOIDP(v, toku_xrealloc(v, (n)*sizeof(*v)))
+
+#define XMALLOC_N_ALIGNED(align, n, v) CAST_FROM_VOIDP(v, toku_xmalloc_aligned((align), (n)*sizeof(*v)))
+
+#define XMEMDUP(dst, src) CAST_FROM_VOIDP(dst, toku_xmemdup(src, sizeof(*src)))
+#define XMEMDUP_N(dst, src, len) CAST_FROM_VOIDP(dst, toku_xmemdup(src, len))
+
+// ZERO_ARRAY writes zeroes to a stack-allocated array
+#define ZERO_ARRAY(o) do { memset((o), 0, sizeof (o)); } while (0)
+// ZERO_STRUCT writes zeroes to a stack-allocated struct
+#define ZERO_STRUCT(o) do { memset(&(o), 0, sizeof (o)); } while (0)
+
+/* Copy memory. Analogous to strdup() */
+void *toku_memdup (const void *v, size_t len);
+/* Toku-version of strdup. Use this so that it calls toku_malloc() */
+char *toku_strdup (const char *s) __attribute__((__visibility__("default")));
+
+/* Copy memory. Analogous to strdup() Crashes instead of returning NULL */
+void *toku_xmemdup (const void *v, size_t len) __attribute__((__visibility__("default")));
+/* Toku-version of strdup. Use this so that it calls toku_xmalloc() Crashes instead of returning NULL */
+char *toku_xstrdup (const char *s) __attribute__((__visibility__("default")));
+
+void toku_malloc_cleanup (void); /* Before exiting, call this function to free up any internal data structures from toku_malloc. Otherwise valgrind will complain of memory leaks. */
+
+/* Check to see if everything malloc'd was free. Might be a no-op depending on how memory.c is configured. */
+void toku_memory_check_all_free (void);
+/* Check to see if memory is "sane". Might be a no-op. Probably better to simply use valgrind. */
+void toku_do_memory_check(void);
+
+typedef void *(*malloc_fun_t)(size_t);
+typedef void (*free_fun_t)(void*);
+typedef void *(*realloc_fun_t)(void*,size_t);
+typedef void *(*malloc_aligned_fun_t)(size_t /*alignment*/, size_t /*size*/);
+typedef void *(*realloc_aligned_fun_t)(size_t /*alignment*/, void */*pointer*/, size_t /*size*/);
+
+void toku_set_func_malloc(malloc_fun_t f);
+void toku_set_func_xmalloc_only(malloc_fun_t f);
+void toku_set_func_malloc_only(malloc_fun_t f);
+void toku_set_func_realloc(realloc_fun_t f);
+void toku_set_func_xrealloc_only(realloc_fun_t f);
+void toku_set_func_realloc_only(realloc_fun_t f);
+void toku_set_func_free(free_fun_t f);
+
+typedef struct memory_status {
+ uint64_t malloc_count; // number of malloc operations
+ uint64_t free_count; // number of free operations
+ uint64_t realloc_count; // number of realloc operations
+ uint64_t malloc_fail; // number of malloc operations that failed
+ uint64_t realloc_fail; // number of realloc operations that failed
+ uint64_t requested; // number of bytes requested
+ uint64_t used; // number of bytes used (requested + overhead), obtained from malloc_usable_size()
+ uint64_t freed; // number of bytes freed;
+ volatile uint64_t max_in_use; // maximum memory footprint (used - freed), approximate (not worth threadsafety overhead for exact)
+ const char *mallocator_version;
+ uint64_t mmap_threshold;
+} LOCAL_MEMORY_STATUS_S, *LOCAL_MEMORY_STATUS;
+
+void toku_memory_get_status(LOCAL_MEMORY_STATUS s);
+
+size_t toku_memory_footprint(void * p, size_t touched);
+
+#endif
diff --git a/storage/tokudb/ft-index/toku_include/old-db.h b/storage/tokudb/ft-index/toku_include/old-db.h
new file mode 100644
index 00000000000..eb23b6cfbb5
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/old-db.h
@@ -0,0 +1,275 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+#ifndef _YOBI_DB_H
+#define _YOBI_DB_H
+
+#include "ydb-constants.h"
+
+
+#include <sys/types.h>
+#include <stdio.h>
+
+typedef enum {
+ DB_BTREE=1,
+ // DB_HASH=2,
+ // DB_RECNO=3,
+ // DB_QUEUE=4,
+ // DB_UNKNOWN=5 /* Figure it out on open. */
+} DBTYPE;
+
+typedef enum {
+ DB_NOTICE_LOGFILE_CHANGED
+} db_notices;
+
+enum {
+ DB_VERB_CHKPOINT = 0x0001,
+ DB_VERB_DEADLOCK = 0x0002,
+ DB_VERB_RECOVERY = 0x0004
+
+};
+
+typedef struct yobi_db DB;
+typedef struct yobi_db_btree_stat DB_BTREE_STAT;
+typedef struct yobi_db_env DB_ENV;
+typedef struct yobi_db_key_range DB_KEY_RANGE;
+typedef struct yobi_db_lsn DB_LSN;
+typedef struct yobi_db_txn DB_TXN;
+typedef struct yobi_db_txn_active DB_TXN_ACTIVE;
+typedef struct yobi_db_txn_stat DB_TXN_STAT;
+typedef struct yobi_dbc DBC;
+typedef struct yobi_dbt DBT;
+
+struct yobi_db {
+ void *app_private;
+ int (*close) (DB *, uint32_t);
+ int (*cursor) (DB *, DB_TXN *, DBC **, uint32_t);
+ int (*del) (DB *, DB_TXN *, DBT *, uint32_t);
+ int (*get) (DB *, DB_TXN *, DBT *, DBT *, uint32_t);
+ int (*key_range) (DB *, DB_TXN *, DBT *, DB_KEY_RANGE *, uint32_t);
+ int (*open) (DB *, DB_TXN *,
+ const char *, const char *, DBTYPE, uint32_t, int);
+ int (*put) (DB *, DB_TXN *, DBT *, DBT *, uint32_t);
+ int (*remove) (DB *, const char *, const char *, uint32_t);
+ int (*rename) (DB *, const char *, const char *, const char *, uint32_t);
+ int (*set_bt_compare) (DB *,
+ int (*)(DB *, const DBT *, const DBT *));
+ int (*set_flags) (DB *, uint32_t);
+ int (*stat) (DB *, void *, uint32_t);
+
+ struct ydb_db_internal *i;
+};
+enum {
+ DB_DBT_MALLOC = 0x002,
+ DB_DBT_REALLOC = 0x010,
+ DB_DBT_USERMEM = 0x020,
+ DB_DBT_DUPOK = 0x040
+};
+struct yobi_dbt {
+ void *app_private;
+ void *data;
+ uint32_t flags;
+ uint32_t size;
+ uint32_t ulen;
+};
+struct yobi_db_txn {
+ int (*commit) (DB_TXN*, uint32_t);
+ uint32_t (*id) (DB_TXN *);
+ // internal stuff
+ struct yobi_db_txn_internal *i;
+};
+struct yobi_dbc {
+ int (*c_get) (DBC *, DBT *, DBT *, uint32_t);
+ int (*c_close) (DBC *);
+ int (*c_del) (DBC *, uint32_t);
+ struct yobi_dbc_internal *i;
+};
+struct yobi_db_env {
+ // Methods used by MYSQL
+ void (*err) (const DB_ENV *, int, const char *, ...);
+ int (*open) (DB_ENV *, const char *, uint32_t, int);
+ int (*close) (DB_ENV *, uint32_t);
+ int (*txn_checkpoint) (DB_ENV *, uint32_t, uint32_t, uint32_t);
+ int (*log_flush) (DB_ENV *, const DB_LSN *);
+ void (*set_errcall) (DB_ENV *, void (*)(const char *, char *));
+ void (*set_errpfx) (DB_ENV *, const char *);
+ void (*set_noticecall) (DB_ENV *, void (*)(DB_ENV *, db_notices));
+ int (*set_flags) (DB_ENV *, uint32_t, int);
+ int (*set_data_dir) (DB_ENV *, const char *);
+ int (*set_tmp_dir) (DB_ENV *, const char *);
+ int (*set_verbose) (DB_ENV *, uint32_t, int);
+ int (*set_lg_bsize) (DB_ENV *, uint32_t);
+ int (*set_lg_dir) (DB_ENV *, const char *);
+ int (*set_lg_max) (DB_ENV *, uint32_t);
+ int (*set_cachesize) (DB_ENV *, uint32_t, uint32_t, int);
+ int (*set_lk_detect) (DB_ENV *, uint32_t);
+ int (*set_lk_max) (DB_ENV *, uint32_t);
+ int (*log_archive) (DB_ENV *, char **[], uint32_t);
+ int (*txn_stat) (DB_ENV *, DB_TXN_STAT **, uint32_t);
+#ifdef _YDB_WRAP_H
+#undef txn_begin
+#endif
+ int (*txn_begin) (DB_ENV *, DB_TXN *, DB_TXN **, uint32_t);
+#ifdef _YDB_WRAP_H
+#define txn_begin txn_begin_ydb
+#endif
+ // Internal state
+ struct db_env_ydb_internal *i;
+};
+struct yobi_db_key_range {
+ double less,equal,greater;
+};
+struct yobi_db_btree_stat {
+ uint32_t bt_ndata;
+ uint32_t bt_nkeys;
+};
+struct yobi_db_txn_stat {
+ uint32_t st_nactive;
+ DB_TXN_ACTIVE *st_txnarray;
+};
+struct yobi_db_lsn {
+ int hello;
+};
+struct yobi_db_txn_active {
+ DB_LSN lsn;
+ uint32_t txnid;
+};
+
+#ifndef _YDB_WRAP_H
+#define DB_VERSION_STRING "Yobiduck: Fractal DB (November 19, 2006)"
+#else
+#define DB_VERSION_STRING_ydb "Yobiduck: Fractal DB (November 19, 2006) (wrapped bdb)"
+#endif
+
+enum {
+ DB_ARCH_ABS = 0x001,
+ DB_ARCH_LOG = 0x004
+};
+
+enum {
+ DB_CREATE = 0x0000001,
+ DB_RDONLY = 0x0000010,
+ DB_RECOVER = 0x0000020,
+ DB_THREAD = 0x0000040,
+ DB_TXN_NOSYNC = 0x0000100,
+
+ DB_PRIVATE = 0x0100000
+};
+
+enum {
+ DB_LOCK_DEFAULT = 1,
+ DB_LOCK_OLDEST = 7,
+ DB_LOCK_RANDOM = 8
+};
+
+enum {
+ DB_DUP = 0x000002
+};
+
+enum {
+ DB_NOOVERWRITE = 23
+};
+
+enum {
+ DB_INIT_LOCK = 0x001000,
+ DB_INIT_LOG = 0x002000,
+ DB_INIT_MPOOL = 0x004000,
+ DB_INIT_TXN = 0x008000
+};
+
+int db_create (DB **, DB_ENV *, uint32_t);
+int db_env_create (DB_ENV **, uint32_t);
+
+int txn_begin (DB_ENV *, DB_TXN *, DB_TXN **, uint32_t);
+int txn_commit (DB_TXN *, uint32_t);
+int txn_abort (DB_TXN *);
+
+int log_compare (const DB_LSN *, const DB_LSN *);
+
+#endif
diff --git a/storage/tokudb/ft-index/toku_include/rdtsc.h b/storage/tokudb/ft-index/toku_include/rdtsc.h
new file mode 100644
index 00000000000..047d4be58f7
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/rdtsc.h
@@ -0,0 +1,126 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+// read the processor time stamp register
+
+#if defined __ICC
+
+#define USE_RDTSC 1
+#define rdtsc _rdtsc
+
+#elif defined __i386__
+
+#define USE_RDTSC 1
+
+static inline unsigned long long rdtsc(void) {
+ unsigned long hi, lo;
+ __asm__ __volatile__ ("rdtsc\n"
+ "movl %%edx,%0\n"
+ "movl %%eax,%1" : "=r"(hi), "=r"(lo) : : "edx", "eax");
+ return ((unsigned long long) hi << 32ULL) + (unsigned long long) lo;
+}
+
+#elif defined __x86_64__
+
+#define USE_RDTSC 1
+
+static inline unsigned long long rdtsc(void) {
+ unsigned long long r;
+ __asm__ __volatile__ ("rdtsc\n"
+ "shl $32,%%rdx\n"
+ "or %%rdx,%%rax\n"
+ "movq %%rax,%0" : "=r"(r) : : "edx", "eax", "rdx", "rax");
+ return r;
+}
+
+#else
+
+#define USE_RDTSC 0
+
+#endif
diff --git a/storage/tokudb/ft-index/toku_include/toku_assert.h b/storage/tokudb/ft-index/toku_include/toku_assert.h
new file mode 100644
index 00000000000..79bdd18f3ef
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_assert.h
@@ -0,0 +1,196 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+#ifndef TOKU_ASSERT_H
+#define TOKU_ASSERT_H
+/* The problem with assert.h: If NDEBUG is set then it doesn't execute the function, if NDEBUG isn't set then we get a branch that isn't taken. */
+/* This version will complain if NDEBUG is set. */
+/* It evaluates the argument and then calls a function toku_do_assert() which takes all the hits for the branches not taken. */
+
+#include "toku_config.h"
+
+#include <stdint.h>
+#include <errno.h>
+
+#ifdef NDEBUG
+#error NDEBUG should not be set
+#endif
+
+
+static inline int get_error_errno(void);
+
+static inline int
+get_maybe_error_errno(void)
+{
+ return errno;
+}
+
+static inline void
+set_errno(int new_errno)
+{
+ errno = new_errno;
+}
+
+void toku_assert_init(void) __attribute__((constructor));
+
+void toku_assert_set_fpointers(int (*toku_maybe_get_engine_status_text_pointer)(char*, int),
+ void (*toku_maybe_set_env_panic_pointer)(int, const char*),
+ uint64_t num_rows);
+
+void toku_do_assert(int /*expr*/,const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default")));
+
+void toku_do_assert_fail(const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
+void toku_do_assert_zero_fail(uintptr_t/*expr*/, const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
+void toku_do_assert_expected_fail(uintptr_t/*expr*/, uintptr_t /*expected*/, const char*/*expr_as_string*/,const char */*fun*/,const char*/*file*/,int/*line*/, int/*errno*/) __attribute__((__visibility__("default"))) __attribute__((__noreturn__));
+
+// Define GCOV if you want to get test-coverage information that ignores the assert statements.
+// #define GCOV
+
+extern void (*do_assert_hook)(void); // Set this to a function you want called after printing the assertion failure message but before calling abort(). By default this is NULL.
+
+#if defined(GCOV) || TOKU_WINDOWS
+#define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno())
+#define assert_zero(expr) toku_do_assert((expr) == 0, #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno())
+#define assert_equals(expr, expected) toku_do_assert((expr) == (expected), (expected), #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno())
+#else
+#define assert(expr) ((expr) ? (void)0 : toku_do_assert_fail(#expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno()))
+#define assert_zero(expr) ((expr) == 0 ? (void)0 : toku_do_assert_zero_fail((uintptr_t)(expr), #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno()))
+#define assert_equals(expr, expected) ((expr) == (expected) ? (void)0 : toku_do_assert_expected_fail((uintptr_t)(expr), (uintptr_t)(expected), #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno()))
+#define assert_null(expr) ((expr) == nullptr ? (void)0 : toku_do_assert_zero_fail((uintptr_t)(expr), #expr, __FUNCTION__, __FILE__, __LINE__, get_maybe_error_errno()))
+#endif
+
+#ifdef GCOV
+#define WHEN_GCOV(x) x
+#define WHEN_NOT_GCOV(x)
+#else
+#define WHEN_GCOV(x)
+#define WHEN_NOT_GCOV(x) x
+#endif
+
+#if !defined(__clang__)
+#include <type_traits>
+# define ENSURE_POD(type) static_assert(std::is_pod<type>::value, #type " isn't POD")
+#else
+# define ENSURE_POD(type) // TEMP, clang is much more strict about POD.
+#endif
+
+#define lazy_assert(a) assert(a) // indicates code is incomplete
+#define lazy_assert_zero(a) assert_zero(a) // indicates code is incomplete
+#define lazy_assert_equals(a, b) assert_equals(a, b) // indicates code is incomplete
+#define invariant(a) assert(a) // indicates a code invariant that must be true
+#define invariant_null(a) assert_null(a) // indicates a code invariant that must be true
+#define invariant_notnull(a) assert(a) // indicates a code invariant that must be true
+#define invariant_zero(a) assert_zero(a) // indicates a code invariant that must be true
+#define invariant_equals(a, b) assert_equals(a, b) // indicates a code invariant that must be true
+#define resource_assert(a) assert(a) // indicates resource must be available, otherwise unrecoverable
+#define resource_assert_zero(a) assert_zero(a) // indicates resource must be available, otherwise unrecoverable
+#define resource_assert_equals(a, b) assert_equals(a, b) // indicates resource must be available, otherwise unrecoverable
+
+#if TOKU_DEBUG_PARANOID
+#define paranoid_invariant(a) assert(a)
+#define paranoid_invariant_null(a) assert_null(a)
+#define paranoid_invariant_notnull(a) assert(a)
+#define paranoid_invariant_zero(a) assert_zero(a)
+#else // !TOKU_DEBUG_PARANOID
+#define paranoid_invariant(a) ((void) 0)
+#define paranoid_invariant_null(a) ((void) 0)
+#define paranoid_invariant_notnull(a) ((void) 0)
+#define paranoid_invariant_zero(a) ((void) 0)
+#endif
+
+static inline int
+get_error_errno(void)
+{
+ invariant(errno);
+ return errno;
+}
+
+extern bool toku_gdb_dump_on_assert;
+
+#endif
diff --git a/storage/tokudb/ft-index/toku_include/toku_config.h.in b/storage/tokudb/ft-index/toku_include/toku_config.h.in
new file mode 100644
index 00000000000..c56674ece9e
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_config.h.in
@@ -0,0 +1,67 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#ident "$Id$"
+#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+
+#define TOKUDB_REVISION @CMAKE_TOKUDB_REVISION@
+
+#cmakedefine TOKU_DEBUG_PARANOID 1
+#cmakedefine USE_VALGRIND 1
+
+#cmakedefine HAVE_ALLOCA_H 1
+#cmakedefine HAVE_ARPA_INET_H 1
+#cmakedefine HAVE_BYTESWAP_H 1
+#cmakedefine HAVE_ENDIAN_H 1
+#cmakedefine HAVE_FCNTL_H 1
+#cmakedefine HAVE_INTTYPES_H 1
+#cmakedefine HAVE_LIBKERN_OSATOMIC_H 1
+#cmakedefine HAVE_LIBKERN_OSBYTEORDER_H 1
+#cmakedefine HAVE_LIMITS_H 1
+#cmakedefine HAVE_MACHINE_ENDIAN_H 1
+#cmakedefine HAVE_MALLOC_H 1
+#cmakedefine HAVE_MALLOC_MALLOC_H 1
+#cmakedefine HAVE_MALLOC_NP_H 1
+#cmakedefine HAVE_PTHREAD_H 1
+#cmakedefine HAVE_PTHREAD_NP_H 1
+#cmakedefine HAVE_STDINT_H 1
+#cmakedefine HAVE_STDLIB_H 1
+#cmakedefine HAVE_STRING_H 1
+#cmakedefine HAVE_SYSCALL_H 1
+#cmakedefine HAVE_SYS_ENDIAN_H 1
+#cmakedefine HAVE_SYS_FILE_H 1
+#cmakedefine HAVE_SYS_MALLOC_H 1
+#cmakedefine HAVE_SYS_RESOURCE_H 1
+#cmakedefine HAVE_SYS_STATVFS_H 1
+#cmakedefine HAVE_SYS_SYSCALL_H 1
+#cmakedefine HAVE_SYS_SYSCTL_H 1
+#cmakedefine HAVE_SYS_SYSLIMITS_H 1
+#cmakedefine HAVE_SYS_TIME_H 1
+#cmakedefine HAVE_UNISTD_H 1
+
+#cmakedefine HAVE_M_MMAP_THRESHOLD 1
+#cmakedefine HAVE_CLOCK_REALTIME 1
+#cmakedefine HAVE_O_DIRECT 1
+#cmakedefine HAVE_F_NOCACHE 1
+
+#cmakedefine HAVE_MALLOC_SIZE 1
+#cmakedefine HAVE_MALLOC_USABLE_SIZE 1
+#cmakedefine HAVE_MEMALIGN 1
+#cmakedefine HAVE_VALLOC 1
+#cmakedefine HAVE_NRAND48 1
+#cmakedefine HAVE_RANDOM_R 1
+
+#cmakedefine HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP 1
+#cmakedefine HAVE_PTHREAD_YIELD 1
+#cmakedefine HAVE_PTHREAD_YIELD_NP 1
+#cmakedefine HAVE_PTHREAD_GETTHREADID_NP 1
+
+#cmakedefine PTHREAD_YIELD_RETURNS_INT 1
+#cmakedefine PTHREAD_YIELD_RETURNS_VOID 1
+
+#cmakedefine HAVE_GNU_TLS 1
+
+#endif /* __CONFIG_H__ */
diff --git a/storage/tokudb/ft-index/toku_include/toku_htod.h b/storage/tokudb/ft-index/toku_include/toku_htod.h
new file mode 100644
index 00000000000..f2b67407080
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_htod.h
@@ -0,0 +1,172 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+
+
+/* Purpose of this file is to provide definitions of
+ * Host to Disk byte transposition functions, an abstraction of
+ * htod32()/dtoh32() and htod16()/dtoh16() functions.
+ *
+ * These htod/dtoh functions will only perform the transposition
+ * if the disk and host are defined to be in opposite endian-ness.
+ * If we define the disk to be in host order, then no byte
+ * transposition is performed. (We might do this to save the
+ * the time used for byte transposition.)
+ *
+ * This abstraction layer allows us to define the disk to be in
+ * any byte order with a single compile-time switch (in htod.c).
+ *
+ * NOTE: THIS FILE DOES NOT CURRENTLY SUPPORT A BIG-ENDIAN
+ * HOST AND A LITTLE-ENDIAN DISK.
+ */
+
+#ifndef _TOKU_HTOD_H
+#define _TOKU_HTOD_H
+
+#include "toku_config.h"
+
+#if defined(HAVE_ENDIAN_H)
+# include <endian.h>
+#elif defined(HAVE_MACHINE_ENDIAN_H)
+# include <machine/endian.h>
+# define __BYTE_ORDER __DARWIN_BYTE_ORDER
+# define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+# define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+#endif
+#if !defined(__BYTE_ORDER) || \
+ !defined(__LITTLE_ENDIAN) || \
+ !defined(__BIG_ENDIAN)
+#error Standard endianness things not all defined
+#endif
+
+
+static const int64_t toku_byte_order_host = 0x0102030405060708LL;
+
+#define NETWORK_BYTE_ORDER (__BIG_ENDIAN)
+#define INTEL_BYTE_ORDER (__LITTLE_ENDIAN)
+#define HOST_BYTE_ORDER (__BYTE_ORDER)
+
+//DISK_BYTE_ORDER is the byte ordering for integers written to disk.
+//If DISK_BYTE_ORDER is the same as HOST_BYTE_ORDER no conversions are necessary.
+//Otherwise some structures require conversion to HOST_BYTE_ORDER on loading from disk (HOST_BYTE_ORDER in memory), and
+//others require conversion to HOST_BYTE_ORDER on every access/mutate (DISK_BYTE_ORDER in memory).
+#define DISK_BYTE_ORDER (INTEL_BYTE_ORDER)
+
+#if HOST_BYTE_ORDER!=INTEL_BYTE_ORDER
+//Even though the functions are noops if DISK==HOST, we do not have the logic to test whether the file was moved from another BYTE_ORDER machine.
+#error Only intel byte order supported so far.
+#endif
+
+#if DISK_BYTE_ORDER == HOST_BYTE_ORDER
+static inline uint64_t
+toku_dtoh64(uint64_t i) {
+ return i;
+}
+
+static inline uint64_t
+toku_htod64(uint64_t i) {
+ return i;
+}
+
+static inline uint32_t
+toku_dtoh32(uint32_t i) {
+ return i;
+}
+
+static inline uint32_t
+toku_htod32(uint32_t i) {
+ return i;
+}
+#else
+#error Not supported
+#endif
+
+
+
+#endif
+
diff --git a/storage/tokudb/ft-index/toku_include/toku_list.h b/storage/tokudb/ft-index/toku_include/toku_list.h
new file mode 100644
index 00000000000..d8d6fb0bfce
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_list.h
@@ -0,0 +1,182 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ifndef _TOKUDB_LIST_H
+#define _TOKUDB_LIST_H
+
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007, 2008, 2009 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+
+//TODO: #1378 This is not threadsafe. Make sure when splitting locks
+//that we protect these calls.
+
+
+// This toku_list is intended to be embedded in other data structures.
+struct toku_list {
+ struct toku_list *next, *prev;
+};
+
+static inline int toku_list_num_elements_est(struct toku_list *head) {
+ if (head->next == head) return 0;
+ if (head->next == head->prev) return 1;
+ return 2;
+}
+
+
+static inline void toku_list_init(struct toku_list *head) {
+ head->next = head->prev = head;
+}
+
+static inline int toku_list_empty(struct toku_list *head) {
+ return head->next == head;
+}
+
+static inline struct toku_list *toku_list_head(struct toku_list *head) {
+ return head->next;
+}
+
+static inline struct toku_list *toku_list_tail(struct toku_list *head) {
+ return head->prev;
+}
+
+static inline void toku_list_insert_between(struct toku_list *a, struct toku_list *toku_list, struct toku_list *b) {
+
+ toku_list->next = a->next;
+ toku_list->prev = b->prev;
+ a->next = b->prev = toku_list;
+}
+
+static inline void toku_list_push(struct toku_list *head, struct toku_list *toku_list) {
+ toku_list_insert_between(head->prev, toku_list, head);
+}
+
+static inline void toku_list_push_head(struct toku_list *head, struct toku_list *toku_list) {
+ toku_list_insert_between(head, toku_list, head->next);
+}
+
+static inline void toku_list_remove(struct toku_list *toku_list) {
+ struct toku_list *prev = toku_list->prev;
+ struct toku_list *next = toku_list->next;
+ next->prev = prev;
+ prev->next = next;
+ toku_list_init(toku_list); // Set the toku_list element to be empty
+}
+
+static inline struct toku_list *toku_list_pop(struct toku_list *head) {
+ struct toku_list *toku_list = head->prev;
+ toku_list_remove(toku_list);
+ return toku_list;
+}
+
+static inline struct toku_list *toku_list_pop_head(struct toku_list *head) {
+ struct toku_list *toku_list = head->next;
+ toku_list_remove(toku_list);
+ return toku_list;
+}
+
+static inline void toku_list_move(struct toku_list *newhead, struct toku_list *oldhead) {
+ struct toku_list *first = oldhead->next;
+ struct toku_list *last = oldhead->prev;
+ // assert(!toku_list_empty(oldhead));
+ newhead->next = first;
+ newhead->prev = last;
+ last->next = first->prev = newhead;
+ toku_list_init(oldhead);
+}
+
+// Note: Need the extra level of parens in these macros so that
+// toku_list_struct(h, foo, b)->zot
+// will work right. Otherwise the type cast will try to include ->zot, and it will be all messed up.
+#if ((defined(__GNUC__) && __GNUC__ >= 4) || defined(__builtin_offsetof) ) && !defined(__clang__)
+#define toku_list_struct(p, t, f) ((t*)((char*)(p) - __builtin_offsetof(t, f)))
+#else
+#define toku_list_struct(p, t, f) ((t*)((char*)(p) - ((char*)&((t*)0)->f)))
+#endif
+
+
+
+#endif
diff --git a/storage/tokudb/ft-index/toku_include/toku_os.h b/storage/tokudb/ft-index/toku_include/toku_os.h
new file mode 100644
index 00000000000..f7b3ad2c0a6
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_os.h
@@ -0,0 +1,185 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+
+#ifndef TOKU_OS_H
+#define TOKU_OS_H
+
+#include <dirent.h>
+#include <sys/time.h>
+
+#include <toku_os_types.h>
+
+// Returns: the current process id
+int toku_os_getpid(void) __attribute__((__visibility__("default")));
+
+// Returns: the current thread id
+int toku_os_gettid(void) __attribute__((__visibility__("default")));
+
+// Returns: the number of processors in the system
+int toku_os_get_number_processors(void);
+
+// Returns: the number of active processors in the system
+int toku_os_get_number_active_processors(void);
+
+// Returns: the system page size (in bytes)
+int toku_os_get_pagesize(void);
+
+// Returns: the size of physical memory (in bytes)
+uint64_t toku_os_get_phys_memory_size(void) __attribute__((__visibility__("default")));
+
+// Returns the processor frequency in Hz
+// Returns 0 if success
+int toku_os_get_processor_frequency(uint64_t *hz);
+
+// Returns: 0 on success
+// sets fsize to the number of bytes in a file
+int toku_os_get_file_size(int fildes, int64_t *fsize) __attribute__((__visibility__("default")));
+
+// Returns: 0 on success
+// Initializes id as a unique fileid for fildes on success.
+int toku_os_get_unique_file_id(int fildes, struct fileid *id);
+
+//Locks a file (should not be open to begin with).
+//Returns: file descriptor (or -1 on error)
+int toku_os_lock_file(const char *name);
+
+//Unlocks and closes a file locked by toku_os_lock_on_file
+int toku_os_unlock_file(int fildes);
+
+int toku_os_mkdir(const char *pathname, mode_t mode) __attribute__((__visibility__("default")));
+
+// Get the current process user and kernel use times
+int toku_os_get_process_times(struct timeval *usertime, struct timeval *kerneltime);
+
+// Get the maximum size of the process data size (in bytes)
+// Success: returns 0 and sets *maxdata to the data size
+// Fail: returns an error number
+int toku_os_get_max_process_data_size(uint64_t *maxdata) __attribute__((__visibility__("default")));
+
+int toku_os_initialize_settings(int verbosity) __attribute__((__visibility__("default")));
+
+bool toku_os_is_absolute_name(const char* path) __attribute__((__visibility__("default")));
+
+// Set whether or not writes assert when ENOSPC is returned or they wait for space
+void toku_set_assert_on_write_enospc(int do_assert) __attribute__((__visibility__("default")));
+
+// Get file system write information
+// *enospc_last_time is the last time ENOSPC was returned by write or pwrite
+// *enospc_current is the number of threads waiting on space
+// *enospc_total is the number of times ENOSPC was returned by write or pwrite
+void toku_fs_get_write_info(time_t *enospc_last_time, uint64_t *enospc_current, uint64_t *enospc_total);
+
+void toku_fsync_dirfd_without_accounting(DIR *dirp);
+
+int toku_fsync_dir_by_name_without_accounting(const char *dir_name);
+
+// Get the file system free and total space for the file system that contains a path name
+// *avail_size is set to the bytes of free space in the file system available for non-root
+// *free_size is set to the bytes of free space in the file system
+// *total_size is set to the total bytes in the file system
+// Return 0 on success, otherwise an error number
+int toku_get_filesystem_sizes(const char *path, uint64_t *avail_size, uint64_t *free_size, uint64_t *total_size);
+
+#if TOKU_WINDOWS
+#include <sys/types.h>
+#include <sys/stat.h>
+//Test if st_mode (from stat) is a directory
+#define S_ISDIR(bitvector) (((bitvector)&_S_IFDIR)!=0)
+#endif
+
+// Portable linux 'stat'
+int toku_stat(const char *name, toku_struct_stat *statbuf) __attribute__((__visibility__("default")));
+// Portable linux 'fstat'
+int toku_fstat(int fd, toku_struct_stat *statbuf) __attribute__((__visibility__("default")));
+
+// Portable linux 'dup2'
+int toku_dup2(int fd, int fd2) __attribute__((__visibility__("default")));
+
+#endif /* TOKU_OS_H */
diff --git a/storage/tokudb/ft-index/toku_include/toku_portability.h b/storage/tokudb/ft-index/toku_include/toku_portability.h
new file mode 100644
index 00000000000..97bb70b9c15
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_portability.h
@@ -0,0 +1,433 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+#ifndef TOKU_PORTABILITY_H
+#define TOKU_PORTABILITY_H
+
+#include "toku_config.h"
+
+// Tokutek portability layer
+
+#if defined(__clang__)
+# define constexpr_static_assert(a, b)
+#else
+# define constexpr_static_assert(a, b) static_assert(a, b)
+#endif
+
+#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(__ICL))
+
+#define TOKU_WINDOWS 1
+#define DEV_NULL_FILE "NUL"
+
+# if defined(_WIN64)
+# define TOKU_WINDOWS_32 0
+# define TOKU_WINDOWS_64 1
+# else
+# define TOKU_WINDOWS_32 1
+# define TOKU_WINDOWS_64 2
+#endif
+
+#else
+
+#define TOKU_WINDOWS 0
+#define TOKU_WINDOWS_32 0
+#define TOKU_WINDOWS_64 0
+#define DEV_NULL_FILE "/dev/null"
+
+#endif
+
+// include here, before they get deprecated
+#include <toku_atomic.h>
+
+#if TOKU_WINDOWS
+// Windows
+
+#define DO_GCC_PRAGMA(x) /* Nothing */
+
+#if defined(__ICL)
+#define __attribute__(x) /* Nothing */
+#endif
+
+#include <malloc.h>
+#include "toku_stdint.h"
+
+#ifndef TOKU_OFF_T_DEFINED
+#define TOKU_OFF_T_DEFINED
+typedef int64_t toku_off_t;
+#endif
+
+#include <direct.h>
+#include <sys/types.h>
+#include "unistd.h"
+#include "misc.h"
+#include "toku_pthread.h"
+
+#define UNUSED_WARNING(a) a=a /* To make up for missing attributes */
+
+#define cast_to_typeof(v)
+
+#elif defined(__INTEL_COMPILER)
+
+#define DO_GCC_PRAGMA(x) /* Nothing */
+
+#if defined(__ICC)
+// Intel linux
+
+#include <alloca.h>
+#include <toku_stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <stdio.h>
+
+#define static_assert(foo, bar)
+#endif
+
+#if defined(__cplusplus)
+# define cast_to_typeof(v) (decltype(v))
+#else
+# define cast_to_typeof(v) (__typeof__(v))
+#endif
+
+#elif defined(__GNUC__)
+// GCC linux
+
+#define DO_GCC_PRAGMA(x) _Pragma (#x)
+
+#include <toku_stdint.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#if __FreeBSD__
+#include <stdarg.h>
+#endif
+#if defined(HAVE_ALLOCA_H)
+# include <alloca.h>
+#endif
+#if defined(__cplusplus)
+# include <type_traits>
+#endif
+
+#if defined(__cplusplus)
+# define cast_to_typeof(v) (decltype(v))
+#else
+# define cast_to_typeof(v) (__typeof__(v))
+#endif
+
+#else
+
+#error Not ICC and not GNUC. What compiler?
+
+#endif
+
+// Define some constants for Yama in case the build-machine's software is too old.
+#if !defined(HAVE_PR_SET_PTRACER)
+/*
+ * Set specific pid that is allowed to ptrace the current task.
+ * A value of 0 mean "no process".
+ */
+// Well defined ("Yama" in ascii)
+#define PR_SET_PTRACER 0x59616d61
+#endif
+#if !defined(HAVE_PR_SET_PTRACER_ANY)
+#define PR_SET_PTRACER_ANY ((unsigned long)-1)
+#endif
+
+#if defined(__cplusplus)
+// decltype() here gives a reference-to-pointer instead of just a pointer,
+// just use __typeof__
+# define CAST_FROM_VOIDP(name, value) name = static_cast<__typeof__(name)>(value)
+#else
+# define CAST_FROM_VOIDP(name, value) name = cast_to_typeof(name) (value)
+#endif
+
+#ifndef TOKU_OFF_T_DEFINED
+#define TOKU_OFF_T_DEFINED
+typedef int64_t toku_off_t;
+#endif
+
+#include "toku_os.h"
+#include "toku_htod.h"
+#include "toku_assert.h"
+#include "toku_crash.h"
+
+#define UU(x) x __attribute__((__unused__))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+// Deprecated functions.
+#if !defined(TOKU_ALLOW_DEPRECATED)
+# if defined(__ICL) || defined(__ICC) // Intel Compiler
+# pragma deprecated (creat, fstat, stat, getpid, syscall, sysconf, mkdir, strdup)
+//# pragma poison off_t
+//# pragma poison pthread_attr_t pthread_t
+//# pragma poison pthread_mutexattr_t pthread_mutex_t
+//# pragma poison pthread_condattr_t pthread_cond_t
+//# pragma poison pthread_rwlockattr_t pthread_rwlock_t
+//# pragma poison timespec
+# ifndef DONT_DEPRECATE_WRITES
+# pragma poison write pwrite
+# endif
+# ifndef DONT_DEPRECATE_MALLOC
+# pragma deprecated (malloc, free, realloc)
+# endif
+# ifndef DONT_DEPRECATE_ERRNO
+# pragma deprecated (errno)
+# endif
+# ifndef TOKU_WINDOWS_ALLOW_DEPRECATED
+# pragma poison dup2
+# pragma poison _dup2
+# endif
+# else
+int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__));
+int fstat(int fd, struct stat *buf) __attribute__((__deprecated__));
+int stat(const char *path, struct stat *buf) __attribute__((__deprecated__));
+int getpid(void) __attribute__((__deprecated__));
+# if defined(__FreeBSD__) || defined(__APPLE__)
+int syscall(int __sysno, ...) __attribute__((__deprecated__));
+# else
+long int syscall(long int __sysno, ...) __attribute__((__deprecated__));
+# endif
+// Sadly, dlmalloc needs sysconf, and on linux this causes trouble with -combine. So let the warnings show up under windows only.
+// long int sysconf(int) __attribute__((__deprecated__));
+int mkdir(const char *pathname, mode_t mode) __attribute__((__deprecated__));
+int dup2(int fd, int fd2) __attribute__((__deprecated__));
+int _dup2(int fd, int fd2) __attribute__((__deprecated__));
+// strdup is a macro in some libraries.
+#undef strdup
+# if defined(__FreeBSD__)
+char* strdup(const char *) __malloc_like __attribute__((__deprecated__));
+# elif defined(__APPLE__)
+char* strdup(const char *) __attribute__((__deprecated__));
+# else
+char* strdup(const char *) __THROW __attribute_malloc__ __nonnull ((1)) __attribute__((__deprecated__));
+# endif
+#undef __strdup
+char* __strdup(const char *) __attribute__((__deprecated__));
+# ifndef DONT_DEPRECATE_WRITES
+ssize_t write(int, const void *, size_t) __attribute__((__deprecated__));
+ssize_t pwrite(int, const void *, size_t, off_t) __attribute__((__deprecated__));
+#endif
+# ifndef DONT_DEPRECATE_MALLOC
+# if defined(__FreeBSD__)
+extern void *malloc(size_t) __malloc_like __attribute__((__deprecated__));
+extern void free(void*) __attribute__((__deprecated__));
+extern void *realloc(void*, size_t) __malloc_like __attribute__((__deprecated__));
+# elif defined(__APPLE__)
+extern void *malloc(size_t) __attribute__((__deprecated__));
+extern void free(void*) __attribute__((__deprecated__));
+extern void *realloc(void*, size_t) __attribute__((__deprecated__));
+# else
+extern void *malloc(size_t) __THROW __attribute__((__deprecated__));
+extern void free(void*) __THROW __attribute__((__deprecated__));
+extern void *realloc(void*, size_t) __THROW __attribute__((__deprecated__));
+# endif
+# endif
+# ifndef DONT_DEPRECATE_ERRNO
+//extern int errno __attribute__((__deprecated__));
+# endif
+#if !defined(__APPLE__)
+// Darwin headers use these types, we should not poison them
+# pragma GCC poison u_int8_t
+# pragma GCC poison u_int16_t
+# pragma GCC poison u_int32_t
+# pragma GCC poison u_int64_t
+# pragma GCC poison BOOL
+# pragma GCC poison FALSE
+# pragma GCC poison TRUE
+#endif
+#pragma GCC poison __sync_fetch_and_add
+#pragma GCC poison __sync_fetch_and_sub
+#pragma GCC poison __sync_fetch_and_or
+#pragma GCC poison __sync_fetch_and_and
+#pragma GCC poison __sync_fetch_and_xor
+#pragma GCC poison __sync_fetch_and_nand
+#pragma GCC poison __sync_add_and_fetch
+#pragma GCC poison __sync_sub_and_fetch
+#pragma GCC poison __sync_or_and_fetch
+#pragma GCC poison __sync_and_and_fetch
+#pragma GCC poison __sync_xor_and_fetch
+#pragma GCC poison __sync_nand_and_fetch
+#pragma GCC poison __sync_bool_compare_and_swap
+#pragma GCC poison __sync_val_compare_and_swap
+#pragma GCC poison __sync_synchronize
+#pragma GCC poison __sync_lock_test_and_set
+#pragma GCC poison __sync_release
+# endif
+#endif
+
+#if defined(__cplusplus)
+};
+#endif
+
+void *os_malloc(size_t) __attribute__((__visibility__("default")));
+// Effect: See man malloc(2)
+
+void *os_malloc_aligned(size_t /*alignment*/, size_t /*size*/) __attribute__((__visibility__("default")));
+// Effect: Perform a malloc(size) with the additional property that the returned pointer is a multiple of ALIGNMENT.
+// Requires: alignment is a power of two.
+
+
+void *os_realloc(void*,size_t) __attribute__((__visibility__("default")));
+// Effect: See man realloc(2)
+
+void *os_realloc_aligned(size_t/*alignment*/, void*,size_t) __attribute__((__visibility__("default")));
+// Effect: Perform a realloc(p, size) with the additional property that the returned pointer is a multiple of ALIGNMENT.
+// Requires: alignment is a power of two.
+
+void os_free(void*) __attribute__((__visibility__("default")));
+// Effect: See man free(2)
+
+size_t os_malloc_usable_size(const void *p) __attribute__((__visibility__("default")));
+// Effect: Return an estimate of the usable size inside a pointer. If this function is not defined the memory.cc will
+// look for the jemalloc, libc, or darwin versions of the function for computing memory footprint.
+
+// full_pwrite and full_write performs a pwrite, and checks errors. It doesn't return unless all the data was written. */
+void toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
+void toku_os_full_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
+
+// os_write returns 0 on success, otherwise an errno.
+ssize_t toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
+int toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
+
+// wrappers around file system calls
+FILE * toku_os_fdopen(int fildes, const char *mode);
+FILE * toku_os_fopen(const char *filename, const char *mode);
+int toku_os_open(const char *path, int oflag, int mode);
+int toku_os_open_direct(const char *path, int oflag, int mode);
+int toku_os_close(int fd);
+int toku_os_fclose(FILE * stream);
+ssize_t toku_os_read(int fd, void *buf, size_t count);
+ssize_t toku_os_pread(int fd, void *buf, size_t count, off_t offset);
+void toku_os_recursive_delete(const char *path);
+
+// wrapper around fsync
+void toku_file_fsync_without_accounting(int fd);
+void toku_file_fsync(int fd);
+int toku_fsync_directory(const char *fname);
+
+// get the number of fsync calls and the fsync times (total)
+void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time);
+
+// get the number of fsync calls and the fsync times for use by scheduler (subset of total)
+void toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time);
+
+void toku_set_func_fsync (int (*fsync_function)(int));
+void toku_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
+void toku_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
+void toku_set_func_write (ssize_t (*)(int, const void *, size_t));
+void toku_set_func_full_write (ssize_t (*)(int, const void *, size_t));
+void toku_set_func_fdopen (FILE * (*)(int, const char *));
+void toku_set_func_fopen (FILE * (*)(const char *, const char *));
+void toku_set_func_open (int (*)(const char *, int, int));
+void toku_set_func_fclose(int (*)(FILE*));
+void toku_set_func_read(ssize_t (*)(int, void *, size_t));
+void toku_set_func_pread (ssize_t (*)(int, void *, size_t, off_t));
+
+int toku_portability_init(void);
+void toku_portability_destroy(void);
+
+static inline uint64_t roundup_to_multiple(uint64_t alignment, uint64_t v)
+// Effect: Return X, where X the smallest multiple of ALIGNMENT such that X>=V.
+// Requires: ALIGNMENT is a power of two
+{
+ assert(0==(alignment&(alignment-1))); // alignment must be a power of two
+ uint64_t result = (v+alignment-1)&~(alignment-1);
+ assert(result>=v); // The result is >=V.
+ assert(result%alignment==0); // The result is a multiple of alignment.
+ assert(result<v+alignment); // The result is the smallest such multiple of alignment.
+ return result;
+}
+
+
+#endif /* TOKU_PORTABILITY_H */
diff --git a/storage/tokudb/ft-index/toku_include/toku_race_tools.h b/storage/tokudb/ft-index/toku_include/toku_race_tools.h
new file mode 100644
index 00000000000..fc7c5b7de7d
--- /dev/null
+++ b/storage/tokudb/ft-index/toku_include/toku_race_tools.h
@@ -0,0 +1,141 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
+#ident "$Id$"
+/*
+COPYING CONDITIONS NOTICE:
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License as
+ published by the Free Software Foundation, and provided that the
+ following conditions are met:
+
+ * Redistributions of source code must retain this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below).
+
+ * Redistributions in binary form must reproduce this COPYING
+ CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
+ DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
+ PATENT MARKING NOTICE (below), and the PATENT RIGHTS
+ GRANT (below) in the documentation and/or other materials
+ provided with the distribution.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+COPYRIGHT NOTICE:
+
+ TokuDB, Tokutek Fractal Tree Indexing Library.
+ Copyright (C) 2007-2013 Tokutek, Inc.
+
+DISCLAIMER:
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+UNIVERSITY PATENT NOTICE:
+
+ The technology is licensed by the Massachusetts Institute of
+ Technology, Rutgers State University of New Jersey, and the Research
+ Foundation of State University of New York at Stony Brook under
+ United States of America Serial No. 11/760379 and to the patents
+ and/or patent applications resulting from it.
+
+PATENT MARKING NOTICE:
+
+ This software is covered by US Patent No. 8,185,551.
+
+PATENT RIGHTS GRANT:
+
+ "THIS IMPLEMENTATION" means the copyrightable works distributed by
+ Tokutek as part of the Fractal Tree project.
+
+ "PATENT CLAIMS" means the claims of patents that are owned or
+ licensable by Tokutek, both currently or in the future; and that in
+ the absence of this license would be infringed by THIS
+ IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
+
+ "PATENT CHALLENGE" shall mean a challenge to the validity,
+ patentability, enforceability and/or non-infringement of any of the
+ PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
+
+ Tokutek hereby grants to you, for the term and geographical scope of
+ the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
+ irrevocable (except as stated in this section) patent license to
+ make, have made, use, offer to sell, sell, import, transfer, and
+ otherwise run, modify, and propagate the contents of THIS
+ IMPLEMENTATION, where such license applies only to the PATENT
+ CLAIMS. This grant does not include claims that would be infringed
+ only as a consequence of further modifications of THIS
+ IMPLEMENTATION. If you or your agent or licensee institute or order
+ or agree to the institution of patent litigation against any entity
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
+ THIS IMPLEMENTATION constitutes direct or contributory patent
+ infringement, or inducement of patent infringement, then any rights
+ granted to you under this License shall terminate as of the date
+ such litigation is filed. If you or your agent or exclusive
+ licensee institute or order or agree to the institution of a PATENT
+ CHALLENGE, then Tokutek may terminate any rights granted to you
+ under this License.
+*/
+
+#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
+#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
+#ifndef TOKU_RACE_TOOLS_H
+#define TOKU_RACE_TOOLS_H
+
+#include "toku_config.h"
+
+#if defined(__linux__) && USE_VALGRIND
+
+# include <valgrind/helgrind.h>
+# include <valgrind/drd.h>
+
+# define TOKU_ANNOTATE_NEW_MEMORY(p, size) ANNOTATE_NEW_MEMORY(p, size)
+# define TOKU_VALGRIND_HG_ENABLE_CHECKING(p, size) VALGRIND_HG_ENABLE_CHECKING(p, size)
+# define TOKU_VALGRIND_HG_DISABLE_CHECKING(p, size) VALGRIND_HG_DISABLE_CHECKING(p, size)
+# define TOKU_DRD_IGNORE_VAR(v) DRD_IGNORE_VAR(v)
+# define TOKU_DRD_STOP_IGNORING_VAR(v) DRD_STOP_IGNORING_VAR(v)
+
+/*
+ * How to make helgrind happy about tree rotations and new mutex orderings:
+ *
+ * // Tell helgrind that we unlocked it so that the next call doesn't get a "destroyed a locked mutex" error.
+ * // Tell helgrind that we destroyed the mutex.
+ * VALGRIND_HG_MUTEX_UNLOCK_PRE(&locka);
+ * VALGRIND_HG_MUTEX_DESTROY_PRE(&locka);
+ *
+ * // And recreate it. It would be better to simply be able to say that the order on these two can now be reversed, because this code forgets all the ordering information for this mutex.
+ * // Then tell helgrind that we have locked it again.
+ * VALGRIND_HG_MUTEX_INIT_POST(&locka, 0);
+ * VALGRIND_HG_MUTEX_LOCK_POST(&locka);
+ *
+ * When the ordering of two locks changes, we don't need tell Helgrind about do both locks. Just one is good enough.
+ */
+
+# define TOKU_VALGRIND_RESET_MUTEX_ORDERING_INFO(mutex) \
+ VALGRIND_HG_MUTEX_UNLOCK_PRE(mutex); \
+ VALGRIND_HG_MUTEX_DESTROY_PRE(mutex); \
+ VALGRIND_HG_MUTEX_INIT_POST(mutex, 0); \
+ VALGRIND_HG_MUTEX_LOCK_POST(mutex);
+
+#else // !defined(__linux__) || !USE_VALGRIND
+
+# define NVALGRIND 1
+# define TOKU_ANNOTATE_NEW_MEMORY(p, size) ((void) 0)
+# define TOKU_VALGRIND_HG_ENABLE_CHECKING(p, size) ((void) 0)
+# define TOKU_VALGRIND_HG_DISABLE_CHECKING(p, size) ((void) 0)
+# define TOKU_DRD_IGNORE_VAR(v)
+# define TOKU_DRD_STOP_IGNORING_VAR(v)
+# define TOKU_VALGRIND_RESET_MUTEX_ORDERING_INFO(mutex)
+# define RUNNING_ON_VALGRIND (0U)
+
+#endif
+
+#endif // TOKU_RACE_TOOLS_H