1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 #include "test.h"
40
41 #include <db.h>
42 #include <dirent.h>
43 #include <fcntl.h>
44 #include <sys/stat.h>
45
46 static void
check_logmax(int max)47 check_logmax (int max) {
48 int any_too_big=0;
49 DIR *dir = opendir(TOKU_TEST_FILENAME);
50 struct dirent *ent;
51 while ((ent=readdir(dir))) {
52 if ((ent->d_type==DT_REG || ent->d_type==DT_UNKNOWN) && strncmp(ent->d_name, "log", 3)==0) {
53 // It is a "log*" file
54 char full_fname[TOKU_PATH_MAX + 1];
55 toku_struct_stat sbuf;
56 int r = toku_stat(
57 toku_path_join(full_fname, 2, TOKU_TEST_FILENAME, ent->d_name),
58 &sbuf,
59 toku_uninstrumented);
60 assert(r == 0);
61 if (verbose)
62 printf("%s is of size %" PRId64 "\n",
63 ent->d_name,
64 (int64_t)sbuf.st_size);
65 if (sbuf.st_size > max) any_too_big=1;
66 }
67 }
68 assert(!any_too_big);
69 int r=closedir(dir);
70 assert(r==0);
71 }
72
73 static void
test_logmax(int logmax)74 test_logmax (int logmax) {
75 int r;
76 DB_ENV *env;
77 DB *db;
78 DB_TXN *tid;
79
80 toku_os_recursive_delete(TOKU_TEST_FILENAME);
81 r=toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0);
82 r=db_env_create(&env, 0); assert(r==0);
83 if (logmax>0) {
84 r=env->set_lg_max(env, logmax);
85 assert(r==0);
86 }
87 r=env->open(env, TOKU_TEST_FILENAME, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
88 {
89 uint32_t lmax;
90 r=env->get_lg_max(env, &lmax);
91 assert(r==0);
92 if (logmax>0) {
93 assert(lmax==(uint32_t)logmax);
94 } else {
95 assert(lmax>0);
96
97 }
98 }
99 r=db_create(&db, env, 0); CKERR(r);
100 r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
101 r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
102 r=tid->commit(tid, 0); assert(r==0);
103
104 int i;
105 int sum = 0;
106 int effective_max;
107 if (logmax>0) effective_max = logmax;
108 else {
109 effective_max = 100<<20;
110 }
111
112 r=env->txn_begin(env, 0, &tid, 0); CKERR(r);
113 char there[1000];
114 memset(there, 'a',sizeof(there));
115 there[999]=0;
116 for (i=0; sum<(effective_max*3)/2; i++) {
117 DBT key,data;
118 char hello[20];
119 snprintf(hello, 20, "hello%d", i);
120 r=db->put(db, tid,
121 dbt_init(&key, hello, strlen(hello)+1),
122 dbt_init(&data, there, sizeof(there)),
123 0);
124 assert(r==0);
125 sum+=strlen(hello)+1+sizeof(there);
126 if ((i+1)%10==0) {
127 r=tid->commit(tid, 0); assert(r==0);
128 r=env->txn_begin(env, 0, &tid, 0); CKERR(r);
129 }
130 }
131 if (verbose) printf("i=%d sum=%d effmax=%d\n", i, sum, effective_max);
132 r=tid->commit(tid, 0); assert(r==0);
133 r=db->close(db, 0); assert(r==0);
134 r=env->close(env, 0); assert(r==0);
135 check_logmax(effective_max);
136 }
137
138 int
test_main(int argc,char * const argv[])139 test_main (int argc, char *const argv[]) {
140 parse_args(argc, argv);
141 test_logmax(1<<20);
142 test_logmax(-1);
143 return 0;
144 }
145