Commit 3c9a0435 authored by Rich Prohaska's avatar Rich Prohaska

#17 test env open with open file limit

parent 63bc7424
......@@ -290,16 +290,17 @@ toku_logger_open_rollback(TOKULOGGER logger, CACHETABLE cachetable, bool create)
FT_HANDLE t = NULL; // Note, there is no DB associated with this BRT.
toku_ft_handle_create(&t);
int r = toku_ft_handle_open(t, toku_product_name_strings.rollback_cachefile, create, create, cachetable, NULL_TXN);
assert_zero(r);
logger->rollback_cachefile = t->ft->cf;
toku_logger_initialize_rollback_cache(logger, t->ft);
//Verify it is empty
//Must have no data blocks (rollback logs or otherwise).
toku_block_verify_no_data_blocks_except_root(t->ft->blocktable, t->ft->h->root_blocknum);
bool is_empty;
is_empty = toku_ft_is_empty_fast(t);
assert(is_empty);
if (r == 0) {
logger->rollback_cachefile = t->ft->cf;
toku_logger_initialize_rollback_cache(logger, t->ft);
//Verify it is empty
//Must have no data blocks (rollback logs or otherwise).
toku_block_verify_no_data_blocks_except_root(t->ft->blocktable, t->ft->h->root_blocknum);
bool is_empty;
is_empty = toku_ft_is_empty_fast(t);
assert(is_empty);
}
return r;
}
......
......@@ -203,7 +203,7 @@ public:
class manager {
public:
typedef void (*lt_create_cb)(locktree *lt, void *extra);
typedef int (*lt_create_cb)(locktree *lt, void *extra);
typedef void (*lt_destroy_cb)(locktree *lt);
typedef void (*lt_escalate_cb)(TXNID txnid, const locktree *lt, const range_buffer &buffer, void *extra);
......
......@@ -204,10 +204,17 @@ locktree *locktree::manager::get_lt(DICTIONARY_ID dict_id, DESCRIPTOR desc,
// new locktree created - call the on_create callback
// and put it in the locktree map
if (m_lt_create_callback) {
m_lt_create_callback(lt, on_create_extra);
int r = m_lt_create_callback(lt, on_create_extra);
if (r != 0) {
(void) toku_sync_sub_and_fetch(&lt->m_reference_count, 1);
lt->destroy();
toku_free(lt);
lt = nullptr;
}
}
if (lt) {
locktree_map_put(lt);
}
locktree_map_put(lt);
} else {
reference_lt(lt);
}
......
......@@ -92,11 +92,12 @@ PATENT RIGHTS GRANT:
namespace toku {
static void create_cb(locktree *lt, void *extra) {
static int create_cb(locktree *lt, void *extra) {
lt->set_userdata(extra);
bool *k = (bool *) extra;
invariant(!(*k));
(*k) = true;
return 0;
}
static void destroy_cb(locktree *lt) {
......
......@@ -203,10 +203,8 @@ set_max(uint64_t sum_used, uint64_t sum_freed) {
size_t
toku_memory_footprint(void * p, size_t touched) {
static size_t pagesize = 0;
size_t rval = 0;
if (!pagesize)
pagesize = sysconf(_SC_PAGESIZE);
size_t pagesize = toku_os_get_pagesize();
if (p) {
size_t usable = my_malloc_usable_size(p);
if (usable >= status.mmap_threshold) {
......
......@@ -135,8 +135,9 @@ toku_portability_init(void) {
int r = toku_memory_startup();
if (r == 0) {
uint64_t hz;
r = toku_os_get_processor_frequency(&hz);
r = toku_os_get_processor_frequency(&hz); // get and cache freq
}
(void) toku_os_get_pagesize(); // get and cache pagesize
return r;
}
......@@ -185,9 +186,18 @@ toku_os_get_number_active_processors(void) {
return n;
}
int toku_cached_pagesize = 0;
int
toku_os_get_pagesize(void) {
return sysconf(_SC_PAGESIZE);
int pagesize = toku_cached_pagesize;
if (pagesize == 0) {
pagesize = sysconf(_SC_PAGESIZE);
if (pagesize) {
toku_cached_pagesize = pagesize;
}
}
return pagesize;
}
uint64_t
......@@ -456,4 +466,5 @@ void __attribute__((constructor)) toku_portability_helgrind_ignore(void);
void
toku_portability_helgrind_ignore(void) {
TOKU_VALGRIND_HG_DISABLE_CHECKING(&toku_cached_hz, sizeof toku_cached_hz);
TOKU_VALGRIND_HG_DISABLE_CHECKING(&toku_cached_pagesize, sizeof toku_cached_pagesize);
}
......@@ -111,6 +111,9 @@ if(BUILD_TESTING OR BUILD_SRC_TESTS)
mvcc-create-table
mvcc-many-committed
mvcc-read-committed
openlimit17
openlimit17-locktree
openlimit17-metafiles
perf_checkpoint_var
perf_child_txn
perf_cursor_nop
......
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
/*
COPYING CONDITIONS NOTICE:
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation, and provided that the
following conditions are met:
* Redistributions of source code must retain this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below).
* Redistributions in binary form must reproduce this COPYING
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
GRANT (below) in the documentation and/or other materials
provided with the distribution.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
COPYRIGHT NOTICE:
TokuDB, Tokutek Fractal Tree Indexing Library.
Copyright (C) 2007-2013 Tokutek, Inc.
DISCLAIMER:
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
UNIVERSITY PATENT NOTICE:
The technology is licensed by the Massachusetts Institute of
Technology, Rutgers State University of New Jersey, and the Research
Foundation of State University of New York at Stony Brook under
United States of America Serial No. 11/760379 and to the patents
and/or patent applications resulting from it.
PATENT MARKING NOTICE:
This software is covered by US Patent No. 8,185,551.
PATENT RIGHTS GRANT:
"THIS IMPLEMENTATION" means the copyrightable works distributed by
Tokutek as part of the Fractal Tree project.
"PATENT CLAIMS" means the claims of patents that are owned or
licensable by Tokutek, both currently or in the future; and that in
the absence of this license would be infringed by THIS
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
"PATENT CHALLENGE" shall mean a challenge to the validity,
patentability, enforceability and/or non-infringement of any of the
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
Tokutek hereby grants to you, for the term and geographical scope of
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and
otherwise run, modify, and propagate the contents of THIS
IMPLEMENTATION, where such license applies only to the PATENT
CLAIMS. This grant does not include claims that would be infringed
only as a consequence of further modifications of THIS
IMPLEMENTATION. If you or your agent or licensee institute or order
or agree to the institution of patent litigation against any entity
(including a cross-claim or counterclaim in a lawsuit) alleging that
THIS IMPLEMENTATION constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any rights
granted to you under this License shall terminate as of the date
such litigation is filed. If you or your agent or exclusive
licensee institute or order or agree to the institution of a PATENT
CHALLENGE, then Tokutek may terminate any rights granted to you
under this License.
*/
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include "test.h"
#include <sys/resource.h>
// create 200 databases and close them. set the open file limit to 100 and try to open all of them.
// eventually, the locktree can not clone fractal tree, and the db open fails.
int test_main (int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) {
int r;
const int N = 200;
toku_os_recursive_delete(TOKU_TEST_FILENAME);
r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
DB_ENV *env;
r = db_env_create(&env, 0);
assert(r == 0);
r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
DB **dbs = new DB *[N];
for (int i = 0; i < N; i++) {
dbs[i] = NULL;
}
for (int i = 0; i < N; i++) {
r = db_create(&dbs[i], env, 0);
assert(r == 0);
char dbname[32]; sprintf(dbname, "%d.test", i);
r = dbs[i]->open(dbs[i], NULL, dbname, NULL, DB_BTREE, DB_AUTO_COMMIT+DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
}
for (int i = 0; i < N; i++) {
if (dbs[i]) {
r = dbs[i]->close(dbs[i], 0);
assert(r == 0);
}
}
struct rlimit nofile_limit = { N/2, N/2 };
r = setrlimit(RLIMIT_NOFILE, &nofile_limit);
// assert(r == 0); // valgrind does not like this
if (r != 0) {
printf("warning: set nofile limit to %d failed %d %s\n", N, errno, strerror(errno));
}
for (int i = 0; i < N; i++) {
dbs[i] = NULL;
}
bool emfile_happened = false;
for (int i = 0; i < N; i++) {
r = db_create(&dbs[i], env, 0);
assert(r == 0);
char dbname[32]; sprintf(dbname, "%d.test", i);
r = dbs[i]->open(dbs[i], NULL, dbname, NULL, DB_BTREE, DB_AUTO_COMMIT, S_IRWXU+S_IRWXG+S_IRWXO);
if (r == EMFILE) {
emfile_happened = true;
break;
}
}
assert(emfile_happened);
for (int i = 0; i < N; i++) {
if (dbs[i]) {
r = dbs[i]->close(dbs[i], 0);
assert(r == 0);
}
}
r = env->close(env, 0);
assert(r == 0);
delete [] dbs;
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.
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."
#include "test.h"
#include <fcntl.h>
#include <sys/resource.h>
// try to open the environment with a small number of unused file descriptors
int test_main (int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) {
int r;
toku_os_recursive_delete(TOKU_TEST_FILENAME);
r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
DB_ENV *env;
r = db_env_create(&env, 0);
assert(r == 0);
r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO);
assert(r == 0);
r = env->close(env, 0);
assert(r == 0);
struct rlimit nofile_limit;
r = getrlimit(RLIMIT_NOFILE, &nofile_limit);
assert(r == 0);
const int N = 100;
nofile_limit.rlim_cur = N;
r = setrlimit(RLIMIT_NOFILE, &nofile_limit);
assert(r == 0);
// compute the number of unused file descriptors
int fds[N];
for (int i = 0; i < N; i++) {
fds[i] = -1;
}
int unused = 0;
for (int i = 0; i < N; i++, unused++) {
fds[i] = open("/dev/null", O_RDONLY);
if (fds[i] == -1)
break;
}
for (int i = 0; i < N; i++) {
if (fds[i] != -1) {
close(fds[i]);
}
}
// try to open the environment with a constrained number of unused file descriptors. the env open should return an error rather than crash.
for (int n = N - unused; n < N; n++) {
nofile_limit.rlim_cur = n;
r = setrlimit(RLIMIT_NOFILE, &nofile_limit);
assert(r == 0);
r = db_env_create(&env, 0);
assert(r == 0);
r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL|DB_CREATE|DB_THREAD|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO);
if (r == 0) {
r = env->close(env, 0);
assert(r == 0);
break;
}
assert(r == EMFILE);
r = env->close(env, 0);
assert(r == 0);
}
return 0;
}
......@@ -120,24 +120,21 @@ int test_main (int argc __attribute__((__unused__)), char *const argv[] __attrib
for (int i = 0; i < N; i++) {
dbs[i] = NULL;
}
bool hit_file_limit = false;
int dbnum = 0;
bool emfile_happened = false;
for (int i = 0; i < N; i++) {
r = db_create(&dbs[i], env, 0);
assert(r == 0);
char dbname[32]; sprintf(dbname, "%d.test", i);
r = dbs[i]->open(dbs[i], NULL, dbname, NULL, DB_BTREE, DB_AUTO_COMMIT+DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
if (r == 24) {
hit_file_limit = true;
if (r == EMFILE) {
emfile_happened = true;
break;
}
assert(r == 0);
dbnum = i;
}
printf("dbnum=%d of %d\n", dbnum, N);
assert(hit_file_limit);
assert(emfile_happened);
for (int i = 0; i < N; i++) {
if (dbs[i]) {
......
......@@ -842,6 +842,7 @@ env_open(DB_ENV * env, const char *home, uint32_t flags, int mode) {
bool newenv; // true iff creating a new environment
uint32_t unused_flags=flags;
CHECKPOINTER cp;
DB_TXN *txn = NULL;
if (env_opened(env)) {
r = toku_ydb_do_error(env, EINVAL, "The environment is already open\n");
......@@ -1006,12 +1007,13 @@ env_open(DB_ENV * env, const char *home, uint32_t flags, int mode) {
if (!toku_logger_rollback_is_open(env->i->logger)) {
bool create_new_rollback_file = newenv | upgrade_in_progress;
r = toku_logger_open_rollback(env->i->logger, env->i->cachetable, create_new_rollback_file);
assert(r==0);
if (r != 0) {
r = toku_ydb_do_error(env, r, "cant open rollback");
goto cleanup;
}
}
}
DB_TXN *txn;
txn=NULL;
if (using_txns) {
r = toku_txn_begin(env, 0, &txn, 0);
assert_zero(r);
......@@ -1023,7 +1025,10 @@ env_open(DB_ENV * env, const char *home, uint32_t flags, int mode) {
r = db_use_builtin_key_cmp(env->i->persistent_environment);
assert_zero(r);
r = toku_db_open_iname(env->i->persistent_environment, txn, toku_product_name_strings.environmentdictionary, DB_CREATE, mode);
assert_zero(r);
if (r != 0) {
r = toku_ydb_do_error(env, r, "cant open persistent env");
goto cleanup;
}
if (newenv) {
// create new persistent_environment
DBT key, val;
......@@ -1058,7 +1063,10 @@ env_open(DB_ENV * env, const char *home, uint32_t flags, int mode) {
r = db_use_builtin_key_cmp(env->i->directory);
assert_zero(r);
r = toku_db_open_iname(env->i->directory, txn, toku_product_name_strings.fileopsdirectory, DB_CREATE, mode);
assert_zero(r);
if (r != 0) {
r = toku_ydb_do_error(env, r, "cant open %s", toku_product_name_strings.fileopsdirectory);
goto cleanup;
}
}
if (using_txns) {
r = locked_txn_commit(txn, 0);
......@@ -1072,6 +1080,9 @@ env_open(DB_ENV * env, const char *home, uint32_t flags, int mode) {
env_fsync_log_cron_init(env);
cleanup:
if (r!=0) {
if (txn) {
locked_txn_abort(txn);
}
if (env && env->i) {
unlock_single_process(env);
}
......
......@@ -405,7 +405,7 @@ db_on_redirect_callback(FT_HANDLE ft_handle, void* extra) {
// when a locktree is created, clone a ft handle and store it
// as userdata so we can close it later.
void toku_db_lt_on_create_callback(toku::locktree *lt, void *extra) {
int toku_db_lt_on_create_callback(toku::locktree *lt, void *extra) {
int r;
struct lt_on_create_callback_extra *info = (struct lt_on_create_callback_extra *) extra;
TOKUTXN ttxn = info->txn ? db_txn_struct_i(info->txn)->tokutxn : NULL;
......@@ -413,10 +413,11 @@ void toku_db_lt_on_create_callback(toku::locktree *lt, void *extra) {
FT_HANDLE cloned_ft_handle;
r = toku_ft_handle_clone(&cloned_ft_handle, ft_handle, ttxn);
invariant_zero(r);
assert(lt->get_userdata() == NULL);
lt->set_userdata(cloned_ft_handle);
if (r == 0) {
assert(lt->get_userdata() == NULL);
lt->set_userdata(cloned_ft_handle);
}
return r;
}
// when a locktree is about to be destroyed,
......@@ -499,7 +500,12 @@ toku_db_open_iname(DB * db, DB_TXN * txn, const char *iname_in_env, uint32_t fla
db->cmp_descriptor,
toku_ft_get_bt_compare(db->i->ft_handle),
&on_create_extra);
invariant_notnull(db->i->lt);
if (db->i->lt == nullptr) {
r = errno;
if (r == 0)
r = EINVAL;
goto error_cleanup;
}
}
return 0;
......
......@@ -119,7 +119,7 @@ struct lt_on_create_callback_extra {
DB_TXN *txn;
FT_HANDLE ft_handle;
};
void toku_db_lt_on_create_callback(toku::locktree *lt, void *extra);
int toku_db_lt_on_create_callback(toku::locktree *lt, void *extra);
void toku_db_lt_on_destroy_callback(toku::locktree *lt);
/* db methods */
......
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