Commit 14200dfa authored by Sergei Golubchik's avatar Sergei Golubchik

tokudb-7.1.7

# Copyright (C) 2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# 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.
#
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTOKUDB_VERSION=\\\"TOKUDB_VERSION_REPLACE_ME\\\"")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
INCLUDE_DIRECTORIES(TOKUDB_DIR_REPLACE_ME/windows
TOKUDB_DIR_REPLACE_ME/src
TOKUDB_DIR_REPLACE_ME/include
TOKUDB_DIR_REPLACE_ME/toku_include)
INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake")
SET(TOKUDB_SOURCES hatoku_hton.cc ha_tokudb.cc hatoku_cmp.cc)
MYSQL_STORAGE_ENGINE(TOKUDB)
TARGET_LINK_LIBRARIES(ha_tokudb PowrProf optimized TOKUDB_OBJ_DIR_REPLACE_ME/opt/ipo_libtokudb optimized TOKUDB_OBJ_DIR_REPLACE_ME/opt/libtokuportability debug TOKUDB_OBJ_DIR_REPLACE_ME/debug/static_libtokudb debug TOKUDB_OBJ_DIR_REPLACE_ME/debug/libtokuportability)
......@@ -24,14 +24,14 @@ working MySQL or MariaDB with Tokutek patches, and with the TokuDB storage
engine, called `make.mysql.bash`. This script will download copies of the
needed source code from github and build everything.
To build MySQL 5.5.36 with TokuDB 7.1.5:
To build MySQL 5.5.37 with TokuDB 7.1.6:
```sh
scripts/make.mysql.bash --mysqlbuild=mysql-5.5.36-tokudb-7.1.5-linux-x86_64
scripts/make.mysql.bash --mysqlbuild=mysql-5.5.37-tokudb-7.1.6-linux-x86_64
```
To build MariaDB 5.5.36 with TokuDB 7.1.5:
To build MariaDB 5.5.37 with TokuDB 7.1.6:
```sh
scripts/make.mysql.bash --mysqlbuild=mariadb-5.5.36-tokudb-7.1.5-linux-x86_64
scripts/make.mysql.bash --mysqlbuild=mariadb-5.5.37-tokudb-7.1.6-linux-x86_64
```
Before you start, make sure you have a C++11-compatible compiler (GCC >=
......
......@@ -6,6 +6,31 @@ project(TokuDB)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
## Versions of gcc >= 4.9.0 require special version of 'ar' and 'ranlib' for
## link-time optimizations to work properly.
##
## From https://gcc.gnu.org/gcc-4.9/changes.html:
##
## When using a linker plugin, compiling with the -flto option now
## generates slim objects files (.o) which only contain intermediate
## language representation for LTO. Use -ffat-lto-objects to create
## files which contain additionally the object code. To generate
## static libraries suitable for LTO processing, use gcc-ar and
## gcc-ranlib; to list symbols from a slim object file use
## gcc-nm. (Requires that ar, ranlib and nm have been compiled with
## plugin support.)
if ((CMAKE_CXX_COMPILER_ID STREQUAL GNU) AND
NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0"))
find_program(gcc_ar "gcc-ar")
if (gcc_ar)
set(CMAKE_AR "${gcc_ar}")
endif ()
find_program(gcc_ranlib "gcc-ranlib")
if (gcc_ranlib)
set(CMAKE_RANLIB "${gcc_ranlib}")
endif ()
endif()
include(TokuFeatureDetection)
include(TokuSetupCompiler)
include(TokuSetupCTest)
......
......@@ -3,35 +3,34 @@ include(ExternalProject)
if (CMAKE_PROJECT_NAME STREQUAL TokuDB)
## add jemalloc with an external project
set(JEMALLOC_SOURCE_DIR "${TokuDB_SOURCE_DIR}/third_party/jemalloc" CACHE FILEPATH "Where to find jemalloc sources.")
if (NOT EXISTS "${JEMALLOC_SOURCE_DIR}/configure")
message(FATAL_ERROR "Can't find jemalloc sources. Please check them out to ${JEMALLOC_SOURCE_DIR} or modify JEMALLOC_SOURCE_DIR.")
endif ()
set(jemalloc_configure_opts "CC=${CMAKE_C_COMPILER}" "--with-jemalloc-prefix=" "--with-private-namespace=tokudb_jemalloc_internal_" "--enable-cc-silence")
option(JEMALLOC_DEBUG "Build jemalloc with --enable-debug." OFF)
if (JEMALLOC_DEBUG)
list(APPEND jemalloc_configure_opts --enable-debug)
endif ()
ExternalProject_Add(build_jemalloc
PREFIX jemalloc
SOURCE_DIR "${JEMALLOC_SOURCE_DIR}"
CONFIGURE_COMMAND
"${JEMALLOC_SOURCE_DIR}/configure" ${jemalloc_configure_opts}
"--prefix=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc"
)
if (EXISTS "${JEMALLOC_SOURCE_DIR}/configure")
set(jemalloc_configure_opts "CC=${CMAKE_C_COMPILER}" "--with-jemalloc-prefix=" "--with-private-namespace=tokudb_jemalloc_internal_" "--enable-cc-silence")
option(JEMALLOC_DEBUG "Build jemalloc with --enable-debug." OFF)
if (JEMALLOC_DEBUG)
list(APPEND jemalloc_configure_opts --enable-debug)
endif ()
ExternalProject_Add(build_jemalloc
PREFIX jemalloc
SOURCE_DIR "${JEMALLOC_SOURCE_DIR}"
CONFIGURE_COMMAND
"${JEMALLOC_SOURCE_DIR}/configure" ${jemalloc_configure_opts}
"--prefix=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc"
)
add_library(jemalloc STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc_pic.a")
add_dependencies(jemalloc build_jemalloc)
add_library(jemalloc_nopic STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc_nopic PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc.a")
add_dependencies(jemalloc_nopic build_jemalloc)
add_library(jemalloc STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc_pic.a")
add_dependencies(jemalloc build_jemalloc)
add_library(jemalloc_nopic STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc_nopic PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc.a")
add_dependencies(jemalloc_nopic build_jemalloc)
# detect when we are being built as a subproject
if (NOT DEFINED MYSQL_PROJECT_NAME_DOCSTRING)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib" DESTINATION .
COMPONENT tokukv_libs_extra)
# detect when we are being built as a subproject
if (NOT DEFINED MYSQL_PROJECT_NAME_DOCSTRING)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib" DESTINATION .
COMPONENT tokukv_libs_extra)
endif ()
endif ()
endif ()
......
......@@ -158,8 +158,8 @@ status_init(void) {
STATUS_INIT(CP_TIME_LAST_CHECKPOINT_BEGIN, CHECKPOINT_LAST_BEGAN, UNIXTIME, "last checkpoint began ", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_LAST_CHECKPOINT_BEGIN_COMPLETE, CHECKPOINT_LAST_COMPLETE_BEGAN, UNIXTIME, "last complete checkpoint began ", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_LAST_CHECKPOINT_END, CHECKPOINT_LAST_COMPLETE_ENDED, UNIXTIME, "last complete checkpoint ended", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_CHECKPOINT_DURATION, CHECKPOINT_DURATION, UNIXTIME, "time spent during checkpoint (begin and end phases)", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_CHECKPOINT_DURATION_LAST, CHECKPOINT_DURATION_LAST, UNIXTIME, "time spent during last checkpoint (begin and end phases)", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_CHECKPOINT_DURATION, CHECKPOINT_DURATION, UINT64, "time spent during checkpoint (begin and end phases)", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_TIME_CHECKPOINT_DURATION_LAST, CHECKPOINT_DURATION_LAST, UINT64, "time spent during last checkpoint (begin and end phases)", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_LAST_LSN, nullptr, UINT64, "last complete checkpoint LSN", TOKU_ENGINE_STATUS);
STATUS_INIT(CP_CHECKPOINT_COUNT, CHECKPOINT_TAKEN, UINT64, "checkpoints taken ", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
STATUS_INIT(CP_CHECKPOINT_COUNT_FAIL, CHECKPOINT_FAILED, UINT64, "checkpoints failed", TOKU_ENGINE_STATUS|TOKU_GLOBAL_STATUS);
......@@ -381,8 +381,8 @@ toku_checkpoint(CHECKPOINTER cp, TOKULOGGER logger,
STATUS_VALUE(CP_LONG_BEGIN_TIME) += duration;
STATUS_VALUE(CP_LONG_BEGIN_COUNT) += 1;
}
STATUS_VALUE(CP_TIME_CHECKPOINT_DURATION) += ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_END)) - ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_BEGIN));
STATUS_VALUE(CP_TIME_CHECKPOINT_DURATION_LAST) = ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_END)) - ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_BEGIN));
STATUS_VALUE(CP_TIME_CHECKPOINT_DURATION) += (uint64_t) ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_END)) - ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_BEGIN));
STATUS_VALUE(CP_TIME_CHECKPOINT_DURATION_LAST) = (uint64_t) ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_END)) - ((time_t) STATUS_VALUE(CP_TIME_LAST_CHECKPOINT_BEGIN));
STATUS_VALUE(CP_FOOTPRINT) = 0;
checkpoint_safe_checkpoint_unlock();
......
......@@ -403,3 +403,25 @@ toku_unpin_ftnode_read_only(FT ft, FTNODE node)
);
assert(r==0);
}
void toku_ftnode_swap_pair_values(FTNODE a, FTNODE b)
// Effect: Swap the blocknum, fullhash, and PAIR for for a and b
// Requires: Both nodes are pinned
{
BLOCKNUM tmp_blocknum = a->thisnodename;
uint32_t tmp_fullhash = a->fullhash;
PAIR tmp_pair = a->ct_pair;
a->thisnodename = b->thisnodename;
a->fullhash = b->fullhash;
a->ct_pair = b->ct_pair;
b->thisnodename = tmp_blocknum;
b->fullhash = tmp_fullhash;
b->ct_pair = tmp_pair;
// A and B swapped pair pointers, but we still have to swap
// the actual pair values (ie: the FTNODEs they represent)
// in the cachetable.
toku_cachetable_swap_pair_values(a->ct_pair, b->ct_pair);
}
......@@ -190,4 +190,7 @@ int toku_maybe_pin_ftnode_clean(FT ft, BLOCKNUM blocknum, uint32_t fullhash, pai
void toku_unpin_ftnode(FT h, FTNODE node);
void toku_unpin_ftnode_read_only(FT ft, FTNODE node);
// Effect: Swaps pair values of two pinned nodes
void toku_ftnode_swap_pair_values(FTNODE nodea, FTNODE nodeb);
#endif
......@@ -565,6 +565,7 @@ static bool may_node_be_reactive(FT ft, FTNODE node)
*/
static void
handle_split_of_child(
FT ft,
FTNODE node,
int childnum,
FTNODE childa,
......@@ -607,8 +608,20 @@ handle_split_of_child(
paranoid_invariant(BP_BLOCKNUM(node, childnum).b==childa->thisnodename.b); // use the same child
// We never set the rightmost blocknum to be the root.
// Instead, we wait for the root to split and let promotion initialize the rightmost
// blocknum to be the first non-root leaf node on the right extreme to recieve an insert.
invariant(ft->h->root_blocknum.b != ft->rightmost_blocknum.b);
if (childa->thisnodename.b == ft->rightmost_blocknum.b) {
// The rightmost leaf (a) split into (a) and (b). We want (b) to swap pair values
// with (a), now that it is the new rightmost leaf. This keeps the rightmost blocknum
// constant, the same the way we keep the root blocknum constant.
toku_ftnode_swap_pair_values(childa, childb);
BP_BLOCKNUM(node, childnum) = childa->thisnodename;
}
BP_BLOCKNUM(node, childnum+1) = childb->thisnodename;
BP_WORKDONE(node, childnum+1) = 0;
BP_WORKDONE(node, childnum+1) = 0;
BP_STATE(node,childnum+1) = PT_AVAIL;
NONLEAF_CHILDINFO new_bnc = toku_create_empty_nl();
......@@ -1071,7 +1084,7 @@ ft_split_child(
ft_nonleaf_split(h, child, &nodea, &nodeb, &splitk, 2, dep_nodes);
}
// printf("%s:%d child did split\n", __FILE__, __LINE__);
handle_split_of_child (node, childnum, nodea, nodeb, &splitk);
handle_split_of_child (h, node, childnum, nodea, nodeb, &splitk);
// for test
call_flusher_thread_callback(flt_flush_during_split);
......@@ -1489,6 +1502,14 @@ ft_merge_child(
&node->childkeys[childnuma+1],
(node->n_children-childnumb)*sizeof(node->childkeys[0]));
REALLOC_N(node->n_children-1, node->childkeys);
// Handle a merge of the rightmost leaf node.
if (did_merge && childb->thisnodename.b == h->rightmost_blocknum.b) {
invariant(childb->thisnodename.b != h->h->root_blocknum.b);
toku_ftnode_swap_pair_values(childa, childb);
BP_BLOCKNUM(node, childnuma) = childa->thisnodename;
}
paranoid_invariant(BP_BLOCKNUM(node, childnuma).b == childa->thisnodename.b);
childa->dirty = 1; // just to make sure
childb->dirty = 1; // just to make sure
......
......@@ -123,6 +123,10 @@ enum { FT_DEFAULT_FANOUT = 16 };
enum { FT_DEFAULT_NODE_SIZE = 4 * 1024 * 1024 };
enum { FT_DEFAULT_BASEMENT_NODE_SIZE = 128 * 1024 };
// We optimize for a sequential insert pattern if 100 consecutive injections
// happen into the rightmost leaf node due to promotion.
enum { FT_SEQINSERT_SCORE_THRESHOLD = 100 };
//
// Field in ftnode_fetch_extra that tells the
// partial fetch callback what piece of the node
......@@ -572,6 +576,22 @@ struct ft {
// is this ft a blackhole? if so, all messages are dropped.
bool blackhole;
// The blocknum of the rightmost leaf node in the tree. Stays constant through splits
// and merges using pair-swapping (like the root node, see toku_ftnode_swap_pair_values())
//
// This field only transitions from RESERVED_BLOCKNUM_NULL to non-null, never back.
// We initialize it when promotion inserts into a non-root leaf node on the right extreme.
// We use the blocktable lock to protect the initialize transition, though it's not really
// necessary since all threads should be setting it to the same value. We maintain that invariant
// on first initialization, see ft_set_or_verify_rightmost_blocknum()
BLOCKNUM rightmost_blocknum;
// sequential access pattern heuristic
// - when promotion pushes a message directly into the rightmost leaf, the score goes up.
// - if the score is high enough, we optimistically attempt to insert directly into the rightmost leaf
// - if our attempt fails because the key was not in range of the rightmost leaf, we reset the score back to 0
uint32_t seqinsert_score;
};
// Allocate a DB struct off the stack and only set its comparison
......@@ -1037,7 +1057,7 @@ toku_get_node_for_verify(
int
toku_verify_ftnode (FT_HANDLE ft_h,
MSN rootmsn, MSN parentmsn, bool messages_exist_above,
MSN rootmsn, MSN parentmsn_with_messages, bool messages_exist_above,
FTNODE node, int height,
const DBT *lesser_pivot, // Everything in the subtree should be > lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
const DBT *greatereq_pivot, // Everything in the subtree should be <= lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
......@@ -1186,6 +1206,9 @@ typedef enum {
FT_PRO_NUM_DIDNT_WANT_PROMOTE,
FT_BASEMENT_DESERIALIZE_FIXED_KEYSIZE, // how many basement nodes were deserialized with a fixed keysize
FT_BASEMENT_DESERIALIZE_VARIABLE_KEYSIZE, // how many basement nodes were deserialized with a variable keysize
FT_PRO_RIGHTMOST_LEAF_SHORTCUT_SUCCESS,
FT_PRO_RIGHTMOST_LEAF_SHORTCUT_FAIL_POS,
FT_PRO_RIGHTMOST_LEAF_SHORTCUT_FAIL_REACTIVE,
FT_STATUS_NUM_ROWS
} ft_status_entry;
......
This diff is collapsed.
......@@ -213,6 +213,9 @@ int toku_ft_lookup (FT_HANDLE ft_h, DBT *k, FT_GET_CALLBACK_FUNCTION getf, void
// Effect: Insert a key and data pair into an ft
void toku_ft_insert (FT_HANDLE ft_h, DBT *k, DBT *v, TOKUTXN txn);
// Returns: 0 if the key was inserted, DB_KEYEXIST if the key already exists
int toku_ft_insert_unique(FT_HANDLE ft, DBT *k, DBT *v, TOKUTXN txn, bool do_logging);
// Effect: Optimize the ft
void toku_ft_optimize (FT_HANDLE ft_h);
......
......@@ -462,6 +462,7 @@ serialize_ft_min_size (uint32_t version) {
size_t size = 0;
switch(version) {
case FT_LAYOUT_VERSION_27:
case FT_LAYOUT_VERSION_26:
case FT_LAYOUT_VERSION_25:
case FT_LAYOUT_VERSION_24:
......
......@@ -310,7 +310,7 @@ toku_get_node_for_verify(
static int
toku_verify_ftnode_internal(FT_HANDLE ft_handle,
MSN rootmsn, MSN parentmsn, bool messages_exist_above,
MSN rootmsn, MSN parentmsn_with_messages, bool messages_exist_above,
FTNODE node, int height,
const DBT *lesser_pivot, // Everything in the subtree should be > lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
const DBT *greatereq_pivot, // Everything in the subtree should be <= lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
......@@ -328,7 +328,7 @@ toku_verify_ftnode_internal(FT_HANDLE ft_handle,
invariant(height == node->height); // this is a bad failure if wrong
}
if (node->height > 0 && messages_exist_above) {
VERIFY_ASSERTION((parentmsn.msn >= this_msn.msn), 0, "node msn must be descending down tree, newest messages at top");
VERIFY_ASSERTION((parentmsn_with_messages.msn >= this_msn.msn), 0, "node msn must be descending down tree, newest messages at top");
}
// Verify that all the pivot keys are in order.
for (int i = 0; i < node->n_children-2; i++) {
......@@ -450,7 +450,7 @@ done:
// input is a pinned node, on exit, node is unpinned
int
toku_verify_ftnode (FT_HANDLE ft_handle,
MSN rootmsn, MSN parentmsn, bool messages_exist_above,
MSN rootmsn, MSN parentmsn_with_messages, bool messages_exist_above,
FTNODE node, int height,
const DBT *lesser_pivot, // Everything in the subtree should be > lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
const DBT *greatereq_pivot, // Everything in the subtree should be <= lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
......@@ -469,7 +469,7 @@ toku_verify_ftnode (FT_HANDLE ft_handle,
// Otherwise we'll just do the next call
result = toku_verify_ftnode_internal(
ft_handle, rootmsn, parentmsn, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
ft_handle, rootmsn, parentmsn_with_messages, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
verbose, keep_going_on_failure, false);
if (result != 0 && (!keep_going_on_failure || result != TOKUDB_NEEDS_REPAIR)) goto done;
}
......@@ -477,7 +477,7 @@ toku_verify_ftnode (FT_HANDLE ft_handle,
toku_move_ftnode_messages_to_stale(ft_handle->ft, node);
}
result2 = toku_verify_ftnode_internal(
ft_handle, rootmsn, parentmsn, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
ft_handle, rootmsn, parentmsn_with_messages, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
verbose, keep_going_on_failure, true);
if (result == 0) {
result = result2;
......@@ -489,12 +489,16 @@ toku_verify_ftnode (FT_HANDLE ft_handle,
for (int i = 0; i < node->n_children; i++) {
FTNODE child_node;
toku_get_node_for_verify(BP_BLOCKNUM(node, i), ft_handle, &child_node);
int r = toku_verify_ftnode(ft_handle, rootmsn, this_msn, messages_exist_above || toku_bnc_n_entries(BNC(node, i)) > 0,
child_node, node->height-1,
(i==0) ? lesser_pivot : &node->childkeys[i-1],
(i==node->n_children-1) ? greatereq_pivot : &node->childkeys[i],
progress_callback, progress_extra,
recurse, verbose, keep_going_on_failure);
int r = toku_verify_ftnode(ft_handle, rootmsn,
(toku_bnc_n_entries(BNC(node, i)) > 0
? this_msn
: parentmsn_with_messages),
messages_exist_above || toku_bnc_n_entries(BNC(node, i)) > 0,
child_node, node->height-1,
(i==0) ? lesser_pivot : &node->childkeys[i-1],
(i==node->n_children-1) ? greatereq_pivot : &node->childkeys[i],
progress_callback, progress_extra,
recurse, verbose, keep_going_on_failure);
if (r) {
result = r;
if (!keep_going_on_failure || result != TOKUDB_NEEDS_REPAIR) goto done;
......
......@@ -120,6 +120,7 @@ enum ft_layout_version_e {
FT_LAYOUT_VERSION_24 = 24, // Riddler: change logentries that log transactions to store TXNID_PAIRs instead of TXNIDs
FT_LAYOUT_VERSION_25 = 25, // SecretSquirrel: ROLLBACK_LOG_NODES (on disk and in memory) now just use blocknum (instead of blocknum + hash) to point to other log nodes. same for xstillopen log entry
FT_LAYOUT_VERSION_26 = 26, // Hojo: basements store key/vals separately on disk for fixed klpair length BNs
FT_LAYOUT_VERSION_27 = 27, // serialize message trees with nonleaf buffers to avoid key, msn sort on deserialize
FT_NEXT_VERSION, // the version after the current version
FT_LAYOUT_VERSION = FT_NEXT_VERSION-1, // A hack so I don't have to change this line.
FT_LAYOUT_MIN_SUPPORTED_VERSION = FT_LAYOUT_VERSION_13, // Minimum version supported
......
......@@ -291,8 +291,13 @@ serialize_ftnode_partition_size (FTNODE node, int i)
paranoid_invariant(node->bp[i].state == PT_AVAIL);
result++; // Byte that states what the partition is
if (node->height > 0) {
result += 4; // size of bytes in buffer table
result += toku_bnc_nbytesinbuf(BNC(node, i));
NONLEAF_CHILDINFO bnc = BNC(node, i);
// number of messages (4 bytes) plus size of the buffer
result += (4 + toku_bnc_nbytesinbuf(bnc));
// number of offsets (4 bytes) plus an array of 4 byte offsets, for each message tree
result += (4 + (4 * bnc->fresh_message_tree.size()));
result += (4 + (4 * bnc->stale_message_tree.size()));
result += (4 + (4 * bnc->broadcast_list.size()));
}
else {
result += 4 + bn_data::HEADER_LENGTH; // n_entries in buffer table + basement header
......@@ -305,8 +310,35 @@ serialize_ftnode_partition_size (FTNODE node, int i)
#define FTNODE_PARTITION_DMT_LEAVES 0xaa
#define FTNODE_PARTITION_FIFO_MSG 0xbb
UU() static int
assert_fresh(const int32_t &offset, const uint32_t UU(idx), struct fifo *const f) {
struct fifo_entry *entry = toku_fifo_get_entry(f, offset);
assert(entry->is_fresh);
return 0;
}
UU() static int
assert_stale(const int32_t &offset, const uint32_t UU(idx), struct fifo *const f) {
struct fifo_entry *entry = toku_fifo_get_entry(f, offset);
assert(!entry->is_fresh);
return 0;
}
static void bnc_verify_message_trees(NONLEAF_CHILDINFO UU(bnc)) {
#ifdef TOKU_DEBUG_PARANOID
bnc->fresh_message_tree.iterate<struct fifo, assert_fresh>(bnc->buffer);
bnc->stale_message_tree.iterate<struct fifo, assert_stale>(bnc->buffer);
#endif
}
static int
wbuf_write_offset(const int32_t &offset, const uint32_t UU(idx), struct wbuf *const wb) {
wbuf_nocrc_int(wb, offset);
return 0;
}
static void
serialize_nonleaf_childinfo(NONLEAF_CHILDINFO bnc, struct wbuf *wb)
serialize_child_buffer(NONLEAF_CHILDINFO bnc, struct wbuf *wb)
{
unsigned char ch = FTNODE_PARTITION_FIFO_MSG;
wbuf_nocrc_char(wb, ch);
......@@ -323,6 +355,19 @@ serialize_nonleaf_childinfo(NONLEAF_CHILDINFO bnc, struct wbuf *wb)
wbuf_nocrc_bytes(wb, key, keylen);
wbuf_nocrc_bytes(wb, data, datalen);
});
bnc_verify_message_trees(bnc);
// serialize the message trees (num entries, offsets array):
// fresh, stale, broadcast
wbuf_nocrc_int(wb, bnc->fresh_message_tree.size());
bnc->fresh_message_tree.iterate<struct wbuf, wbuf_write_offset>(wb);
wbuf_nocrc_int(wb, bnc->stale_message_tree.size());
bnc->stale_message_tree.iterate<struct wbuf, wbuf_write_offset>(wb);
wbuf_nocrc_int(wb, bnc->broadcast_list.size());
bnc->broadcast_list.iterate<struct wbuf, wbuf_write_offset>(wb);
}
//
......@@ -346,7 +391,7 @@ serialize_ftnode_partition(FTNODE node, int i, struct sub_block *sb) {
wbuf_init(&wb, sb->uncompressed_ptr, sb->uncompressed_size);
if (node->height > 0) {
// TODO: (Zardosht) possibly exit early if there are no messages
serialize_nonleaf_childinfo(BNC(node, i), &wb);
serialize_child_buffer(BNC(node, i), &wb);
}
else {
unsigned char ch = FTNODE_PARTITION_DMT_LEAVES;
......@@ -1024,8 +1069,8 @@ toku_serialize_ftnode_to (int fd, BLOCKNUM blocknum, FTNODE node, FTNODE_DISK_DA
}
static void
deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf,
DESCRIPTOR desc, ft_compare_func cmp) {
deserialize_child_buffer_v26(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf,
DESCRIPTOR desc, ft_compare_func cmp) {
int r;
int n_in_this_buffer = rbuf_int(rbuf);
int32_t *fresh_offsets = NULL, *stale_offsets = NULL;
......@@ -1090,6 +1135,68 @@ deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf,
}
}
// effect: deserialize a single message from rbuf and enqueue the result into the given fifo
static void
fifo_deserialize_msg_from_rbuf(FIFO fifo, struct rbuf *rbuf) {
bytevec key, val;
ITEMLEN keylen, vallen;
enum ft_msg_type type = (enum ft_msg_type) rbuf_char(rbuf);
bool is_fresh = rbuf_char(rbuf);
MSN msn = rbuf_msn(rbuf);
XIDS xids;
xids_create_from_buffer(rbuf, &xids);
rbuf_bytes(rbuf, &key, &keylen); /* Returns a pointer into the rbuf. */
rbuf_bytes(rbuf, &val, &vallen);
int r = toku_fifo_enq(fifo, key, keylen, val, vallen, type, msn, xids, is_fresh, nullptr);
lazy_assert_zero(r);
xids_destroy(&xids);
}
static void
deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf) {
int n_in_this_buffer = rbuf_int(rbuf);
int nfresh = 0, nstale = 0, nbroadcast_offsets = 0;
int32_t *XMALLOC_N(n_in_this_buffer, stale_offsets);
int32_t *XMALLOC_N(n_in_this_buffer, fresh_offsets);
int32_t *XMALLOC_N(n_in_this_buffer, broadcast_offsets);
toku_fifo_resize(bnc->buffer, rbuf->size + 64);
for (int i = 0; i < n_in_this_buffer; i++) {
fifo_deserialize_msg_from_rbuf(bnc->buffer, rbuf);
}
// read in each message tree (fresh, stale, broadcast)
nfresh = rbuf_int(rbuf);
bytevec fresh_offsets_src_v;
rbuf_literal_bytes(rbuf, &fresh_offsets_src_v, nfresh * (sizeof *fresh_offsets));
const int32_t *fresh_offsets_src = (const int32_t *) fresh_offsets_src_v;
for (int i = 0; i < nfresh; i++) {
fresh_offsets[i] = toku_dtoh32(fresh_offsets_src[i]);
}
nstale = rbuf_int(rbuf);
bytevec stale_offsets_src_v;
rbuf_literal_bytes(rbuf, &stale_offsets_src_v, nstale * (sizeof *stale_offsets));
const int32_t *stale_offsets_src = (const int32_t *) stale_offsets_src_v;
for (int i = 0; i < nstale; i++) {
stale_offsets[i] = toku_dtoh32(stale_offsets_src[i]);
}
nbroadcast_offsets = rbuf_int(rbuf);
bytevec broadcast_offsets_src_v;
rbuf_literal_bytes(rbuf, &broadcast_offsets_src_v, nbroadcast_offsets * (sizeof *broadcast_offsets));
const int32_t *broadcast_offsets_src = (const int32_t *) broadcast_offsets_src_v;
for (int i = 0; i < nbroadcast_offsets; i++) {
broadcast_offsets[i] = toku_dtoh32(broadcast_offsets_src[i]);
}
// build OMTs out of each offset array
bnc->fresh_message_tree.destroy();
bnc->fresh_message_tree.create_steal_sorted_array(&fresh_offsets, nfresh, n_in_this_buffer);
bnc->stale_message_tree.destroy();
bnc->stale_message_tree.create_steal_sorted_array(&stale_offsets, nstale, n_in_this_buffer);
bnc->broadcast_list.destroy();
bnc->broadcast_list.create_steal_sorted_array(&broadcast_offsets, nbroadcast_offsets, n_in_this_buffer);
}
// dump a buffer to stderr
// no locking around this for now
void
......@@ -1161,13 +1268,16 @@ NONLEAF_CHILDINFO toku_create_empty_nl(void) {
return cn;
}
// does NOT create OMTs, just the FIFO
// must clone the OMTs, since we serialize them along with the FIFO
NONLEAF_CHILDINFO toku_clone_nl(NONLEAF_CHILDINFO orig_childinfo) {
NONLEAF_CHILDINFO XMALLOC(cn);
toku_fifo_clone(orig_childinfo->buffer, &cn->buffer);
cn->fresh_message_tree.create_no_array();
cn->fresh_message_tree.clone(orig_childinfo->fresh_message_tree);
cn->stale_message_tree.create_no_array();
cn->stale_message_tree.clone(orig_childinfo->stale_message_tree);
cn->broadcast_list.create_no_array();
cn->broadcast_list.clone(orig_childinfo->broadcast_list);
memset(cn->flow, 0, sizeof cn->flow);
return cn;
}
......@@ -1513,7 +1623,13 @@ deserialize_ftnode_partition(
if (node->height > 0) {
assert(ch == FTNODE_PARTITION_FIFO_MSG);
deserialize_child_buffer(BNC(node, childnum), &rb, desc, cmp);
NONLEAF_CHILDINFO bnc = BNC(node, childnum);
if (node->layout_version_read_from_disk <= FT_LAYOUT_VERSION_26) {
// Layout version <= 26 did not serialize sorted message trees to disk.
deserialize_child_buffer_v26(bnc, &rb, desc, cmp);
} else {
deserialize_child_buffer(bnc, &rb);
}
BP_WORKDONE(node, childnum) = 0;
}
else {
......
......@@ -245,6 +245,7 @@ struct ft_loader_s {
CACHETABLE cachetable;
bool did_reserve_memory;
bool compress_intermediates;
bool allow_puts;
uint64_t reserved_memory; // how much memory are we allowed to use?
/* To make it easier to recover from errors, we don't use FILE*, instead we use an index into the file_infos. */
......@@ -346,7 +347,8 @@ int toku_ft_loader_internal_init (/* out */ FTLOADER *blp,
TOKUTXN txn,
bool reserve_memory,
uint64_t reserve_memory_size,
bool compress_intermediates);
bool compress_intermediates,
bool allow_puts);
void toku_ft_loader_internal_destroy (FTLOADER bl, bool is_error);
......
This diff is collapsed.
......@@ -113,7 +113,8 @@ int toku_ft_loader_open (FTLOADER *bl,
TOKUTXN txn,
bool reserve_memory,
uint64_t reserve_memory_size,
bool compress_intermediates);
bool compress_intermediates,
bool allow_puts);
int toku_ft_loader_put (FTLOADER bl, DBT *key, DBT *val);
......
......@@ -321,8 +321,8 @@ toku_maybe_upgrade_log(const char *env_dir, const char *log_dir, LSN * lsn_of_cl
r = 0; //Logs are up to date
else {
FOOTPRINT(4);
LSN last_lsn;
TXNID last_xid;
LSN last_lsn = ZERO_LSN;
TXNID last_xid = TXNID_NONE;
r = verify_clean_shutdown_of_log_version(log_dir, version_of_logs_on_disk, &last_lsn, &last_xid);
if (r != 0) {
goto cleanup;
......
......@@ -621,7 +621,7 @@ int toku_logger_find_next_unused_log_file(const char *directory, long long *resu
if (d==0) return get_error_errno();
while ((de=readdir(d))) {
if (de==0) return get_error_errno();
long long thisl;
long long thisl = -1;
if ( is_a_logfile(de->d_name, &thisl) ) {
if ((long long)thisl > maxf) maxf = thisl;
}
......
......@@ -170,7 +170,7 @@ static void test_extractor(int nrows, int nrowsets, bool expect_fail) {
}
FTLOADER loader;
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, "tempXXXXXX", ZERO_LSN, nullptr, true, 0, false);
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, "tempXXXXXX", ZERO_LSN, nullptr, true, 0, false, true);
assert(r == 0);
struct rowset *rowset[nrowsets];
......
......@@ -180,7 +180,7 @@ static void test_extractor(int nrows, int nrowsets, bool expect_fail, const char
sprintf(temp, "%s/%s", testdir, "tempXXXXXX");
FTLOADER loader;
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, "tempXXXXXX", ZERO_LSN, nullptr, true, 0, false);
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, "tempXXXXXX", ZERO_LSN, nullptr, true, 0, false, true);
assert(r == 0);
struct rowset *rowset[nrowsets];
......
......@@ -402,7 +402,7 @@ static void test_extractor(int nrows, int nrowsets, const char *testdir) {
sprintf(temp, "%s/%s", testdir, "tempXXXXXX");
FTLOADER loader;
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, temp, ZERO_LSN, nullptr, true, 0, false);
r = toku_ft_loader_open(&loader, NULL, generate, NULL, N, fts, dbs, fnames, compares, temp, ZERO_LSN, nullptr, true, 0, false, true);
assert(r == 0);
struct rowset *rowset[nrowsets];
......
......@@ -412,7 +412,7 @@ static void test (const char *directory, bool is_error) {
bt_compare_functions,
"tempxxxxxx",
*lsnp,
nullptr, true, 0, false);
nullptr, true, 0, false, true);
assert(r==0);
}
......@@ -500,11 +500,6 @@ static void test (const char *directory, bool is_error) {
assert(cthunk.n_read == N_RECORDS);
}
}
//printf("%s:%d Destroying\n", __FILE__, __LINE__);
{
int r = queue_destroy(bl->primary_rowset_queue);
assert(r==0);
}
{
int r = queue_destroy(q);
assert(r==0);
......
......@@ -143,7 +143,7 @@ static void test_loader_open(int ndbs) {
for (i = 0; ; i++) {
set_my_malloc_trigger(i+1);
r = toku_ft_loader_open(&loader, NULL, NULL, NULL, ndbs, fts, dbs, fnames, compares, "", ZERO_LSN, nullptr, true, 0, false);
r = toku_ft_loader_open(&loader, NULL, NULL, NULL, ndbs, fts, dbs, fnames, compares, "", ZERO_LSN, nullptr, true, 0, false, true);
if (r == 0)
break;
}
......
/* -*- 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-2014 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.
This software is covered by US Patent No. 8,489,638.
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) 2014 Tokutek Inc. All rights reserved."
#include "test.h"
#include <ft/ybt.h>
#include <ft/ft-cachetable-wrappers.h>
// Each FT maintains a sequential insert heuristic to determine if its
// worth trying to insert directly into a well-known rightmost leaf node.
//
// The heuristic is only maintained when a rightmost leaf node is known.
//
// This test verifies that sequential inserts increase the seqinsert score
// and that a single non-sequential insert resets the score.
static void test_seqinsert_heuristic(void) {
int r = 0;
char name[TOKU_PATH_MAX + 1];
toku_path_join(name, 2, TOKU_TEST_FILENAME, "ftdata");
toku_os_recursive_delete(TOKU_TEST_FILENAME);
r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU); CKERR(r);
FT_HANDLE ft_handle;
CACHETABLE ct;
toku_cachetable_create(&ct, 0, ZERO_LSN, NULL_LOGGER);
r = toku_open_ft_handle(name, 1, &ft_handle,
4*1024*1024, 64*1024,
TOKU_DEFAULT_COMPRESSION_METHOD, ct, NULL,
toku_builtin_compare_fun); CKERR(r);
FT ft = ft_handle->ft;
int k;
DBT key, val;
const int val_size = 1024 * 1024;
char *XMALLOC_N(val_size, val_buf);
memset(val_buf, 'x', val_size);
toku_fill_dbt(&val, val_buf, val_size);
// Insert many rows sequentially. This is enough data to:
// - force the root to split (the righmost leaf will then be known)
// - raise the seqinsert score high enough to enable direct rightmost injections
const int rows_to_insert = 200;
for (int i = 0; i < rows_to_insert; i++) {
k = toku_htonl(i);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
}
invariant(ft->rightmost_blocknum.b != RESERVED_BLOCKNUM_NULL);
invariant(ft->seqinsert_score == FT_SEQINSERT_SCORE_THRESHOLD);
// Insert on the left extreme. The seq insert score is high enough
// that we will attempt to insert into the rightmost leaf. We won't
// be successful because key 0 won't be in the bounds of the rightmost leaf.
// This failure should reset the seqinsert score back to 0.
k = toku_htonl(0);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
invariant(ft->seqinsert_score == 0);
// Insert in the middle. The score should not go up.
k = toku_htonl(rows_to_insert / 2);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
invariant(ft->seqinsert_score == 0);
// Insert on the right extreme. The score should go up.
k = toku_htonl(rows_to_insert);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
invariant(ft->seqinsert_score == 1);
// Insert again on the right extreme again, the score should go up.
k = toku_htonl(rows_to_insert + 1);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
invariant(ft->seqinsert_score == 2);
// Insert close to, but not at, the right extreme. The score should reset.
// -- the magic number 4 derives from the fact that vals are 1mb and nodes are 4mb
k = toku_htonl(rows_to_insert - 4);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
invariant(ft->seqinsert_score == 0);
toku_free(val_buf);
toku_ft_handle_close(ft_handle);
toku_cachetable_close(&ct);
toku_os_recursive_delete(TOKU_TEST_FILENAME);
}
int test_main(int argc, const char *argv[]) {
default_parse_args(argc, argv);
test_seqinsert_heuristic();
return 0;
}
/* -*- 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-2014 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.
This software is covered by US Patent No. 8,489,638.
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) 2014 Tokutek Inc. All rights reserved."
#include "test.h"
#include <ft/ybt.h>
#include <ft/ft-cachetable-wrappers.h>
// Promotion tracks the rightmost blocknum in the FT when a message
// is successfully promoted to a non-root leaf node on the right extreme.
//
// This test verifies that a split or merge of the rightmost leaf properly
// maintains the rightmost blocknum (which is constant - the pair's swap values,
// like the root blocknum).
static void test_split_merge(void) {
int r = 0;
char name[TOKU_PATH_MAX + 1];
toku_path_join(name, 2, TOKU_TEST_FILENAME, "ftdata");
toku_os_recursive_delete(TOKU_TEST_FILENAME);
r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU); CKERR(r);
FT_HANDLE ft_handle;
CACHETABLE ct;
toku_cachetable_create(&ct, 0, ZERO_LSN, NULL_LOGGER);
r = toku_open_ft_handle(name, 1, &ft_handle,
4*1024*1024, 64*1024,
TOKU_DEFAULT_COMPRESSION_METHOD, ct, NULL,
toku_builtin_compare_fun); CKERR(r);
// We have a root blocknum, but no rightmost blocknum yet.
FT ft = ft_handle->ft;
invariant(ft->h->root_blocknum.b != RESERVED_BLOCKNUM_NULL);
invariant(ft->rightmost_blocknum.b == RESERVED_BLOCKNUM_NULL);
int k;
DBT key, val;
const int val_size = 1 * 1024 * 1024;
char *XMALLOC_N(val_size, val_buf);
memset(val_buf, 'x', val_size);
toku_fill_dbt(&val, val_buf, val_size);
// Insert 16 rows (should induce a few splits)
const int rows_to_insert = 16;
for (int i = 0; i < rows_to_insert; i++) {
k = toku_htonl(i);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_insert(ft_handle, &key, &val, NULL);
}
// rightmost blocknum should be set, because the root split and promotion
// did a rightmost insertion directly into the rightmost leaf, lazily
// initializing the rightmost blocknum.
invariant(ft->rightmost_blocknum.b != RESERVED_BLOCKNUM_NULL);
BLOCKNUM root_blocknum = ft->h->root_blocknum;
FTNODE root_node;
struct ftnode_fetch_extra bfe;
fill_bfe_for_full_read(&bfe, ft);
toku_pin_ftnode(ft, root_blocknum,
toku_cachetable_hash(ft->cf, ft->h->root_blocknum),
&bfe, PL_WRITE_EXPENSIVE, &root_node, true);
// root blocknum should be consistent
invariant(root_node->thisnodename.b == ft->h->root_blocknum.b);
// root should have split at least once, and it should now be at height 1
invariant(root_node->n_children > 1);
invariant(root_node->height == 1);
// rightmost blocknum should no longer be the root, since the root split
invariant(ft->h->root_blocknum.b != ft->rightmost_blocknum.b);
// the right child should have the rightmost blocknum
invariant(BP_BLOCKNUM(root_node, root_node->n_children - 1).b == ft->rightmost_blocknum.b);
BLOCKNUM rightmost_blocknum_before_merge = ft->rightmost_blocknum;
const int num_children_before_merge = root_node->n_children;
// delete the last 6 rows.
// - 1mb each, so 6mb deleted
// - should be enough to delete the entire rightmost leaf + some of its neighbor
const int rows_to_delete = 6;
toku_unpin_ftnode(ft, root_node);
for (int i = 0; i < rows_to_delete; i++) {
k = toku_htonl(rows_to_insert - i);
toku_fill_dbt(&key, &k, sizeof(k));
toku_ft_delete(ft_handle, &key, NULL);
}
toku_pin_ftnode(ft, root_blocknum,
toku_cachetable_hash(ft->cf, root_blocknum),
&bfe, PL_WRITE_EXPENSIVE, &root_node, true);
// - rightmost leaf should be fusible after those deletes (which were promoted directly to the leaf)
FTNODE rightmost_leaf;
toku_pin_ftnode(ft, rightmost_blocknum_before_merge,
toku_cachetable_hash(ft->cf, rightmost_blocknum_before_merge),
&bfe, PL_WRITE_EXPENSIVE, &rightmost_leaf, true);
invariant(get_node_reactivity(ft, rightmost_leaf) == RE_FUSIBLE);
toku_unpin_ftnode(ft, rightmost_leaf);
// - merge the rightmost child now that it's fusible
toku_ft_merge_child(ft, root_node, root_node->n_children - 1);
toku_pin_ftnode(ft, root_blocknum,
toku_cachetable_hash(ft->cf, root_blocknum),
&bfe, PL_WRITE_EXPENSIVE, &root_node, true);
// the merge should have worked, and the root should still be at height 1
invariant(root_node->n_children < num_children_before_merge);
invariant(root_node->height == 1);
// the rightmost child of the root has the rightmost blocknum
invariant(BP_BLOCKNUM(root_node, root_node->n_children - 1).b == ft->rightmost_blocknum.b);
// the value for rightmost blocknum itself should not have changed
// (we keep it constant, like the root blocknum)
invariant(rightmost_blocknum_before_merge.b == ft->rightmost_blocknum.b);
toku_unpin_ftnode(ft, root_node);
toku_free(val_buf);
toku_ft_handle_close(ft_handle);
toku_cachetable_close(&ct);
toku_os_recursive_delete(TOKU_TEST_FILENAME);
}
int test_main(int argc, const char *argv[]) {
default_parse_args(argc, argv);
test_split_merge();
return 0;
}
This diff is collapsed.
......@@ -735,6 +735,7 @@ if __name__ == '__main__':
'test_stress6.tdb',
'test_stress7.tdb',
'test_stress_hot_indexing.tdb',
'test_stress_with_verify.tdb',
'test_stress_openclose.tdb']
default_recover_testnames = ['recover-test_stress1.tdb',
'recover-test_stress2.tdb',
......@@ -766,8 +767,8 @@ if __name__ == '__main__':
help="skip the tests that don't involve upgrade [default=False]")
upgrade_group.add_option('--double_upgrade', action='store_true', dest='double_upgrade', default=False,
help='run the upgrade tests twice in a row [default=False]')
upgrade_group.add_option('--add_old_version', action='append', type='choice', dest='old_versions', choices=['4.2.0', '5.0.8', '5.2.7', '6.0.0', '6.1.0', '6.5.1', '6.6.3'],
help='which old versions to use for running the stress tests in upgrade mode. can be specified multiple times [options=4.2.0, 5.0.8, 5.2.7, 6.0.0, 6.1.0, 6.5.1, 6.6.3]')
upgrade_group.add_option('--add_old_version', action='append', type='choice', dest='old_versions', choices=['4.2.0', '5.0.8', '5.2.7', '6.0.0', '6.1.0', '6.5.1', '6.6.3', '7.1.6'],
help='which old versions to use for running the stress tests in upgrade mode. can be specified multiple times [options=4.2.0, 5.0.8, 5.2.7, 6.0.0, 6.1.0, 6.5.1, 6.6.3, 7.1.6]')
upgrade_group.add_option('--old_environments_dir', type='string', dest='old_environments_dir',
default=('%s/old-stress-test-envs' % default_tokudb_data),
help='directory containing old version environments (should contain 5.0.8/, 5.2.7/, etc, and the environments should be in those) [default=../../tokudb.data/stress_environments]')
......
......@@ -172,6 +172,13 @@ struct __toku_loader_internal {
char **inames_in_env; /* [N] inames of new files to be created */
};
static void free_inames(char **inames, int n) {
for (int i = 0; i < n; i++) {
toku_free(inames[i]);
}
toku_free(inames);
}
/*
* free_loader_resources() frees all of the resources associated with
* struct __toku_loader_internal
......@@ -185,16 +192,15 @@ static void free_loader_resources(DB_LOADER *loader)
toku_destroy_dbt(&loader->i->err_val);
if (loader->i->inames_in_env) {
for (int i=0; i<loader->i->N; i++) {
if (loader->i->inames_in_env[i]) toku_free(loader->i->inames_in_env[i]);
}
toku_free(loader->i->inames_in_env);
free_inames(loader->i->inames_in_env, loader->i->N);
loader->i->inames_in_env = nullptr;
}
if (loader->i->temp_file_template) toku_free(loader->i->temp_file_template);
toku_free(loader->i->temp_file_template);
loader->i->temp_file_template = nullptr;
// loader->i
toku_free(loader->i);
loader->i = NULL;
loader->i = nullptr;
}
}
......@@ -245,6 +251,7 @@ toku_loader_create_loader(DB_ENV *env,
bool check_empty) {
int rval;
HANDLE_READ_ONLY_TXN(txn);
DB_TXN *loader_txn = nullptr;
*blp = NULL; // set later when created
......@@ -299,6 +306,13 @@ toku_loader_create_loader(DB_ENV *env,
}
{
if (env->i->open_flags & DB_INIT_TXN) {
rval = env->txn_begin(env, txn, &loader_txn, 0);
if (rval) {
goto create_exit;
}
}
ft_compare_func compare_functions[N];
for (int i=0; i<N; i++) {
compare_functions[i] = env->i->bt_compare;
......@@ -306,18 +320,21 @@ toku_loader_create_loader(DB_ENV *env,
// time to open the big kahuna
char **XMALLOC_N(N, new_inames_in_env);
for (int i = 0; i < N; i++) {
new_inames_in_env[i] = nullptr;
}
FT_HANDLE *XMALLOC_N(N, fts);
for (int i=0; i<N; i++) {
fts[i] = dbs[i]->i->ft_handle;
}
LSN load_lsn;
rval = locked_load_inames(env, txn, N, dbs, new_inames_in_env, &load_lsn, puts_allowed);
rval = locked_load_inames(env, loader_txn, N, dbs, new_inames_in_env, &load_lsn, puts_allowed);
if ( rval!=0 ) {
toku_free(new_inames_in_env);
free_inames(new_inames_in_env, N);
toku_free(fts);
goto create_exit;
}
TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
TOKUTXN ttxn = loader_txn ? db_txn_struct_i(loader_txn)->tokutxn : NULL;
rval = toku_ft_loader_open(&loader->i->ft_loader,
env->i->cachetable,
env->i->generate_row_for_put,
......@@ -331,12 +348,14 @@ toku_loader_create_loader(DB_ENV *env,
ttxn,
puts_allowed,
env->get_loader_memory_size(env),
compress_intermediates);
compress_intermediates,
puts_allowed);
if ( rval!=0 ) {
toku_free(new_inames_in_env);
free_inames(new_inames_in_env, N);
toku_free(fts);
goto create_exit;
}
loader->i->inames_in_env = new_inames_in_env;
toku_free(fts);
......@@ -348,10 +367,19 @@ toku_loader_create_loader(DB_ENV *env,
rval = 0;
}
rval = loader_txn->commit(loader_txn, 0);
assert_zero(rval);
loader_txn = nullptr;
rval = 0;
}
*blp = loader;
create_exit:
if (loader_txn) {
int r = loader_txn->abort(loader_txn);
assert_zero(r);
loader_txn = nullptr;
}
if (rval == 0) {
(void) toku_sync_fetch_and_add(&STATUS_VALUE(LOADER_CREATE), 1);
(void) toku_sync_fetch_and_add(&STATUS_VALUE(LOADER_CURRENT), 1);
......@@ -441,7 +469,7 @@ static void redirect_loader_to_empty_dictionaries(DB_LOADER *loader) {
loader->i->dbs,
loader->i->db_flags,
loader->i->dbt_flags,
0,
LOADER_DISALLOW_PUTS,
false
);
lazy_assert_zero(r);
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
/*
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.
This software is covered by US Patent No. 8,489,638.
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) 2014 Tokutek Inc. All rights reserved."
#ident "$Id$"
// This test verifies that the env->dbremove function returns an error rather than
// crash when the NOFILE resource limit is exceeded.
#include "test.h"
#include <db.h>
#include <sys/resource.h>
static const char *envdir = TOKU_TEST_FILENAME;
static void test_dbremove() {
int r;
char rmcmd[32 + strlen(envdir)];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", envdir);
r = system(rmcmd); CKERR(r);
r = toku_os_mkdir(envdir, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
DB *db;
r = db_create(&db, env, 0); CKERR(r);
char fname[32];
sprintf(fname, "db%d", 0);
r = db->open(db, nullptr, fname, nullptr, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db->close(db, 0); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, nullptr, &txn, 0); CKERR(r);
struct rlimit current_limit;
r = getrlimit(RLIMIT_NOFILE, &current_limit);
assert(r == 0);
struct rlimit new_limit = current_limit;
new_limit.rlim_cur = 0;
r = setrlimit(RLIMIT_NOFILE, &new_limit);
assert(r == 0);
r = env->dbremove(env, txn, fname, nullptr, 0);
CKERR2(r, EMFILE);
r = setrlimit(RLIMIT_NOFILE, &current_limit);
assert(r == 0);
r = env->dbremove(env, txn, fname, nullptr, 0);
CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
static void do_args(int argc, char * const argv[]) {
int resultcode;
char *cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: %s -h -v -q\n", cmd);
exit(resultcode);
} else if (strcmp(argv[0], "-v")==0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
}
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
test_dbremove();
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
/*
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.
This software is covered by US Patent No. 8,489,638.
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.
*/
// Verify that loader->close works correctly (does not crash, does not leak memory, returns the right error code)
// when the NPROC limit is exceeded.
#ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved."
#ident "$Id$"
#include "test.h"
#include <db.h>
#include <sys/resource.h>
static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME;
static void run_test(int ndb) {
int r;
char rmcmd[32 + strlen(envdir)];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", envdir);
r = system(rmcmd); CKERR(r);
r = toku_os_mkdir(envdir, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
DB *dbs[ndb];
uint32_t db_flags[ndb];
uint32_t dbt_flags[ndb];
for (int i = 0; i < ndb; i++) {
db_flags[i] = DB_NOOVERWRITE;
dbt_flags[i] = 0;
r = db_create(&dbs[i], env, 0); CKERR(r);
char name[32];
sprintf(name, "db%d", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
DB_LOADER *loader;
r = env->create_loader(env, txn, &loader, ndb > 0 ? dbs[0] : NULL, ndb, dbs, db_flags, dbt_flags, loader_flags); CKERR(r);
struct rlimit current_nproc_limit;
r = getrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
struct rlimit new_nproc_limit = current_nproc_limit;
new_nproc_limit.rlim_cur = 0;
r = setrlimit(RLIMIT_NPROC, &new_nproc_limit);
assert(r == 0);
r = loader->close(loader);
if (loader_flags & LOADER_DISALLOW_PUTS)
CKERR(r);
else
CKERR2(r, EAGAIN);
r = setrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
r = txn->abort(txn); CKERR(r);
for (int i = 0; i < ndb; i++) {
r = dbs[i]->close(dbs[i], 0); CKERR(r);
}
r = env->close(env, 0); CKERR(r);
}
static void do_args(int argc, char * const argv[]) {
int resultcode;
char *cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: %s -h -v -q -p\n", cmd);
exit(resultcode);
} else if (strcmp(argv[0], "-v")==0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "-p") == 0) {
loader_flags |= LOADER_DISALLOW_PUTS;
} else if (strcmp(argv[0], "-z") == 0) {
loader_flags |= LOADER_COMPRESS_INTERMEDIATES;
} else if (strcmp(argv[0], "-e") == 0) {
argc--; argv++;
if (argc > 0)
envdir = argv[0];
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
}
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
run_test(1);
return 0;
}
......@@ -97,11 +97,7 @@ PATENT RIGHTS GRANT:
static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME;
static int put_multiple_generate(DB *UU(dest_db), DB *UU(src_db), DBT_ARRAY *UU(dest_keys), DBT_ARRAY *UU(dest_vals), const DBT *UU(src_key), const DBT *UU(src_val)) {
return ENOMEM;
}
static void loader_open_abort(int ndb) {
static void test_loader_create_close(int ndb) {
int r;
char rmcmd[32 + strlen(envdir)];
......@@ -111,8 +107,6 @@ static void loader_open_abort(int ndb) {
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
r = env->set_generate_row_callback_for_put(env, put_multiple_generate);
CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
......@@ -181,8 +175,8 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
loader_open_abort(0);
loader_open_abort(1);
loader_open_abort(2);
test_loader_create_close(0);
test_loader_create_close(1);
test_loader_create_close(2);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
/*
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.
This software is covered by US Patent No. 8,489,638.
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) 2010-2013 Tokutek Inc. All rights reserved."
#ident "$Id$"
// This test crashes if a failed loader creation causes the db to be corrupted by unlinking
// the underlying fractal tree files. This unlinking occurs because the txn that logs the
// load log entries is committed rather than aborted.
#include "test.h"
#include <db.h>
#include <sys/resource.h>
static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME;
static void run_test(int ndb) {
int r;
char rmcmd[32 + strlen(envdir)];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", envdir);
r = system(rmcmd); CKERR(r);
r = toku_os_mkdir(envdir, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
DB *dbs[ndb];
uint32_t db_flags[ndb];
uint32_t dbt_flags[ndb];
for (int i = 0; i < ndb; i++) {
db_flags[i] = DB_NOOVERWRITE;
dbt_flags[i] = 0;
r = db_create(&dbs[i], env, 0); CKERR(r);
char name[32];
sprintf(name, "db%d", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
struct rlimit current_nproc_limit;
r = getrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
struct rlimit new_nproc_limit = current_nproc_limit;
new_nproc_limit.rlim_cur = 0;
r = setrlimit(RLIMIT_NPROC, &new_nproc_limit);
assert(r == 0);
DB_LOADER *loader;
int loader_r = env->create_loader(env, txn, &loader, ndb > 0 ? dbs[0] : NULL, ndb, dbs, db_flags, dbt_flags, loader_flags);
r = setrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
if (loader_flags & LOADER_DISALLOW_PUTS) {
CKERR(loader_r);
loader_r = loader->close(loader);
CKERR(loader_r);
} else {
CKERR2(loader_r, EAGAIN);
}
r = txn->commit(txn, 0); CKERR(r);
for (int i = 0; i < ndb; i++) {
r = dbs[i]->close(dbs[i], 0); CKERR(r);
}
for (int i = 0; i < ndb; i++) {
r = db_create(&dbs[i], env, 0); CKERR(r);
char name[32];
sprintf(name, "db%d", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, 0, 0666); CKERR(r);
}
for (int i = 0; i < ndb; i++) {
r = dbs[i]->close(dbs[i], 0); CKERR(r);
}
r = env->close(env, 0); CKERR(r);
}
static void do_args(int argc, char * const argv[]) {
int resultcode;
char *cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: %s -h -v -q -p\n", cmd);
exit(resultcode);
} else if (strcmp(argv[0], "-v")==0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "-p") == 0) {
loader_flags |= LOADER_DISALLOW_PUTS;
} else if (strcmp(argv[0], "-z") == 0) {
loader_flags |= LOADER_COMPRESS_INTERMEDIATES;
} else if (strcmp(argv[0], "-e") == 0) {
argc--; argv++;
if (argc > 0)
envdir = argv[0];
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
}
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
run_test(1);
return 0;
}
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
/*
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.
This software is covered by US Patent No. 8,489,638.
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.
*/
// Verify that env->create_loader works correctly (does not crash, does not leak memory, returns the right error code)
// when the NPROC limit is exceeded.
#ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved."
#ident "$Id$"
#include "test.h"
#include <db.h>
#include <sys/resource.h>
static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME;
static void run_test(int ndb) {
int r;
char rmcmd[32 + strlen(envdir)];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", envdir);
r = system(rmcmd); CKERR(r);
r = toku_os_mkdir(envdir, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
DB *dbs[ndb];
uint32_t db_flags[ndb];
uint32_t dbt_flags[ndb];
for (int i = 0; i < ndb; i++) {
db_flags[i] = DB_NOOVERWRITE;
dbt_flags[i] = 0;
r = db_create(&dbs[i], env, 0); CKERR(r);
char name[32];
sprintf(name, "db%d", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
struct rlimit current_nproc_limit;
r = getrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
struct rlimit new_nproc_limit = current_nproc_limit;
new_nproc_limit.rlim_cur = 0;
r = setrlimit(RLIMIT_NPROC, &new_nproc_limit);
assert(r == 0);
DB_LOADER *loader;
int loader_r = env->create_loader(env, txn, &loader, ndb > 0 ? dbs[0] : NULL, ndb, dbs, db_flags, dbt_flags, loader_flags);
r = setrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
if (loader_flags & LOADER_DISALLOW_PUTS) {
CKERR(loader_r);
loader_r = loader->close(loader);
CKERR(loader_r);
} else {
CKERR2(loader_r, EAGAIN);
}
r = txn->abort(txn); CKERR(r);
for (int i = 0; i < ndb; i++) {
r = dbs[i]->close(dbs[i], 0); CKERR(r);
}
r = env->close(env, 0); CKERR(r);
}
static void do_args(int argc, char * const argv[]) {
int resultcode;
char *cmd = argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: %s -h -v -q -p\n", cmd);
exit(resultcode);
} else if (strcmp(argv[0], "-v")==0) {
verbose++;
} else if (strcmp(argv[0],"-q")==0) {
verbose--;
if (verbose<0) verbose=0;
} else if (strcmp(argv[0], "-p") == 0) {
loader_flags |= LOADER_DISALLOW_PUTS;
} else if (strcmp(argv[0], "-z") == 0) {
loader_flags |= LOADER_COMPRESS_INTERMEDIATES;
} else if (strcmp(argv[0], "-e") == 0) {
argc--; argv++;
if (argc > 0)
envdir = argv[0];
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
goto do_usage;
}
argc--;
argv++;
}
}
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
run_test(1);
return 0;
}
/* -*- 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.
This software is covered by US Patent No. 8,489,638.
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."
/**
* Test that unique inserts work correctly. This exercises the rightmost leaf inject optimization.
*/
#include <portability/toku_random.h>
#include "test.h"
static char random_buf[8];
static struct random_data random_data;
static void test_simple_unique_insert(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0); CKERR(r);
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0644); CKERR(r);
DBT key1, key2, key3;
dbt_init(&key1, "a", sizeof("a"));
dbt_init(&key2, "b", sizeof("b"));
dbt_init(&key3, "c", sizeof("c"));
r = db->put(db, NULL, &key1, &key1, DB_NOOVERWRITE); CKERR(r);
r = db->put(db, NULL, &key1, &key1, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
r = db->put(db, NULL, &key3, &key3, DB_NOOVERWRITE); CKERR(r);
r = db->put(db, NULL, &key3, &key3, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
r = db->put(db, NULL, &key2, &key2, DB_NOOVERWRITE); CKERR(r);
r = db->put(db, NULL, &key2, &key2, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
// sanity check
r = db->put(db, NULL, &key1, &key1, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
r = db->put(db, NULL, &key1, &key3, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
r = db->close(db, 0); CKERR(r);
r = env->dbremove(env, NULL, "db", NULL, 0); CKERR(r);
}
static void test_large_sequential_insert_unique(DB_ENV *env) {
int r;
DB *db;
r = db_create(&db, env, 0); CKERR(r);
// very small nodes/basements to make a taller tree
r = db->set_pagesize(db, 8 * 1024); CKERR(r);
r = db->set_readpagesize(db, 2 * 1024); CKERR(r);
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0644); CKERR(r);
const int val_size = 1024;
char *XMALLOC_N(val_size, val_buf);
memset(val_buf, 'k', val_size);
DBT val;
dbt_init(&val, val_buf, val_size);
// grow a tree to about depth 3, taking sanity checks along the way
const int start_num_rows = (64 * 1024 * 1024) / val_size;
for (int i = 0; i < start_num_rows; i++) {
DBT key;
int k = toku_htonl(i);
dbt_init(&key, &k, sizeof(k));
r = db->put(db, NULL, &key, &val, DB_NOOVERWRITE); CKERR(r);
if (i % 50 == 0) {
// sanity check - should not be able to insert this key twice in a row
r = db->put(db, NULL, &key, &val, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
// .. but re-inserting is okay, if we provisionally deleted the row
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = db->del(db, NULL, &key, DB_DELETE_ANY); CKERR(r);
r = db->put(db, NULL, &key, &val, DB_NOOVERWRITE); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
}
if (i > 0 && i % 250 == 0) {
// sanity check - unique checks on random keys we already inserted should
// fail (exercises middle-of-the-tree checks)
for (int check_i = 0; check_i < 4; check_i++) {
DBT rand_key;
int rand_k = toku_htonl(myrandom_r(&random_data) % i);
dbt_init(&rand_key, &rand_k, sizeof(rand_k));
r = db->put(db, NULL, &rand_key, &val, DB_NOOVERWRITE); CKERR2(r, DB_KEYEXIST);
}
}
}
toku_free(val_buf);
r = db->close(db, 0); CKERR(r);
r = env->dbremove(env, NULL, "db", NULL, 0); CKERR(r);
}
int test_main(int argc, char * const argv[]) {
default_parse_args(argc, argv);
int r;
const int envflags = DB_INIT_MPOOL | DB_CREATE | DB_THREAD |
DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN | DB_PRIVATE;
// startup
DB_ENV *env;
toku_os_recursive_delete(TOKU_TEST_FILENAME);
r = toku_os_mkdir(TOKU_TEST_FILENAME, 0755); CKERR(r);
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, TOKU_TEST_FILENAME, envflags, 0755);
r = myinitstate_r(random(), random_buf, 8, &random_data); CKERR(r);
test_simple_unique_insert(env);
test_large_sequential_insert_unique(env);
// cleanup
r = env->close(env, 0); CKERR(r);
return 0;
}
......@@ -1160,6 +1160,7 @@ env_close(DB_ENV * env, uint32_t flags) {
goto panic_and_quit_early;
}
}
env_fsync_log_cron_destroy(env);
if (env->i->cachetable) {
toku_cachetable_minicron_shutdown(env->i->cachetable);
if (env->i->logger) {
......@@ -1200,7 +1201,6 @@ env_close(DB_ENV * env, uint32_t flags) {
}
env_fs_destroy(env);
env_fsync_log_cron_destroy(env);
env->i->ltm.destroy();
if (env->i->data_dir)
toku_free(env->i->data_dir);
......@@ -2901,7 +2901,13 @@ env_dbremove(DB_ENV * env, DB_TXN *txn, const char *fname, const char *dbname, u
r = toku_db_create(&db, env, 0);
lazy_assert_zero(r);
r = toku_db_open_iname(db, txn, iname, 0, 0);
lazy_assert_zero(r);
if (txn && r) {
if (r == EMFILE || r == ENFILE)
r = toku_ydb_do_error(env, r, "toku dbremove failed because open file limit reached\n");
else
r = toku_ydb_do_error(env, r, "toku dbremove failed\n");
goto exit;
}
if (txn) {
// Now that we have a writelock on dname, verify that there are still no handles open. (to prevent race conditions)
if (env_is_db_with_dname_open(env, dname)) {
......
......@@ -1221,36 +1221,14 @@ load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[/*N*/], const char * new
int
locked_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[/*N*/], char * new_inames_in_env[/*N*/], LSN *load_lsn, bool mark_as_loader) {
int ret, r;
int r;
HANDLE_READ_ONLY_TXN(txn);
DB_TXN *child_txn = NULL;
int using_txns = env->i->open_flags & DB_INIT_TXN;
if (using_txns) {
ret = toku_txn_begin(env, txn, &child_txn, 0);
invariant_zero(ret);
}
// cannot begin a checkpoint
toku_multi_operation_client_lock();
r = load_inames(env, child_txn, N, dbs, (const char **) new_inames_in_env, load_lsn, mark_as_loader);
r = load_inames(env, txn, N, dbs, (const char **) new_inames_in_env, load_lsn, mark_as_loader);
toku_multi_operation_client_unlock();
if (using_txns) {
if (r == 0) {
ret = locked_txn_commit(child_txn, DB_TXN_NOSYNC);
invariant_zero(ret);
} else {
ret = locked_txn_abort(child_txn);
invariant_zero(ret);
for (int i = 0; i < N; i++) {
if (new_inames_in_env[i]) {
toku_free(new_inames_in_env[i]);
new_inames_in_env[i] = NULL;
}
}
}
}
return r;
}
......
......@@ -253,6 +253,30 @@ toku_db_del(DB *db, DB_TXN *txn, DBT *key, uint32_t flags, bool holds_mo_lock) {
return r;
}
static int
db_put(DB *db, DB_TXN *txn, DBT *key, DBT *val, int flags, bool do_log) {
int r = 0;
bool unique = false;
enum ft_msg_type type = FT_INSERT;
if (flags == DB_NOOVERWRITE) {
unique = true;
} else if (flags == DB_NOOVERWRITE_NO_ERROR) {
type = FT_INSERT_NO_OVERWRITE;
} else if (flags != 0) {
// All other non-zero flags are unsupported
r = EINVAL;
}
if (r == 0) {
TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : nullptr;
if (unique) {
r = toku_ft_insert_unique(db->i->ft_handle, key, val, ttxn, do_log);
} else {
toku_ft_maybe_insert(db->i->ft_handle, key, val, ttxn, false, ZERO_LSN, do_log, type);
}
invariant(r == DB_KEYEXIST || r == 0);
}
return r;
}
int
toku_db_put(DB *db, DB_TXN *txn, DBT *key, DBT *val, uint32_t flags, bool holds_mo_lock) {
......@@ -265,25 +289,16 @@ toku_db_put(DB *db, DB_TXN *txn, DBT *key, DBT *val, uint32_t flags, bool holds_
flags &= ~lock_flags;
r = db_put_check_size_constraints(db, key, val);
if (r == 0) {
//Do any checking required by the flags.
r = db_put_check_overwrite_constraint(db, txn, key, lock_flags, flags);
}
//Do locking if necessary. Do not grab the lock again if this DB had a unique
//check performed because the lock was already grabbed by its cursor callback.
//Do locking if necessary.
bool do_locking = (bool)(db->i->lt && !(lock_flags&DB_PRELOCKED_WRITE));
if (r == 0 && do_locking && !(flags & DB_NOOVERWRITE)) {
if (r == 0 && do_locking) {
r = toku_db_get_point_write_lock(db, txn, key);
}
if (r == 0) {
//Insert into the ft.
TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
enum ft_msg_type type = FT_INSERT;
if (flags==DB_NOOVERWRITE_NO_ERROR) {
type = FT_INSERT_NO_OVERWRITE;
}
if (!holds_mo_lock) toku_multi_operation_client_lock();
toku_ft_maybe_insert(db->i->ft_handle, key, val, ttxn, false, ZERO_LSN, true, type);
r = db_put(db, txn, key, val, flags, true);
if (!holds_mo_lock) toku_multi_operation_client_unlock();
}
......@@ -635,9 +650,11 @@ log_put_multiple(DB_TXN *txn, DB *src_db, const DBT *src_key, const DBT *src_val
}
}
// Requires: If remaining_flags is non-null, this function performs any required uniqueness checks
// Otherwise, the caller is responsible.
static int
do_put_multiple(DB_TXN *txn, uint32_t num_dbs, DB *db_array[], DBT_ARRAY keys[], DBT_ARRAY vals[], DB *src_db, const DBT *src_key, bool indexer_shortcut) {
TOKUTXN ttxn = db_txn_struct_i(txn)->tokutxn;
do_put_multiple(DB_TXN *txn, uint32_t num_dbs, DB *db_array[], DBT_ARRAY keys[], DBT_ARRAY vals[], uint32_t *remaining_flags, DB *src_db, const DBT *src_key, bool indexer_shortcut) {
int r = 0;
for (uint32_t which_db = 0; which_db < num_dbs; which_db++) {
DB *db = db_array[which_db];
......@@ -666,16 +683,21 @@ do_put_multiple(DB_TXN *txn, uint32_t num_dbs, DB *db_array[], DBT_ARRAY keys[],
}
if (do_put) {
for (uint32_t i = 0; i < keys[which_db].size; i++) {
// if db is being indexed by an indexer, then put into that db if the src key is to the left or equal to the
// indexers cursor. we have to get the src_db from the indexer and find it in the db_array.
toku_ft_maybe_insert(db->i->ft_handle,
&keys[which_db].dbts[i], &vals[which_db].dbts[i],
ttxn, false, ZERO_LSN, false, FT_INSERT);
int flags = 0;
if (remaining_flags != nullptr) {
flags = remaining_flags[which_db];
invariant(!(flags & DB_NOOVERWRITE_NO_ERROR));
}
r = db_put(db, txn, &keys[which_db].dbts[i], &vals[which_db].dbts[i], flags, false);
if (r != 0) {
goto done;
}
}
}
}
}
return 0;
done:
return r;
}
static int
......@@ -754,20 +776,14 @@ env_put_multiple_internal(
r = db_put_check_size_constraints(db, &put_key, &put_val);
if (r != 0) goto cleanup;
//Check overwrite constraints
r = db_put_check_overwrite_constraint(db, txn,
&put_key,
lock_flags[which_db], remaining_flags[which_db]);
if (r != 0) goto cleanup;
if (remaining_flags[which_db] == DB_NOOVERWRITE_NO_ERROR) {
//put_multiple does not support delaying the no error, since we would
//have to log the flag in the put_multiple.
r = EINVAL; goto cleanup;
}
//Do locking if necessary. Do not grab the lock again if this DB had a unique
//check performed because the lock was already grabbed by its cursor callback.
if (db->i->lt && !(lock_flags[which_db] & DB_PRELOCKED_WRITE) && !(remaining_flags[which_db] & DB_NOOVERWRITE)) {
//Do locking if necessary.
if (db->i->lt && !(lock_flags[which_db] & DB_PRELOCKED_WRITE)) {
//Needs locking
r = toku_db_get_point_write_lock(db, txn, &put_key);
if (r != 0) goto cleanup;
......@@ -790,8 +806,10 @@ env_put_multiple_internal(
}
}
toku_multi_operation_client_lock();
log_put_multiple(txn, src_db, src_key, src_val, num_dbs, fts);
r = do_put_multiple(txn, num_dbs, db_array, put_keys, put_vals, src_db, src_key, indexer_shortcut);
r = do_put_multiple(txn, num_dbs, db_array, put_keys, put_vals, remaining_flags, src_db, src_key, indexer_shortcut);
if (r == 0) {
log_put_multiple(txn, src_db, src_key, src_val, num_dbs, fts);
}
toku_multi_operation_client_unlock();
if (indexer_lock_taken) {
toku_indexer_unlock(indexer);
......@@ -1075,7 +1093,7 @@ env_update_multiple(DB_ENV *env, DB *src_db, DB_TXN *txn,
// recovery so we don't end up losing data.
// So unlike env->put_multiple, we ONLY log a 'put_multiple' log entry.
log_put_multiple(txn, src_db, new_src_key, new_src_data, n_put_dbs, put_fts);
r = do_put_multiple(txn, n_put_dbs, put_dbs, put_key_arrays, put_val_arrays, src_db, new_src_key, indexer_shortcut);
r = do_put_multiple(txn, n_put_dbs, put_dbs, put_key_arrays, put_val_arrays, nullptr, src_db, new_src_key, indexer_shortcut);
}
toku_multi_operation_client_unlock();
if (indexer_lock_taken) {
......
......@@ -207,6 +207,9 @@ void omt<omtdata_t, omtdataout_t, supports_marks>::clone(const omt &src) {
src.fill_array_with_subtree_values(&this->d.a.values[0], src.d.t.root);
}
this->d.a.num_values = src.size();
if (supports_marks) {
this->convert_to_tree();
}
}
template<typename omtdata_t, typename omtdataout_t, bool supports_marks>
......
/* -*- 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.
This software is covered by US Patent No. 8,489,638.
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) 2014 Tokutek Inc. All rights reserved."
// this test verifies that the toku thread pool is resilient when hitting the nproc limit.
#include <util/threadpool.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/resource.h>
int verbose = 0;
static int usage(void) {
fprintf(stderr, "[-q] [-v] [--verbose] (%d)\n", verbose);
return 1;
}
static void *f(void *arg) {
return arg;
}
static int dotest(int the_limit) {
if (verbose)
fprintf(stderr, "%s:%u %d\n", __FILE__, __LINE__, the_limit);
int r;
struct toku_thread_pool *pool = nullptr;
r = toku_thread_pool_create(&pool, 10);
assert(r == 0 && pool != nullptr);
struct rlimit current_nproc_limit;
r = getrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
struct rlimit new_nproc_limit = current_nproc_limit;
new_nproc_limit.rlim_cur = the_limit;
r = setrlimit(RLIMIT_NPROC, &new_nproc_limit);
assert(r == 0);
int want_n = 20;
int got_n = want_n;
r = toku_thread_pool_run(pool, 0, &got_n, f, nullptr);
if (r == 0)
assert(want_n == got_n);
else {
assert(r == EWOULDBLOCK);
assert(got_n <= want_n);
}
r = setrlimit(RLIMIT_NPROC, &current_nproc_limit);
assert(r == 0);
if (verbose)
toku_thread_pool_print(pool, stderr);
toku_thread_pool_destroy(&pool);
return got_n > 0;
}
int main(int argc, char *argv[]) {
// parse args
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (arg[0] != '-')
break;
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0) {
verbose = verbose+1;
continue;
}
if (strcmp(arg, "-q") == 0) {
verbose = verbose > 0 ? verbose-1 : 0;
continue;
}
return usage();
}
// set increasing nproc limits until the test succeeds in hitting the limit after > 0 threads are created
for (int i = 0; 1; i++) {
if (dotest(i))
break;
}
return 0;
}
......@@ -132,13 +132,18 @@ static int
toku_thread_create(struct toku_thread_pool *pool, struct toku_thread **toku_thread_return) {
int r;
struct toku_thread *MALLOC(thread);
if (thread == NULL) {
if (thread == nullptr) {
r = get_error_errno();
} else {
memset(thread, 0, sizeof *thread);
thread->pool = pool;
toku_cond_init(&thread->wait, NULL);
r = toku_pthread_create(&thread->tid, NULL, toku_thread_run_internal, thread); resource_assert_zero(r);
toku_cond_init(&thread->wait, nullptr);
r = toku_pthread_create(&thread->tid, nullptr, toku_thread_run_internal, thread);
if (r) {
toku_cond_destroy(&thread->wait);
toku_free(thread);
thread = nullptr;
}
*toku_thread_return = thread;
}
return r;
......@@ -192,7 +197,7 @@ toku_thread_run_internal(void *arg) {
if (doexit)
break;
toku_thread_pool_lock(pool);
thread->f = NULL;
thread->f = nullptr;
toku_list_push(&pool->free_threads, &thread->free_link);
}
return arg;
......@@ -202,13 +207,13 @@ int
toku_thread_pool_create(struct toku_thread_pool **pool_return, int max_threads) {
int r;
struct toku_thread_pool *CALLOC(pool);
if (pool == NULL) {
if (pool == nullptr) {
r = get_error_errno();
} else {
toku_mutex_init(&pool->lock, NULL);
toku_mutex_init(&pool->lock, nullptr);
toku_list_init(&pool->free_threads);
toku_list_init(&pool->all_threads);
toku_cond_init(&pool->wait_free, NULL);
toku_cond_init(&pool->wait_free, nullptr);
pool->cur_threads = 0;
pool->max_threads = max_threads;
*pool_return = pool;
......@@ -230,7 +235,7 @@ toku_thread_pool_unlock(struct toku_thread_pool *pool) {
void
toku_thread_pool_destroy(struct toku_thread_pool **poolptr) {
struct toku_thread_pool *pool = *poolptr;
*poolptr = NULL;
*poolptr = nullptr;
// ask the threads to exit
toku_thread_pool_lock(pool);
......@@ -260,7 +265,7 @@ toku_thread_pool_destroy(struct toku_thread_pool **poolptr) {
static int
toku_thread_pool_add(struct toku_thread_pool *pool) {
struct toku_thread *thread = NULL;
struct toku_thread *thread = nullptr;
int r = toku_thread_create(pool, &thread);
if (r == 0) {
pool->cur_threads += 1;
......@@ -294,7 +299,7 @@ toku_thread_pool_get_one(struct toku_thread_pool *pool, int dowait, struct toku_
struct toku_thread *thread = toku_list_struct(list, struct toku_thread, free_link);
*toku_thread_return = thread;
} else
*toku_thread_return = NULL;
*toku_thread_return = nullptr;
toku_thread_pool_unlock(pool);
return r;
}
......
This diff is collapsed.
......@@ -109,15 +109,6 @@ typedef struct loader_context {
ha_tokudb* ha;
} *LOADER_CONTEXT;
typedef struct hot_optimize_context {
THD *thd;
char* write_status_msg;
ha_tokudb *ha;
uint progress_stage;
uint current_table;
uint num_tables;
} *HOT_OPTIMIZE_CONTEXT;
//
// This object stores table information that is to be shared
// among all ha_tokudb objects.
......@@ -475,7 +466,7 @@ private:
);
int create_main_dictionary(const char* name, TABLE* form, DB_TXN* txn, KEY_AND_COL_INFO* kc_info, toku_compression_method compression_method);
void trace_create_table_info(const char *name, TABLE * form);
int is_index_unique(bool* is_unique, DB_TXN* txn, DB* db, KEY* key_info);
int is_index_unique(bool* is_unique, DB_TXN* txn, DB* db, KEY* key_info, int lock_flags);
int is_val_unique(bool* is_unique, uchar* record, KEY* key_info, uint dict_index, DB_TXN* txn);
int do_uniqueness_checks(uchar* record, DB_TXN* txn, THD* thd);
void set_main_dict_put_flags(THD* thd, bool opt_eligible, uint32_t* put_flags);
......@@ -803,6 +794,7 @@ private:
void remove_from_trx_handler_list();
private:
int do_optimize(THD *thd);
int map_to_handler_error(int error);
};
......
......@@ -128,8 +128,15 @@ static int analyze_progress(void *v_extra, uint64_t rows) {
int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) {
TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name);
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
uint64_t rec_per_key[table_share->key_parts];
int result = HA_ADMIN_OK;
// stub out analyze if optimize is remapped to alter recreate + analyze
if (thd_sql_command(thd) != SQLCOM_ANALYZE) {
TOKUDB_HANDLER_DBUG_RETURN(result);
}
DB_TXN *txn = transaction;
if (!txn) {
result = HA_ADMIN_FAILED;
......@@ -168,9 +175,19 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) {
if (error)
result = HA_ADMIN_FAILED;
}
thd_proc_info(thd, orig_proc_info);
TOKUDB_HANDLER_DBUG_RETURN(result);
}
typedef struct hot_optimize_context {
THD *thd;
char* write_status_msg;
ha_tokudb *ha;
uint progress_stage;
uint current_table;
uint num_tables;
} *HOT_OPTIMIZE_CONTEXT;
static int hot_poll_fun(void *extra, float progress) {
HOT_OPTIMIZE_CONTEXT context = (HOT_OPTIMIZE_CONTEXT)extra;
if (context->thd->killed) {
......@@ -194,9 +211,9 @@ static int hot_poll_fun(void *extra, float progress) {
}
// flatten all DB's in this table, to do so, peform hot optimize on each db
int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
int ha_tokudb::do_optimize(THD *thd) {
TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name);
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
int error;
uint curr_num_DBs = table->s->keys + tokudb_test(hidden_primary_key);
......@@ -206,9 +223,7 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
thd_progress_init(thd, curr_num_DBs);
#endif
//
// for each DB, run optimize and hot_optimize
//
for (uint i = 0; i < curr_num_DBs; i++) {
DB* db = share->key_file[i];
error = db->optimize(db);
......@@ -228,14 +243,24 @@ int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
goto cleanup;
}
}
error = 0;
cleanup:
cleanup:
#ifdef HA_TOKUDB_HAS_THD_PROGRESS
thd_progress_end(thd);
#endif
thd_proc_info(thd, orig_proc_info);
TOKUDB_HANDLER_DBUG_RETURN(error);
}
int ha_tokudb::optimize(THD *thd, HA_CHECK_OPT *check_opt) {
TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name);
int error;
#if TOKU_OPTIMIZE_WITH_RECREATE
error = HA_ADMIN_TRY_ALTER;
#else
error = do_optimize(thd);
#endif
TOKUDB_HANDLER_DBUG_RETURN(error);
}
......@@ -266,10 +291,7 @@ static void ha_tokudb_check_info(THD *thd, TABLE *table, const char *msg) {
int ha_tokudb::check(THD *thd, HA_CHECK_OPT *check_opt) {
TOKUDB_HANDLER_DBUG_ENTER("%s", share->table_name);
const char *old_proc_info = tokudb_thd_get_proc_info(thd);
thd_proc_info(thd, "tokudb::check");
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
int result = HA_ADMIN_OK;
int r;
......@@ -321,6 +343,6 @@ int ha_tokudb::check(THD *thd, HA_CHECK_OPT *check_opt) {
}
}
}
thd_proc_info(thd, old_proc_info);
thd_proc_info(thd, orig_proc_info);
TOKUDB_HANDLER_DBUG_RETURN(result);
}
......@@ -122,6 +122,7 @@ public:
expand_varchar_update_needed(false),
expand_fixed_update_needed(false),
expand_blob_update_needed(false),
optimize_needed(false),
table_kc_info(NULL),
altered_table_kc_info(NULL) {
}
......@@ -141,6 +142,7 @@ public:
bool expand_varchar_update_needed;
bool expand_fixed_update_needed;
bool expand_blob_update_needed;
bool optimize_needed;
Dynamic_array<uint> changed_fields;
KEY_AND_COL_INFO *table_kc_info;
KEY_AND_COL_INFO *altered_table_kc_info;
......@@ -219,6 +221,11 @@ static bool change_type_is_supported(TABLE *table, TABLE *altered_table, Alter_i
static ulong fix_handler_flags(THD *thd, TABLE *table, TABLE *altered_table, Alter_inplace_info *ha_alter_info) {
ulong handler_flags = ha_alter_info->handler_flags;
#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099
// This is automatically supported, hide the flag from later checks
handler_flags &= ~Alter_inplace_info::ALTER_PARTITIONED;
#endif
// workaround for fill_alter_inplace_info bug (#5193)
// the function erroneously sets the ADD_INDEX and DROP_INDEX flags for a column addition that does not
// change the keys. the following code turns the ADD_INDEX and DROP_INDEX flags so that we can do hot
......@@ -434,7 +441,13 @@ enum_alter_inplace_result ha_tokudb::check_if_supported_inplace_alter(TABLE *alt
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
}
}
}
#if TOKU_OPTIMIZE_WITH_RECREATE
else if (only_flags(ctx->handler_flags, Alter_inplace_info::RECREATE_TABLE + Alter_inplace_info::ALTER_COLUMN_DEFAULT)) {
ctx->optimize_needed = true;
result = HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE;
}
#endif
if (result != HA_ALTER_INPLACE_NOT_SUPPORTED && table->s->null_bytes != altered_table->s->null_bytes &&
(tokudb_debug & TOKUDB_DEBUG_ALTER_TABLE)) {
......@@ -517,6 +530,9 @@ bool ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha
if (error == 0 && ctx->reset_card) {
error = tokudb::set_card_from_status(share->status_block, ctx->alter_txn, table->s, altered_table->s);
}
if (error == 0 && ctx->optimize_needed) {
error = do_optimize(ha_thd());
}
#if (50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \
(50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799)
......@@ -728,7 +744,8 @@ bool ha_tokudb::commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_i
if (commit) {
#if (50613 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \
(50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799)
(50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) || \
(100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099)
if (ha_alter_info->group_commit_ctx) {
ha_alter_info->group_commit_ctx = NULL;
}
......@@ -752,7 +769,7 @@ bool ha_tokudb::commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_i
if (!commit) {
// abort the alter transaction NOW so that any alters are rolled back. this allows the following restores to work.
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
assert(ctx->alter_txn == trx->stmt);
assert(trx->tokudb_lock_count > 0);
// for partitioned tables, we use a single transaction to do all of the partition changes. the tokudb_lock_count
......
......@@ -814,7 +814,7 @@ int ha_tokudb::write_frm_data(const uchar *frm_data, size_t frm_len) {
if (TOKU_PARTITION_WRITE_FRM_DATA || table->part_info == NULL) {
// write frmdata to status
THD *thd = ha_thd();
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
assert(trx);
DB_TXN *txn = trx->stmt; // use alter table transaction
assert(txn);
......
......@@ -96,6 +96,10 @@ PATENT RIGHTS GRANT:
#pragma interface /* gcc class implementation */
#endif
#if !defined(TOKUDB_CHECK_JEMALLOC)
#define TOKUDB_CHECK_JEMALLOC 1
#endif
#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099
// mariadb 10.0
#define TOKU_USE_DB_TYPE_TOKUDB 1
......@@ -108,6 +112,7 @@ PATENT RIGHTS GRANT:
#define TOKU_INCLUDE_EXTENDED_KEYS 1
#endif
#define TOKU_INCLUDE_OPTION_STRUCTS 1
#define TOKU_OPTIMIZE_WITH_RECREATE 1
#elif 50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799
// mysql 5.7 with no patches
......@@ -130,17 +135,18 @@ PATENT RIGHTS GRANT:
#define TOKU_PARTITION_WRITE_FRM_DATA 0
#else
// mysql 5.6 with tokutek patches
#define TOKU_USE_DB_TYPE_TOKUDB 1 /* has DB_TYPE_TOKUDB patch */
#define TOKU_USE_DB_TYPE_TOKUDB 1 // has DB_TYPE_TOKUDB patch
#define TOKU_INCLUDE_ALTER_56 1
#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 /* has tokudb row format compression patch */
#define TOKU_INCLUDE_XA 1 /* has patch that fixes TC_LOG_MMAP code */
#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 // has tokudb row format compression patch
#define TOKU_INCLUDE_XA 1 // has patch that fixes TC_LOG_MMAP code
#define TOKU_PARTITION_WRITE_FRM_DATA 0
#define TOKU_INCLUDE_WRITE_FRM_DATA 0
#define TOKU_INCLUDE_UPSERT 1 /* has tokudb upsert patch */
#define TOKU_INCLUDE_UPSERT 1 // has tokudb upsert patch
#if defined(HTON_SUPPORTS_EXTENDED_KEYS)
#define TOKU_INCLUDE_EXTENDED_KEYS 1
#endif
#endif
#define TOKU_OPTIMIZE_WITH_RECREATE 1
#elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599
#define TOKU_USE_DB_TYPE_TOKUDB 1
......
......@@ -589,9 +589,6 @@ static int tokudb_done_func(void *p) {
toku_global_status_rows = NULL;
my_hash_free(&tokudb_open_tables);
tokudb_pthread_mutex_destroy(&tokudb_mutex);
#if defined(_WIN64)
toku_ydb_destroy();
#endif
TOKUDB_DBUG_RETURN(0);
}
......@@ -637,8 +634,7 @@ int tokudb_end(handlerton * hton, ha_panic_function type) {
static int tokudb_close_connection(handlerton * hton, THD * thd) {
int error = 0;
tokudb_trx_data* trx = NULL;
trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
if (trx && trx->checkpoint_lock_taken) {
error = db_env->checkpointing_resume(db_env);
}
......@@ -702,25 +698,27 @@ static void txn_progress_func(TOKU_TXN_PROGRESS progress, void* extra) {
}
static void commit_txn_with_progress(DB_TXN* txn, uint32_t flags, THD* thd) {
int r;
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
struct txn_progress_info info;
info.thd = thd;
r = txn->commit_with_progress(txn, flags, txn_progress_func, &info);
int r = txn->commit_with_progress(txn, flags, txn_progress_func, &info);
if (r != 0) {
sql_print_error("tried committing transaction %p and got error code %d", txn, r);
}
assert(r == 0);
thd_proc_info(thd, orig_proc_info);
}
static void abort_txn_with_progress(DB_TXN* txn, THD* thd) {
int r;
const char *orig_proc_info = tokudb_thd_get_proc_info(thd);
struct txn_progress_info info;
info.thd = thd;
r = txn->abort_with_progress(txn, txn_progress_func, &info);
int r = txn->abort_with_progress(txn, txn_progress_func, &info);
if (r != 0) {
sql_print_error("tried aborting transaction %p and got error code %d", txn, r);
}
assert(r == 0);
thd_proc_info(thd, orig_proc_info);
}
static void tokudb_cleanup_handlers(tokudb_trx_data *trx, DB_TXN *txn) {
......@@ -736,7 +734,7 @@ static int tokudb_commit(handlerton * hton, THD * thd, bool all) {
TOKUDB_DBUG_ENTER("");
DBUG_PRINT("trans", ("ending transaction %s", all ? "all" : "stmt"));
uint32_t syncflag = THDVAR(thd, commit_sync) ? 0 : DB_TXN_NOSYNC;
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
DB_TXN **txn = all ? &trx->all : &trx->stmt;
DB_TXN *this_txn = *txn;
if (this_txn) {
......@@ -765,7 +763,7 @@ static int tokudb_commit(handlerton * hton, THD * thd, bool all) {
static int tokudb_rollback(handlerton * hton, THD * thd, bool all) {
TOKUDB_DBUG_ENTER("");
DBUG_PRINT("trans", ("aborting transaction %s", all ? "all" : "stmt"));
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
DB_TXN **txn = all ? &trx->all : &trx->stmt;
DB_TXN *this_txn = *txn;
if (this_txn) {
......@@ -795,7 +793,7 @@ static int tokudb_xa_prepare(handlerton* hton, THD* thd, bool all) {
TOKUDB_DBUG_ENTER("");
int r = 0;
DBUG_PRINT("trans", ("preparing transaction %s", all ? "all" : "stmt"));
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
DB_TXN* txn = all ? trx->all : trx->stmt;
if (txn) {
if (tokudb_debug & TOKUDB_DEBUG_TXN) {
......@@ -874,7 +872,7 @@ static int tokudb_savepoint(handlerton * hton, THD * thd, void *savepoint) {
TOKUDB_DBUG_ENTER("");
int error;
SP_INFO save_info = (SP_INFO)savepoint;
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
if (thd->in_sub_stmt) {
assert(trx->stmt);
error = txn_begin(db_env, trx->sub_sp_level, &(save_info->txn), DB_INHERIT_ISOLATION, thd);
......@@ -905,7 +903,7 @@ static int tokudb_rollback_to_savepoint(handlerton * hton, THD * thd, void *save
DB_TXN* parent = NULL;
DB_TXN* txn_to_rollback = save_info->txn;
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
parent = txn_to_rollback->parent;
if (!(error = txn_to_rollback->abort(txn_to_rollback))) {
if (save_info->in_sub_stmt) {
......@@ -927,7 +925,7 @@ static int tokudb_release_savepoint(handlerton * hton, THD * thd, void *savepoin
DB_TXN* parent = NULL;
DB_TXN* txn_to_commit = save_info->txn;
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, hton);
parent = txn_to_commit->parent;
if (!(error = txn_to_commit->commit(txn_to_commit, 0))) {
if (save_info->in_sub_stmt) {
......@@ -984,10 +982,10 @@ static int tokudb_discover3(handlerton *hton, THD* thd, const char *db, const ch
HA_METADATA_KEY curr_key = hatoku_frm_data;
DBT key = {};
DBT value = {};
bool do_commit;
bool do_commit = false;
#if 100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data *trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
if (thd_sql_command(thd) == SQLCOM_CREATE_TABLE && trx && trx->sub_sp_level) {
do_commit = false;
txn = trx->sub_sp_level;
......@@ -1142,15 +1140,14 @@ static bool tokudb_show_engine_status(THD * thd, stat_print_fn * stat_print) {
static void tokudb_checkpoint_lock(THD * thd) {
int error;
const char *old_proc_info;
tokudb_trx_data* trx = NULL;
trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
if (!trx) {
error = create_tokudb_trx_data_instance(&trx);
//
// can only fail due to memory allocation, so ok to assert
//
assert(!error);
thd_data_set(thd, tokudb_hton->slot, trx);
thd_set_ha_data(thd, tokudb_hton, trx);
}
if (trx->checkpoint_lock_taken) {
......@@ -1174,8 +1171,7 @@ cleanup:
static void tokudb_checkpoint_unlock(THD * thd) {
int error;
const char *old_proc_info;
tokudb_trx_data* trx = NULL;
trx = (tokudb_trx_data *) thd_data_get(thd, tokudb_hton->slot);
tokudb_trx_data* trx = (tokudb_trx_data *) thd_get_ha_data(thd, tokudb_hton);
if (!trx) {
error = 0;
goto cleanup;
......
......@@ -9,6 +9,7 @@ locks_trx_id locks_mysql_thread_id locks_dname locks_key_left locks_key_right
select * from information_schema.tokudb_lock_waits;
requesting_trx_id blocking_trx_id lock_waits_dname lock_waits_key_left lock_waits_key_right lock_waits_start_time
set autocommit=0;
set tokudb_prelock_empty=OFF;
insert into t values (1);
set autocommit=0;
insert into t values (1);
......@@ -38,6 +39,7 @@ locks_trx_id locks_mysql_thread_id locks_dname locks_key_left locks_key_right
select * from information_schema.tokudb_lock_waits;
requesting_trx_id blocking_trx_id lock_waits_dname lock_waits_key_left lock_waits_key_right lock_waits_start_time
set autocommit=0;
set tokudb_prelock_empty=OFF;
replace into t values (1);
set autocommit=0;
replace into t values (1);
......
......@@ -9,6 +9,7 @@ locks_trx_id locks_mysql_thread_id locks_dname locks_key_left locks_key_right
select * from information_schema.tokudb_lock_waits;
requesting_trx_id blocking_trx_id lock_waits_dname lock_waits_key_left lock_waits_key_right lock_waits_start_time
set autocommit=0;
set tokudb_prelock_empty=OFF;
insert into t values (1);
set autocommit=0;
insert into t values (1);
......
......@@ -12,7 +12,7 @@ set autocommit=0;
insert into t values (2);
insert into t values (4);
insert into t values (6);
select * from information_schema.tokudb_locks order by locks_trx_id;
select * from information_schema.tokudb_locks order by locks_trx_id,locks_key_left;
locks_trx_id locks_mysql_thread_id locks_dname locks_key_left locks_key_right
TRX_ID MYSQL_ID ./test/t-main 0001000000 0001000000
TRX_ID MYSQL_ID ./test/t-main 0003000000 0003000000
......
......@@ -6,6 +6,7 @@ set autocommit=0;
select * from information_schema.tokudb_locks;
locks_trx_id locks_mysql_thread_id locks_dname locks_key_left locks_key_right
set autocommit=0;
set tokudb_prelock_empty=OFF;
insert into t values (1);
set autocommit=0;
insert into t values (1);
......
......@@ -16,6 +16,7 @@ select * from information_schema.tokudb_lock_waits;
connect (conn_a,localhost,root,,);
set autocommit=0;
set tokudb_prelock_empty=OFF;
insert into t values (1);
connect (conn_b,localhost,root,,);
......
This diff is collapsed.
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