mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
d145d1b6ee
Merge into the MariaDB tree the pull request from Rich Prohaska for PerconaFT. These changes are needed to get parallel replication to work with TokuDB. Once the pull request is accepted by Percona and the new upstream version enters MariaDB, this commit can be superseded. Original commit message from Rich Prohaska: 1. Fix the release before wait race The release before wait race occurs when a lock is released by transaction A after transaction B tried to acquire it but before transaction B has a chance to register it's pending lock request. There are several ways to fix this problem, but we want to optimize for the common situation of minimal lock conflicts, which is what the lock acquisition algorithm currently does. Our solution to the release before wait race is for transaction B to retry its lock request after its lock request has been added to the pending lock set. 2. Fix the retry race The retry race occurs in the current lock retry algorithm which assumes that if some transaction is running lock retry, then my transaction does not also need to run it. There is a chance that some pending lock requests will be skipped, but these lock requests will eventually time out. For applications with small numbers of concurrent transactions, timeouts will frequently occur, and the application throughput will be very small. The solution to the retry race is to use a group retry algorithm. All threads run through the retry logic. Sequence numbers are used to group retries into batches such that one transaction can run the retry logic on behalf of several transactions. This amortizes the retry cost. The sequence numbers also ensure that when a transaction releases its locks, all of the pending lock requests that it is blocking are retried. 3. Implement a mechanism to find and kill a pending lock request Tags lock requests with a client id, use the client id as a key into the pending lock requests sets to find a lock request, complete the lock request with a lock timeout error. Copyright (c) 2016, Rich Prohaska All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155 lines
3.8 KiB
C
155 lines
3.8 KiB
C
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
|
#ident "$Id$"
|
|
/*======
|
|
This file is part of TokuDB
|
|
|
|
|
|
Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
|
|
|
|
TokuDBis is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License, version 2,
|
|
as published by the Free Software Foundation.
|
|
|
|
TokuDB 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 TokuDB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
======= */
|
|
|
|
#ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
|
|
|
|
#ifndef _TOKUDB_TXN_H
|
|
#define _TOKUDB_TXN_H
|
|
|
|
#include "hatoku_defines.h"
|
|
#include "tokudb_debug.h"
|
|
#include "tokudb_sysvars.h"
|
|
|
|
typedef enum {
|
|
hatoku_iso_not_set = 0,
|
|
hatoku_iso_read_uncommitted,
|
|
hatoku_iso_read_committed,
|
|
hatoku_iso_repeatable_read,
|
|
hatoku_iso_serializable
|
|
} HA_TOKU_ISO_LEVEL;
|
|
|
|
typedef struct st_tokudb_stmt_progress {
|
|
ulonglong inserted;
|
|
ulonglong updated;
|
|
ulonglong deleted;
|
|
ulonglong queried;
|
|
bool using_loader;
|
|
} tokudb_stmt_progress;
|
|
|
|
typedef struct st_tokudb_trx_data {
|
|
DB_TXN* all;
|
|
DB_TXN* stmt;
|
|
DB_TXN* sp_level;
|
|
DB_TXN* sub_sp_level;
|
|
uint tokudb_lock_count;
|
|
uint create_lock_count;
|
|
tokudb_stmt_progress stmt_progress;
|
|
bool checkpoint_lock_taken;
|
|
LIST* handlers;
|
|
} tokudb_trx_data;
|
|
|
|
extern char* tokudb_data_dir;
|
|
extern const char* ha_tokudb_ext;
|
|
|
|
inline void reset_stmt_progress(tokudb_stmt_progress* val) {
|
|
val->deleted = 0;
|
|
val->inserted = 0;
|
|
val->updated = 0;
|
|
val->queried = 0;
|
|
}
|
|
|
|
inline int get_name_length(const char* name) {
|
|
int n = 0;
|
|
const char* newname = name;
|
|
n += strlen(newname);
|
|
n += strlen(ha_tokudb_ext);
|
|
return n;
|
|
}
|
|
|
|
//
|
|
// returns maximum length of path to a dictionary
|
|
//
|
|
inline int get_max_dict_name_path_length(const char* tablename) {
|
|
int n = 0;
|
|
n += get_name_length(tablename);
|
|
n += 1; //for the '-'
|
|
n += MAX_DICT_NAME_LEN;
|
|
return n;
|
|
}
|
|
|
|
inline void make_name(
|
|
char* newname,
|
|
size_t newname_len,
|
|
const char* tablename,
|
|
const char* dictname) {
|
|
|
|
assert_always(tablename);
|
|
assert_always(dictname);
|
|
size_t real_size = snprintf(
|
|
newname,
|
|
newname_len,
|
|
"%s-%s",
|
|
tablename,
|
|
dictname);
|
|
assert_always(real_size < newname_len);
|
|
}
|
|
|
|
inline int txn_begin(
|
|
DB_ENV* env,
|
|
DB_TXN* parent,
|
|
DB_TXN** txn,
|
|
uint32_t flags,
|
|
THD* thd) {
|
|
|
|
*txn = NULL;
|
|
int r = env->txn_begin(env, parent, txn, flags);
|
|
if (r == 0 && thd) {
|
|
DB_TXN* this_txn = *txn;
|
|
this_txn->set_client_id(this_txn, thd_get_thread_id(thd), thd);
|
|
}
|
|
TOKUDB_TRACE_FOR_FLAGS(
|
|
TOKUDB_DEBUG_TXN,
|
|
"begin txn %p %p %u r=%d",
|
|
parent,
|
|
*txn,
|
|
flags,
|
|
r);
|
|
return r;
|
|
}
|
|
|
|
inline void commit_txn(DB_TXN* txn, uint32_t flags) {
|
|
TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_TXN, "commit txn %p", txn);
|
|
int r = txn->commit(txn, flags);
|
|
if (r != 0) {
|
|
sql_print_error(
|
|
"tried committing transaction %p and got error code %d",
|
|
txn,
|
|
r);
|
|
}
|
|
assert_always(r == 0);
|
|
}
|
|
|
|
inline void abort_txn(DB_TXN* txn) {
|
|
TOKUDB_TRACE_FOR_FLAGS(TOKUDB_DEBUG_TXN, "abort txn %p", txn);
|
|
int r = txn->abort(txn);
|
|
if (r != 0) {
|
|
sql_print_error(
|
|
"tried aborting transaction %p and got error code %d",
|
|
txn,
|
|
r);
|
|
}
|
|
assert_always(r == 0);
|
|
}
|
|
|
|
#endif // _TOKUDB_TXN_H
|