summaryrefslogtreecommitdiff
path: root/innobase
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-05-11 12:21:38 +0300
committerunknown <monty@mysql.com>2004-05-11 12:21:38 +0300
commit19f41e6e0df2d875cff2404f9bbbab30d81b72b1 (patch)
tree0752eb9dfe0f1e306cf9a542e09d9cc646c11a0f /innobase
parentcb24e8b9b29f1aa3edfc4d7a61a9d842cb48ca69 (diff)
parentf3d691a970627f34ed825a9cf7b84520dcdd43b3 (diff)
downloadmariadb-git-19f41e6e0df2d875cff2404f9bbbab30d81b72b1.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/my/mysql-5.0 sql/mysql_priv.h: Auto merged sql/opt_range.cc: Auto merged sql/sp.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_lex.cc: Auto merged sql-bench/limits/mysql-4.0.cfg: Auto merged
Diffstat (limited to 'innobase')
-rw-r--r--innobase/Makefile.am4
-rw-r--r--innobase/btr/btr0btr.c78
-rw-r--r--innobase/btr/btr0cur.c119
-rw-r--r--innobase/btr/btr0pcur.c4
-rw-r--r--innobase/btr/btr0sea.c135
-rw-r--r--innobase/btr/ts/isql.c312
-rw-r--r--innobase/btr/ts/makefile16
-rw-r--r--innobase/btr/ts/trash/TSIT.C483
-rw-r--r--innobase/btr/ts/trash/tsbtrold5.c798
-rw-r--r--innobase/btr/ts/trash/tscli.c2263
-rw-r--r--innobase/btr/ts/tsbtr97.c5080
-rw-r--r--innobase/btr/ts/tsbtrfull.c4925
-rw-r--r--innobase/btr/ts/tsbtrins.c802
-rw-r--r--innobase/btr/ts/tscli.c3380
-rw-r--r--innobase/btr/ts/tsrecv.c4909
-rw-r--r--innobase/btr/ts/tsrecv97.c4909
-rw-r--r--innobase/btr/ts/tss.c397
-rw-r--r--innobase/btr/ts/tssrv.c535
-rw-r--r--innobase/buf/buf0buf.c29
-rw-r--r--innobase/buf/buf0flu.c13
-rw-r--r--innobase/buf/buf0lru.c42
-rw-r--r--innobase/buf/ts/makefile20
-rw-r--r--innobase/buf/ts/tsbuf.c885
-rw-r--r--innobase/buf/ts/tsos.c185
-rw-r--r--innobase/com/Makefile.am24
-rw-r--r--innobase/com/com0com.c345
-rw-r--r--innobase/com/com0shm.c1163
-rw-r--r--innobase/com/makefilewin12
-rw-r--r--innobase/com/ts/makefile19
-rw-r--r--innobase/com/ts/tscli.c96
-rw-r--r--innobase/com/ts/tscom.c94
-rw-r--r--innobase/configure.in5
-rw-r--r--innobase/cry/makefilewin12
-rw-r--r--innobase/data/data0data.c421
-rw-r--r--innobase/data/data0type.c91
-rw-r--r--innobase/dict/dict0boot.c25
-rw-r--r--innobase/dict/dict0crea.c178
-rw-r--r--innobase/dict/dict0dict.c714
-rw-r--r--innobase/dict/dict0load.c31
-rw-r--r--innobase/dict/dict0mem.c6
-rw-r--r--innobase/dict/ts/makefile16
-rw-r--r--innobase/dict/ts/tsdict.c73
-rw-r--r--innobase/dyn/ts/makefile12
-rw-r--r--innobase/dyn/ts/tsdyn.c57
-rw-r--r--innobase/fil/fil0fil.c12
-rw-r--r--innobase/fil/ts/makefile15
-rw-r--r--innobase/fil/ts/tsfil.c329
-rw-r--r--innobase/fsp/fsp0fsp.c125
-rw-r--r--innobase/fsp/trash/FSP0FSP.C3100
-rw-r--r--innobase/fsp/ts/del.c891
-rw-r--r--innobase/fsp/ts/makefile16
-rw-r--r--innobase/fsp/ts/tsfsp.c1234
-rw-r--r--innobase/ha/ha0ha.c36
-rw-r--r--innobase/ha/hash0hash.c38
-rw-r--r--innobase/ha/ts/makefile12
-rw-r--r--innobase/ha/ts/tsha.c120
-rw-r--r--innobase/ibuf/ibuf0ibuf.c30
-rw-r--r--innobase/include/Makefile.am9
-rw-r--r--innobase/include/btr0btr.ic3
-rw-r--r--innobase/include/btr0cur.h21
-rw-r--r--innobase/include/btr0sea.h37
-rw-r--r--innobase/include/btr0sea.ic6
-rw-r--r--innobase/include/buf0buf.h5
-rw-r--r--innobase/include/buf0buf.ic23
-rw-r--r--innobase/include/buf0flu.ic4
-rw-r--r--innobase/include/com0com.h125
-rw-r--r--innobase/include/com0com.ic7
-rw-r--r--innobase/include/com0shm.h103
-rw-r--r--innobase/include/com0shm.ic7
-rw-r--r--innobase/include/data0data.h92
-rw-r--r--innobase/include/data0data.ic25
-rw-r--r--innobase/include/data0type.h142
-rw-r--r--innobase/include/data0type.ic68
-rw-r--r--innobase/include/dict0crea.h24
-rw-r--r--innobase/include/dict0dict.h35
-rw-r--r--innobase/include/dict0dict.ic10
-rw-r--r--innobase/include/dict0mem.h17
-rw-r--r--innobase/include/fut0fut.ic2
-rw-r--r--innobase/include/ha0ha.ic8
-rw-r--r--innobase/include/hash0hash.h75
-rw-r--r--innobase/include/hash0hash.ic8
-rw-r--r--innobase/include/ib_odbc.h149
-rw-r--r--innobase/include/ibuf0ibuf.h9
-rw-r--r--innobase/include/lock0lock.h8
-rw-r--r--innobase/include/lock0lock.ic2
-rw-r--r--innobase/include/log0log.h4
-rw-r--r--innobase/include/log0log.ic10
-rw-r--r--innobase/include/mach0data.h19
-rw-r--r--innobase/include/mach0data.ic38
-rw-r--r--innobase/include/mem0dbg.h18
-rw-r--r--innobase/include/mem0dbg.ic2
-rw-r--r--innobase/include/mem0mem.ic52
-rw-r--r--innobase/include/mtr0log.h10
-rw-r--r--innobase/include/mtr0mtr.h25
-rw-r--r--innobase/include/odbc0odbc.h20
-rw-r--r--innobase/include/os0file.h61
-rw-r--r--innobase/include/os0proc.h31
-rw-r--r--innobase/include/os0thread.h7
-rw-r--r--innobase/include/page0cur.h5
-rw-r--r--innobase/include/pars0pars.h31
-rw-r--r--innobase/include/que0que.h25
-rw-r--r--innobase/include/que0que.ic18
-rw-r--r--innobase/include/rem0cmp.ic18
-rw-r--r--innobase/include/row0ins.h5
-rw-r--r--innobase/include/row0mysql.h21
-rw-r--r--innobase/include/row0row.h25
-rw-r--r--innobase/include/row0upd.h5
-rw-r--r--innobase/include/row0upd.ic2
-rw-r--r--innobase/include/srv0srv.h29
-rw-r--r--innobase/include/srv0start.h10
-rw-r--r--innobase/include/sync0rw.h14
-rw-r--r--innobase/include/sync0rw.ic45
-rw-r--r--innobase/include/sync0sync.h23
-rw-r--r--innobase/include/sync0sync.ic13
-rw-r--r--innobase/include/trx0rseg.ic8
-rw-r--r--innobase/include/trx0sys.ic22
-rw-r--r--innobase/include/trx0trx.h19
-rw-r--r--innobase/include/trx0undo.h14
-rw-r--r--innobase/include/trx0undo.ic4
-rw-r--r--innobase/include/univold.i164
-rw-r--r--innobase/include/univoldmysql.i181
-rw-r--r--innobase/include/usr0sess.h261
-rw-r--r--innobase/include/usr0sess.ic24
-rw-r--r--innobase/include/usr0types.h2
-rw-r--r--innobase/include/ut0dbg.h23
-rw-r--r--innobase/include/ut0mem.h18
-rw-r--r--innobase/include/ut0rnd.ic8
-rw-r--r--innobase/lock/lock0lock.c284
-rw-r--r--innobase/log/log0log.c128
-rw-r--r--innobase/log/log0recv.c60
-rw-r--r--innobase/log/trash/log0trsh.c648
-rw-r--r--innobase/mach/ts/makefile12
-rw-r--r--innobase/mach/ts/tsmach.c158
-rw-r--r--innobase/mem/mem0dbg.c197
-rw-r--r--innobase/mem/mem0mem.c4
-rw-r--r--innobase/mem/mem0pool.c14
-rw-r--r--innobase/mem/ts/makefile12
-rw-r--r--innobase/mem/ts/tsmem.c497
-rw-r--r--innobase/mtr/mtr0log.c13
-rw-r--r--innobase/mtr/mtr0mtr.c4
-rw-r--r--innobase/mtr/ts/makefile8
-rw-r--r--innobase/mtr/ts/tsbuf.c531
-rw-r--r--innobase/mtr/ts/tsmtr.c158
-rw-r--r--innobase/odbc/Makefile.am24
-rw-r--r--innobase/odbc/makefilewin7
-rw-r--r--innobase/odbc/odbc0dummy.c62
-rw-r--r--innobase/odbc/odbc0odbc.c714
-rw-r--r--innobase/os/os0file.c215
-rw-r--r--innobase/os/os0fileold.c1956
-rw-r--r--innobase/os/os0proc.c77
-rw-r--r--innobase/os/os0trash.c43
-rw-r--r--innobase/os/ts/makefile20
-rw-r--r--innobase/os/ts/tsos.c793
-rw-r--r--innobase/os/ts/tsosaux.c83
-rw-r--r--innobase/page/page0cur.c9
-rw-r--r--innobase/page/page0page.c32
-rw-r--r--innobase/page/ts/makefile16
-rw-r--r--innobase/page/ts/tspage.c705
-rw-r--r--innobase/pars/lexyy.c2
-rw-r--r--innobase/pars/pars0pars.c258
-rw-r--r--innobase/que/que0que.c340
-rw-r--r--innobase/read/read0read.c12
-rw-r--r--innobase/rem/rem0cmp.c59
-rw-r--r--innobase/rem/rem0rec.c4
-rw-r--r--innobase/rem/ts/makefile16
-rw-r--r--innobase/rem/ts/tsrem.c464
-rw-r--r--innobase/row/row0ins.c93
-rw-r--r--innobase/row/row0mysql.c165
-rw-r--r--innobase/row/row0purge.c6
-rw-r--r--innobase/row/row0row.c59
-rw-r--r--innobase/row/row0sel.c19
-rw-r--r--innobase/row/row0undo.c2
-rw-r--r--innobase/row/row0upd.c23
-rw-r--r--innobase/row/row0vers.c8
-rw-r--r--innobase/row/ts/makefile16
-rw-r--r--innobase/row/ts/tstcur.c1087
-rw-r--r--innobase/srv/srv0que.c2
-rw-r--r--innobase/srv/srv0srv.c990
-rw-r--r--innobase/srv/srv0start.c102
-rw-r--r--innobase/srv/ts/makefile15
-rw-r--r--innobase/srv/ts/tsdbc.c118
-rw-r--r--innobase/srv/ts/tssrv.c39
-rw-r--r--innobase/sync/sync0arr.c36
-rw-r--r--innobase/sync/sync0rw.c50
-rw-r--r--innobase/sync/sync0sync.c131
-rw-r--r--innobase/sync/ts/makefile14
-rw-r--r--innobase/sync/ts/tssync.c1366
-rw-r--r--innobase/thr/thr0loc.c12
-rw-r--r--innobase/thr/ts/makefile14
-rw-r--r--innobase/thr/ts/tsthr.c131
-rw-r--r--innobase/trx/trx0purge.c37
-rw-r--r--innobase/trx/trx0rec.c47
-rw-r--r--innobase/trx/trx0roll.c32
-rw-r--r--innobase/trx/trx0rseg.c11
-rw-r--r--innobase/trx/trx0sys.c25
-rw-r--r--innobase/trx/trx0trx.c122
-rw-r--r--innobase/trx/trx0undo.c107
-rw-r--r--innobase/trx/ts/makefile16
-rw-r--r--innobase/trx/ts/tstrx.c1663
-rw-r--r--innobase/trx/ts/tsttrxold.c1089
-rw-r--r--innobase/usr/usr0sess.c1116
-rw-r--r--innobase/ut/ts/makefile12
-rw-r--r--innobase/ut/ts/tsut.c347
-rw-r--r--innobase/ut/ut0dbg.c7
-rw-r--r--innobase/ut/ut0mem.c48
205 files changed, 2905 insertions, 56944 deletions
diff --git a/innobase/Makefile.am b/innobase/Makefile.am
index cc4ce312d8d..8ff90d16a2c 100644
--- a/innobase/Makefile.am
+++ b/innobase/Makefile.am
@@ -22,8 +22,8 @@ TAR = gtar
noinst_HEADERS = ib_config.h
-SUBDIRS = os ut btr buf com data dict dyn eval fil fsp fut \
- ha ibuf include lock log mach mem mtr odbc page \
+SUBDIRS = os ut btr buf data dict dyn eval fil fsp fut \
+ ha ibuf include lock log mach mem mtr page \
pars que read rem row srv sync thr trx usr
# Don't update the files from bitkeeper
diff --git a/innobase/btr/btr0btr.c b/innobase/btr/btr0btr.c
index eb18fecb368..77bb4231404 100644
--- a/innobase/btr/btr0btr.c
+++ b/innobase/btr/btr0btr.c
@@ -5,7 +5,7 @@ The B-tree
Created 6/2/1994 Heikki Tuuri
*******************************************************/
-
+
#include "btr0btr.h"
#ifdef UNIV_NONINL
@@ -76,9 +76,6 @@ make them consecutive on disk if possible. From the other file segment
we allocate pages for the non-leaf levels of the tree.
*/
-/* If this many inserts occur sequentially, it affects page split */
-#define BTR_PAGE_SEQ_INSERT_LIMIT 5
-
/******************************************************************
Creates a new index page to the tree (not the root, and also not
used in page reorganization). */
@@ -299,7 +296,9 @@ btr_page_alloc_for_ibuf(
new_page = buf_page_get(dict_tree_get_space(tree), node_addr.page,
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(new_page, SYNC_TREE_NODE_NEW);
+#endif /* UNIV_SYNC_DEBUG */
flst_remove(root + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST,
new_page + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE,
@@ -357,7 +356,9 @@ btr_page_alloc(
new_page = buf_page_get(dict_tree_get_space(tree), new_page_no,
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(new_page, SYNC_TREE_NODE_NEW);
+#endif /* UNIV_SYNC_DEBUG */
return(new_page);
}
@@ -398,7 +399,7 @@ btr_get_size(
n += fseg_n_reserved_pages(seg_header, &dummy, &mtr);
} else {
- ut_a(0);
+ ut_error;
}
mtr_commit(&mtr);
@@ -664,8 +665,9 @@ btr_create(
ibuf_hdr_frame = fseg_create(space, 0,
IBUF_HEADER + IBUF_TREE_SEG_HEADER, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(ibuf_hdr_frame, SYNC_TREE_NODE_NEW);
-
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(buf_frame_get_page_no(ibuf_hdr_frame)
== IBUF_HEADER_PAGE_NO);
/* Allocate then the next page to the segment: it will be the
@@ -690,7 +692,9 @@ btr_create(
page_no = buf_frame_get_page_no(frame);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(frame, SYNC_TREE_NODE_NEW);
+#endif /* UNIV_SYNC_DEBUG */
if (type & DICT_IBUF) {
/* It is an insert buffer tree: initialize the free list */
@@ -705,7 +709,9 @@ btr_create(
mtr);
/* The fseg create acquires a second latch on the page,
therefore we must declare it: */
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(frame, SYNC_TREE_NODE_NEW);
+#endif /* UNIV_SYNC_DEBUG */
}
/* Create a new index page on the the allocated segment page */
@@ -1080,18 +1086,18 @@ btr_page_get_split_rec_to_left(
page = btr_cur_get_page(cursor);
insert_point = btr_cur_get_rec(cursor);
- if ((page_header_get_ptr(page, PAGE_LAST_INSERT)
- == page_rec_get_next(insert_point))
- && (page_header_get_field(page, PAGE_DIRECTION) == PAGE_LEFT)
- && ((page_header_get_field(page, PAGE_N_DIRECTION)
- >= BTR_PAGE_SEQ_INSERT_LIMIT)
- || (page_header_get_field(page, PAGE_N_DIRECTION) + 1
- >= page_get_n_recs(page)))) {
+ if (page_header_get_ptr(page, PAGE_LAST_INSERT)
+ == page_rec_get_next(insert_point)) {
infimum = page_get_infimum_rec(page);
-
- if ((infimum != insert_point)
- && (page_rec_get_next(infimum) != insert_point)) {
+
+ /* If the convergence is in the middle of a page, include also
+ the record immediately before the new insert to the upper
+ page. Otherwise, we could repeatedly move from page to page
+ lots of records smaller than the convergence point. */
+
+ if (infimum != insert_point
+ && page_rec_get_next(infimum) != insert_point) {
*split_rec = insert_point;
} else {
@@ -1125,29 +1131,29 @@ btr_page_get_split_rec_to_right(
page = btr_cur_get_page(cursor);
insert_point = btr_cur_get_rec(cursor);
- if ((page_header_get_ptr(page, PAGE_LAST_INSERT) == insert_point)
- && (page_header_get_field(page, PAGE_DIRECTION) == PAGE_RIGHT)
- && ((page_header_get_field(page, PAGE_N_DIRECTION)
- >= BTR_PAGE_SEQ_INSERT_LIMIT)
- || (page_header_get_field(page, PAGE_N_DIRECTION) + 1
- >= page_get_n_recs(page)))) {
+ /* We use eager heuristics: if the new insert would be right after
+ the previous insert on the same page, we assume that there is a
+ pattern of sequential inserts here. */
+
+ if (page_header_get_ptr(page, PAGE_LAST_INSERT) == insert_point) {
supremum = page_get_supremum_rec(page);
- if ((page_rec_get_next(insert_point) != supremum)
- && (page_rec_get_next(page_rec_get_next(insert_point))
- != supremum)
- && (page_rec_get_next(page_rec_get_next(
- page_rec_get_next(insert_point)))
- != supremum)) {
-
- /* If there are >= 3 user records up from the insert
- point, split all but 2 off */
-
- *split_rec = page_rec_get_next(page_rec_get_next(
- page_rec_get_next(insert_point)));
+ if (page_rec_get_next(insert_point) != supremum
+ && page_rec_get_next(page_rec_get_next(insert_point))
+ != supremum) {
+
+ /* If there are >= 2 user records up from the insert
+ point, split all but 1 off. We want to keep one because
+ then sequential inserts can use the adaptive hash
+ index, as they can do the necessary checks of the right
+ search position just by looking at the records on this
+ page. */
+
+ *split_rec = page_rec_get_next(
+ page_rec_get_next(insert_point));
} else {
- /* Else split at inserted record */
+ /* Else split at the new record to insert */
*split_rec = NULL;
}
@@ -1520,7 +1526,9 @@ func_start:
ut_ad(mtr_memo_contains(mtr, dict_tree_get_lock(tree),
MTR_MEMO_X_LOCK));
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(dict_tree_get_lock(tree), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
page = btr_cur_get_page(cursor);
diff --git a/innobase/btr/btr0cur.c b/innobase/btr/btr0cur.c
index b2bfdbec4e4..fdc8343e190 100644
--- a/innobase/btr/btr0cur.c
+++ b/innobase/btr/btr0cur.c
@@ -66,6 +66,16 @@ this many index pages */
#define BTR_BLOB_HDR_SIZE 8
/***********************************************************************
+Marks all extern fields in a record as owned by the record. This function
+should be called if the delete mark of a record is removed: a not delete
+marked record always owns all its extern fields. */
+static
+void
+btr_cur_unmark_extern_fields(
+/*=========================*/
+ rec_t* rec, /* in: record in a clustered index */
+ mtr_t* mtr); /* in: mtr */
+/***********************************************************************
Adds path information to the cursor for the current page, for which
the binary search has been performed. */
static
@@ -1323,66 +1333,6 @@ btr_cur_parse_update_in_place(
}
/*****************************************************************
-Updates a secondary index record when the update causes no size
-changes in its fields. The only case when this function is currently
-called is that in a char field characters change to others which
-are identified in the collation order. */
-
-ulint
-btr_cur_update_sec_rec_in_place(
-/*============================*/
- /* out: DB_SUCCESS or error number */
- btr_cur_t* cursor, /* in: cursor on the record to update;
- cursor stays valid and positioned on the
- same record */
- upd_t* update, /* in: update vector */
- que_thr_t* thr, /* in: query thread */
- mtr_t* mtr) /* in: mtr */
-{
- dict_index_t* index = cursor->index;
- dict_index_t* clust_index;
- ulint err;
- rec_t* rec;
- dulint roll_ptr = ut_dulint_zero;
- trx_t* trx = thr_get_trx(thr);
-
- /* Only secondary index records are updated using this function */
- ut_ad(0 == (index->type & DICT_CLUSTERED));
-
- rec = btr_cur_get_rec(cursor);
-
- if (btr_cur_print_record_ops && thr) {
- printf(
- "Trx with id %lu %lu going to update table %s index %s\n",
- (unsigned long) ut_dulint_get_high(thr_get_trx(thr)->id),
- (unsigned long) ut_dulint_get_low(thr_get_trx(thr)->id),
- index->table_name, index->name);
- rec_print(rec);
- }
-
- err = lock_sec_rec_modify_check_and_lock(0, rec, index, thr);
-
- if (err != DB_SUCCESS) {
-
- return(err);
- }
-
- /* Remove possible hash index pointer to this record */
- btr_search_update_hash_on_delete(cursor);
-
- row_upd_rec_in_place(rec, update);
-
- clust_index = dict_table_get_first_index(index->table);
-
- /* Note that roll_ptr is really just a dummy value since
- a secondary index record does not contain any sys columns */
-
- btr_cur_update_in_place_log(BTR_KEEP_SYS_FLAG, rec, clust_index,
- update, trx, roll_ptr, mtr);
- return(DB_SUCCESS);
-}
-
-/*****************************************************************
Updates a record when the update causes no size changes in its fields.
We assume here that the ordering fields of the record do not change. */
@@ -2709,7 +2659,7 @@ btr_estimate_number_of_different_key_vals(
ulint n_cols;
ulint matched_fields;
ulint matched_bytes;
- ulint* n_diff;
+ ib_longlong* n_diff;
ulint not_empty_flag = 0;
ulint total_external_size = 0;
ulint i;
@@ -2732,10 +2682,11 @@ btr_estimate_number_of_different_key_vals(
btr_cur_open_at_rnd_pos(index, BTR_SEARCH_LEAF, &cursor, &mtr);
- /* Count the number of different key values minus one
- for each prefix of the key on this index page: we subtract
- one because otherwise our algorithm would give a wrong
- estimate for an index where there is just one key value */
+ /* Count the number of different key values for each prefix of
+ the key on this index page. If the prefix does not determine
+ the index record uniquely in te B-tree, then we subtract one
+ because otherwise our algorithm would give a wrong estimate
+ for an index where there is just one key value. */
page = btr_cur_get_page(&cursor);
@@ -2757,6 +2708,9 @@ btr_estimate_number_of_different_key_vals(
&matched_bytes);
for (j = matched_fields + 1; j <= n_cols; j++) {
+ /* We add one if this index record has
+ a different prefix from the previous */
+
n_diff[j]++;
}
@@ -2766,6 +2720,18 @@ btr_estimate_number_of_different_key_vals(
rec = page_rec_get_next(rec);
}
+ if (n_cols == dict_index_get_n_unique_in_tree(index)) {
+ /* We add one because we know that the first record
+ on the page certainly had a different prefix than the
+ last record on the previous index page in the
+ alphabetical order. Before this fix, if there was
+ just one big record on each clustered index page, the
+ algorithm grossly underestimated the number of rows
+ in the table. */
+
+ n_diff[n_cols]++;
+ }
+
total_external_size +=
btr_rec_get_externally_stored_len(rec);
mtr_commit(&mtr);
@@ -2781,7 +2747,8 @@ btr_estimate_number_of_different_key_vals(
for (j = 0; j <= n_cols; j++) {
index->stat_n_diff_key_vals[j] =
- (n_diff[j] * index->stat_n_leaf_pages
+ (n_diff[j]
+ * (ib_longlong)index->stat_n_leaf_pages
+ BTR_KEY_VAL_ESTIMATE_N_PAGES - 1
+ total_external_size
+ not_empty_flag)
@@ -2992,7 +2959,7 @@ btr_cur_mark_dtuple_inherited_extern(
Marks all extern fields in a record as owned by the record. This function
should be called if the delete mark of a record is removed: a not delete
marked record always owns all its extern fields. */
-
+static
void
btr_cur_unmark_extern_fields(
/*=========================*/
@@ -3216,8 +3183,10 @@ btr_store_big_rec_extern_fields(
prev_page_no,
RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(prev_page,
SYNC_EXTERN_STORAGE);
+#endif /* UNIV_SYNC_DEBUG */
mlog_write_ulint(prev_page + FIL_PAGE_DATA
+ BTR_BLOB_HDR_NEXT_PAGE_NO,
@@ -3252,9 +3221,9 @@ btr_store_big_rec_extern_fields(
rec_page = buf_page_get(space_id,
buf_frame_get_page_no(data),
RW_X_LATCH, &mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(rec_page, SYNC_NO_ORDER_CHECK);
-
+#endif /* UNIV_SYNC_DEBUG */
mlog_write_ulint(data + local_len + BTR_EXTERN_LEN, 0,
MLOG_4BYTES, &mtr);
mlog_write_ulint(data + local_len + BTR_EXTERN_LEN + 4,
@@ -3346,9 +3315,9 @@ btr_free_externally_stored_field(
rec_page = buf_page_get(buf_frame_get_space_id(data),
buf_frame_get_page_no(data), RW_X_LATCH, &mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(rec_page, SYNC_NO_ORDER_CHECK);
-
+#endif /* UNIV_SYNC_DEBUG */
space_id = mach_read_from_4(data + local_len
+ BTR_EXTERN_SPACE_ID);
@@ -3391,9 +3360,9 @@ btr_free_externally_stored_field(
}
page = buf_page_get(space_id, page_no, RW_X_LATCH, &mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_EXTERN_STORAGE);
-
+#endif /* UNIV_SYNC_DEBUG */
next_page_no = mach_read_from_4(page + FIL_PAGE_DATA
+ BTR_BLOB_HDR_NEXT_PAGE_NO);
@@ -3571,9 +3540,9 @@ btr_copy_externally_stored_field(
mtr_start(&mtr);
page = buf_page_get(space_id, page_no, RW_S_LATCH, &mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_EXTERN_STORAGE);
-
+#endif /* UNIV_SYNC_DEBUG */
blob_header = page + offset;
part_len = btr_blob_get_part_len(blob_header);
diff --git a/innobase/btr/btr0pcur.c b/innobase/btr/btr0pcur.c
index 39e70d91be8..cf8a612ef28 100644
--- a/innobase/btr/btr0pcur.c
+++ b/innobase/btr/btr0pcur.c
@@ -238,9 +238,9 @@ btr_pcur_restore_position(
cursor->block_when_stored, page,
cursor->modify_clock, mtr)) {
cursor->pos_state = BTR_PCUR_IS_POSITIONED;
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE);
-
+#endif /* UNIV_SYNC_DEBUG */
if (cursor->rel_pos == BTR_PCUR_ON) {
cursor->latch_mode = latch_mode;
diff --git a/innobase/btr/btr0sea.c b/innobase/btr/btr0sea.c
index 207ebcfb641..2093d5ea757 100644
--- a/innobase/btr/btr0sea.c
+++ b/innobase/btr/btr0sea.c
@@ -22,7 +22,9 @@ Created 2/17/1996 Heikki Tuuri
ulint btr_search_this_is_zero = 0; /* A dummy variable to fool the
compiler */
+#ifdef UNIV_SEARCH_PERF_STAT
ulint btr_search_n_succ = 0;
+#endif /* UNIV_SEARCH_PERF_STAT */
ulint btr_search_n_hash_fail = 0;
byte btr_sea_pad1[64]; /* padding to prevent other memory update
@@ -93,8 +95,10 @@ btr_search_check_free_space_in_heap(void)
hash_table_t* table;
mem_heap_t* heap;
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
table = btr_search_sys->hash_index;
@@ -194,8 +198,10 @@ btr_search_info_update_hash(
ulint n_unique;
int cmp;
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
index = cursor->index;
@@ -317,10 +323,12 @@ btr_search_update_block_hash_info(
buf_block_t* block, /* in: buffer block */
btr_cur_t* cursor) /* in: cursor */
{
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
- ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
- || rw_lock_own(&(block->lock), RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+ ut_ad(rw_lock_own(&((buf_block_t*) block)->lock, RW_LOCK_SHARED)
+ || rw_lock_own(&((buf_block_t*) block)->lock, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(cursor);
info->last_hash_succ = FALSE;
@@ -398,9 +406,11 @@ btr_search_update_hash_ref(
dulint tree_id;
ut_ad(cursor->flag == BTR_CUR_HASH_FAIL);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
|| rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
if (block->is_hashed
&& (info->n_hash_potential > 0)
&& (block->curr_n_fields == info->n_fields)
@@ -419,7 +429,9 @@ btr_search_update_hash_ref(
fold = rec_fold(rec, block->curr_n_fields,
block->curr_n_bytes, tree_id);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
ha_insert_for_fold(btr_search_sys->hash_index, fold, rec);
}
@@ -439,8 +451,10 @@ btr_search_info_update_slow(
ulint* params;
ulint* params2;
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
block = buf_block_align(btr_cur_get_rec(cursor));
@@ -762,7 +776,9 @@ btr_search_guess_on_hash(
can_only_compare_to_cursor_rec = FALSE;
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE_FROM_HASH);
+#endif /* UNIV_SYNC_DEBUG */
}
block = buf_block_align(page);
@@ -910,10 +926,12 @@ btr_search_drop_page_hash_index(
ulint n_recs;
ulint* folds;
ulint i;
-
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
-
+
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
+
rw_lock_s_lock(&btr_search_latch);
block = buf_block_align(page);
@@ -927,9 +945,11 @@ btr_search_drop_page_hash_index(
table = btr_search_sys->hash_index;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
|| rw_lock_own(&(block->lock), RW_LOCK_EX)
|| (block->buf_fix_count == 0));
+#endif /* UNIV_SYNC_DEBUG */
n_fields = block->curr_n_fields;
n_bytes = block->curr_n_bytes;
@@ -1031,8 +1051,10 @@ btr_search_drop_page_hash_when_freed(
BUF_GET_IF_IN_POOL, IB__FILE__, __LINE__,
&mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE_FROM_HASH);
-
+#endif /* UNIV_SYNC_DEBUG */
+
btr_search_drop_page_hash_index(page);
mtr_commit(&mtr);
@@ -1072,9 +1094,11 @@ btr_search_build_page_hash_index(
block = buf_block_align(page);
table = btr_search_sys->hash_index;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
|| rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
rw_lock_s_lock(&btr_search_latch);
@@ -1237,8 +1261,10 @@ btr_search_move_or_delete_hash_entries(
block = buf_block_align(page);
new_block = buf_block_align(new_page);
- ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX)
- && rw_lock_own(&(new_block->lock), RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
+ ut_ad(rw_lock_own(&(new_block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
rw_lock_s_lock(&btr_search_latch);
@@ -1298,7 +1324,9 @@ btr_search_update_hash_on_delete(
block = buf_block_align(rec);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
if (!block->is_hashed) {
@@ -1339,7 +1367,9 @@ btr_search_update_hash_node_on_insert(
block = buf_block_align(rec);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
if (!block->is_hashed) {
@@ -1400,7 +1430,9 @@ btr_search_update_hash_on_insert(
block = buf_block_align(rec);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
if (!block->is_hashed) {
@@ -1500,75 +1532,6 @@ function_exit:
}
/************************************************************************
-Prints info of the search system. */
-
-void
-btr_search_print_info(void)
-/*=======================*/
-{
- printf("SEARCH SYSTEM INFO\n");
-
- rw_lock_x_lock(&btr_search_latch);
-
-/* ha_print_info(btr_search_sys->hash_index); */
-
- rw_lock_x_unlock(&btr_search_latch);
-}
-
-/************************************************************************
-Prints info of searches on an index. */
-
-void
-btr_search_index_print_info(
-/*========================*/
- dict_index_t* index) /* in: index */
-{
- btr_search_t* info;
-
- printf("INDEX SEARCH INFO\n");
-
- rw_lock_x_lock(&btr_search_latch);
-
- info = btr_search_get_info(index);
-
- printf("Searches %lu, hash succ %lu, fail %lu, patt succ %lu\n",
- (ulong) info->n_searches, (ulong) info->n_hash_succ,
- (ulong) info->n_hash_fail, (ulong) info->n_patt_succ);
-
- printf("Total of page cur short succ for all indexes %lu\n",
- (ulong) page_cur_short_succ);
- rw_lock_x_unlock(&btr_search_latch);
-}
-
-/************************************************************************
-Prints info of searches on a table. */
-
-void
-btr_search_table_print_info(
-/*========================*/
- char* name) /* in: table name */
-{
- dict_table_t* table;
- dict_index_t* index;
-
- mutex_enter(&(dict_sys->mutex));
-
- table = dict_table_get_low(name);
-
- ut_a(table);
-
- mutex_exit(&(dict_sys->mutex));
-
- index = dict_table_get_first_index(table);
-
- while (index) {
- btr_search_index_print_info(index);
-
- index = dict_table_get_next_index(index);
- }
-}
-
-/************************************************************************
Validates the search system. */
ibool
diff --git a/innobase/btr/ts/isql.c b/innobase/btr/ts/isql.c
deleted file mode 100644
index db56aa65a66..00000000000
--- a/innobase/btr/ts/isql.c
+++ /dev/null
@@ -1,312 +0,0 @@
-/************************************************************************
-Test for the client: interactive SQL
-
-(c) 1996-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "univ.i"
-#include "ib_odbc.h"
-#include "mem0mem.h"
-#include "sync0sync.h"
-#include "os0thread.h"
-#include "os0proc.h"
-#include "os0sync.h"
-#include "srv0srv.h"
-
-ulint n_exited = 0;
-
-char cli_srv_endpoint_name[100];
-char cli_user_name[100];
-
-ulint n_warehouses = ULINT_MAX;
-ulint n_customers_d = ULINT_MAX;
-bool is_tpc_d = FALSE;
-ulint n_rounds = ULINT_MAX;
-ulint n_users = ULINT_MAX;
-ulint startdate = 0;
-ulint enddate = 0;
-bool own_warehouse = FALSE;
-
-ulint mem_pool_size = ULINT_MAX;
-
-/*************************************************************************
-Reads a keywords and a values from an initfile. In case of an error, exits
-from the process. */
-static
-void
-cli_read_initfile(
-/*==============*/
- FILE* initfile) /* in: file pointer */
-{
- char str_buf[10000];
- ulint ulint_val;
-
- srv_read_init_val(initfile, FALSE, "SRV_ENDPOINT_NAME", str_buf,
- &ulint_val);
-
- ut_a(ut_strlen(str_buf) < COM_MAX_ADDR_LEN);
-
- ut_memcpy(cli_srv_endpoint_name, str_buf, COM_MAX_ADDR_LEN);
-
- srv_read_init_val(initfile, FALSE, "USER_NAME", str_buf,
- &ulint_val);
- ut_a(ut_strlen(str_buf) < COM_MAX_ADDR_LEN);
-
- ut_memcpy(cli_user_name, str_buf, COM_MAX_ADDR_LEN);
-
- srv_read_init_val(initfile, TRUE, "MEM_POOL_SIZE", str_buf,
- &mem_pool_size);
-
- srv_read_init_val(initfile, TRUE, "N_WAREHOUSES", str_buf,
- &n_warehouses);
-
- srv_read_init_val(initfile, TRUE, "N_CUSTOMERS_D", str_buf,
- &n_customers_d);
-
- srv_read_init_val(initfile, TRUE, "IS_TPC_D", str_buf,
- &is_tpc_d);
-
- srv_read_init_val(initfile, TRUE, "N_ROUNDS", str_buf,
- &n_rounds);
-
- srv_read_init_val(initfile, TRUE, "N_USERS", str_buf,
- &n_users);
-
- srv_read_init_val(initfile, TRUE, "STARTDATE", str_buf,
- &startdate);
-
- srv_read_init_val(initfile, TRUE, "ENDDATE", str_buf,
- &enddate);
-
- srv_read_init_val(initfile, TRUE, "OWN_WAREHOUSE", str_buf,
- &own_warehouse);
-}
-
-/*************************************************************************
-Reads configuration info for the client. */
-static
-void
-cli_boot(
-/*=====*/
- char* name) /* in: the initialization file name */
-{
- FILE* initfile;
-
- initfile = fopen(name, "r");
-
- if (initfile == NULL) {
- printf(
- "Error in client booting: could not open initfile whose name is %s!\n",
- name);
- os_process_exit(1);
- }
-
- cli_read_initfile(initfile);
-
- fclose(initfile);
-}
-
-/*********************************************************************
-Interactive SQL loop. */
-static
-void
-isql(
-/*=*/
- FILE* inputfile) /* in: input file containing SQL strings,
- or stdin */
-{
- HENV env;
- HDBC conn;
- RETCODE ret;
- HSTMT sql_query;
- ulint tm, oldtm;
- char buf[1000];
- char* str;
- ulint count;
- ulint n_begins;
- ulint len;
- ulint n;
- ulint i;
- ulint n_lines;
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- cli_user_name,
- (SWORD)ut_strlen(cli_user_name),
- (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- printf("Interactive SQL performs queries by first making a stored\n");
- printf("procedure from them, and then calling the procedure.\n");
- printf("Put a semicolon after each statement and\n");
- printf("end your query with two <enter>s.\n\n");
- printf("You can also give a single input file\n");
- printf("as a command line argument to isql.\n\n");
- printf("In the file separate SQL queries and procedure bodies\n");
- printf("by a single empty line. Do not write the final END; into\n");
- printf("a procedure body.\n\n");
-
- count = 0;
-loop:
- count++;
- n = 0;
- n_lines = 0;
-
- sprintf(buf, "PROCEDURE P%s%lu () IS\nBEGIN ", cli_user_name,
- count);
- for (;;) {
- len = ut_strlen(buf + n) - 1;
- n += len;
-
- if (len == 0) {
- break;
- } else {
- sprintf(buf + n, "\n");
- n++;
- n_lines++;
- }
-
- str = fgets(buf + n, 1000, inputfile);
-
- if ((str == NULL) && (inputfile != stdin)) {
- /* Reached end-of-file: switch to input from
- keyboard */
-
- inputfile = stdin;
-
- break;
- }
-
- ut_a(str);
- }
-
- if (n_lines == 1) {
- /* Empty procedure */
-
- goto loop;
- }
-
- /* If the statement is actually the body of a procedure,
- erase the first BEGIN from the string: */
-
- n_begins = 0;
-
- for (i = 0; i < n - 5; i++) {
-
- if (ut_memcmp(buf + i, "BEGIN", 5) == 0) {
-
- n_begins++;
- }
- }
-
- if (n_begins > 1) {
-
- for (i = 0; i < n - 5; i++) {
-
- if (ut_memcmp(buf + i, "BEGIN", 5) == 0) {
-
- /* Erase the first BEGIN: */
- ut_memcpy(buf + i, " ", 5);
-
- break;
- }
- }
- }
-
- sprintf(buf + n, "END;\n");
-
- printf("SQL procedure to execute:\n%s\n", buf);
-
- ret = SQLAllocStmt(conn, &sql_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(sql_query, (UCHAR*)buf, ut_strlen(buf));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(sql_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- sprintf(buf, "{P%s%lu ()}", cli_user_name, count);
-
- ret = SQLAllocStmt(conn, &sql_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(sql_query, (UCHAR*)buf, ut_strlen(buf));
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("Starting to execute the query\n");
-
- oldtm = ut_clock();
-
- ret = SQLExecute(sql_query);
-
- tm = ut_clock();
-
- printf("Wall time for query %lu milliseconds\n\n", tm - oldtm);
-
- ut_a(ret == SQL_SUCCESS);
-
- goto loop;
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(int argc, char* argv[])
-/*========================*/
-{
- ulint tm, oldtm;
- FILE* inputfile;
-
- if (argc > 2) {
- printf("Only one input file allowed\n");
-
- os_process_exit(1);
-
- } else if (argc == 2) {
- inputfile = fopen(argv[1], "r");
-
- if (inputfile == NULL) {
- printf(
- "Error: could not open the inputfile whose name is %s!\n",
- argv[1]);
- os_process_exit(1);
- }
- } else {
- inputfile = stdin;
- }
-
- cli_boot("cli_init");
-
- sync_init();
-
- mem_init(mem_pool_size);
-
- oldtm = ut_clock();
-
- isql(inputfile);
-
- tm = ut_clock();
-
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/makefile b/innobase/btr/ts/makefile
deleted file mode 100644
index 58364717472..00000000000
--- a/innobase/btr/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-include ..\..\makefile.i
-
-doall: tssrv tscli isql
-
-tssrv: ..\btr.lib tssrv.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\btr.lib ..\..\eval.lib ..\..\ibuf.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tssrv.c $(LFL)
-
-tscli: ..\btr.lib tscli.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\btr.lib ..\..\ib_odbc.lib ..\..\eval.lib ..\..\ibuf.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tscli.c $(LFL)
-
-isql: ..\btr.lib isql.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\btr.lib ..\..\ib_odbc.lib ..\..\eval.lib ..\..\ibuf.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib isql.c $(LFL)
-
-tsrecv: ..\btr.lib tsrecv.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\btr.lib ..\..\ibuf.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsrecv.c $(LFL)
-
diff --git a/innobase/btr/ts/trash/TSIT.C b/innobase/btr/ts/trash/TSIT.C
deleted file mode 100644
index 775d4036c6d..00000000000
--- a/innobase/btr/ts/trash/TSIT.C
+++ /dev/null
@@ -1,483 +0,0 @@
-/************************************************************************
-The test module for the record manager of MVB.
-
-(c) 1994 Heikki Tuuri
-
-Created 1/25/1994 Heikki Tuuri
-*************************************************************************/
-
-
-#include "rm0phr.h"
-#include "rm0lgr.h"
-#include "ut0ut.h"
-#include "buf0mem.h"
-#include "rm0ipg.h"
-#include "../it0it.h"
-#include "../it0hi.h"
-#include "../it0ads.h"
-
-byte buf[100];
-byte buf2[100];
-lint lintbuf[2048];
-
-byte numbuf[6000];
-byte numlogrecbuf[100];
-phr_record_t* qs_table[100000];
-
-lint qs_comp = 0;
-
-extern
-void
-test1(void);
-
-#ifdef NOT_DEFINED
-
-void
-q_sort(lint low, lint up)
-{
- phr_record_t* temp, *pivot;
- lint i, j;
-
-
- pivot = qs_table[(low + up) / 2];
-
- i = low;
- j = up;
-
- while (i < j) {
- qs_comp++;
- if (cmp_phr_compare(qs_table[i], pivot)<= 0) {
- i++;
- } else {
- j--;
- temp = qs_table[i];
- qs_table[i] = qs_table[j];
- qs_table[j] = temp;
- }
- }
-
- if (j == up) {
- temp = qs_table[(low + up) / 2];
- qs_table[(low + up) / 2] = qs_table[up - 1];
- qs_table[up - 1] = temp;
- j--;
- }
-
-
- if (j - low <= 1) {
- /* do nothing */
- } else if (j - low == 2) {
- qs_comp++;
- if (cmp_phr_compare(qs_table[low],
- qs_table[low + 1])
- <= 0) {
- /* do nothing */
- } else {
- temp = qs_table[low];
- qs_table[low] = qs_table[low + 1];
- qs_table[low + 1] = temp;
- }
- } else {
- q_sort(low, j);
- }
-
- if (up - j <= 1) {
- /* do nothing */
- } else if (up - j == 2) {
- qs_comp++;
- if (cmp_phr_compare(qs_table[j],
- qs_table[j + 1])
- <= 0) {
- /* do nothing */
- } else {
- temp = qs_table[j];
- qs_table[j] = qs_table[j + 1];
- qs_table[j + 1] = temp;
- }
- } else {
- q_sort(j, up);
- }
-}
-
-#endif
-
-extern
-void
-test1(void)
-{
- phr_record_t* physrec;
- phr_record_t* rec1;
- phr_record_t* rec2;
- lgr_record_t* logrec;
- lgrf_field_t* logfield;
- lint len;
- byte* str;
- lint len2;
- lint tm;
- lint oldtm;
- lint i, j, k, l, m;
- bool b;
- it_cur_cursor_t cursor;
- ipg_cur_cursor_t* page_cursor;
- ipg_page_t* page;
-
- byte c4, c3, c2, c1, c0;
- lint rand, rnd1, rnd2;
- byte* nb;
- lgr_record_t* numlogrec;
- byte* pgbuf;
- mem_stream_t* stream;
- lint tree1, tree2, tree3;
- lint dummy1, dummy2;
-
- pgbuf = (byte*)lintbuf;
-
- stream = mem_stream_create(0);
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Speed and basic tests.\n");
-
- logrec = lgr_create_logical_record(stream, 2);
-
- nb = numbuf;
-
- c4 = '0';
- c3 = '0';
- for (c2 = '0'; c2 <= '9'; c2++) {
- for (c1 = '0'; c1 <= '9'; c1++) {
- for (c0 = '0'; c0 <= '9'; c0++) {
- *nb = c4; nb++;
- *nb = c3; nb++;
- *nb = c2; nb++;
- *nb = c1; nb++;
- *nb = c0; nb++;
- *nb = '\0'; nb++;
- }
- }
- }
-
- numlogrec = lgr_create_logical_record(stream, 2);
-
-
- tree1 = it_create_index_tree();
-
- oldtm = ut_clock();
-
- rand = 99900;
- rnd1 = 67;
- for (j = 0; j < 1; j++) {
- for (i = 0 ; i < 100000; i++) {
-
- rand = (rand + 1) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-/*
- it_insert(tree1, numlogrec);
-*/
-
-
-
- it_cur_search_tree_to_nth_level(tree1, 1, numlogrec,
- IPG_SE_L_GE, &cursor, &dummy1, &dummy2);
-
-/*
- it_cur_set_to_first(tree1, &cursor);
-*/
-
- it_cur_insert_record(&cursor, numlogrec);
-
- }
- }
- tm = ut_clock();
- printf("Time for inserting %ld recs = %ld \n", i* j, tm - oldtm);
-
-/* it_print_tree(tree1, 10);*/
- hi_print_info();
- ads_print_info();
-/*
- oldtm = ut_clock();
-
- rand = 11113;
- for (i = 0; i < 5000; i++) {
-
- rand = (rand + 57123) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- it_cur_search_tree_to_nth_level(tree1, 1, numlogrec,
- IPG_SE_L_GE, &cursor, &dummy1, &dummy2);
-
- }
- tm = ut_clock();
- printf("Time for searching %ld recs = %ld \n", i, tm - oldtm);
-*/
-
- it_cur_set_to_first(tree1, &cursor);
-
- rec1 = ipg_cur_get_record(it_cur_get_page_cursor(&cursor));
-
- for (i = 0;; i++) {
- it_cur_move_to_next(&cursor);
- if (it_cur_end_of_level(&cursor)) {
- break;
- }
- rec2 = ipg_cur_get_record(it_cur_get_page_cursor(&cursor));
- ut_a(cmp_phr_compare(rec1, rec2) == -1);
- rec1 = rec2;
- }
-
- printf("tree1 checked for right sorted order!\n");
-
-#ifdef not_defined
-
- oldtm = ut_clock();
-
- for (j = 0; j < 1; j++) {
- rand = 11113;
- for (i = 0; i < 3000; i++) {
-
- rand = (rand + 57123) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- physrec = hi_search(numlogrec);
-
- ut_a(physrec);
- }
-
- }
- ut_a(physrec);
- tm = ut_clock();
- printf("Time for hi_search %ld recs = %ld \n", i * j,
- tm - oldtm);
-
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000; i++) {
-/* j += lgr_fold(numlogrec, -1, -1);*/
-/* b += phr_lgr_equal(physrec, numlogrec, -1);*/
- k += ut_hash_lint(j, HI_TABLE_SIZE);
- }
-
-
-/* ut_a(b);*/
- tm = ut_clock();
- printf("Time for fold + equal %ld recs %s = %ld \n", i, physrec,
- tm - oldtm);
-
- printf("%ld %ld %ld\n", j, b, k);
-
- hi_print_info();
-
- tree2 = it_create_index_tree();
-
- rand = 90000;
- for (i = 0; i < 300; i++) {
-
- rand = (rand + 1) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- it_cur_search_tree_to_nth_level(tree2, 1, numlogrec,
- IPG_SE_L_GE, &cursor);
-
- it_cur_insert_record(&cursor, numlogrec);
-
- }
-
- oldtm = ut_clock();
-
- rand = 10000;
- for (i = 0; i < 3000; i++) {
-
- rand = (rand + 1) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- it_cur_search_tree_to_nth_level(tree2, 1, numlogrec,
- IPG_SE_L_GE, &cursor);
-
- it_cur_insert_record(&cursor, numlogrec);
-
- }
- tm = ut_clock();
- printf("Time for inserting sequentially %ld recs = %ld \n",
- i, tm - oldtm);
-
-
-/* it_print_tree(tree2, 10); */
-
-
- tree3 = it_create_index_tree();
-
- rand = 0;
- for (i = 0; i < 300; i++) {
-
- rand = (rand + 1) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- it_cur_search_tree_to_nth_level(tree3, 1, numlogrec,
- IPG_SE_L_GE, &cursor);
-
- it_cur_insert_record(&cursor, numlogrec);
-
- }
-
- oldtm = ut_clock();
-
- rand = 100000;
- for (i = 0; i < 3000; i++) {
-
- rand = (rand - 1) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- it_cur_search_tree_to_nth_level(tree3, 1, numlogrec,
- IPG_SE_L_GE, &cursor);
-
- it_cur_insert_record(&cursor, numlogrec);
-
- }
- tm = ut_clock();
- printf("Time for inserting sequentially downw. %ld recs = %ld \n",
- i, tm - oldtm);
-
-
-/* it_print_tree(tree3, 10); */
-
-#endif
-
-}
-
-#ifdef NOT_DEFINED
-
-/* Test of quicksort */
-void
-test2(void)
-{
- mem_stream_t* stream;
- byte* stbuf;
- lgrf_field_t* logfield;
- lint tm;
- lint oldtm;
- lint i, j, k, l, m;
- lint rand;
- lgr_record_t* numlogrec;
- phr_record_t* ph_rec;
-
- stream = mem_stream_create(1000);
-
- numlogrec = lgr_create_logical_record(stream, 2);
-
- oldtm = ut_clock();
-
- rand = 11113;
- for (i = 0; i < 50000; i++) {
- stbuf = mem_stream_alloc(stream, 30);
-
- rand = (rand + 57123) % 100000;
-
- logfield = lgr_get_nth_field(numlogrec, 0);
- lgrf_set_data(logfield, numbuf + 6 * (rand / 300));
- lgrf_set_len(logfield, 6);
-
- logfield = lgr_get_nth_field(numlogrec, 1);
- lgrf_set_data(logfield, numbuf + 6 * (rand % 300));
- lgrf_set_len(logfield, 6);
-
- ph_rec = phr_create_physical_record(stbuf, 30, numlogrec);
-
- qs_table[i] = ph_rec;
-
- }
- tm = ut_clock();
- printf("Time for inserting %ld recs to mem stream = %ld \n",
- i, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- q_sort(0, 50000);
-
- tm = ut_clock();
- printf("Time for quicksort of %ld recs = %ld, comps: %ld \n",
- i, tm - oldtm, qs_comp);
-
-
-
- for (i = 1; i < 49999; i++) {
- ut_a(-1 ==
- cmp_phr_compare(qs_table[i], qs_table[i+1]
- ));
- }
- tm = ut_clock();
-
-
- oldtm = ut_clock();
- for (i = 1; i < 50000; i++) {
- k += cmp_phr_compare(qs_table[i & 0xF],
- qs_table[5]);
- }
- tm = ut_clock();
- printf("%ld\n", k);
-
- printf("Time for cmp of %ld ph_recs = %ld \n",
- i, tm - oldtm);
-
- mem_stream_free(stream);
-
-}
-#endif
-
-void
-main(void)
-{
- test1();
-/* test2(); */
-}
-
diff --git a/innobase/btr/ts/trash/tsbtrold5.c b/innobase/btr/ts/trash/tsbtrold5.c
deleted file mode 100644
index 370cf0b14bd..00000000000
--- a/innobase/btr/ts/trash/tsbtrold5.c
+++ /dev/null
@@ -1,798 +0,0 @@
-/************************************************************************
-The test for the index tree
-
-(c) 1994-1996 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "..\btr0btr.h"
-#include "..\btr0cur.h"
-#include "..\btr0pcur.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 1
-#define N_FILES 2
-#define FILE_SIZE 1000 /* must be > 512 */
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "j:\\tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[9] = (char)((ulint)'0' + k);
- name[10] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space 0. */
-
-void
-init_space(void)
-/*============*/
-{
- mtr_t mtr;
-
- printf("Init space header\n");
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test1(void)
-/*=======*/
-{
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint rnd = 0;
- dict_index_t* index;
- dict_table_t* table;
- dict_tree_t* tree;
- mtr_t mtr;
- byte buf[8];
- ulint i;
- ulint tm, oldtm;
- btr_pcur_t cursor;
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. Basic test\n");
-
- heap = mem_heap_create(0);
-
- table = dict_mem_table_create("TS_TABLE1", 2);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- dict_table_add_to_cache(table);
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0, 2, 0);
-
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- dict_index_add_to_cache(index);
-
- index = dict_index_get("TS_TABLE1", "IND1");
- ut_a(index);
-
- tree = dict_index_get_tree(index);
-
- tuple = dtuple_create(heap, 3);
-
- mtr_start(&mtr);
-
- btr_root_create(tree, 0, &mtr);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- dtuple_gen_test_tuple3(tuple, 0, buf);
- btr_insert(tree, tuple, &mtr);
-
- mtr_commit(&mtr);
-
- rnd = 90000;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- if (i == 77000) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 15675751) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- btr_insert(tree, tuple, &mtr);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- rnd = 90000;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- if (i == 50000) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 595659561) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- btr_pcur_open(tree, tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &cursor, &mtr);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- rnd = (rnd + 35608971) % 200000 + 1;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
-/* btr_print_tree(tree, 3); */
-
- mem_heap_free(heap);
-}
-
-
-#ifdef notdefined
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 534671) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
-/* page_print_list(page, 151); */
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 7771) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_get_n_recs(page) == 0);
-
- ut_a(page_validate(page, index));
- page = page_create(frame, &mtr);
-
- rnd = 311;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 217;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
- page = page_create(frame, &mtr);
-
- rnd = 291;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 277;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- mem_heap_free(heap);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test2(void)
-/*=======*/
-{
- page_t* page;
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint i, j;
- ulint rnd = 0;
- rec_t* rec;
- page_cur_t cursor;
- dict_index_t* index;
- dict_table_t* table;
- buf_block_t* block;
- buf_frame_t* frame;
- ulint tm, oldtm;
- byte buf[8];
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. Speed test\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf, bigbuf + 800, 800);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- rnd = 0;
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf + rnd, bigbuf + rnd + 800, 800);
- rnd += 1600;
- if (rnd > 995000) {
- rnd = 0;
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- heap = mem_heap_create(0);
-
- table = dict_table_create("TS_TABLE2", 2);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE2", "IND2", 0, 2, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE2", "IND2");
- ut_a(index);
-
- tuple = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, 5, &mtr);
- buf_page_s_lock(block, &mtr);
-
- page = buf_block_get_frame(block);
- ut_a(page_validate(page, index));
- mtr_commit(&mtr);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for %lu empty loops with page create %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 100;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for sequential insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 500;
- for (j = 0; j < 250; j++) {
- rnd = (rnd - 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for descend. seq. insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
-
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
- }
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insert and delete of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- ut_a(page_validate(page, index));
- mtr_print(&mtr);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for search of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu empty loops %lu milliseconds\n",
- i * j, tm - oldtm);
- mtr_commit(&mtr);
-}
-
-#endif
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
- os_aio_init(160, 5);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- dict_init();
- fsp_init();
- log_init();
-
- create_files();
-
- init_space();
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1();
-
-/* mem_print_info(); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/trash/tscli.c b/innobase/btr/ts/trash/tscli.c
deleted file mode 100644
index 622da894e02..00000000000
--- a/innobase/btr/ts/trash/tscli.c
+++ /dev/null
@@ -1,2263 +0,0 @@
-/************************************************************************
-Test for the client
-
-(c) 1996-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "ib_odbc.h"
-
-/*********************************************************************
-Test for TPC-C. */
-
-ulint
-test_c(
-/*===*/
- void* arg)
-{
- HSTMT* query;
- HSTMT* commit_query;
- HSTMT* new_order_query;
- HSTMT* payment_query;
- HSTMT* order_status_query;
- HSTMT* delivery_query;
- HSTMT* stock_level_query;
- HSTMT* print_query;
- ulint tm, oldtm;
- char* str;
- char* str1;
- char* str2;
- char* str3;
- char* str4;
- char* str5;
- char* str6;
- ulint i;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST. CREATE TABLES FOR TPC-C\n");
-
- /*------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE CREATE_TABLES () IS"
-" BEGIN"
-" CREATE TABLE WAREHOUSE (W_ID CHAR, W_NAME CHAR,"
-" W_STREET_1 CHAR, W_STREET_2 CHAR,"
-" W_CITY CHAR,"
-" W_STATE CHAR, W_ZIP CHAR,"
-" W_TAX INT,"
-" W_YTD_HIGH INT,"
-" W_YTD INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX W_IND ON WAREHOUSE (W_ID);"
-""
-" CREATE TABLE DISTRICT (D_ID CHAR, D_W_ID CHAR,"
-" D_NAME CHAR,"
-" D_STREET_1 CHAR, D_STREET_2 CHAR,"
-" D_CITY CHAR,"
-" D_STATE CHAR, D_ZIP CHAR,"
-" D_TAX INT,"
-" D_YTD_HIGH INT,"
-" D_YTD INT,"
-" D_NEXT_O_ID INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX D_IND ON DISTRICT (D_W_ID, D_ID);"
-""
-" CREATE TABLE CUSTOMER (C_ID CHAR, C_D_ID CHAR, C_W_ID CHAR,"
-" C_FIRST CHAR, C_MIDDLE CHAR,"
-" C_LAST CHAR,"
-" C_STREET_1 CHAR, C_STREET_2 CHAR,"
-" C_CITY CHAR,"
-" C_STATE CHAR, C_ZIP CHAR,"
-" C_PHONE CHAR,"
-" C_SINCE_TIME INT,"
-" C_SINCE INT,"
-" C_CREDIT CHAR,"
-" C_CREDIT_LIM_HIGH INT,"
-" C_CREDIT_LIM INT,"
-" C_DISCOUNT INT,"
-" C_BALANCE_HIGH INT,"
-" C_BALANCE INT,"
-" C_YTD_PAYMENT_HIGH INT,"
-" C_YTD_PAYMENT INT,"
-" C_PAYMENT_CNT INT,"
-" C_DELIVERY_CNT INT,"
-" C_DATA CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX C_IND ON CUSTOMER (C_W_ID, C_D_ID,"
-" C_ID);"
-""
-" CREATE INDEX C_LAST_IND ON CUSTOMER (C_W_ID, C_D_ID, C_LAST,"
-" C_FIRST);"
-""
-" CREATE TABLE HISTORY (H_C_ID CHAR, H_C_D_ID CHAR, H_C_W_ID CHAR,"
-" H_D_ID CHAR, H_W_ID CHAR,"
-" H_DATE INT,"
-" H_AMOUNT INT,"
-" H_DATA CHAR);"
-""
-" CREATE CLUSTERED INDEX H_IND ON HISTORY (H_W_ID);"
-""
-" CREATE TABLE NEW_ORDER (NO_O_ID INT,"
-" NO_D_ID CHAR,"
-" NO_W_ID CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX NO_IND ON NEW_ORDER (NO_W_ID, NO_D_ID,"
-" NO_O_ID);"
- ;
-
- str2 =
-
-" CREATE TABLE ORDERS (O_ID INT, O_D_ID CHAR, O_W_ID CHAR,"
-" O_C_ID CHAR,"
-" O_ENTRY_D INT,"
-" O_CARRIER_ID INT,"
-" O_OL_CNT INT,"
-" O_ALL_LOCAL CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX O_IND ON ORDERS (O_W_ID, O_D_ID,"
-" O_ID);"
-" CREATE INDEX O_C_IND ON ORDERS (O_W_ID, O_D_ID, O_C_ID);"
-""
-" CREATE TABLE ORDER_LINE (OL_O_ID INT, OL_D_ID CHAR, OL_W_ID CHAR,"
-" OL_NUMBER CHAR,"
-" OL_I_ID CHAR,"
-" OL_SUPPLY_W_ID CHAR,"
-" OL_DELIVERY_D INT,"
-" OL_QUANTITY INT,"
-" OL_AMOUNT INT,"
-" OL_DIST_INFO CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX OL_IND ON ORDER_LINE"
-" (OL_W_ID, OL_D_ID, OL_O_ID, OL_NUMBER);"
-""
-" CREATE TABLE ITEM (I_ID CHAR, I_IM_ID CHAR, I_NAME CHAR,"
-" I_PRICE INT,"
-" I_DATA CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX I_IND ON ITEM (I_ID);"
-""
-" CREATE TABLE STOCK (S_I_ID CHAR,"
-" S_W_ID CHAR,"
-" S_QUANTITY INT,"
-" S_DIST_01 CHAR,"
-" S_DIST_02 CHAR,"
-" S_DIST_03 CHAR,"
-" S_DIST_04 CHAR,"
-" S_DIST_05 CHAR,"
-" S_DIST_06 CHAR,"
-" S_DIST_07 CHAR,"
-" S_DIST_08 CHAR,"
-" S_DIST_09 CHAR,"
-" S_DIST_10 CHAR,"
-" S_YTD INT,"
-" S_ORDER_CNT INT,"
-" S_REMOTE_CNT INT,"
-" S_DATA CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX S_IND ON STOCK (S_W_ID, S_I_ID);"
-" END;"
- ;
-
- str = ut_str_catenate(str1, str2);
-
- query = pars_sql(str);
-
- mem_free(str);
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- /*-----------------------------------------------------------*/
- printf("\n\nPopulate TPC-C tables\n\n");
-
- str1 =
-
-" PROCEDURE POPULATE_TABLES () IS"
-""
-" i INT;"
-" j INT;"
-" k INT;"
-" t INT;"
-" string CHAR;"
-" rnd1 INT;"
-" rnd2 INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-""
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-""
-" PRINTF('Starting to populate ITEMs');"
-""
-" FOR i IN 1 .. n_items LOOP"
-" rnd1 := RND(26, 50);"
-" string := RND_STR(rnd1);"
-""
-" IF (RND(0, 9) = 0) THEN"
-" rnd2 := RND(0, rnd1 - 8);"
-" REPLSTR(string, 'ORIGINAL', rnd2, 8);"
-" COMMIT WORK;"
-" END IF;"
-""
-" INSERT INTO ITEM VALUES (TO_BINARY(i, 3),"
-" TO_BINARY(RND(1, 10000), 3),"
-" RND_STR(RND(14, 24)),"
-" RND(100, 10000),"
-" string);"
-" END LOOP;"
-""
-" FOR i IN 1 .. n_warehouses LOOP"
-" PRINTF('Starting to populate warehouse number ', i);"
-" INSERT INTO WAREHOUSE VALUES (TO_BINARY(i, 2),"
-" RND_STR(RND(6, 10)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR(TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND(0, 2000),"
-" 0,"
-" 0);"
-" FOR j IN 1 .. n_items LOOP"
-""
-" rnd1 := RND(26, 50);"
-" string := RND_STR(rnd1);"
-""
-" IF (RND(0, 9) = 0) THEN"
-" rnd2 := RND(0, rnd1 - 8);"
-" REPLSTR(string, 'ORIGINAL', rnd2, 8);"
-" COMMIT WORK;"
-" END IF; "
-""
-" INSERT INTO STOCK VALUES (TO_BINARY(j, 3),"
-" TO_BINARY(i, 2),"
-" RND(10, 100),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" 0, 0, 0,"
-" string);"
-" END LOOP;"
- ;
-
- str2 =
-" FOR j IN 1 .. n_districts LOOP"
-""
-" COMMIT WORK;"
-" PRINTF('Starting to populate district number ', j);"
-" INSERT INTO DISTRICT VALUES (TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" RND_STR(RND(6, 10)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR("
-" TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND(0, 2000),"
-" 0,"
-" 0,"
-" 3001);"
-""
-" FOR k IN 1 .. n_customers LOOP"
-""
-" string := 'GC';"
-""
-" IF (RND(0, 9) = 7) THEN"
-" COMMIT WORK;"
-" string := 'BC';"
-" END IF;"
-" "
-" INSERT INTO CUSTOMER VALUES ("
-" TO_BINARY(k, 3),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" RND_STR(RND(8, 16)),"
-" 'OE',"
-" CONCAT('NAME',"
-" TO_CHAR(k / 3)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR("
-" TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND_STR(16),"
-" SYSDATE(), 0,"
-" string,"
-" 0, 5000000,"
-" RND(0, 5000),"
-" 0, 0, 0, 0, 0, 0,"
-" RND_STR(RND(300, 500)));"
- ;
-
- str3 =
-" INSERT INTO HISTORY VALUES ("
-" TO_BINARY(k, 3),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" SYSDATE(),"
-" 1000,"
-" RND_STR(RND(12, 24)));"
-""
-" rnd1 := RND(5, 15);"
-""
-" INSERT INTO ORDERS VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(k, 3),"
-" SYSDATE(),"
-" RND(1, 10),"
-" rnd1,"
-" '1');"
-""
-" FOR t IN 1 .. rnd1 LOOP"
-" INSERT INTO ORDER_LINE VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(t, 1),"
-" TO_BINARY("
-" RND(0, n_items - 1),"
-" 3),"
-" TO_BINARY(i, 2),"
-" SYSDATE(),"
-" RND(0, 99),"
-" RND(0, 9999),"
-" RND_STR(24));"
-" END LOOP;"
-" END LOOP;"
-" "
-" FOR k IN (2 * n_customers) / 3 .. n_customers LOOP"
-" "
-" INSERT INTO NEW_ORDER VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2));"
-" END LOOP;"
-" END LOOP;"
-" END LOOP; "
-" "
-" COMMIT WORK;"
-" END;"
- ;
-
- str4 = ut_str_catenate(str1, str2);
- str = ut_str_catenate(str4, str3);
-
- query = pars_sql(str);
-
- mem_free(str);
- mem_free(str4);
-
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE PRINT_TABLES () IS"
-" BEGIN"
-""
-" /* PRINTF('Printing ITEM table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ITEM;"
-""
-" PRINTF('Printing WAREHOUSE table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM WAREHOUSE;"
-""
-" PRINTF('Printing STOCK table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM STOCK;"
-""
-" PRINTF('Printing DISTRICT table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM DISTRICT;"
-""
-" PRINTF('Printing CUSTOMER table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM CUSTOMER;"
-""
-" PRINTF('Printing HISTORY table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM HISTORY;"
-""
-" PRINTF('Printing ORDERS table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ORDERS;"
-""
-" PRINTF('Printing ORDER_LINE table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ORDER_LINE"
-" WHERE OL_O_ID >= 3000; */"
-""
-" PRINTF('Printing NEW_ORDER table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM NEW_ORDER;"
-""
-" COMMIT WORK;"
-" END;"
- ;
-
- print_query = pars_sql(str);
-
- /*-----------------------------------------------------------*/
- commit_query = pars_sql(
-
-" PROCEDURE COMMIT_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE NEW_ORDER () IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" w_tax INT;"
-" c_w_id CHAR;"
-" c_d_id CHAR;"
-" c_id CHAR;"
-" c_discount INT;"
-" c_last CHAR;"
-" c_credit CHAR;"
-" d_tax INT;"
-" o_id INT;"
-" o_ol_cnt INT;"
-" ol_i_id CHAR;"
-" o_entry_d INT;"
-" o_all_local CHAR;"
-" i_price INT;"
-" i_name CHAR;"
-" i_data CHAR;"
-" s_quantity INT;"
-" s_data CHAR;"
-" s_dist_01 CHAR;"
-" s_dist_02 CHAR;"
-" s_dist_03 CHAR;"
-" s_dist_04 CHAR;"
-" s_dist_05 CHAR;"
-" s_dist_06 CHAR;"
-" s_dist_07 CHAR;"
-" s_dist_08 CHAR;"
-" s_dist_09 CHAR;"
-" s_dist_10 CHAR;"
-" bg CHAR;"
-" ol_quantity INT;"
-" ol_amount INT;"
-" ol_supply_w_id CHAR;"
-" ol_dist_info CHAR;"
-" total INT;"
-""
-" DECLARE CURSOR district_cursor IS"
-" SELECT D_NEXT_O_ID, D_TAX"
-" FROM DISTRICT"
-" WHERE D_ID = c_d_id AND D_W_ID = c_w_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR stock_cursor IS"
-" SELECT S_QUANTITY, S_DATA,"
-" S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04,"
-" S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08,"
-" S_DIST_09, S_DIST_10"
-" FROM STOCK"
-" WHERE S_W_ID = ol_supply_w_id AND S_I_ID = ol_i_id"
-" FOR UPDATE;"
- ;
- str2 =
-
-" BEGIN"
-" "
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-" "
-" c_w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" c_d_id := TO_BINARY(RND(1, n_districts) + 47, 1);"
-" c_id := TO_BINARY(RND(1, n_customers), 3);"
-""
-" o_ol_cnt := RND(5, 15);"
-" o_all_local := '1';"
-" bg := 'GGGGGGGGGGGGGGG';"
-" total := 0;"
-" "
-" SELECT W_TAX INTO w_tax"
-" FROM WAREHOUSE"
-" WHERE W_ID = c_w_id;"
-""
-" OPEN district_cursor;"
-""
-" FETCH district_cursor INTO o_id, d_tax;"
-""
-" /* PRINTF('C-warehouse id ', BINARY_TO_NUMBER(c_w_id),"
-" ' C-district id ', c_d_id,"
-" ' order id ', o_id, ' linecount ', o_ol_cnt); */"
-""
-" UPDATE DISTRICT SET D_NEXT_O_ID = o_id + 1"
-" WHERE CURRENT OF district_cursor;"
-""
-" CLOSE district_cursor;"
-""
-" SELECT C_DISCOUNT, C_LAST, C_CREDIT INTO c_discount, c_last, c_credit"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id AND C_ID = c_id;"
-""
- ;
- str3 =
-
-" FOR i IN 1 .. o_ol_cnt LOOP"
-""
-" ol_i_id := TO_BINARY(RND(1, n_items), 3);"
-""
-" ol_supply_w_id := c_w_id;"
-""
-" ol_quantity := RND(1, 10);"
-""
-" SELECT I_PRICE, I_NAME, I_DATA INTO i_price, i_name, i_data"
-" FROM ITEM"
-" WHERE I_ID = ol_i_id;"
-""
-" IF (SQL % NOTFOUND) THEN"
-" PRINTF('Rolling back');"
-" ROLLBACK WORK;"
-""
-" RETURN;"
-" END IF;"
-""
-" OPEN stock_cursor;"
-""
-" FETCH stock_cursor INTO s_quantity, s_data,"
-" s_dist_01, s_dist_02, s_dist_03,"
-" s_dist_04, s_dist_05, s_dist_06,"
-" s_dist_07, s_dist_08, s_dist_09,"
-" s_dist_10;"
-""
-" IF (s_quantity >= ol_quantity + 10) THEN"
-" s_quantity := s_quantity - ol_quantity;"
-" ELSE"
-" s_quantity := (s_quantity + 91) - ol_quantity;"
-" END IF;"
-""
-" UPDATE STOCK SET S_QUANTITY = s_quantity,"
-" S_YTD = S_YTD + ol_quantity,"
-" S_ORDER_CNT = S_ORDER_CNT + 1"
-" WHERE CURRENT OF stock_cursor;"
-""
-" IF (ol_supply_w_id <> c_w_id) THEN"
-""
-" o_all_local := '0';"
-" PRINTF('Remote order ',"
-" BINARY_TO_NUMBER(ol_supply_w_id), ' ',"
-" BINARY_TO_NUMBER(c_w_id));"
-""
-" UPDATE STOCK SET S_REMOTE_CNT = S_REMOTE_CNT + 1"
-" WHERE CURRENT OF stock_cursor;"
-" END IF;"
-""
-" CLOSE stock_cursor;"
-""
-" IF ((INSTR(i_data, 'ORIGINAL') > 0)"
-" OR (INSTR(s_data, 'ORIGINAL') > 0)) THEN"
-" REPLSTR(bg, 'B', i - 1, 1);"
-" END IF;"
-""
-" ol_amount := ol_quantity * i_price;"
-""
-" total := total + ol_amount;"
- ;
- str4 =
-" IF (c_d_id = '0') THEN"
-" ol_dist_info := s_dist_01;"
-" ELSIF (c_d_id = '1') THEN"
-" ol_dist_info := s_dist_02;"
-" ELSIF (c_d_id = '2') THEN"
-" ol_dist_info := s_dist_03;"
-" ELSIF (c_d_id = '3') THEN"
-" ol_dist_info := s_dist_04;"
-" ELSIF (c_d_id = '4') THEN"
-" ol_dist_info := s_dist_05;"
-" ELSIF (c_d_id = '5') THEN"
-" ol_dist_info := s_dist_06;"
-" ELSIF (c_d_id = '6') THEN"
-" ol_dist_info := s_dist_07;"
-" ELSIF (c_d_id = '7') THEN"
-" ol_dist_info := s_dist_08;"
-" ELSIF (c_d_id = '8') THEN"
-" ol_dist_info := s_dist_09;"
-" ELSIF (c_d_id = '9') THEN"
-" ol_dist_info := s_dist_10;"
-" END IF;"
-""
-" INSERT INTO ORDER_LINE VALUES (o_id, c_d_id, c_w_id,"
-" TO_BINARY(i, 1), ol_i_id,"
-" ol_supply_w_id, NULL, ol_quantity,"
-" ol_amount, ol_dist_info); "
-" END LOOP;"
-""
-" total := (((total * (10000 + w_tax + d_tax)) / 10000)"
-" * (10000 - c_discount)) / 10000;"
-""
-" o_entry_d := SYSDATE();"
-""
-" INSERT INTO ORDERS VALUES (o_id, c_d_id, c_w_id, c_id, o_entry_d,"
-" NULL, o_ol_cnt, o_all_local);"
-" INSERT INTO NEW_ORDER VALUES (o_id, c_d_id, c_w_id);"
-""
-" /* PRINTF('Inserted order lines:');"
-" ROW_PRINTF"
-" SELECT * FROM ORDER_LINE WHERE OL_O_ID = o_id AND"
-" OL_D_ID = c_d_id"
-" AND OL_W_ID = c_w_id; */"
-" /* COMMIT WORK; */"
-" END;"
- ;
-
- str5 = ut_str_catenate(str1, str2);
- str6 = ut_str_catenate(str3, str4);
-
- str = ut_str_catenate(str5, str6);
-
- new_order_query = pars_sql(str);
-
- mem_free(str);
- mem_free(str5);
- mem_free(str6);
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE PAYMENT () IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" w_id CHAR;"
-" w_street_1 CHAR;"
-" w_street_2 CHAR;"
-" w_city CHAR;"
-" w_state CHAR;"
-" w_zip CHAR;"
-" w_name CHAR;"
-" d_id CHAR;"
-" d_street_1 CHAR;"
-" d_street_2 CHAR;"
-" d_city CHAR;"
-" d_state CHAR;"
-" d_zip CHAR;"
-" d_name CHAR;"
-" c_w_id CHAR;"
-" c_d_id CHAR;"
-" c_street_1 CHAR;"
-" c_street_2 CHAR;"
-" c_city CHAR;"
-" c_state CHAR;"
-" c_zip CHAR;"
-" c_id CHAR;"
-" c_last CHAR;"
-" c_first CHAR;"
-" c_middle CHAR;"
-" c_phone CHAR;"
-" c_credit CHAR;"
-" c_credit_lim INT;"
-" c_discount INT;"
-" c_balance INT;"
-" c_since INT;"
-" c_data CHAR;"
-" byname INT;"
-" namecnt INT;"
-" amount INT;"
-" h_data CHAR;"
-" h_date INT;"
-" c_more_data CHAR;"
-" more_len INT;"
-" data_len INT;"
-""
-" DECLARE CURSOR warehouse_cursor IS"
-" SELECT W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP, W_NAME"
-" FROM WAREHOUSE"
-" WHERE W_ID = w_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR district_cursor IS"
-" SELECT D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, D_NAME"
-" FROM DISTRICT"
-" WHERE D_W_ID = w_id AND D_ID = d_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR customer_by_name_cursor IS"
-" SELECT C_ID"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last"
-" ORDER BY C_FIRST ASC;"
-""
-" DECLARE CURSOR customer_cursor IS"
-" SELECT C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2,"
-" C_CITY, C_STATE, C_ZIP, C_PHONE, C_CREDIT,"
-" C_CREDIT_LIM, C_DISCOUNT, C_BALANCE,"
-" C_SINCE"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_ID = c_id"
-" FOR UPDATE;"
- ;
-
- str2 =
-
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-""
-" byname := RND(1, 100);"
-" amount := RND(1, 1000);"
-" h_date := SYSDATE();"
-" w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-" c_w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" c_d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-""
-" OPEN warehouse_cursor;"
-""
-" FETCH warehouse_cursor INTO w_street_1, w_street_2, w_city, w_state,"
-" w_zip, w_name;"
-" UPDATE WAREHOUSE SET W_YTD = W_YTD + amount"
-" WHERE CURRENT OF warehouse_cursor;"
-""
-" CLOSE warehouse_cursor;"
-""
-" OPEN district_cursor;"
-""
-" FETCH district_cursor INTO d_street_1, d_street_2, d_city, d_state,"
-" d_zip, d_name;"
-" UPDATE DISTRICT SET D_YTD = D_YTD + amount"
-" WHERE CURRENT OF district_cursor;"
-""
-" CLOSE district_cursor;"
-""
-" IF (byname <= 60) THEN"
-" c_last := CONCAT('NAME', TO_CHAR(RND(1, n_customers) / 3));"
-""
-" SELECT COUNT(*) INTO namecnt"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last;"
-" /* PRINTF('Payment trx: Customer name ', c_last,"
-" ' namecount ', namecnt); */"
-" OPEN customer_by_name_cursor;"
-""
-" FOR i IN 1 .. (namecnt + 1) / 2 LOOP"
-" FETCH customer_by_name_cursor INTO c_id;"
-" END LOOP;"
-" /* ASSERT(NOT (customer_by_name_cursor % NOTFOUND)); */"
-" "
-" CLOSE customer_by_name_cursor;"
-" ELSE"
-" c_id := TO_BINARY(RND(1, n_customers), 3);"
-" END IF;"
-
- ;
- str3 =
-""
-" /* PRINTF('Payment for customer ', BINARY_TO_NUMBER(c_w_id), ' ',"
-" c_d_id, ' ', BINARY_TO_NUMBER(c_id)); */"
-" OPEN customer_cursor;"
-""
-" FETCH customer_cursor INTO c_first, c_middle, c_last, c_street_1,"
-" c_street_2, c_city, c_state, c_zip,"
-" c_phone, c_credit, c_credit_lim,"
-" c_discount, c_balance, c_since;"
-" c_balance := c_balance - amount;"
-""
-" h_data := CONCAT(w_name, ' ', d_name);"
-" "
-" IF (c_credit = 'BC') THEN"
-" /* PRINTF('Bad customer pays'); */"
-""
-" SELECT C_DATA INTO c_data"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_ID = c_id;"
-" c_more_data := CONCAT("
-" ' ', TO_CHAR(BINARY_TO_NUMBER(c_id)),"
-" ' ', c_d_id,"
-" ' ', TO_CHAR(BINARY_TO_NUMBER(c_w_id)),"
-" ' ', d_id,"
-" ' ', TO_CHAR(BINARY_TO_NUMBER(w_id)),"
-" TO_CHAR(amount),"
-" TO_CHAR(h_date),"
-" ' ', h_data);"
-""
-" more_len := LENGTH(c_more_data);"
-" data_len := LENGTH(c_data);"
-" "
-" IF (more_len + data_len > 500) THEN"
-" data_len := 500 - more_len;"
-" END IF;"
-" "
-" c_data := CONCAT(c_more_data, SUBSTR(c_data, 0, data_len));"
-" "
-" UPDATE CUSTOMER SET C_BALANCE = c_balance,"
-" C_PAYMENT_CNT = C_PAYMENT_CNT + 1,"
-" C_YTD_PAYMENT = C_YTD_PAYMENT + amount,"
-" C_DATA = c_data"
-" WHERE CURRENT OF customer_cursor;"
-" ELSE"
-" UPDATE CUSTOMER SET C_BALANCE = c_balance,"
-" C_PAYMENT_CNT = C_PAYMENT_CNT + 1,"
-" C_YTD_PAYMENT = C_YTD_PAYMENT + amount"
-" WHERE CURRENT OF customer_cursor;"
-" END IF;"
-""
-" CLOSE customer_cursor;"
-" "
-" INSERT INTO HISTORY VALUES (c_d_id, c_w_id, c_id, d_id, w_id,"
-" h_date, amount, h_data);"
-" /* COMMIT WORK; */"
-""
-" END;"
-
- ;
-
- str4 = ut_str_catenate(str1, str2);
- str = ut_str_catenate(str4, str3);
-
- payment_query = pars_sql(str);
-
- mem_free(str);
- mem_free(str4);
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE ORDER_STATUS () IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" namecnt INT;"
-" c_w_id CHAR;"
-" c_d_id CHAR;"
-" c_id CHAR;"
-" c_last CHAR;"
-" c_first CHAR;"
-" c_middle CHAR;"
-" c_balance INT;"
-" byname INT;"
-" o_id INT;"
-" o_carrier_id CHAR;"
-" o_entry_d INT;"
-" ol_i_id CHAR;"
-" ol_supply_w_id CHAR;"
-" ol_quantity INT;"
-" ol_amount INT;"
-" ol_delivery_d INT;"
-""
-" DECLARE CURSOR orders_cursor IS"
-" SELECT O_ID, O_CARRIER_ID, O_ENTRY_D"
-" FROM ORDERS"
-" WHERE O_W_ID = c_w_id AND O_D_ID = c_d_id"
-" AND O_C_ID = c_id"
-" ORDER BY O_ID DESC;"
-""
-" DECLARE CURSOR order_line_cursor IS"
-" SELECT OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT,"
-" OL_DELIVERY_D"
-" FROM ORDER_LINE"
-" WHERE OL_W_ID = c_w_id AND OL_D_ID = c_d_id"
-" AND OL_O_ID = o_id;"
-" DECLARE CURSOR customer_by_name_cursor IS"
-" SELECT C_ID"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last"
-" ORDER BY C_FIRST ASC;"
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-""
-" c_w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" byname := RND(1, 100);"
-""
- ;
-
- str2 =
-
-" IF (byname <= 60) THEN"
-" d_id := TO_BINARY(47 + RND(1, n_districts), 1); "
-""
-" c_d_id := d_id;"
-""
-" c_last := CONCAT('NAME', TO_CHAR(RND(1, n_customers) / 3));"
-""
-" SELECT COUNT(*) INTO namecnt"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last;"
-" OPEN customer_by_name_cursor;"
-""
-" /* PRINTF('Order status trx: Customer name ', c_last,"
-" ' namecount ', namecnt); */"
-" FOR i IN 1 .. (namecnt + 1) / 2 LOOP"
-" FETCH customer_by_name_cursor INTO c_id;"
-" END LOOP;"
-" /* ASSERT(NOT (customer_by_name_cursor % NOTFOUND)); */"
-""
-" CLOSE customer_by_name_cursor;"
-" ELSE"
-" c_d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-" c_id := TO_BINARY(RND(1, n_customers), 3);"
-" END IF;"
-""
-" SELECT C_BALANCE, C_FIRST, C_MIDDLE, C_LAST INTO c_balance, c_first,"
-" c_middle, c_last"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id AND C_ID = c_id;"
-""
-" OPEN orders_cursor;"
-""
-" FETCH orders_cursor INTO o_id, o_carrier_id, o_entry_d;"
-""
-" IF (orders_cursor % NOTFOUND) THEN"
-" PRINTF('Order status trx: customer has no order');"
-" CLOSE orders_cursor;"
-""
-" /* COMMIT WORK; */"
-""
-" RETURN;"
-" END IF;"
-""
-" CLOSE orders_cursor;"
-""
-" OPEN order_line_cursor;"
-""
-" FOR i IN 0 .. 15 LOOP"
-" FETCH order_line_cursor INTO ol_i_id, ol_supply_w_id,"
-" ol_quantity, ol_amount,"
-" ol_delivery_d;"
-""
-" IF (order_line_cursor % NOTFOUND) THEN"
-" CLOSE order_line_cursor;"
-""
-" /* COMMIT WORK; */"
-""
-" RETURN;"
-" END IF;"
-" END LOOP;"
-" ASSERT(0 = 1);"
-" "
-" END;"
- ;
-
- str = ut_str_catenate(str1, str2);
-
- order_status_query = pars_sql(str);
-
- mem_free(str);
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE DELIVERY () IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" w_id CHAR;"
-" c_id CHAR;"
-" o_id INT;"
-" o_carrier_id INT;"
-" ol_delivery_d INT;"
-" ol_total INT;"
-""
-" DECLARE CURSOR new_order_cursor IS"
-" SELECT NO_O_ID"
-" FROM NEW_ORDER"
-" WHERE NO_W_ID = w_id AND NO_D_ID = d_id"
-" ORDER BY NO_O_ID ASC;"
-""
-" DECLARE CURSOR orders_cursor IS"
-" SELECT O_C_ID"
-" FROM ORDERS"
-" WHERE O_W_ID = w_id AND O_D_ID = d_id"
-" AND O_ID = o_id"
-" FOR UPDATE;"
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-""
-" w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" o_carrier_id := RND(1, 10);"
-" ol_delivery_d := SYSDATE();"
-
- ;
-
- str2 =
-
-" FOR i IN 1 .. n_districts LOOP"
-""
-" d_id := TO_BINARY(47 + i, 1);"
-""
-" OPEN new_order_cursor;"
-""
-" FETCH new_order_cursor INTO o_id;"
-""
-" IF (new_order_cursor % NOTFOUND) THEN"
-" /* PRINTF('No order to deliver'); */"
-""
-" CLOSE new_order_cursor;"
-" ELSE"
-" CLOSE new_order_cursor;"
-" /* PRINTF('Order to deliver'); */"
-""
-" DELETE FROM NEW_ORDER"
-" WHERE NO_W_ID = w_id AND NO_D_ID = d_id"
-" AND NO_O_ID = o_id;"
-" OPEN orders_cursor;"
-""
-" FETCH orders_cursor INTO c_id;"
-""
-" UPDATE ORDERS SET O_CARRIER_ID = o_carrier_id"
-" WHERE CURRENT OF orders_cursor;"
-""
-" CLOSE orders_cursor;"
-""
-" UPDATE ORDER_LINE SET OL_DELIVERY_D = ol_delivery_d"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID = o_id;"
-""
-" SELECT SUM(OL_AMOUNT) INTO ol_total"
-" FROM ORDER_LINE"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID = o_id;"
-""
-" UPDATE CUSTOMER SET C_BALANCE = C_BALANCE - ol_total"
-" WHERE C_W_ID = w_id AND C_D_ID = d_id"
-" AND C_ID = c_id;"
-" END IF;"
-" END LOOP;"
-""
-" /* COMMIT WORK; */"
-" "
-" END;"
- ;
-
- str = ut_str_catenate(str1, str2);
-
- delivery_query = pars_sql(str);
-
- mem_free(str);
-
- /*-----------------------------------------------------------*/
-
- /* NOTE: COUNT(DISTINCT ...) not implemented yet */
-
- str =
-
-" PROCEDURE STOCK_LEVEL () IS"
-""
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" w_id CHAR;"
-" o_id INT;"
-" stock_count INT;"
-" threshold INT;"
-""
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 200;"
-""
-" w_id := TO_BINARY(RND(1, n_warehouses), 2);"
-" d_id := TO_BINARY(47 + 4, 1);"
-""
-" threshold := RND(10, 20);"
-""
-" SELECT D_NEXT_O_ID INTO o_id"
-" FROM DISTRICT"
-" WHERE D_W_ID = w_id AND D_ID = d_id;"
-""
-" SELECT COUNT(*) INTO stock_count"
-" FROM ORDER_LINE, STOCK"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID >= o_id - 20 AND OL_O_ID < o_id"
-" AND S_W_ID = w_id AND S_I_ID = OL_I_ID"
-" AND S_QUANTITY < threshold;"
-" /* PRINTF(stock_count, ' items under threshold ', threshold); */"
-" /* COMMIT WORK; */"
-""
-" END;"
- ;
-
- stock_level_query = pars_sql(str);
- /*-----------------------------------------------------------*/
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10; i++) {
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(new_order_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(payment_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 10 == 3) {
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(order_status_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- if ((i % 10 == 6) || (i % 100 == 60)) {
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(delivery_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- if (i % 10 == 9) {
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(stock_level_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- if ((i > 0) && (i % 200 == 0)) {
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(commit_query,
- SESS_COMM_EXECUTE, 0);
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-#ifdef notdefined
-
-/*********************************************************************
-General test. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- sess_t* sess2;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* query;
- que_thr_t* thr;
- trx_t* trx;
- trx_t* trx2;
- ulint tm, oldtm;
- ulint j;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. GENERAL TEST\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
- sess2 = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user2", 6);
-
- trx = sess->trx;
- trx2 = sess2->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*------------------------------------------------------*/
- query = pars_sql(
-" PROCEDURE CREATE_TABLE () IS"
-" BEGIN"
-" CREATE TABLE TS_TABLE1 (COL1 CHAR, COL2 CHAR, COL3 CHAR);"
-" CREATE TABLE TS_TABLE2 (COL21 INT, COL22 INT, COL23 CHAR);"
-" CREATE TABLE TS_TABLE3 (COL31 INT, COL32 INT, COL33 CHAR);"
-" CREATE TABLE TS_TABLE4 (COL41 INT, COL42 INT, COL43 CHAR);"
-" CREATE UNIQUE CLUSTERED INDEX IND1 ON TS_TABLE1 (COL1);"
-" CREATE UNIQUE CLUSTERED INDEX IND21 ON TS_TABLE2 (COL21);"
-" CREATE UNIQUE CLUSTERED INDEX IND31 ON TS_TABLE3 (COL31);"
-" CREATE CLUSTERED INDEX IND41 ON TS_TABLE4 (COL41);"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-
- printf("Will start insert test\n");
-
- query = pars_sql(
-
-" PROCEDURE INSERT_SPEED_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" int2 := 0;"
-" int1 := 0;"
-" WHILE int1 < 40 LOOP"
-" INSERT INTO TS_TABLE2 VALUES (int1, int1 - 100 * (int1 / 100),"
-" '123456789012345678901234567890');"
-" int1 := int1 + 1;"
-" "
-" END LOOP;"
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for insert test %lu milliseconds\n", tm - oldtm);
-
-
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE2"); */
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
- printf("Will start insert test2\n");
-
- query = pars_sql(
-
-" PROCEDURE INSERT_SPEED_TEST2 () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" INSERT INTO TS_TABLE3 SELECT * FROM TS_TABLE2;"
-" "
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for insert test2 %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE2"); */
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-/* os_thread_sleep(1000000); */
-
-/* btr_search_table_print_info("TS_TABLE3"); */
-
- query = pars_sql(
-
-" PROCEDURE JOIN_SPEED_TEST () IS"
-" int1 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*) INTO int1"
-" FROM TS_TABLE2, TS_TABLE3"
-" WHERE COL21 = COL31"
-" CONSISTENT READ;"
-" PRINTF(int1);"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- for (j = 0; j < 20; j++) {
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE,
- 0));
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- printf("Wall time for join test %lu milliseconds\n",
- tm - oldtm);
- }
-
-/* btr_search_table_print_info("TS_TABLE3"); */
-
- /*------------------------------------------------------*/
- printf("Will start update test\n");
-
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE UPDATE_SPEED_TEST () IS"
-" int1 INT;"
-" BEGIN"
-" UPDATE TS_TABLE2 SET COL22 = COL22 + 1;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for update test %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE2"); */
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
- printf("Will start TPC-A\n");
- os_thread_sleep(2000000);
-
- query = pars_sql(
-" PROCEDURE TPC_A_SPEED_TEST () IS"
-" int1 INT;"
-" "
-" BEGIN"
-" int1 := 0;"
-" WHILE int1 < 1000 LOOP"
-" INSERT INTO TS_TABLE4 VALUES (int1, int1,"
-" '123456789012345678901234567890');"
-" UPDATE TS_TABLE2 SET COL22 = COL22 + 1"
-" WHERE COL21 = int1;"
-" UPDATE TS_TABLE2 SET COL22 = COL22 + 1"
-" WHERE COL21 = int1 + 1;"
-" UPDATE TS_TABLE2 SET COL22 = COL22 + 1"
-" WHERE COL21 = int1 + 2;"
-" int1 := int1 + 1;"
-" END LOOP;"
-" "
-" END;"
- );
-
-/*" SELECT COUNT(*) INTO int1 FROM TS_TABLE2 WHERE COL22 = COL21 + 4;"
-" PRINTF(int1);"
-" SELECT COUNT(*) INTO int1 FROM TS_TABLE4;"
-" PRINTF(int1);"
-*/
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for TPC-A test %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
- printf("Will start insert test\n");
-
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE INSERT_SPEED_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" int2 := 0;"
-" int1 := 0;"
-" WHILE int1 < 1000 LOOP"
-" INSERT INTO TS_TABLE2 VALUES (int1, int1,"
-" '123456789012345678901234567890');"
-" int1 := int1 + 1;"
-" "
-" END LOOP;"
-" SELECT COUNT(*) INTO int2"
-" FROM TS_TABLE2;"
-" ASSERT(int1 = int2);"
-" "
-" COMMIT WORK;"
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for insert test %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE DELETE_SPEED_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int1 = 1000);"
-" ASSERT(int2 = 999 * 500);"
-" DELETE FROM TS_TABLE2;"
-" "
-" SELECT COUNT(*), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int1 = 0);"
-" ASSERT(int2 = 0);"
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for delete test %lu milliseconds\n", tm - oldtm);
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE CONSISTENT_READ_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int2 = 999 * 500);"
-" ASSERT(int1 = 1000);"
-" "
-" "
-" END;"
- );
-
- query->trx = trx2;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for consistent read test %lu milliseconds\n",
- tm - oldtm);
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE ROLLBACK_SPEED_TEST () IS"
-" "
-" BEGIN"
-" ROLLBACK WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE UPDATE_SPEED_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" UPDATE TS_TABLE2 SET COL21 = COL21 + 1000, COL22 = COL22 + 1"
-" WHERE COL21 < 1000;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" UPDATE TS_TABLE2 SET COL21 = COL21, COL22 = COL22;"
-" "
-" SELECT SUM(COL21), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int2 = 1000 + 999 * 500);"
-" ASSERT(int1 = 1000000 + 999 * 500);"
-" UPDATE TS_TABLE2 SET COL21 = COL21 + 1000, COL22 = COL22 + 1"
-" WHERE COL21 < 2000;"
-" UPDATE TS_TABLE2 SET COL21 = COL21 + 1000, COL22 = COL22 + 1"
-" WHERE COL21 < 3000;"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for update test %lu milliseconds\n", tm - oldtm);
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE CONSISTENT_READ_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int1 = 1000);"
-" ASSERT(int2 = 999 * 500);"
-" "
-" "
-" END;"
- );
-
- query->trx = trx2;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for consistent read test %lu milliseconds\n",
- tm - oldtm);
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE2"); */
- /*------------------------------------------------------*/
- /*------------------------------------------------------*/
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE CONSISTENT_READ_TEST () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*), SUM(COL22) INTO int1, int2"
-" FROM TS_TABLE2"
-" CONSISTENT READ;"
-" ASSERT(int1 = 1000);"
-" ASSERT(int2 = 999 * 500);"
-" "
-" "
-" END;"
- );
-
- query->trx = trx2;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for consistent read test %lu milliseconds\n",
- tm - oldtm);
- /*------------------------------------------------------*/
- printf("Will start insert test2\n");
- os_thread_sleep(2000000);
-
- query = pars_sql(
-
-" PROCEDURE INSERT_SPEED_TEST2 () IS"
-" int1 INT;"
-" int2 INT;"
-" "
-" BEGIN"
-" INSERT INTO TS_TABLE3 SELECT * FROM TS_TABLE2;"
-" "
-" SELECT COUNT(*) INTO int1"
-" FROM TS_TABLE2;"
-" SELECT COUNT(*) INTO int2"
-" FROM TS_TABLE3;"
-" ASSERT(int1 = int2);"
-" "
-" COMMIT WORK;"
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for insert test2 %lu milliseconds\n", tm - oldtm);
-
-/* sync_print(); */
-
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE COMMIT_SPEED_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
-
- query = pars_sql(
-
-" PROCEDURE JOIN_SPEED_TEST () IS"
-" int1 INT;"
-" "
-" BEGIN"
-" SELECT COUNT(*) INTO int1"
-" FROM TS_TABLE2, TS_TABLE3"
-" WHERE COL21 = COL31;"
-" ASSERT(int1 = 1000);"
-" "
-" COMMIT WORK;"
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for join test %lu milliseconds\n", tm - oldtm);
-
- /*------------------------------------------------------*/
-
- dict_table_print_by_name("TS_TABLE1");
- dict_table_print_by_name("TS_TABLE2");
-
-/*
- dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS");
- dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS");
-*/
- query = pars_sql(
-
-" PROCEDURE INSERT_TEST () IS"
-" var1 CHAR;"
-" var2 CHAR;"
-" int1 INT;"
-" int2 INT;"
-" sum1 INT;"
-" finished INT;"
-" rnd_var1 INT;"
-" rnd_var2 INT;"
-" "
-" DECLARE CURSOR cursor2"
-" IS SELECT COL21, COL22"
-" FROM TS_TABLE2"
-" WHERE COL21 > 5;"
-" "
-" BEGIN"
-" int1 := 0;"
-" WHILE int1 < 10 LOOP"
-" rnd_var1 := int1;"
-" PRINTF('Round '); PRINTF(int1);"
-" INSERT INTO TS_TABLE2 VALUES (int1, rnd_var1,"
-" '123456789012345678901234567890');"
-" SELECT COL22 INTO rnd_var2 FROM TS_TABLE2"
-" WHERE COL21 = int1;"
-" ASSERT(rnd_var1 = rnd_var2);"
-" int1 := int1 + 1;"
-" END LOOP;"
-" "
-" PRINTF('First explicit cursor loop:');"
-" OPEN cursor2;"
-" finished := 0;"
-" "
-" WHILE finished = 0 LOOP"
-" FETCH cursor2 INTO int1, int2;"
-" IF cursor2 % NOTFOUND THEN"
-" finished := 1;"
-" PRINTF('Loop now finished');"
-" ELSE"
-" PRINTF('Row fetched, values:');"
-" PRINTF(int1); PRINTF(int2);"
-" ASSERT(int1 = int2);"
-" UPDATE TS_TABLE2 SET COL22 = COL22 + 100"
-" WHERE CURRENT OF cursor2;"
-" END IF;"
-" END LOOP;"
-" CLOSE cursor2;"
-" "
-" PRINTF('Second explicit cursor loop:');"
-" OPEN cursor2;"
-" finished := 0;"
-" "
-" WHILE finished = 0 LOOP"
-" FETCH cursor2 INTO int1, int2;"
-" IF cursor2 % NOTFOUND THEN"
-" finished := 1;"
-" ELSE"
-" PRINTF('Row fetched, values:');"
-" PRINTF(int1); PRINTF(int2);"
-" ASSERT(int1 + 100 = int2);"
-" UPDATE TS_TABLE2 SET COL22 = int2 + 100"
-" WHERE CURRENT OF cursor2;"
-" END IF;"
-" END LOOP;"
-" CLOSE cursor2;"
-" "
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" PRINTF('Now table 2 has this many rows: '); PRINTF(int1);"
-" PRINTF('and the sum of COL22: '); PRINTF(sum1);"
-" "
-" INSERT INTO TS_TABLE3"
-" SELECT COL21, COL22 + 10, COL23 FROM TS_TABLE2;"
-" "
-" SELECT COUNT(*), SUM(COL32) INTO int1, sum1"
-" FROM TS_TABLE2, TS_TABLE3"
-" WHERE COL21 + 2 = COL31;"
-" PRINTF('Join table has this many rows: '); PRINTF(int1);"
-" PRINTF('and the sum of COL32: '); PRINTF(sum1);"
-" "
-" ROLLBACK WORK;"
-" "
-" SELECT COUNT(*), SUM(COL21) INTO int1, sum1 FROM TS_TABLE2;"
-" PRINTF('Now table 2 has this many rows: '); PRINTF(int1);"
-" PRINTF('and the sum of COL21: '); PRINTF(sum1);"
-" "
-" "
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- dict_table_print_by_name("TS_TABLE2");
-
- query = pars_sql(
-
-" PROCEDURE DELETE_TEST () IS"
-" int1 INT;"
-" sum1 INT;"
-" finished INT;"
-" "
-" DECLARE CURSOR cursor2"
-" IS SELECT"
-" FROM TS_TABLE2"
-" WHERE COL21 < 10;"
-" "
-" BEGIN"
-" int1 := 0;"
-" WHILE int1 < 10 LOOP"
-" PRINTF('Round '); PRINTF(int1);"
-" INSERT INTO TS_TABLE2 VALUES (int1, int1, TO_CHAR(int1));"
-" int1 := int1 + 1;"
-" END LOOP;"
-" COMMIT WORK;"
-" PRINTF('Delete all the rows:');"
-" OPEN cursor2;"
-" finished := 0;"
-" "
-" WHILE finished = 0 LOOP"
-" FETCH cursor2 INTO;"
-" IF cursor2 % NOTFOUND THEN"
-" finished := 1;"
-" PRINTF('Loop now finished: all rows deleted');"
-" ELSE"
-" DELETE FROM TS_TABLE2"
-" WHERE CURRENT OF cursor2;"
-" END IF;"
-" END LOOP;"
-" CLOSE cursor2;"
-" "
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" PRINTF('Now table 2 has this many rows, and their sum is: ');"
-" PRINTF(int1); PRINTF(sum1);"
-" ASSERT((int1 = 0) AND (sum1 = 0));"
-" "
-" ROLLBACK WORK;"
-" "
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" "
-" PRINTF(int1); PRINTF(sum1);"
-" ASSERT((int1 = 10) AND (sum1 = 45));"
-" COMMIT WORK;"
-" DELETE FROM TS_TABLE2 WHERE COL22 = 5;"
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" PRINTF(int1); PRINTF(sum1);"
-" ASSERT((int1 = 9) AND (sum1 = 40));"
-" DELETE FROM TS_TABLE2 WHERE COL23 = TO_CHAR(6);"
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" PRINTF(int1);"
-" PRINTF(sum1);"
-" ASSERT((int1 = 8) AND (sum1 = 34));"
-" DELETE FROM TS_TABLE2 WHERE COL23 = TO_CHAR(6);"
-" SELECT COUNT(*), SUM(COL22) INTO int1, sum1"
-" FROM TS_TABLE2;"
-" PRINTF(int1);"
-" PRINTF(sum1);"
-" ASSERT((int1 = 8) AND (sum1 = 34));"
-" COMMIT WORK;"
-" END;"
- );
-
- query->trx = trx;
-
- thr = UT_LIST_GET_FIRST(query->thrs);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(query, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- return(0);
-}
-
-#endif
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- test_c(NULL);
-
- tm = ut_clock();
-
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
-
diff --git a/innobase/btr/ts/tsbtr97.c b/innobase/btr/ts/tsbtr97.c
deleted file mode 100644
index 633fb7f22ae..00000000000
--- a/innobase/btr/ts/tsbtr97.c
+++ /dev/null
@@ -1,5080 +0,0 @@
-/************************************************************************
-Test for the B-tree
-
-(c) 1996-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "buf0flu.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "log0recv.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "row0del.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 2
-#define N_FILES 1
-#define FILE_SIZE 512 /* must be > 512 */
-#define POOL_SIZE 500
-#define COUNTER_OFFSET 1500
-
-#define N_LOG_GROUPS 2
-#define N_LOG_FILES 3
-#define LOG_FILE_SIZE 500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-#define COUNT 1
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-ulint dummy = 0;
-
-byte rnd_buf[256 * 256];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- ulint i;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates or opens the log files. */
-
-void
-create_log_files(void)
-/*==================*/
-{
- bool ret;
- ulint i, k;
- char name[20];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open log files\n");
-
- strcpy(name, "logfile00");
-
- for (k = 0; k < N_LOG_GROUPS; k++) {
- for (i = 0; i < N_LOG_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_AIO,
- &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * LOG_FILE_SIZE, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k + 100, FIL_LOG);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, LOG_FILE_SIZE, k + 100);
- }
-
- fil_space_create(name, k + 200, FIL_LOG);
-
- log_group_init(k, N_LOG_FILES, LOG_FILE_SIZE * UNIV_PAGE_SIZE,
- k + 100, k + 200);
- }
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k, j, c;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < 2 * N_SPACES; k += 2) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_NORMAL, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_NORMAL, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- UNIV_PAGE_SIZE * FILE_SIZE, 0));
- /* Initialize the file contents to a random value */
-
- for (j = 0; j < FILE_SIZE; j++) {
- for (c = 0; c < UNIV_PAGE_SIZE; c++) {
- rnd_buf[c] = 0xFF;
- /*(byte)
- (ut_rnd_gen_ulint() % 256); */
- }
-
- os_file_write(files[i], rnd_buf,
- UNIV_PAGE_SIZE * j, 0,
- UNIV_PAGE_SIZE);
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, FIL_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space headers of spaces 0 and 2. */
-
-void
-init_spaces(void)
-/*=============*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
- fsp_header_init(2, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS");
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0,
- /*DICT_UNIQUE |*/ DICT_CLUSTERED, 1);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* CREATE YET ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND4", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-#endif
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE2", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE2", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_6(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.6. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE3", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE3", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_7(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.7. CREATE TABLE WITH 12 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE4", 0, 12);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL4", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL5", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL6", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL7", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL8", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL9", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL10", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL11", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL12", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE4", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for inserts. */
-
-ulint
-test2(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- dict_index_t* index;
-/* ulint size; */
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. MASSIVE INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- /* MASSIVE RANDOM INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 100 == 0) {
- printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print();
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-/*
- for (i = 0; i < 10; i++) {
- size = ibuf_contract(TRUE);
-
- printf("%lu bytes will be contracted\n", size);
-
- os_thread_sleep(1000000);
- }
-*/
-/* index = dict_table_get_next_index(dict_table_get_first_index(table));
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- index = dict_table_get_next_index(index);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-*/
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- btr_search_print_info();
-
- /* Check inserted entries */
-
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < 1 /* *((ulint*)arg) */; i++) {
-
- rnd = (rnd + 7857641) % 200000;
- dtuple_gen_search_tuple3(entry, rnd, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
-/* btr_validate_tree(tree); */
-
-/* btr_print_tree(tree, 5); */
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- btr_validate_tree(tree);
-
-/* btr_search_print_info();
- dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_1(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ins_node_t* node;
- ulint count = 0;
- ulint rnd;
- dtuple_t* row;
-/* buf_frame_t* frame_table[2000];
- dict_tree_t* tree;
- dict_index_t* index;
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr; */
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1. MASSIVE ASCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- rnd = 0;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 5000 == 0) {
-
- /* fsp_print(0); */
- /* ibuf_print(); */
- /* buf_print(); */
-
- /* buf_print_io(); */
-
- tm = ut_clock();
- /*
- printf("Wall time for %lu inserts %lu milliseconds\n",
- i, tm - oldtm); */
- }
-
- rnd = rnd + 1;
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- ibuf_print();
-
- index = dict_table_get_first_index(table);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- /* Check inserted entries */
-
- btr_search_print_info();
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
-/* btr_validate_tree(tree); */
-
- for (i = 0; i < POOL_SIZE - 1; i++) {
- frame_table[i] = buf_frame_alloc(FALSE);
- }
-
- for (i = 0; i < POOL_SIZE - 1; i++) {
- buf_frame_free(frame_table[i]);
- }
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-#endif
-#ifdef notdefined
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_search_print_info();
-
-#endif
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
- /*-------------------------------------*/
-
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_2(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2. MASSIVE DESCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = *((ulint*)arg) + 1;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND3500, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
-/* printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print(); */
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i + 1, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_validate_tree(tree);
-/* dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- btr_validate_tree(tree);
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for random inserts. */
-
-ulint
-test2mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2MT. MULTITHREADED RANDOM INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
- rnd = 78675;
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- if (i % 100 == 0) {
- printf("*******Inserted %lu rows\n", i);
-/* buf_print(); */
- ibuf_print();
- }
-
- rnd = (rnd + 7857641) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_1mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1MT. MULTITHREADED ASCENDING INSERT\n");
-
- rnd = 8757677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 98667501;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_2mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2MT. MULTITHREADED DESCENDING INSERT\n");
-
- rnd = 87677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 78667;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- mem_print_info();
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for updates. */
-
-ulint
-test3(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 3. UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 3; i++) {
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_RND30, buf);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- ut_a(DB_SUCCESS == lock_clust_rec_read_check_and_lock(0,
- btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr));
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-#ifdef notdefined
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Init for update test. */
-
-ulint
-test4_1(void)
-/*=========*/
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.1. UPDATE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*************************************************************************
-Checks that the multithreaded update test has rolled back its updates. */
-
-void
-test4_2(void)
-/*=========*/
-{
- dtuple_t* entry;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- mtr_t mtr;
- byte buf[32];
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- btr_pcur_t pcur;
- rec_t* rec;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.2. CHECK UPDATE RESULT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*------------------------------------------*/
-
- table = dict_table_get("TS_TABLE1", trx);
-
- index = dict_table_get_first_index(table);
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < 200; i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- rec = btr_pcur_get_rec(&pcur);
-
- ut_a(0 == cmp_dtuple_rec(entry, rec));
-
- heap2 = mem_heap_create(200);
-
- row = row_build(ROW_COPY_DATA, index, rec, heap2);
-
- ut_a(30 == dfield_get_len(dtuple_get_nth_field(row, 2)));
- ut_a(0 == ut_memcmp(
- dfield_get_data(dtuple_get_nth_field(row, 2)),
- "12345678901234567890123456789", 30));
-
- mem_heap_free(heap2);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-}
-
-/*********************************************************************
-Test for massive updates. */
-
-ulint
-test4mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4. MULTITHREADED UPDATES\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 999; i++) {
-
- rnd += 874681;
- tuple_no = (rnd % 40) * 5 + thr_no;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("%lu: thread %lu to update row %lu\n", i, thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 200);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- if ((count == 1) && (thr_no != 4)) {
-
- return(0);
- }
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(7000000);
-
- btr_validate_tree(tree);
-
- ut_a(trx->conc_state != TRX_ACTIVE);
- ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
-
- count++;
-
- if (count < 2) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for join. */
-
-ulint
-test6(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ulint count = 0;
- dtuple_t* entry;
- dict_index_t* index;
- dict_tree_t* tree;
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- ulint rnd;
- ulint latch_mode;
-
- printf("-------------------------------------------------\n");
- printf("TEST 6. MASSIVE EQUIJOIN\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*--------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
- /*--------------*/
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- table = dict_table_get("TS_TABLE1", trx);
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- oldtm = ut_clock();
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IS, thr));
-
- rnd = 98651;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- btr_pcur_store_position(&pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-
- btr_pcur_commit_specify_mtr(&pcur, &mtr);
-
- if (i % 1211 == 0) {
- dummy++;
- }
-
- rnd = 55321;
-
- dtuple_gen_search_tuple3(entry, rnd % *((ulint*)arg), buf);
-
-/* if (i == 0) { */
- latch_mode = BTR_SEARCH_LEAF;
-/* } else {
- latch_mode = BTR_SEARCH_LEAF | BTR_GUESS_LATCH;
- } */
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, latch_mode,
- &pcur2, &mtr2);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur2),
- index));
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur2)));
-
- mtr_commit(&mtr2);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for join of %lu rows %lu milliseconds\n",
- i, tm - oldtm);
- btr_search_index_print_info(index);
- /*-------------------------------------*/
- /* COMMIT */
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-/* printf("Wall time for commit %lu milliseconds\n", tm - oldtm); */
-
- /*-------------------------------------*/
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 3) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for lock wait. Requires Test 4.1 first. */
-
-ulint
-test7(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- trx_t* trx2;
- ulint rnd;
- dtuple_t* entry;
- dtuple_t* row;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 7. LOCK WAIT\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx2 = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- /* UPDATE by trx */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- ut_a(trx_start(trx2, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- rnd += 874681;
- tuple_no = 3;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 1500);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* INSERT by trx2 */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx2;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx2);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx2->sess);
-
- trx2->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- dtuple_gen_test_tuple3(row, 2, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- /* Insert should be left to wait until trx releases the row lock */
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* COMMIT of trx */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- /*-------------------------------------*/
- os_thread_sleep(1000000);
-
- printf(
- "trx2 can now continue to do the insert, after trx committed.\n");
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-A. */
-
-ulint
-test8A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 8A. 1000 INSERTS FOR TPC-A\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE2", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_test_tuple_TPC_A(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_search_tuple_TPC_A(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE2"); */
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-A transaction. */
-
-ulint
-test8(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 8. TPC-A %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE2", trx);
-
- update = upd_create(1, heap);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-
-loop:
-/* printf("Round %lu\n", count); */
-
- /*-------------------------------------*/
- /* INSERT */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-------------------------------------*/
- /* 3 UPDATES */
-
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
- for (i = 0; i < 3; i++) {
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_A(entry, rnd % 1000, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
-/* ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur))); */
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- tm = ut_clock();
- printf("Wall time for TPC-A %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-
-
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-C. */
-
-ulint
-test9A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-/* dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
- dict_index_t* index;
- dict_tree_t* tree;
-*/
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 9A. INSERTS FOR TPC-C\n");
-
-#define TPC_C_TABLE_SIZE 15000
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE4", trx);
-
- row = dtuple_create(heap, 12 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_test_tuple_TPC_C(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-#endif
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE4"); */
-
-/* mem_heap_free(heap); */
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-C transaction. Test 9A must be run first to populate table. */
-
-ulint
-test9(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint j;
- ulint i;
- byte* ptr;
- ulint len;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
- byte buf2[240];
- rec_t* rec;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 9. TPC-C %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE4", trx);
-
- update = upd_create(3, heap);
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 2);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-loop:
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IS, thr));
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
-/* printf("Round %lu\n", count); */
-
-for (j = 0; j < 13; j++) {
-
- /*-------------------------------------*/
- /* SELECT FROM 'ITEM' */
-
- rnd += 876751;
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_S, thr);
- ut_a(err == DB_SUCCESS);
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 5; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* UPDATE 'STOCK' */
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 10; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
-/* btr_pcur_commit(&pcur); */
-
-/* err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr); */
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-/* ut_a(err == DB_SUCCESS); */
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 1);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 2);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- btr_pcur_close(&pcur);
- /*-------------------------------------*/
- /* INSERT INTO 'ORDERLINE' */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count * 13 + j, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-}
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
- tm = ut_clock();
- printf("Wall time for TPC-C %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Init for purge test. */
-
-ulint
-test10_1(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.1. PURGE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i * 100 + thr_no,
- DTUPLE_TEST_FIXED30, buf);
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 200);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2_r(
-/*=======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 2000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_3(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.3. PURGE TEST DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- rnd = i;
- tuple_no = rnd;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_5(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.5. PURGE TEST UNCOMMITTED DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 50; i++) {
-
- rnd = i;
- tuple_no = rnd % 100;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for purge. */
-
-ulint
-test10mt(
-/*=====*/
- void* arg)
-{
- ulint i;
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("Thread %lu starts purge test\n", thr_no);
-
- for (i = 0; i < 2; i++) {
- test10_1(arg);
-
- sync_print();
-
- fsp_validate(0);
-
- test10_2_r(arg);
- sync_print();
-
- test10_2(arg);
- sync_print();
-
- lock_validate();
-
- test10_3(arg);
- sync_print();
- }
-
- printf("Thread %lu ends purge test\n", thr_no);
-
- return(0);
-}
-
-/*********************************************************************
-Purge test. */
-
-ulint
-test10_4(
-/*=====*/
- void* arg)
-{
- ulint i;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.4. PURGE TEST\n");
-
- for (i = 0; i < 30; i++) {
- trx_purge();
-
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- os_thread_sleep(5000000);
- }
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to test insert buffer merge. */
-
-ulint
-test_ibuf_merge(
-/*============*/
- void* arg)
-{
- ulint sum_sizes;
- ulint volume;
-
- ut_ad(arg);
-
- printf("Starting ibuf merge\n");
-
- sum_sizes = 0;
- volume = 1;
-
- while (volume) {
- volume = ibuf_contract(FALSE);
-
- sum_sizes += volume;
- }
-
- printf("Ibuf merged %lu bytes\n", sum_sizes);
-
- os_thread_sleep(5000000);
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint count;
-
- ut_ad(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
- count = 0;
-
- for (j = 0; j < 100; j++) {
-
- os_thread_sleep(10000);
-
- if ((&(buf_pool->mutex))->lock_word) {
-
- count++;
- }
- }
-
- printf("Mutex reserved %lu of %lu peeks\n", count, j);
- }
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- os_thread_id_t id[10];
- ulint n1000[10];
- ulint i;
- ulint n5000 = 500;
- ulint n2;
- char buf[100];
-
-/* buf_debug_prints = TRUE; */
- log_do_write = TRUE;
- btr_search_use_hash = TRUE;
- log_debug_writes = TRUE;
-
- srv_boot("initfile");
- os_aio_init(576, 9, 100);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
- lock_sys_create(1024);
-
- create_files();
- create_log_files();
-
- init_spaces();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- dict_create();
-
- log_make_checkpoint_at(ut_dulint_max);
-/* log_debug_writes = TRUE; */
-
-/* os_thread_sleep(500000); */
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1(NULL);
-/* test1_5(NULL);
- test1_6(NULL);
- test1_7(NULL); */
-
-/* for (i = 0; i < 2; i++) {
-
- n1000[i] = i;
- id[i] = id[i];
-
- os_thread_create(test10mt, n1000 + i, id + i);
- }
-*/
- i = 4;
-
- n1000[i] = i;
- id[i] = id[i];
-
-/* os_thread_create(test10_4, n1000 + i, id + i); */
-
- i = 5;
-
-/* test10mt(&i);
-
- i = 6;
-
- test10mt(&i);
-
- trx_purge();
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- dict_table_print_by_name("TS_TABLE1"); */
-
-/* os_thread_create(test_measure_cont, &n3, id + 0); */
-
-/* mem_print_info(); */
-
- log_make_checkpoint_at(ut_dulint_max);
-
- n2 = 100;
-
-/* test2_1(&n2);
-
- log_flush_up_to(ut_dulint_max, LOG_WAIT_ALL_GROUPS); */
-
-/* sync_print();
-
- test9A(&n2);
-
- sync_print();
-
- log_print();
-
- test9(&n2);
-
- log_print();
-
- sync_print(); */
-/* test6(&n2); */
-
-/* test2_2(&n2); */
-
-/* test3(&n2); */
-
-/* mem_print_info(); */
-
- log_archive_stop();
- log_archive_start();
-
- ut_a(DB_SUCCESS == log_switch_backup_state_on());
-
- printf("Type: kukkuu<enter>\n");
- scanf("%s", buf);
-
- ut_a(DB_SUCCESS == log_switch_backup_state_off());
-
- for (i = 0; i < 2; i++) {
-
- n1000[i] = 500 + 10 * i;
- id[i] = id[i];
-/*
- os_thread_create(test2mt, n1000 + i, id + i);
- os_thread_create(test2_1mt, n1000 + i, id + i);
- os_thread_create(test2_2mt, n1000 + i, id + i);
-*/ }
-
- n2 = 5000;
-
-/* fsp_print(0); */
-
- test2_1(&n2);
-
- for (i = 0; i < 20; i++) {
- log_archive_stop();
- log_archive_start();
- }
-
-/* test2(&n2);
- test2(&n2); */
-
-/* buf_print();
- ibuf_print();
- rw_lock_list_print_info();
- mutex_list_print_info(); */
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
-/* mem_print_info(); */
-/*
- n2 = 100;
-
- test4_1();
- test4_2();
-
- for (i = 0; i < 2; i++) {
- n1000[i] = i;
- id[i] = id[i];
- os_thread_create(test4mt, n1000 + i, id + i);
- }
-
- n2 = 4;
- test4mt(&n2);
-
- log_archive_stop();
- log_archive_start();
-
- test4mt(&n2);
-*/
-/* test4_2(); */
-/*
- lock_print_info();
-*/
-/* test7(&n2); */
-
-/* os_thread_sleep(25000000); */
-
-/* ut_a(DB_SUCCESS == log_switch_backup_state_off()); */
-
-/* recv_compare_spaces(0, 1, 100); */
-
- log_flush_up_to(ut_dulint_max, LOG_WAIT_ALL_GROUPS);
-
- printf("Type: kukkuu<enter>\n");
- scanf("%s", buf);
-
- buf_flush_batch(BUF_FLUSH_LIST, ULINT_MAX, ut_dulint_max);
- buf_flush_wait_batch_end(BUF_FLUSH_LIST);
-
-/* log_make_checkpoint_at(ut_dulint_max); */
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
-/* buf_print(); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tsbtrfull.c b/innobase/btr/ts/tsbtrfull.c
deleted file mode 100644
index fc8bbb7bffc..00000000000
--- a/innobase/btr/ts/tsbtrfull.c
+++ /dev/null
@@ -1,4925 +0,0 @@
-/************************************************************************
-Test for the B-tree
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "row0del.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 2 /* must be >= 2 */
-#define N_FILES 1
-#define FILE_SIZE 8096 /* must be > 512 */
-#define POOL_SIZE 1524
-#define IBUF_SIZE 200
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-#define COUNT 1
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-ulint dummy = 0;
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
- ut_a(ret);
- } else {
- if (k == 1) {
- ut_a(os_file_set_size(files[i],
- 8192 * IBUF_SIZE, 0));
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * FILE_SIZE, 0));
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space headers of spaces 0 and 1. */
-
-void
-init_spaces(void)
-/*=============*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
- fsp_header_init(1, IBUF_SIZE, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0,
- DICT_UNIQUE | DICT_CLUSTERED, 1);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* CREATE YET ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND4", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-#endif
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE2", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE2", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_6(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.6. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE3", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE3", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_7(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.7. CREATE TABLE WITH 12 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE4", 0, 12);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL4", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL5", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL6", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL7", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL8", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL9", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL10", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL11", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL12", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE4", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for inserts. */
-
-ulint
-test2(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- dict_index_t* index;
-/* ulint size; */
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. MASSIVE INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- /* MASSIVE RANDOM INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd,
- DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
- printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print();
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-/*
- for (i = 0; i < 10; i++) {
- size = ibuf_contract(TRUE);
-
- printf("%lu bytes will be contracted\n", size);
-
- os_thread_sleep(1000000);
- }
-*/
- index = dict_table_get_next_index(dict_table_get_first_index(table));
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- index = dict_table_get_next_index(index);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- btr_search_print_info();
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
- dtuple_gen_search_tuple3(entry, rnd, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
-/* btr_print_tree(tree, 5); */
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- btr_validate_tree(tree);
-
-/* btr_search_print_info();
- dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_1(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ins_node_t* node;
- ulint count = 0;
- ulint rnd;
- dtuple_t* row;
-/* dict_tree_t* tree;
- dict_index_t* index;
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr; */
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1. MASSIVE ASCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 5000 == 0) {
- /* ibuf_print(); */
- /* buf_print(); */
-
- /* buf_print_io(); */
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
- }
-
- rnd = rnd + 1;
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- ibuf_print();
-
- index = dict_table_get_first_index(table);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- /* Check inserted entries */
-
- btr_search_print_info();
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-#endif
-#ifdef notdefined
- /*-------------------------------------*/
- /* ROLLBACK */
-
-/* btr_validate_tree(tree); */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_search_print_info();
-
-#endif
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
- /*-------------------------------------*/
-
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_2(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2. MASSIVE DESCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = *((ulint*)arg) + 1;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
-/* printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print(); */
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i + 1, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_validate_tree(tree);
-/* dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- btr_validate_tree(tree);
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for random inserts. */
-
-ulint
-test2mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2MT. MULTITHREADED RANDOM INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
- rnd = 78675;
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- if (i % 100 == 0) {
-/* buf_print(); */
-/* ibuf_print(); */
- }
-
- rnd = (rnd + 7857641) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_1mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1MT. MULTITHREADED ASCENDING INSERT\n");
-
- rnd = 8757677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 98667501;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_2mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2MT. MULTITHREADED DESCENDING INSERT\n");
-
- rnd = 87677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 78667;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- mem_print_info();
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for updates. */
-
-ulint
-test3(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
- ulint err;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 3. UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 3; i++) {
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_RND30, buf);
-
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-#ifdef notdefined
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Init for update test. */
-
-ulint
-test4_1(void)
-/*=========*/
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.1. UPDATE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*************************************************************************
-Checks that the multithreaded update test has rolled back its updates. */
-
-void
-test4_2(void)
-/*=========*/
-{
- dtuple_t* entry;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- mtr_t mtr;
- byte buf[32];
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- btr_pcur_t pcur;
- rec_t* rec;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.2. CHECK UPDATE RESULT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*------------------------------------------*/
-
- table = dict_table_get("TS_TABLE1", trx);
-
- index = dict_table_get_first_index(table);
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < 200; i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- rec = btr_pcur_get_rec(&pcur);
-
- ut_a(0 == cmp_dtuple_rec(entry, rec));
-
- heap2 = mem_heap_create(200);
-
- row = row_build(ROW_COPY_DATA, index, rec, heap2);
-
- ut_a(30 == dfield_get_len(dtuple_get_nth_field(row, 2)));
- ut_a(0 == ut_memcmp(
- dfield_get_data(dtuple_get_nth_field(row, 2)),
- "12345678901234567890123456789", 30));
-
- mem_heap_free(heap2);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-}
-
-/*********************************************************************
-Test for massive updates. */
-
-ulint
-test4mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4. MULTITHREADED UPDATES\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 300; i++) {
-
- rnd += 874681;
- tuple_no = (rnd % 40) * 5 + thr_no;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 3000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- btr_validate_tree(tree);
-
- ut_a(trx->conc_state != TRX_ACTIVE);
- ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
-
- count++;
-
- if (count < 2) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for join. */
-
-ulint
-test6(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ulint count = 0;
- dtuple_t* entry;
- dict_index_t* index;
- dict_tree_t* tree;
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- ulint rnd;
- ulint latch_mode;
-
- printf("-------------------------------------------------\n");
- printf("TEST 6. MASSIVE EQUIJOIN\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*--------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
- /*--------------*/
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- table = dict_table_get("TS_TABLE1", trx);
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- oldtm = ut_clock();
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IS, thr));
-
- rnd = 98651;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- btr_pcur_store_position(&pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-
- btr_pcur_commit_specify_mtr(&pcur, &mtr);
-
- if (i % 1211 == 0) {
- dummy++;
- }
-
- rnd = 55321;
-
- dtuple_gen_search_tuple3(entry, rnd % *((ulint*)arg), buf);
-
-/* if (i == 0) { */
- latch_mode = BTR_SEARCH_LEAF;
-/* } else {
- latch_mode = BTR_SEARCH_LEAF | BTR_GUESS_LATCH;
- } */
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, latch_mode,
- &pcur2, &mtr2);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur2),
- index));
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur2)));
-
- mtr_commit(&mtr2);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for join of %lu rows %lu milliseconds\n",
- i, tm - oldtm);
- btr_search_index_print_info(index);
- /*-------------------------------------*/
- /* COMMIT */
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-/* printf("Wall time for commit %lu milliseconds\n", tm - oldtm); */
-
- /*-------------------------------------*/
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 3) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for lock wait. Requires Test 4.1 first. */
-
-ulint
-test7(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- trx_t* trx2;
- ulint rnd;
- dtuple_t* entry;
- dtuple_t* row;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 7. LOCK WAIT\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx2 = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- /* UPDATE by trx */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- ut_a(trx_start(trx2, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- rnd += 874681;
- tuple_no = 3;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 1500);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* INSERT by trx2 */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx2;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx2);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx2->sess);
-
- trx2->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- dtuple_gen_test_tuple3(row, 2, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- /* Insert should be left to wait until trx releases the row lock */
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* COMMIT of trx */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- /*-------------------------------------*/
- os_thread_sleep(1000000);
-
- printf(
- "trx2 can now continue to do the insert, after trx committed.\n");
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-A. */
-
-ulint
-test8A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 8A. 1000 INSERTS FOR TPC-A\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE2", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_test_tuple_TPC_A(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_search_tuple_TPC_A(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE2"); */
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-A transaction. */
-
-ulint
-test8(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 8. TPC-A %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE2", trx);
-
- update = upd_create(1, heap);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-
-loop:
-/* printf("Round %lu\n", count); */
-
- /*-------------------------------------*/
- /* INSERT */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-------------------------------------*/
- /* 3 UPDATES */
-
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
- for (i = 0; i < 3; i++) {
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_A(entry, rnd % 1000, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
-/* ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur))); */
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- tm = ut_clock();
- printf("Wall time for TPC-A %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-
-
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-C. */
-
-ulint
-test9A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-/* dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
- dict_index_t* index;
- dict_tree_t* tree;
-*/
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 9A. INSERTS FOR TPC-C\n");
-
-#define TPC_C_TABLE_SIZE 15000
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE4", trx);
-
- row = dtuple_create(heap, 12 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_test_tuple_TPC_C(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-#endif
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE4"); */
-
-/* mem_heap_free(heap); */
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-C transaction. Test 9A must be run first to populate table. */
-
-ulint
-test9(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint j;
- ulint i;
- byte* ptr;
- ulint len;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
- byte buf2[240];
- rec_t* rec;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 9. TPC-C %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE4", trx);
-
- update = upd_create(3, heap);
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 2);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-loop:
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IS, thr));
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
-/* printf("Round %lu\n", count); */
-
-for (j = 0; j < 13; j++) {
-
- /*-------------------------------------*/
- /* SELECT FROM 'ITEM' */
-
- rnd += 876751;
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_S, thr);
- ut_a(err == DB_SUCCESS);
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 5; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* UPDATE 'STOCK' */
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 10; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
-/* btr_pcur_commit(&pcur); */
-
-/* err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr); */
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-/* ut_a(err == DB_SUCCESS); */
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 1);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 2);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- btr_pcur_close(&pcur);
- /*-------------------------------------*/
- /* INSERT INTO 'ORDERLINE' */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count * 13 + j, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-}
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
- tm = ut_clock();
- printf("Wall time for TPC-C %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Init for purge test. */
-
-ulint
-test10_1(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.1. PURGE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i * 100 + thr_no,
- DTUPLE_TEST_FIXED30, buf);
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 200);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2_r(
-/*=======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 2000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_3(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.3. PURGE TEST DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- rnd = i;
- tuple_no = rnd;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_5(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.5. PURGE TEST UNCOMMITTED DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 50; i++) {
-
- rnd = i;
- tuple_no = rnd % 100;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for purge. */
-
-ulint
-test10mt(
-/*=====*/
- void* arg)
-{
- ulint i;
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("Thread %lu starts purge test\n", thr_no);
-
- for (i = 0; i < 2; i++) {
- test10_1(arg);
-
- sync_print();
-
- fsp_validate(0);
-
- test10_2_r(arg);
- sync_print();
-
- test10_2(arg);
- sync_print();
-
- lock_validate();
-
- test10_3(arg);
- sync_print();
- }
-
- printf("Thread %lu ends purge test\n", thr_no);
-
- return(0);
-}
-
-/*********************************************************************
-Purge test. */
-
-ulint
-test10_4(
-/*=====*/
- void* arg)
-{
- ulint i;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.4. PURGE TEST\n");
-
- for (i = 0; i < 30; i++) {
- trx_purge();
-
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- os_thread_sleep(5000000);
- }
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to test insert buffer merge. */
-
-ulint
-test_ibuf_merge(
-/*============*/
- void* arg)
-{
- ulint sum_sizes;
- ulint volume;
-
- ut_ad(arg);
-
- printf("Starting ibuf merge\n");
-
- sum_sizes = 0;
- volume = 1;
-
- while (volume) {
- volume = ibuf_contract(FALSE);
-
- sum_sizes += volume;
- }
-
- printf("Ibuf merged %lu bytes\n", sum_sizes);
-
- os_thread_sleep(5000000);
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint count;
-
- ut_ad(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
- count = 0;
-
- for (j = 0; j < 100; j++) {
-
- os_thread_sleep(10000);
-
- if ((&(buf_pool->mutex))->lock_word) {
-
- count++;
- }
- }
-
- printf("Mutex reserved %lu of %lu peeks\n", count, j);
- }
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- os_thread_id_t id[10];
- ulint n1000[10];
- ulint i;
- ulint n5000 = 500;
- ulint n2;
-
-/* buf_debug_prints = TRUE; */
- log_do_write = FALSE;
- btr_search_use_hash = FALSE;
-
- srv_boot("initfile");
- os_aio_init(576, 9, 100);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
- lock_sys_create(1024);
-
- create_files();
-
- init_spaces();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- dict_create();
-
-/* os_thread_sleep(500000); */
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1(NULL);
- test1_5(NULL);
- test1_6(NULL);
- test1_7(NULL);
-
-/* for (i = 0; i < 2; i++) {
-
- n1000[i] = i;
- id[i] = id[i];
-
- os_thread_create(test10mt, n1000 + i, id + i);
- }
-*/
- i = 4;
-
- n1000[i] = i;
- id[i] = id[i];
-
-/* os_thread_create(test10_4, n1000 + i, id + i); */
-
- i = 5;
-
-/* test10mt(&i);
-
- i = 6;
-
- test10mt(&i);
-
- trx_purge();
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- dict_table_print_by_name("TS_TABLE1"); */
-
-/* os_thread_create(test_measure_cont, &n3, id + 0); */
-
-/* mem_print_info(); */
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- n2 = 2000;
-
-/* test2_1(&n2); */
-
- sync_print();
-
- test9A(&n2);
-
- sync_print();
-
- log_print();
-
- test9(&n2);
-
- log_print();
-
- sync_print();
-/* test6(&n2); */
-
-/* test2(&n2); */
-
-/* test2_2(&n2); */
-
-/* mem_print_info(); */
-
- for (i = 0; i < 2; i++) {
-
- n1000[i] = 1000 + 10 * i;
- id[i] = id[i];
-
-/* os_thread_create(test2mt, n1000 + i, id + i);
- os_thread_create(test2_1mt, n1000 + i, id + i);
- os_thread_create(test2_2mt, n1000 + i, id + i); */
- }
-
- n2 = 2000;
-
-/* test2mt(&n2); */
-
-/* buf_print();
- ibuf_print();
- rw_lock_list_print_info();
- mutex_list_print_info();
-
- dict_table_print_by_name("TS_TABLE1"); */
-
-/* mem_print_info(); */
-
- n2 = 1000;
-
-/* test4_1();
- test4_2();
-
- for (i = 0; i < 2; i++) {
- n1000[i] = i;
- id[i] = id[i];
- os_thread_create(test4mt, n1000 + i, id + i);
- }
-
- n2 = 4;
- test4mt(&n2);
- test4mt(&n2);
- test4_2();
- lock_print_info(); */
-
-/* test7(&n2); */
-
-/* os_thread_sleep(25000000); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tsbtrins.c b/innobase/btr/ts/tsbtrins.c
deleted file mode 100644
index 85eedd292b1..00000000000
--- a/innobase/btr/ts/tsbtrins.c
+++ /dev/null
@@ -1,802 +0,0 @@
-/************************************************************************
-Test for the B-tree
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "row0del.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-#define N_SPACES 2 /* must be >= 2 */
-#define N_FILES 1
-#define FILE_SIZE 8096 /* must be > 512 */
-#define POOL_SIZE 1024
-#define IBUF_SIZE 200
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-#define COUNT 1
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-ulint dummy = 0;
-
-byte test_buf[8000];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
- ut_a(ret);
- } else {
- if (k == 1) {
- ut_a(os_file_set_size(files[i],
- 8192 * IBUF_SIZE, 0));
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * FILE_SIZE, 0));
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space headers of spaces 0 and 1. */
-
-void
-init_spaces(void)
-/*=============*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
- fsp_header_init(1, IBUF_SIZE, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0,
- DICT_UNIQUE | DICT_CLUSTERED, 1);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* CREATE YET ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND4", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-#endif
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_1(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ins_node_t* node;
- ulint count = 0;
- ulint rnd;
- dtuple_t* row;
- dict_index_t* index;
-/* dict_tree_t* tree;
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr; */
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1. MASSIVE ASCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- log_print();
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 5000 == 0) {
- /* ibuf_print(); */
- /* buf_print(); */
-
- /* buf_print_io(); */
- /*
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n",
- i, tm - oldtm); */
- }
-
- rnd = rnd + 1;
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- log_print();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
-/* ibuf_print(); */
-
- index = index;
-
- index = dict_table_get_first_index(table);
-
- if (zero) {
- btr_search_index_print_info(index);
- }
-
- btr_validate_tree(dict_index_get_tree(index));
-
-#ifdef notdefined
- index = dict_table_get_next_index(index);
-
- if (zero) {
- btr_search_index_print_info(index);
- }
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
-/* btr_search_index_print_info(index); */
-
- btr_validate_tree(dict_index_get_tree(index));
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- /* Check inserted entries */
-
- btr_search_print_info();
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-#endif
- /*-------------------------------------*/
- /* ROLLBACK */
-
-#ifdef notdefined
-/* btr_validate_tree(tree); */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_search_print_info();
-#endif
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
- /*-------------------------------------*/
-
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- os_thread_id_t id[10];
- ulint n1000[10];
- ulint i;
- ulint n5000 = 500;
- ulint n2;
-
-/* buf_debug_prints = TRUE; */
- log_do_write = TRUE;
-
- srv_boot("initfile");
- os_aio_init(576, 9, 100);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
- lock_sys_create(1024);
-
- create_files();
-
- init_spaces();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- dict_create();
-
-/* os_thread_sleep(500000); */
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1(NULL);
-
-/* for (i = 0; i < 2; i++) {
-
- n1000[i] = i;
- id[i] = id[i];
-
- os_thread_create(test10mt, n1000 + i, id + i);
- }
-*/
- i = 4;
-
- n1000[i] = i;
- id[i] = id[i];
-
-/* os_thread_create(test10_4, n1000 + i, id + i); */
-
- i = 5;
-
-/* test10mt(&i);
-
- i = 6;
-
- test10mt(&i);
-
- trx_purge();
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- dict_table_print_by_name("TS_TABLE1"); */
-
-/* os_thread_create(test_measure_cont, &n3, id + 0); */
-
-/* mem_print_info(); */
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- log_flush_up_to(ut_dulint_zero);
-
- os_thread_sleep(500000);
-
- n2 = 10000;
-
- test2_1(&n2);
-
-/* test9A(&n2);
- test9(&n2); */
-
-/* test6(&n2); */
-
-/* test2(&n2); */
-
-/* test2_2(&n2); */
-
-/* mem_print_info(); */
-
- for (i = 0; i < 2; i++) {
-
- n1000[i] = 1000 + 10 * i;
- id[i] = id[i];
-
-/* os_thread_create(test2mt, n1000 + i, id + i);
- os_thread_create(test2_1mt, n1000 + i, id + i);
- os_thread_create(test2_2mt, n1000 + i, id + i); */
- }
-
- n2 = 2000;
-
-/* test2mt(&n2); */
-
-/* buf_print();
- ibuf_print();
- rw_lock_list_print_info();
- mutex_list_print_info();
-
- dict_table_print_by_name("TS_TABLE1"); */
-
-/* mem_print_info(); */
-
- n2 = 1000;
-
-/* test4_1();
- test4_2();
-
- for (i = 0; i < 2; i++) {
- n1000[i] = i;
- id[i] = id[i];
- os_thread_create(test4mt, n1000 + i, id + i);
- }
-
- n2 = 4;
- test4mt(&n2);
- test4mt(&n2);
- test4_2();
- lock_print_info(); */
-
-/* test7(&n2); */
-
-/* os_thread_sleep(25000000); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tscli.c b/innobase/btr/ts/tscli.c
deleted file mode 100644
index 6c42a83cdbe..00000000000
--- a/innobase/btr/ts/tscli.c
+++ /dev/null
@@ -1,3380 +0,0 @@
-/************************************************************************
-Tests for the client, TPC-C, and TPC-D Query 5
-
-(c) 1996-1998 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "univ.i"
-#include "ib_odbc.h"
-#include "mem0mem.h"
-#include "sync0sync.h"
-#include "os0thread.h"
-#include "os0proc.h"
-#include "os0sync.h"
-#include "srv0srv.h"
-
-ulint n_exited = 0;
-
-/* Disk wait simulation array */
-typedef struct srv_sim_disk_struct srv_sim_disk_t;
-struct srv_sim_disk_struct{
- os_event_t event; /* OS event to wait */
- bool event_set;/* TRUE if the event is in the set state */
- bool empty; /* TRUE if this cell not reserved */
-};
-
-#define SRV_N_SIM_DISK_ARRAY 150
-
-srv_sim_disk_t srv_sim_disk[SRV_N_SIM_DISK_ARRAY];
-
-/* Random counter used in disk wait simulation */
-ulint srv_disk_rnd = 982364761;
-ulint srv_disk_n_active_threads = 0;
-
-char cli_srv_endpoint_name[100];
-char cli_user_name[100];
-
-ulint n_warehouses = ULINT_MAX;
-ulint n_customers_d = ULINT_MAX;
-bool is_tpc_d = FALSE;
-ulint n_rounds = ULINT_MAX;
-ulint n_users = ULINT_MAX;
-ulint startdate = 0;
-ulint enddate = 0;
-bool own_warehouse = FALSE;
-
-ulint mem_pool_size = ULINT_MAX;
-
-/*********************************************************************
-Test for TPC-C. */
-
-ulint
-test_init(
-/*======*/
- void* arg)
-{
- HENV env;
- HDBC conn;
- RETCODE ret;
- HSTMT stat;
- HSTMT create_query;
- HSTMT populate_query;
- char* str;
- char* str1;
- char* str2;
- char* str3;
- char* str4;
- char* str5;
- char* str6;
- char* create_str;
- char* populate_str;
- char* commit_str;
- char* new_order_str;
- char* payment_str;
- char* order_status_str;
- char* delivery_str;
- char* stock_level_str;
- char* consistency_str;
- char* query_5_str;
- char* print_str;
- char* lock_wait_str;
- char* join_test_str;
- char* test_errors_str;
- char* test_group_commit_str;
- char* test_single_row_select_str;
- char* rollback_str;
- char* ibuf_test_str;
- SDWORD n_warehouses_buf;
- SDWORD n_warehouses_len;
- SDWORD n_customers_d_buf;
- SDWORD n_customers_d_len;
-
- UT_NOT_USED(arg);
-
- /*------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE CREATE_TABLES () IS"
-" BEGIN"
-" CREATE TABLE WAREHOUSE (W_ID CHAR, W_NAME CHAR,"
-" W_STREET_1 CHAR, W_STREET_2 CHAR,"
-" W_CITY CHAR,"
-" W_STATE CHAR, W_ZIP CHAR,"
-" W_TAX INT,"
-" W_YTD_HIGH INT,"
-" W_YTD INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX W_IND ON WAREHOUSE (W_ID);"
-""
-" CREATE TABLE DISTRICT (D_ID CHAR, D_W_ID CHAR,"
-" D_NAME CHAR,"
-" D_STREET_1 CHAR, D_STREET_2 CHAR,"
-" D_CITY CHAR,"
-" D_STATE CHAR, D_ZIP CHAR,"
-" D_TAX INT,"
-" D_YTD_HIGH INT,"
-" D_YTD INT,"
-" D_NEXT_O_ID INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX D_IND ON DISTRICT (D_W_ID, D_ID);"
-""
-" CREATE TABLE CUSTOMER (C_ID CHAR, C_D_ID CHAR, C_W_ID CHAR,"
-" C_FIRST CHAR, C_MIDDLE CHAR,"
-" C_LAST CHAR,"
-" C_STREET_1 CHAR, C_STREET_2 CHAR,"
-" C_CITY CHAR,"
-" C_STATE CHAR, C_ZIP CHAR,"
-" C_PHONE CHAR,"
-" C_SINCE_TIME INT,"
-" C_SINCE INT,"
-" C_CREDIT CHAR,"
-" C_CREDIT_LIM_HIGH INT,"
-" C_CREDIT_LIM INT,"
-" C_DISCOUNT INT,"
-" C_BALANCE_HIGH INT,"
-" C_BALANCE INT,"
-" C_YTD_PAYMENT_HIGH INT,"
-" C_YTD_PAYMENT INT,"
-" C_PAYMENT_CNT INT,"
-" C_DELIVERY_CNT INT,"
-" C_DATA CHAR) /*DOES_NOT_FIT_IN_MEMORY*/;"
-""
-" CREATE UNIQUE CLUSTERED INDEX C_IND ON CUSTOMER (C_W_ID, C_D_ID,"
-" C_ID);"
-""
-" CREATE INDEX C_LAST_IND ON CUSTOMER (C_W_ID, C_D_ID, C_LAST,"
-" C_FIRST);"
-""
-" CREATE TABLE HISTORY (H_C_ID CHAR, H_C_D_ID CHAR, H_C_W_ID CHAR,"
-" H_D_ID CHAR, H_W_ID CHAR,"
-" H_DATE INT,"
-" H_AMOUNT INT,"
-" H_DATA CHAR);"
-""
-" CREATE CLUSTERED INDEX H_IND ON HISTORY (H_W_ID);"
-""
-" CREATE TABLE NEW_ORDER (NO_O_ID INT,"
-" NO_D_ID CHAR,"
-" NO_W_ID CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX NO_IND ON NEW_ORDER (NO_W_ID, NO_D_ID,"
-" NO_O_ID);"
- ;
-
- str2 =
-
-" CREATE TABLE ORDERS (O_ID INT, O_D_ID CHAR, O_W_ID CHAR,"
-" O_C_ID CHAR,"
-" O_ENTRY_D INT,"
-" O_CARRIER_ID INT,"
-" O_OL_CNT INT,"
-" O_ALL_LOCAL CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX O_IND ON ORDERS (O_W_ID, O_D_ID,"
-" O_ID);"
-" CREATE INDEX O_C_IND ON ORDERS (O_W_ID, O_D_ID, O_C_ID);"
-""
-" CREATE TABLE ORDER_LINE (OL_O_ID INT, OL_D_ID CHAR, OL_W_ID CHAR,"
-" OL_NUMBER CHAR,"
-" OL_I_ID CHAR,"
-" OL_SUPPLY_W_ID CHAR,"
-" OL_DELIVERY_D INT,"
-" OL_QUANTITY INT,"
-" OL_AMOUNT INT,"
-" OL_DIST_INFO CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX OL_IND ON ORDER_LINE"
-" (OL_W_ID, OL_D_ID, OL_O_ID, OL_NUMBER);"
-""
-" CREATE TABLE ITEM (I_ID CHAR, I_IM_ID CHAR, I_NAME CHAR,"
-" I_PRICE INT,"
-" I_DATA CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX I_IND ON ITEM (I_ID);"
-""
-" CREATE TABLE STOCK (S_I_ID CHAR,"
-" S_W_ID CHAR,"
-" S_QUANTITY INT,"
-" S_DIST_01 CHAR,"
-" S_DIST_02 CHAR,"
-" S_DIST_03 CHAR,"
-" S_DIST_04 CHAR,"
-" S_DIST_05 CHAR,"
-" S_DIST_06 CHAR,"
-" S_DIST_07 CHAR,"
-" S_DIST_08 CHAR,"
-" S_DIST_09 CHAR,"
-" S_DIST_10 CHAR,"
-" S_YTD INT,"
-" S_ORDER_CNT INT,"
-" S_REMOTE_CNT INT,"
-" S_DATA CHAR) /*DOES_NOT_FIT_IN_MEMORY*/;"
-""
-" CREATE UNIQUE CLUSTERED INDEX S_IND ON STOCK (S_W_ID, S_I_ID);"
-""
-""
-" CREATE TABLE REGION (R_REGIONKEY INT, R_NAME CHAR, R_COMMENT CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX R_IND ON REGION (R_REGIONKEY);"
-""
-" CREATE TABLE NATION (N_NATIONKEY INT, N_NAME CHAR, N_REGIONKEY INT,"
-" N_COMMENT CHAR);"
-" CREATE UNIQUE CLUSTERED INDEX N_IND ON NATION (N_NATIONKEY);"
-""
-" CREATE TABLE NATION_2 (N2_NATIONKEY INT, N2_NAME CHAR,"
-" N2_REGIONKEY INT, N2_COMMENT CHAR);"
-" CREATE UNIQUE CLUSTERED INDEX N2_IND ON NATION_2 (N2_NAME);"
-""
-" CREATE TABLE SUPPLIER (S_SUPPKEY INT, S_NAME CHAR, S_ADDRESS CHAR,"
-" S_NATIONKEY INT, S_PHONE CHAR,"
-" S_ACCTBAL INT, S_COMMENT CHAR);"
-" CREATE UNIQUE CLUSTERED INDEX SU_IND ON SUPPLIER (S_SUPPKEY);"
-""
-" CREATE TABLE CUSTOMER_D (C_CUSTKEY INT, C_NAME CHAR, C_ADDRESS CHAR,"
-" C_NATIONKEY INT, C_PHONE CHAR,"
-" C_ACCTBAL INT, C_MKTSEGMENT CHAR,"
-" C_COMMENT CHAR);"
-" CREATE UNIQUE CLUSTERED INDEX CU_IND ON CUSTOMER_D (C_CUSTKEY);"
-""
-" CREATE TABLE ORDERS_D (O_ORDERKEY INT, O_CUSTKEY INT,"
-" O_ORDERSTATUS CHAR, O_TOTALPRICE INT,"
-" O_ORDERDATE INT,"
-" O_ORDERPRIORITY CHAR,"
-" O_CLERK CHAR, O_SHIPPRIORITY INT,"
-" O_COMMENT CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX OR_IND ON ORDERS_D (O_ORDERKEY);"
-""
-" CREATE INDEX OR_D_IND ON ORDERS_D (O_ORDERDATE, O_ORDERKEY,"
-" O_CUSTKEY);"
-""
-" CREATE TABLE LINEITEM (L_ORDERKEY INT, L_PARTKEY INT, L_SUPPKEY INT,"
-" L_LINENUMBER INT, L_QUANTITY INT,"
-" L_EXTENDEDPRICE INT,"
-" L_DISCOUNT INT, L_TAX INT,"
-" L_RETURNFLAG CHAR,"
-" L_LINESTATUS CHAR,"
-" L_SHIPDATE INT, L_COMMITDATE INT,"
-" L_RECEIPTDATE INT,"
-" L_SHIPINSTRUCT CHAR,"
-" L_SHIPMODE CHAR, L_COMMENT CHAR);"
-""
-" CREATE UNIQUE CLUSTERED INDEX L_IND ON LINEITEM (L_ORDERKEY,"
-" L_LINENUMBER);"
-""
-" CREATE TABLE ACCOUNTA (A_NUM INT, A_BAL INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX ACCOUNTA_IND ON ACCOUNTA (A_NUM);"
-""
-" CREATE TABLE TELLERA (T_NUM INT, T_BAL INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX TELLERA_IND ON TELLERA (T_NUM);"
-""
-" CREATE TABLE BRANCHA (B_NUM INT, B_BAL INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX BRANCHA_IND ON BRANCHA (B_NUM);"
-""
-" CREATE TABLE HISTORYA (H_NUM INT, H_TEXT CHAR);"
-""
-" CREATE CLUSTERED INDEX HISTORYA_IND ON HISTORYA (H_NUM);"
-""
-" CREATE TABLE JTEST1 (JT1_A INT, JT1_B INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX JT_IND1 ON JTEST1 (JT1_A);"
-""
-" CREATE TABLE JTEST2 (JT2_A INT, JT2_B INT);"
-""
-" CREATE UNIQUE CLUSTERED INDEX JT_IND2 ON JTEST2 (JT2_A);"
-""
-" CREATE TABLE IBUF_TEST (IB_A INT, IB_B CHAR) DOES_NOT_FIT_IN_MEMORY;"
-""
-" CREATE UNIQUE CLUSTERED INDEX IBUF_IND ON IBUF_TEST (IB_A);"
-" END;"
- ;
-
- create_str = ut_str_catenate(str1, str2);
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE POPULATE_TABLES (n_warehouses IN INT, n_customers_d"
-" IN INT) IS"
-""
-" i INT;"
-" j INT;"
-" k INT;"
-" t INT;"
-" string CHAR;"
-" rnd1 INT;"
-" rnd2 INT;"
-" rnd INT;"
-" n_items INT;"
-" n_districts INT;"
-" n_customers INT;"
-""
-" BEGIN"
-""
-"/**********************************************************/"
-" PRINTF('Starting Mikko-test');"
-""
-" FOR i IN 1 .. 5 LOOP"
-" INSERT INTO IBUF_TEST VALUES (i, 'Mikko');"
-" END LOOP;"
-""
-" /* PRINTF('Printing rows from Mikko-test:');"
-""
-" ROW_PRINTF SELECT * FROM IBUF_TEST; */"
-""
-" SELECT SUM(IB_A) INTO t FROM IBUF_TEST;"
-""
-" PRINTF('Sum of 1 to ', i, ' is ', t);"
-" ASSERT(t = (i * (i + 1)) / 2);"
-""
-" ROLLBACK WORK;"
-""
-" PRINTF('Printing rows from Mikko-test after rollback:');"
-""
-" ROW_PRINTF SELECT * FROM IBUF_TEST;"
-""
-"/**********************************************************/"
-" FOR i IN 0 .. 100 LOOP"
-" INSERT INTO ACCOUNTA VALUES (i, i);"
-" INSERT INTO TELLERA VALUES (i, i);"
-" INSERT INTO BRANCHA VALUES (i, i);"
-" INSERT INTO HISTORYA VALUES (i, '12345678901234567890');"
-" END LOOP;"
-""
-" COMMIT WORK;"
-"/**********************************************************/"
-"/* PRINTF('Populating ibuf test tables');"
-" FOR i IN 1 .. 1000 LOOP"
-" INSERT INTO IBUF_TEST VALUES (i, RND_STR(RND(1, 2000)));"
-" END LOOP;"
-" PRINTF('Ibuf test tables populated');"
-" COMMIT WORK; */"
-""
-" n_items := 200;"
-" n_districts := 10;"
-" n_customers := 20;"
-""
-" PRINTF('Starting to populate ITEMs');"
-""
-" FOR i IN 1 .. n_items LOOP"
-" rnd1 := RND(26, 50);"
-" string := RND_STR(rnd1);"
-""
-" IF (RND(0, 99) < 10) THEN"
-" rnd2 := RND(0, rnd1 - 8);"
-" REPLSTR(string, 'ORIGINAL', rnd2, 8);"
-" END IF;"
-""
-" INSERT INTO ITEM VALUES (TO_BINARY(i, 3),"
-" TO_BINARY(RND(1, 10000), 3),"
-" RND_STR(RND(14, 24)),"
-" RND(100, 10000),"
-" string);"
-" END LOOP;"
-" COMMIT WORK;"
-""
-" FOR i IN 1 .. n_warehouses LOOP"
-" COMMIT WORK;"
-" PRINTF('Starting to populate warehouse number ', i);"
-" INSERT INTO WAREHOUSE VALUES (TO_BINARY(i, 2),"
-" RND_STR(RND(6, 10)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR(TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND(0, 2000),"
-" 0,"
-" 0);"
-" FOR j IN 1 .. n_items LOOP"
-""
-" rnd1 := RND(26, 50);"
-" string := RND_STR(rnd1);"
-""
-" IF (RND(0, 99) < 10) THEN"
-" rnd2 := RND(0, rnd1 - 8);"
-" REPLSTR(string, 'ORIGINAL', rnd2, 8);"
-" END IF; "
-""
-" INSERT INTO STOCK VALUES (TO_BINARY(j, 3),"
-" TO_BINARY(i, 2),"
-" 91,"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" RND_STR(24),"
-" 0, 0, 0,"
-" string);"
-" END LOOP;"
- ;
-
- str2 =
-" FOR j IN 1 .. n_districts LOOP"
-""
-" /* PRINTF('Starting to populate district number ', j); */"
-" INSERT INTO DISTRICT VALUES (TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" RND_STR(RND(6, 10)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR("
-" TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND(0, 2000),"
-" 0,"
-" 0,"
-" 3001);"
-""
-" FOR k IN 1 .. n_customers LOOP"
-""
-" string := 'GC';"
-""
-" IF (RND(0, 99) < 10) THEN"
-" string := 'BC';"
-" END IF;"
-" "
-" INSERT INTO CUSTOMER VALUES ("
-" TO_BINARY(k, 3),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" RND_STR(RND(8, 16)),"
-" 'OE',"
-" CONCAT('NAME',"
-" TO_CHAR(k / 3)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(RND(10, 20)),"
-" RND_STR(2),"
-" CONCAT(SUBSTR("
-" TO_CHAR(RND(0, 9999)),"
-" 6, 4),"
-" '11111'),"
-" RND_STR(16),"
-" SYSDATE(), 0,"
-" string,"
-" 0, 5000000,"
-" RND(0, 5000),"
-" 0, 0, 0, 0, 0, 0,"
-" RND_STR(RND(300, 500)));"
- ;
-
- str3 =
-" INSERT INTO HISTORY VALUES ("
-" TO_BINARY(k, 3),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" SYSDATE(),"
-" 1000,"
-" RND_STR(RND(12, 24)));"
-""
-" rnd1 := RND(5, 15);"
-""
-" INSERT INTO ORDERS VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(k, 3),"
-" SYSDATE(),"
-" RND(1, 10),"
-" rnd1,"
-" '1');"
-""
-" FOR t IN 1 .. rnd1 LOOP"
-" INSERT INTO ORDER_LINE VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2),"
-" TO_BINARY(t, 1),"
-" TO_BINARY("
-" RND(1, n_items),"
-" 3),"
-" TO_BINARY(i, 2),"
-" NULL,"
-" 91,"
-" RND(0, 9999),"
-" RND_STR(24));"
-" END LOOP;"
-" END LOOP;"
-" "
-" FOR k IN 1 /* + (2 * n_customers) / 3 */"
-" .. n_customers LOOP"
-" "
-" INSERT INTO NEW_ORDER VALUES ("
-" k,"
-" TO_BINARY(j + 47, 1),"
-" TO_BINARY(i, 2));"
-" END LOOP;"
-" END LOOP;"
-" END LOOP;"
-""
-" COMMIT WORK;"
-""
-" PRINTF('Populating TPC-D tables');"
-""
-" FOR i IN 0 .. 4 LOOP"
-" /* We set the last columns to a long character string, to"
-" reduce latch contention on region and nation database pages."
-" A similar effect could be achieved by setting the page"
-" fillfactor in these tables low. */"
-""
-" INSERT INTO REGION VALUES (i, CONCAT('Region', TO_CHAR(i),"
-" ' '),"
-" RND_STR(1500 + RND(1, 152)));"
-" FOR j IN i * 5 .. i * 5 + 4 LOOP"
-" INSERT INTO NATION VALUES (j,"
-" CONCAT('Nation', TO_CHAR(j),"
-" ' '),"
-" i, RND_STR(1500 + RND(1, 152)));"
-" INSERT INTO NATION_2 VALUES (j,"
-" CONCAT('Nation', TO_CHAR(j),"
-" ' '),"
-" i, RND_STR(1500 + RND(1, 152)));"
-" END LOOP;"
-" END LOOP;"
-""
-" COMMIT WORK;"
-""
-" FOR i IN 0 .. n_customers_d / 15 LOOP"
-" INSERT INTO SUPPLIER VALUES (i,"
-" CONCAT('Supplier', TO_CHAR(i)),"
-" RND_STR(RND(20, 30)),"
-" RND(0, 24),"
-" RND_STR(15),"
-" RND(1, 1000),"
-" RND_STR(RND(40, 80)));"
-" END LOOP;"
-""
-" COMMIT WORK;"
-""
-" FOR i IN 0 .. n_customers_d - 1 LOOP"
-" IF ((i / 100) * 100 = i) THEN"
-" COMMIT WORK;"
-" PRINTF('Populating customer ', i);"
-" END IF;"
-""
-" INSERT INTO CUSTOMER_D VALUES (i,"
-" CONCAT('Customer', TO_CHAR(i)),"
-" RND_STR(RND(20, 30)),"
-" RND(0, 24),"
-" RND_STR(15),"
-" RND(1, 1000),"
-" RND_STR(10),"
-" RND_STR(RND(50, 100)));"
-""
-" FOR j IN i * 10 .. i * 10 + 9 LOOP"
-""
-" rnd := (j * 2400) / (10 * n_customers_d);"
-""
-" INSERT INTO ORDERS_D VALUES (j,"
-" 3 * RND(0, (n_customers_d / 3) - 1)"
-" + RND(1, 2),"
-" 'F', 1000,"
-" rnd,"
-" RND_STR(10),"
-" CONCAT('Clerk', TO_CHAR(RND(0, 1000))),"
-" 0, RND_STR(RND(3, 7)));"
-""
-" FOR k IN 0 .. RND(0, 6) LOOP"
-" INSERT INTO LINEITEM VALUES (j,"
-" RND(1, 1000),"
-" RND(0, n_customers_d / 15),"
-" k,"
-" RND(1, 50),"
-" 100,"
-" 5,"
-" RND(0, 8),"
-" 'N',"
-" 'F',"
-" rnd + RND(1, 100),"
-" rnd + RND(1, 100),"
-" rnd + RND(1, 100),"
-" RND_STR(1),"
-" RND_STR(1),"
-" RND_STR(RND(1, 3)));"
-" END LOOP;"
-" END LOOP;"
-""
-" END LOOP;"
-""
-" COMMIT WORK;"
-" PRINTF('TPC-D tables populated');"
-""
-" PRINTF('Populating join test tables');"
-" FOR i IN 1 .. 1 LOOP"
-" INSERT INTO JTEST1 VALUES (i, i);"
-" INSERT INTO JTEST2 VALUES (i, i);"
-" END LOOP;"
-" PRINTF('Join test tables populated');"
-""
-" COMMIT WORK;"
-" END;"
- ;
-
- str4 = ut_str_catenate(str1, str2);
- populate_str = ut_str_catenate(str4, str3);
-
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE PRINT_TABLES () IS"
-" i INT;"
-" BEGIN"
-""
-" /* PRINTF('Printing ITEM table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ITEM;"
-""
-" PRINTF('Printing WAREHOUSE table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM WAREHOUSE;"
-""
-" PRINTF('Printing STOCK table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM STOCK;"
-""
-" PRINTF('Printing DISTRICT table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM DISTRICT;"
-""
-" PRINTF('Printing CUSTOMER table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM CUSTOMER;"
-""
-" PRINTF('Printing HISTORY table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM HISTORY;"
-""
-" PRINTF('Printing ORDERS table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ORDERS;"
-""
-" PRINTF('Printing ORDER_LINE table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM ORDER_LINE"
-" WHERE OL_O_ID >= 3000; */"
-""
-" PRINTF('Printing NEW_ORDER table:');"
-""
-" ROW_PRINTF"
-" SELECT *"
-" FROM NEW_ORDER;"
-""
-" COMMIT WORK;"
-" END;"
- ;
-
- print_str = str;
- /*-----------------------------------------------------------*/
- commit_str =
-
-" PROCEDURE COMMIT_TEST () IS"
-" "
-" BEGIN"
-" COMMIT WORK;"
-" END;"
- ;
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE NEW_ORDER (c_w_id IN CHAR,"
-" c_d_id IN CHAR,"
-" c_id IN CHAR,"
-" ol_supply_w_ids IN CHAR,"
-" ol_i_ids IN CHAR,"
-" ol_quantities IN CHAR,"
-" c_last OUT CHAR,"
-" c_credit OUT CHAR,"
-" c_discount OUT INT,"
-" w_tax OUT INT,"
-" d_tax OUT INT,"
-" o_ol_count OUT INT,"
-" o_id OUT INT,"
-" o_entry_d OUT INT,"
-" total OUT INT,"
-" i_names OUT CHAR,"
-" s_quantities OUT CHAR,"
-" bg OUT CHAR,"
-" i_prices OUT CHAR,"
-" ol_amounts OUT CHAR) IS"
-""
-" i INT;"
-" j INT;"
-" o_all_local CHAR;"
-" i_price INT;"
-" i_name CHAR;"
-" i_data CHAR;"
-" s_quantity INT;"
-" s_data CHAR;"
-" s_dist_01 CHAR;"
-" s_dist_02 CHAR;"
-" s_dist_03 CHAR;"
-" s_dist_04 CHAR;"
-" s_dist_05 CHAR;"
-" s_dist_06 CHAR;"
-" s_dist_07 CHAR;"
-" s_dist_08 CHAR;"
-" s_dist_09 CHAR;"
-" s_dist_10 CHAR;"
-" ol_i_id CHAR;"
-" ol_quantity INT;"
-" ol_amount INT;"
-" ol_supply_w_id CHAR;"
-" ol_dist_info CHAR;"
-""
-" DECLARE CURSOR district_cursor IS"
-" SELECT D_NEXT_O_ID, D_TAX"
-" FROM DISTRICT"
-" WHERE D_ID = c_d_id AND D_W_ID = c_w_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR stock_cursor IS"
-" SELECT S_QUANTITY, S_DATA,"
-" S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04,"
-" S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08,"
-" S_DIST_09, S_DIST_10"
-" FROM STOCK"
-" WHERE S_W_ID = ol_supply_w_id AND S_I_ID = ol_i_id"
-" FOR UPDATE;"
- ;
- str2 =
-
-" BEGIN"
-" FOR j IN 1 .. 1 LOOP"
-""
-" /* PRINTF('Warehouse ', BINARY_TO_NUMBER(c_w_id)); */"
-" o_all_local := '1';"
-" i_names := '12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "12345678901234567890123456789012345678901234567890"
- "1234567890';"
-" s_quantities := '12345678901234567890123456789012345678901234567890"
- "1234567890';"
-" i_prices := '12345678901234567890123456789012345678901234567890"
- "1234567890';"
-" ol_amounts := '12345678901234567890123456789012345678901234567890"
- "1234567890';"
-" bg := 'GGGGGGGGGGGGGGG';"
-" total := 0;"
-""
-" SELECT C_DISCOUNT, C_LAST, C_CREDIT INTO c_discount, c_last, c_credit"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id AND C_ID = c_id;"
-""
-" OPEN district_cursor;"
-""
-" FETCH district_cursor INTO o_id, d_tax;"
-""
-" UPDATE DISTRICT SET D_NEXT_O_ID = o_id + 1"
-" WHERE CURRENT OF district_cursor;"
-""
-" CLOSE district_cursor;"
-""
-""
- ;
- str3 =
-
-" o_ol_count := LENGTH(ol_quantities);"
-""
-" /* PRINTF('C-WAREHOUSE id ', BINARY_TO_NUMBER(c_w_id),"
-" ' C-district id ', c_d_id,"
-" ' order id ', o_id, ' linecount ', o_ol_count); */"
-""
-" FOR i IN 0 .. (o_ol_count - 1) LOOP"
-""
-" ol_i_id := SUBSTR(ol_i_ids, 3 * i, 3);"
-" ol_supply_w_id := SUBSTR(ol_supply_w_ids, 2 * i, 2);"
-" ol_quantity := BINARY_TO_NUMBER(SUBSTR(ol_quantities, i, 1));"
-""
-" /* PRINTF('ol_i_id ', BINARY_TO_NUMBER(ol_i_id),"
-" ' ol_supply_w_id ', BINARY_TO_NUMBER(ol_supply_w_id),"
-" ' ol_quantity ', ol_quantity); */"
-""
-" SELECT I_PRICE, I_NAME, I_DATA INTO i_price, i_name, i_data"
-" FROM ITEM"
-" WHERE I_ID = ol_i_id"
-" CONSISTENT READ;"
-""
-" IF (SQL % NOTFOUND) THEN"
-" /* PRINTF('Rolling back; item not found: ',"
-" BINARY_TO_NUMBER(ol_i_id)); */"
-" ROLLBACK WORK;"
-" o_ol_count := 0;"
-""
-" RETURN;"
-" END IF;"
-""
-" OPEN stock_cursor;"
-""
-" FETCH stock_cursor INTO s_quantity, s_data,"
-" s_dist_01, s_dist_02, s_dist_03,"
-" s_dist_04, s_dist_05, s_dist_06,"
-" s_dist_07, s_dist_08, s_dist_09,"
-" s_dist_10;"
-""
-" /* PRINTF('Stock quantity ', s_quantity); */"
-""
-" IF (s_quantity >= ol_quantity + 10) THEN"
-" s_quantity := s_quantity - ol_quantity;"
-" ELSE"
-" s_quantity := (s_quantity + 91) - ol_quantity;"
-" END IF;"
-""
-" UPDATE STOCK SET S_QUANTITY = s_quantity,"
-" S_YTD = S_YTD + ol_quantity,"
-" S_ORDER_CNT = S_ORDER_CNT + 1"
- " WHERE CURRENT OF stock_cursor;"
-""
-" IF (ol_supply_w_id <> c_w_id) THEN"
-""
-" o_all_local := '0';"
-" PRINTF('Remote order ',"
-" BINARY_TO_NUMBER(ol_supply_w_id), ' ',"
-" BINARY_TO_NUMBER(c_w_id));"
-""
-" UPDATE STOCK SET S_REMOTE_CNT = S_REMOTE_CNT + 1"
-" WHERE CURRENT OF stock_cursor;"
-" END IF;"
-""
-" CLOSE stock_cursor;"
-""
-" IF ((INSTR(i_data, 'ORIGINAL') > 0)"
-" OR (INSTR(s_data, 'ORIGINAL') > 0)) THEN"
-" REPLSTR(bg, 'B', i, 1);"
-" END IF;"
-""
-" ol_amount := ol_quantity * i_price;"
-""
-" total := total + ol_amount;"
- ;
- str4 =
-" IF (c_d_id = '0') THEN"
-" ol_dist_info := s_dist_01;"
-" ELSIF (c_d_id = '1') THEN"
-" ol_dist_info := s_dist_02;"
-" ELSIF (c_d_id = '2') THEN"
-" ol_dist_info := s_dist_03;"
-" ELSIF (c_d_id = '3') THEN"
-" ol_dist_info := s_dist_04;"
-" ELSIF (c_d_id = '4') THEN"
-" ol_dist_info := s_dist_05;"
-" ELSIF (c_d_id = '5') THEN"
-" ol_dist_info := s_dist_06;"
-" ELSIF (c_d_id = '6') THEN"
-" ol_dist_info := s_dist_07;"
-" ELSIF (c_d_id = '7') THEN"
-" ol_dist_info := s_dist_08;"
-" ELSIF (c_d_id = '8') THEN"
-" ol_dist_info := s_dist_09;"
-" ELSIF (c_d_id = '9') THEN"
-" ol_dist_info := s_dist_10;"
-" END IF;"
-""
-" INSERT INTO ORDER_LINE VALUES (o_id, c_d_id, c_w_id,"
-" TO_BINARY(i + 1, 1), ol_i_id,"
-" ol_supply_w_id, NULL, ol_quantity,"
-" ol_amount, ol_dist_info);"
-""
-" REPLSTR(i_names, i_name, i * 24, LENGTH(i_name));"
-" REPLSTR(s_quantities, TO_BINARY(s_quantity, 4), i * 4, 4);"
-" REPLSTR(i_prices, TO_BINARY(i_price, 4), i * 4, 4);"
-" REPLSTR(ol_amounts, TO_BINARY(ol_amount, 4), i * 4, 4);"
-""
-" /* PRINTF('i_name ', i_name, ' s_quantity ', s_quantity,"
-" ' i_price ', i_price, ' ol_amount ', ol_amount); */"
-" END LOOP;"
-""
-" SELECT W_TAX INTO w_tax"
-" FROM WAREHOUSE"
-" WHERE W_ID = c_w_id;"
-""
-" total := (((total * (10000 + w_tax + d_tax)) / 10000)"
-" * (10000 - c_discount)) / 10000;"
-""
-" o_entry_d := SYSDATE();"
-""
-" INSERT INTO ORDERS VALUES (o_id, c_d_id, c_w_id, c_id, o_entry_d,"
-" NULL, o_ol_count, o_all_local);"
-" INSERT INTO NEW_ORDER VALUES (o_id, c_d_id, c_w_id);"
-""
-" /* PRINTF('Inserted order lines:');"
-" ROW_PRINTF"
-" SELECT * FROM ORDER_LINE WHERE OL_O_ID = o_id AND"
-" OL_D_ID = c_d_id"
-" AND OL_W_ID = c_w_id; */"
-" COMMIT WORK;"
-" END LOOP;"
-" END;"
- ;
-
- str5 = ut_str_catenate(str1, str2);
- str6 = ut_str_catenate(str3, str4);
-
- new_order_str = ut_str_catenate(str5, str6);
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE PAYMENT (c_w_id IN CHAR) IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" w_id CHAR;"
-" w_street_1 CHAR;"
-" w_street_2 CHAR;"
-" w_city CHAR;"
-" w_state CHAR;"
-" w_zip CHAR;"
-" w_name CHAR;"
-" d_id CHAR;"
-" d_street_1 CHAR;"
-" d_street_2 CHAR;"
-" d_city CHAR;"
-" d_state CHAR;"
-" d_zip CHAR;"
-" d_name CHAR;"
-" c_d_id CHAR;"
-" c_street_1 CHAR;"
-" c_street_2 CHAR;"
-" c_city CHAR;"
-" c_state CHAR;"
-" c_zip CHAR;"
-" c_id CHAR;"
-" c_last CHAR;"
-" c_first CHAR;"
-" c_middle CHAR;"
-" c_phone CHAR;"
-" c_credit CHAR;"
-" c_credit_lim INT;"
-" c_discount INT;"
-" c_balance INT;"
-" c_since INT;"
-" c_data CHAR;"
-" byname INT;"
-" namecnt INT;"
-" amount INT;"
-" h_data CHAR;"
-" h_date INT;"
-" c_more_data CHAR;"
-" more_len INT;"
-" data_len INT;"
-""
-" DECLARE CURSOR warehouse_cursor IS"
-" SELECT W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP, W_NAME"
-" FROM WAREHOUSE"
-" WHERE W_ID = w_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR district_cursor IS"
-" SELECT D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, D_NAME"
-" FROM DISTRICT"
-" WHERE D_W_ID = w_id AND D_ID = d_id"
-" FOR UPDATE;"
-""
-" DECLARE CURSOR customer_by_name_cursor IS"
-" SELECT C_ID"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last"
-" ORDER BY C_FIRST ASC;"
-""
-" DECLARE CURSOR customer_cursor IS"
-" SELECT C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2,"
-" C_CITY, C_STATE, C_ZIP, C_PHONE, C_CREDIT,"
-" C_CREDIT_LIM, C_DISCOUNT, C_BALANCE,"
-" C_SINCE"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_ID = c_id"
-" FOR UPDATE;"
- ;
-
- str2 =
-
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 20;"
-""
-" byname := RND(1, 100);"
-" amount := RND(1, 1000);"
-" h_date := SYSDATE();"
-" w_id := c_w_id;"
-" d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-" c_d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-""
-" IF (byname <= 60) THEN"
-" c_last := CONCAT('NAME', TO_CHAR(RND(1, n_customers) / 3));"
-""
-" SELECT COUNT(*) INTO namecnt"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last;"
-" /* PRINTF('Payment trx: Customer name ', c_last,"
-" ' namecount ', namecnt); */"
-" OPEN customer_by_name_cursor;"
-""
-" FOR i IN 1 .. (namecnt + 1) / 2 LOOP"
-" FETCH customer_by_name_cursor INTO c_id;"
-" END LOOP;"
-" /* ASSERT(NOT (customer_by_name_cursor % NOTFOUND)); */"
-" "
-" CLOSE customer_by_name_cursor;"
-" ELSE"
-" c_id := TO_BINARY(RND(1, n_customers), 3);"
-" END IF;"
-
- ;
- str3 =
-""
-" /* PRINTF('Payment for customer ', BINARY_TO_NUMBER(c_w_id), ' ',"
-" c_d_id, ' ', BINARY_TO_NUMBER(c_id)); */"
-" OPEN customer_cursor;"
-""
-" FETCH customer_cursor INTO c_first, c_middle, c_last, c_street_1,"
-" c_street_2, c_city, c_state, c_zip,"
-" c_phone, c_credit, c_credit_lim,"
-" c_discount, c_balance, c_since;"
-" c_balance := c_balance - amount;"
-""
-" OPEN district_cursor;"
-""
-" FETCH district_cursor INTO d_street_1, d_street_2, d_city, d_state,"
-" d_zip, d_name;"
-" UPDATE DISTRICT SET D_YTD = D_YTD + amount"
-" WHERE CURRENT OF district_cursor;"
-""
-" CLOSE district_cursor;"
-""
-" OPEN warehouse_cursor;"
-""
-" FETCH warehouse_cursor INTO w_street_1, w_street_2, w_city, w_state,"
-" w_zip, w_name;"
-" UPDATE WAREHOUSE SET W_YTD = W_YTD + amount"
-" WHERE CURRENT OF warehouse_cursor;"
-""
-" CLOSE warehouse_cursor;"
-""
-" h_data := CONCAT(w_name, ' ', d_name);"
-" "
-" IF (c_credit = 'BC') THEN"
-" /* PRINTF('Bad customer pays'); */"
-""
-" SELECT C_DATA INTO c_data"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_ID = c_id;"
-" c_more_data := CONCAT("
-" ' ', TO_CHAR(BINARY_TO_NUMBER(c_id)),"
-" ' ', c_d_id,"
-" ' ', TO_CHAR(BINARY_TO_NUMBER(c_w_id)),"
-" ' ', d_id,"
-" ' ', TO_CHAR(BINARY_TO_NUMBER(w_id)),"
-" TO_CHAR(amount),"
-" TO_CHAR(h_date),"
-" ' ', h_data);"
-""
-" more_len := LENGTH(c_more_data);"
-" data_len := LENGTH(c_data);"
-" "
-" IF (more_len + data_len > 500) THEN"
-" data_len := 500 - more_len;"
-" END IF;"
-" "
-" c_data := CONCAT(c_more_data, SUBSTR(c_data, 0, data_len));"
-" "
-" UPDATE CUSTOMER SET C_BALANCE = c_balance,"
-" C_PAYMENT_CNT = C_PAYMENT_CNT + 1,"
-" C_YTD_PAYMENT = C_YTD_PAYMENT + amount,"
-" C_DATA = c_data"
-" WHERE CURRENT OF customer_cursor;"
-" ELSE"
-" UPDATE CUSTOMER SET C_BALANCE = c_balance,"
-" C_PAYMENT_CNT = C_PAYMENT_CNT + 1,"
-" C_YTD_PAYMENT = C_YTD_PAYMENT + amount"
-" WHERE CURRENT OF customer_cursor;"
-" END IF;"
-""
-" CLOSE customer_cursor;"
-" "
-" INSERT INTO HISTORY VALUES (c_d_id, c_w_id, c_id, d_id, w_id,"
-" h_date, amount, h_data);"
-" COMMIT WORK;"
-""
-" END;"
-
- ;
-
- str4 = ut_str_catenate(str1, str2);
- payment_str = ut_str_catenate(str4, str3);
-
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE ORDER_STATUS (c_w_id IN CHAR) IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" namecnt INT;"
-" c_d_id CHAR;"
-" c_id CHAR;"
-" c_last CHAR;"
-" c_first CHAR;"
-" c_middle CHAR;"
-" c_balance INT;"
-" byname INT;"
-" o_id INT;"
-" o_carrier_id CHAR;"
-" o_entry_d INT;"
-" ol_i_id CHAR;"
-" ol_supply_w_id CHAR;"
-" ol_quantity INT;"
-" ol_amount INT;"
-" ol_delivery_d INT;"
-""
-" DECLARE CURSOR orders_cursor IS"
-" SELECT O_ID, O_CARRIER_ID, O_ENTRY_D"
-" FROM ORDERS"
-" WHERE O_W_ID = c_w_id AND O_D_ID = c_d_id"
-" AND O_C_ID = c_id"
-" ORDER BY O_ID DESC;"
-""
-" DECLARE CURSOR order_line_cursor IS"
-" SELECT OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT,"
-" OL_DELIVERY_D"
-" FROM ORDER_LINE"
-" WHERE OL_W_ID = c_w_id AND OL_D_ID = c_d_id"
-" AND OL_O_ID = o_id;"
-" DECLARE CURSOR customer_by_name_cursor IS"
-" SELECT C_ID"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last"
-" ORDER BY C_FIRST ASC;"
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 20;"
-""
-" byname := RND(1, 100);"
-""
- ;
-
- str2 =
-
-" IF (byname <= 60) THEN"
-" d_id := TO_BINARY(47 + RND(1, n_districts), 1); "
-""
-" c_d_id := d_id;"
-""
-" c_last := CONCAT('NAME', TO_CHAR(RND(1, n_customers) / 3));"
-""
-" SELECT COUNT(*) INTO namecnt"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id"
-" AND C_LAST = c_last;"
-" OPEN customer_by_name_cursor;"
-""
-" /* PRINTF('Order status trx: Customer name ', c_last,"
-" ' namecount ', namecnt); */"
-" FOR i IN 1 .. (namecnt + 1) / 2 LOOP"
-" FETCH customer_by_name_cursor INTO c_id;"
-" END LOOP;"
-" /* ASSERT(NOT (customer_by_name_cursor % NOTFOUND)); */"
-""
-" CLOSE customer_by_name_cursor;"
-" ELSE"
-" c_d_id := TO_BINARY(47 + RND(1, n_districts), 1);"
-" c_id := TO_BINARY(RND(1, n_customers), 3);"
-" END IF;"
-""
-" SELECT C_BALANCE, C_FIRST, C_MIDDLE, C_LAST INTO c_balance, c_first,"
-" c_middle, c_last"
-" FROM CUSTOMER"
-" WHERE C_W_ID = c_w_id AND C_D_ID = c_d_id AND C_ID = c_id;"
-""
-" OPEN orders_cursor;"
-""
-" FETCH orders_cursor INTO o_id, o_carrier_id, o_entry_d;"
-""
-" IF (orders_cursor % NOTFOUND) THEN"
-" PRINTF('Order status trx: customer has no order');"
-" CLOSE orders_cursor;"
-""
-" COMMIT WORK;"
-""
-" RETURN;"
-" END IF;"
-""
-" CLOSE orders_cursor;"
-""
-" OPEN order_line_cursor;"
-""
-" FOR i IN 0 .. 15 LOOP"
-" FETCH order_line_cursor INTO ol_i_id, ol_supply_w_id,"
-" ol_quantity, ol_amount,"
-" ol_delivery_d;"
-""
-" IF (order_line_cursor % NOTFOUND) THEN"
-" CLOSE order_line_cursor;"
-""
-" COMMIT WORK;"
-""
-" RETURN;"
-" END IF;"
-" END LOOP;"
-" ASSERT(0 = 1);"
-" "
-" END;"
- ;
-
- order_status_str = ut_str_catenate(str1, str2);
- /*-----------------------------------------------------------*/
-
- str1 =
-
-" PROCEDURE DELIVERY (w_id IN CHAR) IS"
-""
-" i INT;"
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" c_id CHAR;"
-" o_id INT;"
-" o_carrier_id INT;"
-" ol_delivery_d INT;"
-" ol_total INT;"
-""
-" DECLARE CURSOR new_order_cursor IS"
-" SELECT NO_O_ID"
-" FROM NEW_ORDER"
-" WHERE NO_W_ID = w_id AND NO_D_ID = d_id"
-" ORDER BY NO_O_ID ASC;"
-""
-" DECLARE CURSOR orders_cursor IS"
-" SELECT O_C_ID"
-" FROM ORDERS"
-" WHERE O_W_ID = w_id AND O_D_ID = d_id"
-" AND O_ID = o_id"
-" FOR UPDATE;"
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 20;"
-""
-" o_carrier_id := RND(1, 10);"
-" ol_delivery_d := SYSDATE();"
-
- ;
-
- str2 =
-
-" FOR i IN 1 .. n_districts LOOP"
-""
-" d_id := TO_BINARY(47 + i, 1);"
-""
-" OPEN new_order_cursor;"
-""
-" FETCH new_order_cursor INTO o_id;"
-""
-" IF (new_order_cursor % NOTFOUND) THEN"
-" /* PRINTF('No order to deliver'); */"
-""
-" CLOSE new_order_cursor;"
-" ELSE"
-" CLOSE new_order_cursor;"
-""
-" DELETE FROM NEW_ORDER"
-" WHERE NO_W_ID = w_id AND NO_D_ID = d_id"
-" AND NO_O_ID = o_id;"
-" OPEN orders_cursor;"
-""
-" FETCH orders_cursor INTO c_id;"
-""
-" UPDATE ORDERS SET O_CARRIER_ID = o_carrier_id"
-" WHERE CURRENT OF orders_cursor;"
-""
-" CLOSE orders_cursor;"
-""
-" UPDATE ORDER_LINE SET OL_DELIVERY_D = ol_delivery_d"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID = o_id;"
-""
-" SELECT SUM(OL_AMOUNT) INTO ol_total"
-" FROM ORDER_LINE"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID = o_id;"
-""
-" UPDATE CUSTOMER SET C_BALANCE = C_BALANCE - ol_total"
-" WHERE C_W_ID = w_id AND C_D_ID = d_id"
-" AND C_ID = c_id;"
-" END IF;"
-" END LOOP;"
-" COMMIT WORK;"
-""
-" "
-" END;"
- ;
-
- delivery_str = ut_str_catenate(str1, str2);
-
- /*-----------------------------------------------------------*/
-
- str =
-
-" PROCEDURE STOCK_LEVEL (w_id IN CHAR) IS"
-""
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" d_id CHAR;"
-" o_id INT;"
-" stock_count INT;"
-" threshold INT;"
-""
-" BEGIN"
-""
-" n_items := 200;"
-" n_warehouses := 1;"
-" n_districts := 10;"
-" n_customers := 20;"
-""
-" d_id := TO_BINARY(47 + 4, 1);"
-""
-" threshold := RND(10, 20);"
-""
-" SELECT D_NEXT_O_ID INTO o_id"
-" FROM DISTRICT"
-" WHERE D_W_ID = w_id AND D_ID = d_id;"
-""
-" /* NOTE: COUNT(DISTINCT ...) not implemented yet: if we used a hash"
-" table, the DISTINCT operation should take at most 15 % more time */"
-""
-" SELECT COUNT(*) INTO stock_count"
-" FROM ORDER_LINE, STOCK"
-" WHERE OL_W_ID = w_id AND OL_D_ID = d_id"
-" AND OL_O_ID >= o_id - 10 AND OL_O_ID < o_id"
-" AND S_W_ID = w_id AND S_I_ID = OL_I_ID"
-" AND S_QUANTITY < threshold"
-" CONSISTENT READ;"
-" /* PRINTF(stock_count, ' items under threshold ', threshold); */"
-" COMMIT WORK;"
-""
-" END;"
- ;
-
- stock_level_str = str;
-
- /*-----------------------------------------------------------*/
-
- str =
-
-" PROCEDURE TPC_CONSISTENCY () IS"
-""
-" n_items INT;"
-" n_warehouses INT;"
-" n_districts INT;"
-" n_customers INT;"
-" n_orders INT;"
-" n_new_orders INT;"
-" n_order_lines INT;"
-" n_history INT;"
-" sum_order_quant INT;"
-" sum_stock_quant INT;"
-" n_delivered INT;"
-" n INT;"
-" n_new_order_lines INT;"
-" n_customers_d INT;"
-" n_regions INT;"
-" n_nations INT;"
-" n_suppliers INT;"
-" n_orders_d INT;"
-" n_lineitems INT;"
-""
-" BEGIN"
-""
-" PRINTF('TPC-C consistency check begins');"
-""
-" SELECT COUNT(*) INTO n_warehouses"
-" FROM WAREHOUSE;"
-" SELECT COUNT(*) INTO n_items"
-" FROM ITEM;"
-" SELECT COUNT(*) INTO n_customers"
-" FROM CUSTOMER;"
-" SELECT COUNT(*) INTO n_districts"
-" FROM DISTRICT;"
-" SELECT COUNT(*) INTO n_orders"
-" FROM ORDERS;"
-" SELECT COUNT(*) INTO n_new_orders"
-" FROM NEW_ORDER;"
-" SELECT COUNT(*) INTO n_order_lines"
-" FROM ORDER_LINE;"
-" SELECT COUNT(*) INTO n_history"
-" FROM HISTORY;"
-""
-" PRINTF('N warehouses ', n_warehouses);"
-""
-" PRINTF('N items ', n_items, ' : ', n_items / n_warehouses,"
-" ' per warehouse');"
-" PRINTF('N districts ', n_districts, ' : ', n_districts / n_warehouses,"
-" ' per warehouse');"
-" PRINTF('N customers ', n_customers, ' : ', n_customers / n_districts,"
-" ' per district');"
-" PRINTF('N orders ', n_orders, ' : ', n_orders / n_customers,"
-" ' per customer');"
-" PRINTF('N new orders ', n_new_orders, ' : ',"
-" n_new_orders / n_customers, ' per customer');"
-" PRINTF('N order lines ', n_order_lines, ' : ',"
-" n_order_lines / n_orders, ' per order');"
-" PRINTF('N history ', n_history, ' : ',"
-" n_history / n_customers, ' per customer');"
-" SELECT COUNT(*) INTO n_delivered"
-" FROM ORDER_LINE"
-" WHERE OL_DELIVERY_D < NULL;"
-""
-" PRINTF('N delivered order lines ', n_delivered);"
-""
-" SELECT COUNT(*) INTO n_new_order_lines"
-" FROM NEW_ORDER, ORDER_LINE"
-" WHERE NO_O_ID = OL_O_ID AND NO_D_ID = OL_D_ID"
-" AND NO_W_ID = OL_W_ID;"
-" PRINTF('N new order lines ', n_new_order_lines);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM NEW_ORDER, ORDER_LINE"
-" WHERE NO_O_ID = OL_O_ID AND NO_D_ID = OL_D_ID"
-" AND NO_W_ID = OL_W_ID AND OL_DELIVERY_D < NULL;"
-" PRINTF('Assertion 1');"
-" ASSERT(n = 0);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM NEW_ORDER, ORDER_LINE"
-" WHERE NO_O_ID = OL_O_ID AND NO_D_ID = OL_D_ID"
-" AND NO_W_ID = OL_W_ID AND OL_DELIVERY_D = NULL;"
-""
-" PRINTF('Assertion 2');"
-" ASSERT(n = n_new_order_lines);"
-" PRINTF('Assertion 2B');"
-" ASSERT(n_delivered + n_new_order_lines = n_order_lines);"
-""
-" PRINTF('Assertion 3');"
-" /* ASSERT(n_orders <= n_history); */"
-" PRINTF('Assertion 4');"
-" ASSERT(n_order_lines <= 15 * n_orders);"
-" PRINTF('Assertion 5');"
-" ASSERT(n_order_lines >= 5 * n_orders);"
-" PRINTF('Assertion 6');"
-" ASSERT(n_new_orders <= n_orders);"
-""
-" SELECT SUM(OL_QUANTITY) INTO sum_order_quant"
-" FROM ORDER_LINE;"
-" SELECT SUM(S_QUANTITY) INTO sum_stock_quant"
-" FROM STOCK;"
-" PRINTF('Sum order quant ', sum_order_quant, ' sum stock quant ',"
-" sum_stock_quant);"
-""
-" PRINTF('Assertion 7');"
-" ASSERT(((sum_stock_quant + sum_order_quant) / 91) * 91"
-" = sum_stock_quant + sum_order_quant);"
-" COMMIT WORK;"
-" PRINTF('TPC-C consistency check passed');"
-""
-" PRINTF('TPC-D consistency check begins');"
-""
-" SELECT COUNT(*) INTO n_customers_d"
-" FROM CUSTOMER_D"
-" CONSISTENT READ;"
-" SELECT COUNT(*) INTO n_nations"
-" FROM NATION"
-" CONSISTENT READ;"
-" SELECT COUNT(*) INTO n_regions"
-" FROM REGION"
-" CONSISTENT READ;"
-" SELECT COUNT(*) INTO n_suppliers"
-" FROM SUPPLIER"
-" CONSISTENT READ;"
-" SELECT COUNT(*) INTO n_orders_d"
-" FROM ORDERS_D"
-" CONSISTENT READ;"
-" SELECT COUNT(*) INTO n_lineitems"
-" FROM LINEITEM"
-" CONSISTENT READ;"
-""
-" PRINTF('N customers TPC-D ', n_customers_d);"
-""
-" PRINTF('N nations ', n_nations);"
-" PRINTF('N regions ', n_regions);"
-""
-" PRINTF('N suppliers ', n_suppliers);"
-" PRINTF('N orders TPC-D ', n_orders_d);"
-""
-" PRINTF('N lineitems ', n_lineitems, ' : ',"
-" n_lineitems / n_orders_d, ' per order');"
-" SELECT COUNT(*) INTO n"
-" FROM NATION, NATION_2"
-" WHERE N_NAME = N2_NAME"
-" CONSISTENT READ;"
-""
-" PRINTF('Assertion D1');"
-" ASSERT(n = n_nations);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM NATION, REGION"
-" WHERE N_REGIONKEY = R_REGIONKEY"
-" CONSISTENT READ;"
-""
-" PRINTF('Assertion D2');"
-" ASSERT(n = n_nations);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM ORDERS_D, CUSTOMER_D"
-" WHERE O_CUSTKEY = C_CUSTKEY"
-" CONSISTENT READ;"
-""
-" PRINTF('Assertion D3');"
-" ASSERT(n = n_orders_d);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM LINEITEM, SUPPLIER"
-" WHERE L_SUPPKEY = S_SUPPKEY"
-" CONSISTENT READ;"
-""
-" PRINTF('Assertion D4');"
-" ASSERT(n = n_lineitems);"
-""
-" SELECT COUNT(*) INTO n"
-" FROM ORDERS_D"
-" WHERE O_ORDERDATE >= 0"
-" AND O_ORDERDATE <= 2500"
-" CONSISTENT READ;"
-""
-" PRINTF('Assertion D5');"
-" ASSERT(n = n_orders_d);"
-""
-" COMMIT WORK;"
-" PRINTF('TPC-D consistency check passed');"
-""
-" END;"
- ;
-
- consistency_str = str;
-
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TPC_D_QUERY_5 (startday IN INT, endday IN INT) IS"
-""
-" revenue INT;"
-" r_name CHAR;"
-""
-" BEGIN"
-""
-" r_name := CONCAT('Region', TO_CHAR(3), ' ');"
-""
-" /* The last join to NATION_2 corresponds to calculating"
-" GROUP BY N_NAME in the original TPC-D query. It should take"
-" approximately the same amount of CPU time as GROUP BY. */"
-""
-" SELECT SUM((L_EXTENDEDPRICE * (100 - L_DISCOUNT)) / 100)"
-" INTO revenue"
-" FROM REGION, ORDERS_D, CUSTOMER_D, NATION,"
-" LINEITEM, SUPPLIER, NATION_2"
-" WHERE R_NAME = r_name"
-" AND O_ORDERDATE >= startday"
-" AND O_ORDERDATE < endday"
-" AND O_CUSTKEY = C_CUSTKEY"
-" AND C_NATIONKEY = N_NATIONKEY"
-" AND N_REGIONKEY = R_REGIONKEY"
-" AND O_ORDERKEY = L_ORDERKEY"
-" AND L_SUPPKEY = S_SUPPKEY"
-" AND S_NATIONKEY = C_NATIONKEY"
-" AND N_NAME = N2_NAME"
-" CONSISTENT READ;"
-""
-" PRINTF('Startdate ', startday, '; enddate ', endday,"
-" ': revenue ', revenue);"
-" COMMIT WORK;"
-""
-" END;"
- ;
-
- query_5_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE ROLLBACK_QUERY () IS"
-""
-" BEGIN"
-""
-" ROLLBACK WORK;"
-""
-" END;"
- ;
-
- rollback_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TEST_LOCK_WAIT () IS"
-""
-" w_id CHAR;"
-" BEGIN"
-""
-" w_id := TO_BINARY(1, 2);"
-" UPDATE WAREHOUSE SET W_YTD = W_YTD + 1 WHERE W_ID = w_id;"
-""
-" END;"
- ;
-
- lock_wait_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TEST_IBUF () IS"
-""
-" i INT;"
-" rnd INT;"
-" j INT;"
-" found INT;"
-""
-" DECLARE CURSOR desc_cursor IS"
-" SELECT IB_A"
-" FROM IBUF_TEST"
-" WHERE IB_A >= rnd AND IB_A < rnd + 50"
-" ORDER BY IB_A DESC;"
-""
-" BEGIN"
-""
-" PRINTF('Ibuf QUERY starts!!!!!!');"
-" rnd := RND(1, 1000);"
-""
-" FOR i IN 1 .. 50 LOOP"
-" INSERT INTO IBUF_TEST VALUES (rnd + i,"
-" RND_STR(RND(1, 2000)));"
-" END LOOP;"
-" IF (RND(1, 100) < 30) THEN"
-" PRINTF('Ibuf rolling back ---!!!');"
-" ROLLBACK WORK;"
-" END IF;"
-""
-""
-" IF (RND(1, 100) < 101) THEN"
-" rnd := RND(1, 1000);"
-" DELETE FROM IBUF_TEST WHERE IB_A >= rnd "
-" AND IB_A <= rnd + 50;"
-" END IF;"
-""
-" rnd := RND(1, 1000);"
-" SELECT COUNT(*) INTO j"
-" FROM IBUF_TEST"
-" WHERE IB_A >= rnd AND IB_A < rnd + 50;"
-""
-" PRINTF('Count: ', j);"
-""
-" rnd := RND(1, 1000);"
-" UPDATE IBUF_TEST"
-" SET IB_B = RND_STR(RND(1, 2000))"
-" WHERE IB_A >= rnd AND IB_A < rnd + 50;"
-""
-" OPEN desc_cursor;"
-""
-" rnd := RND(1, 1000);"
-" found := 1;"
-" WHILE (found > 0) LOOP"
-""
-" FETCH desc_cursor INTO j;"
-""
-" IF (desc_cursor % NOTFOUND) THEN"
-" found := 0;"
-" END IF;"
-" END LOOP;"
-""
-" CLOSE desc_cursor;"
-""
-" IF (RND(1, 100) < 30) THEN"
-" PRINTF('Ibuf rolling back!!!');"
-" ROLLBACK WORK;"
-" ELSE"
-" COMMIT WORK;"
-" END IF;"
-""
-" PRINTF('Ibuf QUERY ends!!!!!!');"
-" END;"
- ;
-
- ibuf_test_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TEST_GROUP_COMMIT (w_id IN CHAR) IS"
-""
-" i INT;"
-""
-" BEGIN"
-""
-" FOR i IN 1 .. 200 LOOP"
-" UPDATE WAREHOUSE SET W_YTD = W_YTD + 1 WHERE W_ID = w_id;"
-" COMMIT WORK;"
-" END LOOP;"
-" END;"
- ;
-
- test_group_commit_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TEST_SINGLE_ROW_SELECT ("
-" i_id IN CHAR,"
-" i_name OUT CHAR) IS"
-" BEGIN"
-" SELECT I_NAME INTO i_name"
-" FROM ITEM"
-" WHERE I_ID = i_id"
-" CONSISTENT READ;"
-" END;"
- ;
-
- test_single_row_select_str = str;
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE JOIN_TEST () IS"
-""
-" n_rows INT;"
-" i INT;"
-""
-" BEGIN"
-""
-" FOR i IN 0 .. 0 LOOP"
-" SELECT COUNT(*) INTO n_rows"
-" FROM JTEST1, JTEST2"
-" WHERE JT2_A = JT1_B"
-" CONSISTENT READ;"
-" PRINTF(n_rows);"
-""
-" COMMIT WORK;"
-" END LOOP;"
-""
-" END;"
- ;
-
- join_test_str = str;
-
- /*-----------------------------------------------------------*/
- str =
-
-" PROCEDURE TEST_ERRORS (switch IN CHAR) IS"
-""
-" count INT;"
-" val INT;"
-""
-" BEGIN"
-""
-" IF (switch = '01') THEN"
-" /* Test duplicate key error: run this first */"
-" ROW_PRINTF SELECT * FROM JTEST1;"
-" PRINTF('To insert first');"
-" INSERT INTO JTEST1 VALUES (1, 1);"
-" PRINTF('To insert second');"
-" INSERT INTO JTEST1 VALUES (2, 2);"
-" END IF;"
-""
-" IF (switch = '02') THEN"
-" /* Test duplicate key error: run this second */"
-" ROW_PRINTF SELECT * FROM JTEST1;"
-" PRINTF('To insert third');"
-" INSERT INTO JTEST1 VALUES (3, 3);"
-" ROW_PRINTF SELECT * FROM JTEST1;"
-" PRINTF('To insert fourth');"
-" INSERT INTO JTEST1 VALUES (1, 1);"
-" END IF;"
-""
-" IF (switch = '03') THEN"
-" /* Test duplicate key error: run this third */"
-" ROW_PRINTF SELECT * FROM JTEST1;"
-" PRINTF('Testing assert');"
-" SELECT COUNT(*) INTO count FROM JTEST1;"
-" ASSERT(count = 2);"
-" END IF;"
-""
-" IF (switch = '04') THEN"
-" /* Test duplicate key error: run this fourth */"
-" ROW_PRINTF SELECT * FROM JTEST1;"
-" PRINTF('Testing update');"
-" UPDATE JTEST1 SET JT1_A = 3 WHERE JT1_A = 2;"
-" PRINTF('Testing update');"
-" UPDATE JTEST1 SET JT1_A = 1 WHERE JT1_A = 3;"
-" END IF;"
-""
-" IF (switch = '05') THEN"
-" /* Test deadlock error: run this fifth in thread 1 */"
-" COMMIT WORK;"
-" PRINTF('Testing update in thread 1');"
-" UPDATE JTEST1 SET JT1_B = 3 WHERE JT1_A = 1;"
-" END IF;"
-""
-" IF (switch = '06') THEN"
-" /* Test deadlock error: run this sixth in thread 2 */"
-" PRINTF('Testing update in thread 2');"
-" UPDATE JTEST1 SET JT1_B = 10 WHERE JT1_A = 2;"
-" PRINTF('Testing update in thread 2');"
-" UPDATE JTEST1 SET JT1_B = 11 WHERE JT1_A = 1;"
-" PRINTF('Update in thread 2 completed');"
-" SELECT JT1_B INTO val FROM JTEST1 WHERE JT1_A = 1;"
-" ASSERT(val = 11);"
-" SELECT JT1_B INTO val FROM JTEST1 WHERE JT1_A = 2;"
-" ASSERT(val = 10);"
-" COMMIT WORK;"
-" END IF;"
-""
-" IF (switch = '07') THEN"
-" /* Test deadlock error: run this seventh in thread 1 */"
-" PRINTF('Testing update in thread 1: deadlock');"
-" UPDATE JTEST1 SET JT1_B = 4 WHERE JT1_A = 2;"
-" END IF;"
-""
-" IF (switch = '08') THEN"
-" /* Test deadlock error: run this eighth in thread 1 */"
-" PRINTF('Testing update in thread 1: commit');"
-" SELECT JT1_B INTO val FROM JTEST1 WHERE JT1_A = 1;"
-" ASSERT(val = 3);"
-" COMMIT WORK;"
-" END IF;"
-""
-" END;"
- ;
-
- test_errors_str = str;
- /*-----------------------------------------------------------*/
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &create_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &populate_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)"use21", 5, (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- ret = SQLPrepare(stat, (UCHAR*)create_str, ut_strlen(create_str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- str = "{CREATE_TABLES()}";
-
- ret = SQLPrepare(create_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(create_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- ret = SQLPrepare(stat, (UCHAR*)populate_str, ut_strlen(populate_str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)lock_wait_str,
- ut_strlen(lock_wait_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)commit_str,
- ut_strlen(commit_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)print_str,
- ut_strlen(print_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)new_order_str,
- ut_strlen(new_order_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)payment_str,
- ut_strlen(payment_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)order_status_str,
- ut_strlen(order_status_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)delivery_str,
- ut_strlen(delivery_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)stock_level_str,
- ut_strlen(stock_level_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)query_5_str,
- ut_strlen(query_5_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)consistency_str,
- ut_strlen(consistency_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)rollback_str, ut_strlen(rollback_str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)join_test_str,
- ut_strlen(join_test_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)test_errors_str,
- ut_strlen(test_errors_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)test_single_row_select_str,
- ut_strlen(test_single_row_select_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)test_group_commit_str,
- ut_strlen(test_group_commit_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLPrepare(stat, (UCHAR*)ibuf_test_str,
- ut_strlen(ibuf_test_str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(stat);
-
- ut_a(ret == SQL_SUCCESS);
-
- str = "{POPULATE_TABLES(?, ?)}";
-
- ret = SQLPrepare(populate_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(populate_query, 1, SQL_PARAM_INPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&n_warehouses_buf,
- 4, &n_warehouses_len);
- ut_a(ret == SQL_SUCCESS);
-
- n_warehouses_buf = n_warehouses;
- n_warehouses_len = 4;
-
- ret = SQLBindParameter(populate_query, 2, SQL_PARAM_INPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&n_customers_d_buf,
- 4, &n_customers_d_len);
- ut_a(ret == SQL_SUCCESS);
-
- n_customers_d_buf = n_customers_d;
- n_customers_d_len = 4;
-
- ret = SQLExecute(populate_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- printf("TPC-C test database initialized\n");
-
- return(0);
-}
-
-/*********************************************************************
-Iterates an SQL query until it returns SQL_SUCCESS. If it returns other
-value, rolls back the trx, prints an error message, and tries again. */
-
-void
-execute_until_success(
-/*==================*/
- HSTMT query, /* in: query */
- HSTMT rollback_query) /* in: trx rollback query to run if error */
-{
- RETCODE ret;
- UCHAR sql_state[6];
- SDWORD native_error;
- UCHAR error_msg[512];
- SWORD error_msg_max = 512;
- SWORD error_msg_len;
-
- for (;;) {
- ret = SQLExecute(query);
-
- if (ret != SQL_SUCCESS) {
- ut_a(ret == SQL_ERROR);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, query,
- sql_state, &native_error, error_msg,
- error_msg_max, &error_msg_len);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("%s\n", error_msg);
-
- /* Roll back to release trx locks, and try again */
-
- ret = SQLExecute(rollback_query);
- ut_a(ret == SQL_SUCCESS);
-
- os_thread_sleep(ut_rnd_gen_ulint() / 1000);
- } else {
-
- return;
- }
- }
-}
-
-/*********************************************************************
-Test for TPC-C. */
-
-ulint
-test_client(
-/*=========*/
- void* arg) /* in: user name as a null-terminated string */
-{
- ulint n_customers = 20;
- ulint n_items = 200;
- ulint n_lines;
- bool put_invalid_item;
- HENV env;
- HDBC conn;
- RETCODE ret;
- HSTMT commit_query;
- HSTMT new_order_query;
- HSTMT payment_query;
- HSTMT order_status_query;
- HSTMT delivery_query;
- HSTMT stock_level_query;
- HSTMT print_query;
- HSTMT lock_wait_query;
- HSTMT join_test_query;
- HSTMT test_group_commit_query;
- HSTMT rollback_query;
- HSTMT ibuf_query;
- ulint tm, oldtm;
- char* str;
- byte c_w_id_buf[2];
- byte c_d_id_buf[1];
- byte c_id_buf[3];
- byte ol_supply_w_ids_buf[30];
- byte ol_i_ids_buf[45];
- byte ol_quantities_buf[15];
- byte c_last_buf[51];
- byte c_credit_buf[3];
- ulint c_discount_buf;
- ulint w_tax_buf;
- ulint d_tax_buf;
- ulint o_ol_count_buf;
- ulint o_id_buf;
- ulint o_entry_d_buf;
- ulint total_buf;
- byte i_names_buf[361];
- byte s_quantities_buf[60];
- byte bg_buf[16];
- byte i_prices_buf[60];
- byte ol_amounts_buf[60];
- SDWORD c_w_id_len;
- SDWORD c_d_id_len;
- SDWORD c_id_len;
- SDWORD ol_supply_w_ids_len;
- SDWORD ol_i_ids_len;
- SDWORD ol_quantities_len;
- SDWORD c_last_len;
- SDWORD c_credit_len;
- SDWORD c_discount_len;
- SDWORD w_tax_len;
- SDWORD d_tax_len;
- SDWORD o_ol_count_len;
- SDWORD o_id_len;
- SDWORD o_entry_d_len;
- SDWORD total_len;
- SDWORD i_names_len;
- SDWORD s_quantities_len;
- SDWORD bg_len;
- SDWORD i_prices_len;
- SDWORD ol_amounts_len;
- ulint i;
- ulint k;
- ulint t;
-
- printf("Client thread %s\n", (UCHAR*)arg);
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &new_order_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &payment_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &order_status_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &delivery_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &stock_level_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &print_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &commit_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &lock_wait_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &join_test_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &test_group_commit_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &rollback_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &ibuf_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)arg, (SWORD)ut_strlen((char*)arg),
- (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str =
- "{NEW_ORDER(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
- " ?, ?, ?, ?)}";
-
- ret = SQLPrepare(new_order_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_w_id_buf,
- 2, &c_w_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 2, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_d_id_buf,
- 1, &c_d_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- c_d_id_len = 1;
-
- ret = SQLBindParameter(new_order_query, 3, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_id_buf,
- 3, &c_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- c_id_len = 3;
-
- ret = SQLBindParameter(new_order_query, 4, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, ol_supply_w_ids_buf,
- 30, &ol_supply_w_ids_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 5, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, ol_i_ids_buf,
- 45, &ol_i_ids_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 6, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, ol_quantities_buf,
- 15, &ol_quantities_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 7, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_last_buf,
- 50, &c_last_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 8, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0,
- (byte*)&c_credit_buf,
- 2, &c_credit_len);
- ut_a(ret == SQL_SUCCESS);
- c_credit_buf[2] = '\0';
-
- ret = SQLBindParameter(new_order_query, 9, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&c_discount_buf,
- 4, &c_discount_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 10, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&w_tax_buf,
- 4, &w_tax_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 11, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&d_tax_buf,
- 4, &d_tax_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 12, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&o_ol_count_buf,
- 4, &o_ol_count_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 13, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&o_id_buf,
- 4, &o_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 14, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&o_entry_d_buf,
- 4, &o_entry_d_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 15, SQL_PARAM_OUTPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)&total_buf,
- 4, &total_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 16, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, i_names_buf,
- 360, &i_names_len);
- ut_a(ret == SQL_SUCCESS);
- i_names_buf[360] = '\0';
-
- ret = SQLBindParameter(new_order_query, 17, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, s_quantities_buf,
- 60, &s_quantities_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 18, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, bg_buf,
- 15, &bg_len);
- ut_a(ret == SQL_SUCCESS);
- bg_buf[15] = '\0';
-
- ret = SQLBindParameter(new_order_query, 19, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, i_prices_buf,
- 60, &i_prices_len);
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(new_order_query, 20, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, ol_amounts_buf,
- 60, &ol_amounts_len);
- ut_a(ret == SQL_SUCCESS);
-
- c_w_id_len = 2;
- c_w_id_buf[1] = (byte)(2 * atoi((char*)arg + 4));
- c_w_id_buf[0] = (byte)(2 * (atoi((char*)arg + 4) / 256));
-
- k = atoi((char*)arg + 4);
-
- printf("Client thread %lu starts\n", k);
-
- /*-----------------------------------------------------------*/
- str = "{PAYMENT(?)}";
-
- ret = SQLPrepare(payment_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(payment_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_w_id_buf,
- 2, &c_w_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- str = "{ORDER_STATUS(?)}";
-
- ret = SQLPrepare(order_status_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(order_status_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_w_id_buf,
- 2, &c_w_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- str = "{DELIVERY(?)}";
-
- ret = SQLPrepare(delivery_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(delivery_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_w_id_buf,
- 2, &c_w_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- str = "{STOCK_LEVEL(?)}";
-
- ret = SQLPrepare(stock_level_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(stock_level_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, c_w_id_buf,
- 2, &c_w_id_len);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
- str = "{ROLLBACK_QUERY()}";
-
- ret = SQLPrepare(rollback_query, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
- /*-----------------------------------------------------------*/
-
- oldtm = ut_clock();
-
- for (i = k; i < k + n_rounds / n_users; i++) {
-
- /* execute_until_success(ibuf_query, rollback_query); */
-
- if (i % 100 == 0) {
- printf("User %s round %lu\n", (char*)arg, i);
- }
-
- if (!own_warehouse) {
- c_w_id_buf[1] = (byte)ut_rnd_interval(1, n_warehouses);
- c_w_id_buf[0] = (byte)(ut_rnd_interval(1, n_warehouses)
- / 256);
- }
-
- mach_write_to_1(c_d_id_buf, (ut_rnd_interval(1, 10) + 47));
- mach_write_to_3(c_id_buf, ut_rnd_interval(1, n_customers));
-
- n_lines = ut_rnd_interval(5, 15);
-
- if ((15 * k + i) % 100 == 0) {
- put_invalid_item = TRUE;
-
- /* printf("Will put invalid item\n"); */
- } else {
- put_invalid_item = FALSE;
- }
-
- for (t = 0; t < n_lines; t++) {
- mach_write_to_3(ol_i_ids_buf + 3 * t,
- ut_rnd_interval(1, n_items));
-
- if (put_invalid_item && (t + 1 == n_lines)) {
- mach_write_to_3(ol_i_ids_buf + 3 * t,
- n_items + 1);
- }
-
- mach_write_to_1(ol_quantities_buf + t,
- ut_rnd_interval(10, 20));
- ut_memcpy(ol_supply_w_ids_buf + 2 * t, c_w_id_buf, 2);
- }
-
- ol_i_ids_len = 3 * n_lines;
- ol_quantities_len = n_lines;
- ol_supply_w_ids_len = 2 * n_lines;
-
- execute_until_success(new_order_query, rollback_query);
-
- if (put_invalid_item) {
-
- goto skip_prints;
- }
-/*
- c_last_buf[c_last_len] = '\0';
-
- printf(
- "C_LAST %s, c_credit %s, c_discount, %lu, w_tax %lu, d_tax %lu\n",
- c_last_buf, c_credit_buf, w_tax_buf, d_tax_buf);
-
- printf("o_ol_count %lu, o_id %lu, o_entry_d %lu, total %lu\n",
- o_ol_count_buf, o_id_buf, o_entry_d_buf,
- total_buf);
-
- ut_a(c_credit_len == 2);
- ut_a(c_discount_len == 4);
- ut_a(i_names_len == 360);
-
- printf("i_names %s, bg %s\n", i_names_buf, bg_buf);
-
- for (t = 0; t < n_lines; t++) {
- printf("s_quantity %lu, i_price %lu, ol_amount %lu\n",
- mach_read_from_4(s_quantities_buf + 4 * t),
- mach_read_from_4(i_prices_buf + 4 * t),
- mach_read_from_4(ol_amounts_buf + 4 * t));
- }
-*/
- skip_prints:
- ;
-
- execute_until_success(payment_query, rollback_query);
-
- if (i % 10 == 3) {
- execute_until_success(order_status_query,
- rollback_query);
- }
-
- if ((i % 10 == 6) || (i % 100 == 60)) {
- execute_until_success(delivery_query, rollback_query);
- }
-
- if (i % 10 == 9) {
- execute_until_success(stock_level_query,
- rollback_query);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall time for %lu loops %lu milliseconds\n",
- (i - k), tm - oldtm);
-
-/* execute_until_success(print_query, rollback_query); */
-
- n_exited++;
-
- printf("Client thread %lu exits as the %luth\n", k, n_exited);
-
- return(0);
-}
-
-/*********************************************************************
-Test for single row select. */
-
-ulint
-test_single_row_select(
-/*===================*/
- void* arg) /* in: user name as a null-terminated string */
-{
- ulint n_items = 200;
- HENV env;
- HDBC conn;
- RETCODE ret;
- HSTMT single_row_select_query;
- ulint tm, oldtm;
- char* str;
- byte i_id_buf[3];
- byte i_name_buf[25];
- SDWORD i_id_len;
- SDWORD i_name_len;
- ulint i;
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn, &single_row_select_query);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)arg,
- (SWORD)ut_strlen((char*)arg),
- (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str =
- "{TEST_SINGLE_ROW_SELECT(?, ?)}";
-
- ret = SQLPrepare(single_row_select_query, (UCHAR*)str,
- ut_strlen(str));
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(single_row_select_query, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, i_id_buf,
- 3, &i_id_len);
- ut_a(ret == SQL_SUCCESS);
- i_id_len = 3;
-
- ret = SQLBindParameter(single_row_select_query, 2, SQL_PARAM_OUTPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, i_name_buf,
- 24, &i_name_len);
- ut_a(ret == SQL_SUCCESS);
- i_name_buf[24] = '\0';
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000; i++) {
-
- mach_write_to_3(i_id_buf, ut_rnd_interval(1, n_items));
-
- ret = SQLExecute(single_row_select_query);
-
- ut_a(ret == SQL_SUCCESS);
- }
-
- tm = ut_clock();
-
- printf("Wall time for %lu single row selects %lu milliseconds\n",
- i, tm - oldtm);
- return(0);
-}
-
-/*********************************************************************
-TPC-D query 5. */
-
-ulint
-test_tpc_d_client(
-/*==============*/
- void* arg) /* in: pointer to an array of startdate and enddate */
-{
- char buf[20];
- HENV env;
- HDBC conn1;
- RETCODE ret;
- HSTMT query5;
- HSTMT join_test;
- char* str;
- SDWORD len1;
- SDWORD len2;
- ulint i;
- ulint tm, oldtm;
-
- UT_NOT_USED(arg);
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn1, &query5);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn1, &join_test);
-
- ut_a(ret == SQL_SUCCESS);
-
- sprintf(buf, "Use2%5lu", *((ulint*)arg));
-
- ret = SQLConnect(conn1, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)buf,
- (SWORD)9, (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str = "{TPC_D_QUERY_5(?, ?)}";
-
- ret = SQLPrepare(query5, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(query5, 1, SQL_PARAM_INPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)arg,
- 4, &len1);
- ut_a(ret == SQL_SUCCESS);
-
- len1 = 4;
-
- ret = SQLBindParameter(query5, 2, SQL_PARAM_INPUT,
- SQL_C_LONG, SQL_INTEGER, 0, 0,
- (byte*)arg + sizeof(ulint),
- 4, &len2);
- ut_a(ret == SQL_SUCCESS);
-
- len2 = 4;
-
- str = "{JOIN_TEST()}";
-
- ret = SQLPrepare(join_test, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- for (i = 0; i < n_rounds; i++) {
-
- oldtm = ut_clock();
-
- ret = SQLExecute(query5);
-
- /* ret = SQLExecute(join_test); */
-
- ut_a(ret == SQL_SUCCESS);
-
- tm = ut_clock();
-
- printf("Wall time %lu milliseconds\n", tm - oldtm);
- }
-
- printf("%s exits\n", buf);
-
- return(0);
-}
-
-/*********************************************************************
-Checks consistency of the TPC databases. */
-
-ulint
-check_tpc_consistency(
-/*==================*/
- void* arg) /* in: user name */
-{
- HENV env;
- HDBC conn1;
- RETCODE ret;
- HSTMT consistency_query1;
- char* str;
-
- UT_NOT_USED(arg);
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn1, &consistency_query1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn1, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)arg,
- (SWORD)ut_strlen((char*)arg), (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str = "{TPC_CONSISTENCY()}";
-
- ret = SQLPrepare(consistency_query1, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLExecute(consistency_query1);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("Consistency checked\n");
-
- return(0);
-}
-
-/*********************************************************************
-Test for errors. */
-
-ulint
-test_client_errors2(
-/*================*/
- void* arg) /* in: ignored */
-{
- HENV env;
- HDBC conn1;
- RETCODE ret;
- HSTMT error_test_query1;
- char* str;
- byte buf1[2];
- SDWORD len1;
- UCHAR sql_state[6];
- SDWORD native_error;
- UCHAR error_msg[512];
- SWORD error_msg_max = 512;
- SWORD error_msg_len;
-
- UT_NOT_USED(arg);
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn1, &error_test_query1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn1, (UCHAR*)cli_srv_endpoint_name,
- (SWORD)ut_strlen(cli_srv_endpoint_name),
- (UCHAR*)"conn2",
- (SWORD)5, (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str = "{TEST_ERRORS(?)}";
-
- ret = SQLPrepare(error_test_query1, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(error_test_query1, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, buf1,
- 2, &len1);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
-
- printf("Thread 2 to do update\n");
-
- ut_memcpy(buf1, "06", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Thread 2 has done update\n");
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_NO_DATA_FOUND);
-
- return(0);
-}
-
-/*********************************************************************
-Test for errors. */
-
-ulint
-test_client_errors(
-/*===============*/
- void* arg) /* in: ignored */
-{
- HENV env;
- HDBC conn1;
- RETCODE ret;
- HSTMT error_test_query1;
- char* str;
- byte buf1[2];
- SDWORD len1;
- UCHAR sql_state[6];
- SDWORD native_error;
- UCHAR error_msg[512];
- SWORD error_msg_max = 512;
- SWORD error_msg_len;
- os_thread_id_t thread_id;
-
- UT_NOT_USED(arg);
-
- ret = SQLAllocEnv(&env);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocConnect(env, &conn1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLAllocStmt(conn1, &error_test_query1);
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLConnect(conn1, (UCHAR*)"innobase", 8, (UCHAR*)"conn1",
- (SWORD)5, (UCHAR*)"password", 8);
- ut_a(ret == SQL_SUCCESS);
-
- printf("Connection established\n");
-
- /*-----------------------------------------------------------*/
- str = "{TEST_ERRORS(?)}";
-
- ret = SQLPrepare(error_test_query1, (UCHAR*)str, ut_strlen(str));
-
- ut_a(ret == SQL_SUCCESS);
-
- ret = SQLBindParameter(error_test_query1, 1, SQL_PARAM_INPUT,
- SQL_C_CHAR, SQL_CHAR, 0, 0, buf1,
- 2, &len1);
- ut_a(ret == SQL_SUCCESS);
-
- /*-----------------------------------------------------------*/
-
- ut_memcpy(buf1, "01", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- ut_memcpy(buf1, "02", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_ERROR);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("%s\n", error_msg);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_NO_DATA_FOUND);
-
- ut_memcpy(buf1, "03", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- ut_memcpy(buf1, "01", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_ERROR);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("%s\n", error_msg);
-
- ut_memcpy(buf1, "03", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- ut_memcpy(buf1, "04", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_ERROR);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("%s\n", error_msg);
-
- ut_memcpy(buf1, "03", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- ut_memcpy(buf1, "05", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- os_thread_create(&test_client_errors2, "user000", &thread_id);
-
- os_thread_sleep(5000000);
-
- ut_memcpy(buf1, "07", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_ERROR);
-
- ret = SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, error_test_query1,
- sql_state, &native_error, error_msg, error_msg_max,
- &error_msg_len);
-
- ut_a(ret == SQL_SUCCESS);
-
- printf("%s\n", error_msg);
-
- printf("Thread 1 to commit\n");
-
- ut_memcpy(buf1, "08", 2);
- len1 = 2;
- ret = SQLExecute(error_test_query1);
- ut_a(ret == SQL_SUCCESS);
-
- return(0);
-}
-
-/*************************************************************************
-Simulates disk waits: if there are at least two threads active,
-puts the current thread to wait for an event. If there is just the current
-thread active and another thread doing a simulated disk wait, puts the
-current thread to wait and releases another thread from wait, otherwise does
-nothing */
-
-void
-srv_simulate_disk_wait(void)
-/*========================*/
-{
- os_event_t event;
- ulint wait_i;
- ulint count;
- bool found;
- ulint rnd;
- ulint i;
- ulint j;
-
- mutex_enter(&kernel_mutex);
-
- srv_disk_rnd += 98687241;
-
- count = 0;
- found = FALSE;
-
- for (i = 0; i < SRV_N_SIM_DISK_ARRAY; i++) {
-
- if (!srv_sim_disk[i].empty) {
-
- count++;
- }
-
- if (!found && srv_sim_disk[i].empty) {
-
- srv_sim_disk[i].empty = FALSE;
- event = srv_sim_disk[i].event;
-
- os_event_reset(event);
- srv_sim_disk[i].event_set = FALSE;
-
- wait_i = i;
-
- found = TRUE;
- }
- }
-
- ut_a(found);
-
- if (srv_disk_n_active_threads == count + 1) {
- /* We have to release a thread from the disk wait array */;
-
- rnd = srv_disk_rnd;
-
- for (i = rnd; i < SRV_N_SIM_DISK_ARRAY + rnd; i++) {
-
- j = i % SRV_N_SIM_DISK_ARRAY;
-
- if (!srv_sim_disk[j].empty
- && !srv_sim_disk[j].event_set) {
-
- srv_sim_disk[j].event_set = TRUE;
- os_event_set(srv_sim_disk[j].event);
-
- break;
- }
- }
- }
-
- mutex_exit(&kernel_mutex);
-
- os_event_wait(event);
-
- mutex_enter(&kernel_mutex);
-
- srv_sim_disk[wait_i].empty = TRUE;
-
- mutex_exit(&kernel_mutex);
-}
-
-/*************************************************************************
-Releases a thread from the simulated disk wait array if there is any to
-release. */
-
-void
-srv_simulate_disk_wait_release(void)
-/*================================*/
-{
- ulint rnd;
- ulint i;
- ulint j;
-
- mutex_enter(&kernel_mutex);
-
- srv_disk_rnd += 98687241;
- rnd = srv_disk_rnd;
-
- for (i = rnd; i < SRV_N_SIM_DISK_ARRAY + rnd; i++) {
-
- j = i % SRV_N_SIM_DISK_ARRAY;
-
- if (!srv_sim_disk[j].empty
- && !srv_sim_disk[j].event_set) {
-
- srv_sim_disk[j].event_set = TRUE;
- os_event_set(srv_sim_disk[j].event);
-
- break;
- }
- }
-
- mutex_exit(&kernel_mutex);
-}
-
-/*********************************************************************
-Test for many threads and disk waits. */
-
-ulint
-test_disk_waits(
-/*============*/
- void* arg) /* in: ignored */
-{
- ulint i;
- ulint tm, oldtm;
-
- UT_NOT_USED(arg);
-
- n_exited++;
-
- printf("Client thread starts as the %luth\n", n_exited);
-
- oldtm = ut_clock();
-
- mutex_enter(&kernel_mutex);
- srv_disk_n_active_threads++;
- mutex_exit(&kernel_mutex);
-
- for (i = 0; i < 133; i++) {
- ut_delay(500);
-
-/* os_thread_yield(); */
-
-/* os_thread_sleep(10000); */
-
- srv_simulate_disk_wait();
- }
-
- mutex_enter(&kernel_mutex);
- srv_disk_n_active_threads--;
- mutex_exit(&kernel_mutex);
-
- srv_simulate_disk_wait_release();
-
- tm = ut_clock();
-
- printf("Wall time for %lu loops %lu milliseconds\n", i, tm - oldtm);
-
- n_exited++;
-
- printf("Client thread exits as the %luth\n", n_exited);
-
- return(0);
-}
-
-/*************************************************************************
-Reads a keywords and a values from an initfile. In case of an error, exits
-from the process. */
-
-void
-cli_read_initfile(
-/*==============*/
- FILE* initfile) /* in: file pointer */
-{
- char str_buf[10000];
- ulint ulint_val;
-
- srv_read_init_val(initfile, FALSE, "SRV_ENDPOINT_NAME", str_buf,
- &ulint_val);
- ut_a(ut_strlen(str_buf) < COM_MAX_ADDR_LEN);
-
- ut_memcpy(cli_srv_endpoint_name, str_buf, COM_MAX_ADDR_LEN);
-
- srv_read_init_val(initfile, FALSE, "USER_NAME", str_buf,
- &ulint_val);
- ut_a(ut_strlen(str_buf) < COM_MAX_ADDR_LEN);
-
- ut_memcpy(cli_user_name, str_buf, COM_MAX_ADDR_LEN);
-
- srv_read_init_val(initfile, TRUE, "MEM_POOL_SIZE", str_buf,
- &mem_pool_size);
-
- srv_read_init_val(initfile, TRUE, "N_WAREHOUSES", str_buf,
- &n_warehouses);
-
- srv_read_init_val(initfile, TRUE, "N_CUSTOMERS_D", str_buf,
- &n_customers_d);
-
- srv_read_init_val(initfile, TRUE, "IS_TPC_D", str_buf,
- &is_tpc_d);
-
- srv_read_init_val(initfile, TRUE, "N_ROUNDS", str_buf,
- &n_rounds);
-
- srv_read_init_val(initfile, TRUE, "N_USERS", str_buf,
- &n_users);
-
- srv_read_init_val(initfile, TRUE, "STARTDATE", str_buf,
- &startdate);
-
- srv_read_init_val(initfile, TRUE, "ENDDATE", str_buf,
- &enddate);
-
- srv_read_init_val(initfile, TRUE, "OWN_WAREHOUSE", str_buf,
- &own_warehouse);
-}
-
-/*************************************************************************
-*/
-void
-cli_boot(
-/*=====*/
- char* name) /* in: the initialization file name */
-{
- FILE* initfile;
-
- initfile = fopen(name, "r");
-
- if (initfile == NULL) {
- printf(
- "Error in client booting: could not open initfile whose name is %s!\n",
- name);
- os_process_exit(1);
- }
-
- cli_read_initfile(initfile);
-
- fclose(initfile);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- os_thread_t thread_handles[1000];
- os_thread_id_t thread_ids[1000];
- char user_names[1000];
- ulint tm, oldtm;
- ulint i;
- ulint dates[1000];
-
- cli_boot("cli_init");
-
- for (i = 1; i <= n_users; i++) {
- dates[2 * i] = startdate
- + ((enddate - startdate) / n_users) * (i - 1);
- dates[2 * i + 1] = startdate
- + ((enddate - startdate) / n_users) * i;
- }
-
- sync_init();
-
- mem_init(mem_pool_size);
-
- test_init(NULL);
-
- check_tpc_consistency("con21");
-
-/* test_client_errors(NULL); */
-
- os_thread_sleep(4000000);
-
- printf("Sleep ends\n");
-
- oldtm = ut_clock();
-
- for (i = 2; i <= n_users; i++) {
- if (is_tpc_d) {
- thread_handles[i] = os_thread_create(&test_tpc_d_client,
- dates + 2 * i, thread_ids + i);
- } else {
- sprintf(user_names + i * 8, "use2%3lu", i);
-
- thread_handles[i] = os_thread_create(&test_client,
- user_names + i * 8, thread_ids + i);
- }
-
- ut_a(thread_handles[i]);
- }
-
- if (is_tpc_d) {
- test_tpc_d_client(dates + 2 * 1);
- } else {
- test_client("use2 1");
- }
-
- for (i = 2; i <= n_users; i++) {
- os_thread_wait(thread_handles[i]);
-
- printf("Wait for thread %lu ends\n", i);
- }
-
- tm = ut_clock();
-
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- os_thread_sleep(4000000);
-
- printf("Sleep ends\n");
-
- test_single_row_select("con99");
-
- check_tpc_consistency("con22");
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tsrecv.c b/innobase/btr/ts/tsrecv.c
deleted file mode 100644
index 0f30fcd94f1..00000000000
--- a/innobase/btr/ts/tsrecv.c
+++ /dev/null
@@ -1,4909 +0,0 @@
-/************************************************************************
-Test for the B-tree
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "log0recv.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "row0del.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 3 /* must be >= 2 */
-#define N_FILES 1
-#define FILE_SIZE 512 /* must be > 512 */
-#define POOL_SIZE 1000
-#define IBUF_SIZE 200
-#define COUNTER_OFFSET 1500
-
-#define N_LOG_GROUPS 2
-#define N_LOG_FILES 3
-#define LOG_FILE_SIZE 500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-#define COUNT 1
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-ulint dummy = 0;
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- ulint i;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates or opens the log files. */
-
-void
-create_log_files(void)
-/*==================*/
-{
- bool ret;
- ulint i, k;
- char name[20];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open log files\n");
-
- strcpy(name, "logfile00");
-
- for (k = 0; k < N_LOG_GROUPS; k++) {
- for (i = 0; i < N_LOG_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_AIO,
- &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * LOG_FILE_SIZE, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k + 100, FIL_LOG);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, LOG_FILE_SIZE, k + 100);
- }
-
- fil_space_create(name, k + 200, FIL_LOG);
-
- log_group_init(k, N_LOG_FILES, LOG_FILE_SIZE * UNIV_PAGE_SIZE,
- k + 100, k + 200);
- }
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < 2 * N_SPACES; k += 2) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_AIO, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- if (k == 1) {
- ut_a(os_file_set_size(files[i],
- 8192 * IBUF_SIZE, 0));
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * FILE_SIZE, 0));
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, FIL_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0,
- DICT_UNIQUE | DICT_CLUSTERED, 1);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* CREATE YET ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND4", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-#endif
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE2", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE2", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_6(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.6. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE3", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE3", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_7(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.7. CREATE TABLE WITH 12 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE4", 0, 12);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL4", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL5", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL6", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL7", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL8", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL9", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL10", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL11", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL12", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE4", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for inserts. */
-
-ulint
-test2(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- dict_index_t* index;
-/* ulint size; */
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. MASSIVE INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- /* MASSIVE RANDOM INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd,
- DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
- printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print();
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-/*
- for (i = 0; i < 10; i++) {
- size = ibuf_contract(TRUE);
-
- printf("%lu bytes will be contracted\n", size);
-
- os_thread_sleep(1000000);
- }
-*/
- index = dict_table_get_next_index(dict_table_get_first_index(table));
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- index = dict_table_get_next_index(index);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- btr_search_print_info();
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
- dtuple_gen_search_tuple3(entry, rnd, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
-/* btr_print_tree(tree, 5); */
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- btr_validate_tree(tree);
-
-/* btr_search_print_info();
- dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_1(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ins_node_t* node;
- ulint count = 0;
- ulint rnd;
- dtuple_t* row;
-/* dict_tree_t* tree;
- dict_index_t* index;
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr; */
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1. MASSIVE ASCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- rnd = 0;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND3500, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 5000 == 0) {
- /* ibuf_print(); */
- /* buf_print(); */
-
- /* buf_print_io(); */
-
- tm = ut_clock();
- /*
- printf("Wall time for %lu inserts %lu milliseconds\n",
- i, tm - oldtm); */
- }
-
- rnd = rnd + 1;
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- ibuf_print();
-
- index = dict_table_get_first_index(table);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- /* Check inserted entries */
-
- btr_search_print_info();
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-#endif
-#ifdef notdefined
- /*-------------------------------------*/
- /* ROLLBACK */
-
-/* btr_validate_tree(tree); */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_search_print_info();
-
-#endif
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
- /*-------------------------------------*/
-
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 5) {
- goto loop;
- }
-
- mem_heap_free(heap);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_2(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2. MASSIVE DESCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = *((ulint*)arg) + 1;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
-/* printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print(); */
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i + 1, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_validate_tree(tree);
-/* dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- btr_validate_tree(tree);
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for random inserts. */
-
-ulint
-test2mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2MT. MULTITHREADED RANDOM INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
- rnd = 78675;
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- if (i % 100 == 0) {
-/* buf_print(); */
-/* ibuf_print(); */
- }
-
- rnd = (rnd + 7857641) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_1mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1MT. MULTITHREADED ASCENDING INSERT\n");
-
- rnd = 8757677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 98667501;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_2mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2MT. MULTITHREADED DESCENDING INSERT\n");
-
- rnd = 87677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 78667;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- mem_print_info();
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for updates. */
-
-ulint
-test3(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
- ulint err;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 3. UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 3; i++) {
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_RND30, buf);
-
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-#ifdef notdefined
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Init for update test. */
-
-ulint
-test4_1(void)
-/*=========*/
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.1. UPDATE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*************************************************************************
-Checks that the multithreaded update test has rolled back its updates. */
-
-void
-test4_2(void)
-/*=========*/
-{
- dtuple_t* entry;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- mtr_t mtr;
- byte buf[32];
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- btr_pcur_t pcur;
- rec_t* rec;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.2. CHECK UPDATE RESULT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*------------------------------------------*/
-
- table = dict_table_get("TS_TABLE1", trx);
-
- index = dict_table_get_first_index(table);
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < 200; i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- rec = btr_pcur_get_rec(&pcur);
-
- ut_a(0 == cmp_dtuple_rec(entry, rec));
-
- heap2 = mem_heap_create(200);
-
- row = row_build(ROW_COPY_DATA, index, rec, heap2);
-
- ut_a(30 == dfield_get_len(dtuple_get_nth_field(row, 2)));
- ut_a(0 == ut_memcmp(
- dfield_get_data(dtuple_get_nth_field(row, 2)),
- "12345678901234567890123456789", 30));
-
- mem_heap_free(heap2);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-}
-
-/*********************************************************************
-Test for massive updates. */
-
-ulint
-test4mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4. MULTITHREADED UPDATES\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 300; i++) {
-
- rnd += 874681;
- tuple_no = (rnd % 40) * 5 + thr_no;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 3000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- btr_validate_tree(tree);
-
- ut_a(trx->conc_state != TRX_ACTIVE);
- ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
-
- count++;
-
- if (count < 2) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for join. */
-
-ulint
-test6(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ulint count = 0;
- dtuple_t* entry;
- dict_index_t* index;
- dict_tree_t* tree;
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- ulint rnd;
- ulint latch_mode;
-
- printf("-------------------------------------------------\n");
- printf("TEST 6. MASSIVE EQUIJOIN\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*--------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
- /*--------------*/
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- table = dict_table_get("TS_TABLE1", trx);
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- oldtm = ut_clock();
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IS, thr));
-
- rnd = 98651;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- btr_pcur_store_position(&pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-
- btr_pcur_commit_specify_mtr(&pcur, &mtr);
-
- if (i % 1211 == 0) {
- dummy++;
- }
-
- rnd = 55321;
-
- dtuple_gen_search_tuple3(entry, rnd % *((ulint*)arg), buf);
-
-/* if (i == 0) { */
- latch_mode = BTR_SEARCH_LEAF;
-/* } else {
- latch_mode = BTR_SEARCH_LEAF | BTR_GUESS_LATCH;
- } */
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, latch_mode,
- &pcur2, &mtr2);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur2),
- index));
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur2)));
-
- mtr_commit(&mtr2);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for join of %lu rows %lu milliseconds\n",
- i, tm - oldtm);
- btr_search_index_print_info(index);
- /*-------------------------------------*/
- /* COMMIT */
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-/* printf("Wall time for commit %lu milliseconds\n", tm - oldtm); */
-
- /*-------------------------------------*/
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 3) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for lock wait. Requires Test 4.1 first. */
-
-ulint
-test7(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- trx_t* trx2;
- ulint rnd;
- dtuple_t* entry;
- dtuple_t* row;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 7. LOCK WAIT\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx2 = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- /* UPDATE by trx */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- ut_a(trx_start(trx2, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- rnd += 874681;
- tuple_no = 3;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 1500);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* INSERT by trx2 */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx2;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx2);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx2->sess);
-
- trx2->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- dtuple_gen_test_tuple3(row, 2, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- /* Insert should be left to wait until trx releases the row lock */
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* COMMIT of trx */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- /*-------------------------------------*/
- os_thread_sleep(1000000);
-
- printf(
- "trx2 can now continue to do the insert, after trx committed.\n");
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-A. */
-
-ulint
-test8A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 8A. 1000 INSERTS FOR TPC-A\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE2", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_test_tuple_TPC_A(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_search_tuple_TPC_A(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE2"); */
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-A transaction. */
-
-ulint
-test8(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 8. TPC-A %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE2", trx);
-
- update = upd_create(1, heap);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-
-loop:
-/* printf("Round %lu\n", count); */
-
- /*-------------------------------------*/
- /* INSERT */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-------------------------------------*/
- /* 3 UPDATES */
-
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
- for (i = 0; i < 3; i++) {
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_A(entry, rnd % 1000, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
-/* ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur))); */
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- tm = ut_clock();
- printf("Wall time for TPC-A %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-
-
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-C. */
-
-ulint
-test9A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-/* dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
- dict_index_t* index;
- dict_tree_t* tree;
-*/
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 9A. INSERTS FOR TPC-C\n");
-
-#define TPC_C_TABLE_SIZE 15000
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE4", trx);
-
- row = dtuple_create(heap, 12 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_test_tuple_TPC_C(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-#endif
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE4"); */
-
-/* mem_heap_free(heap); */
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-C transaction. Test 9A must be run first to populate table. */
-
-ulint
-test9(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint j;
- ulint i;
- byte* ptr;
- ulint len;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
- byte buf2[240];
- rec_t* rec;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 9. TPC-C %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE4", trx);
-
- update = upd_create(3, heap);
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 2);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-loop:
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IS, thr));
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
-/* printf("Round %lu\n", count); */
-
-for (j = 0; j < 13; j++) {
-
- /*-------------------------------------*/
- /* SELECT FROM 'ITEM' */
-
- rnd += 876751;
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_S, thr);
- ut_a(err == DB_SUCCESS);
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 5; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* UPDATE 'STOCK' */
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 10; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
-/* btr_pcur_commit(&pcur); */
-
-/* err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr); */
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-/* ut_a(err == DB_SUCCESS); */
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 1);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 2);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- btr_pcur_close(&pcur);
- /*-------------------------------------*/
- /* INSERT INTO 'ORDERLINE' */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count * 13 + j, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-}
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
- tm = ut_clock();
- printf("Wall time for TPC-C %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Init for purge test. */
-
-ulint
-test10_1(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.1. PURGE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i * 100 + thr_no,
- DTUPLE_TEST_FIXED30, buf);
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 200);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2_r(
-/*=======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 2000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_3(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.3. PURGE TEST DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- rnd = i;
- tuple_no = rnd;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_5(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.5. PURGE TEST UNCOMMITTED DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 50; i++) {
-
- rnd = i;
- tuple_no = rnd % 100;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for purge. */
-
-ulint
-test10mt(
-/*=====*/
- void* arg)
-{
- ulint i;
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("Thread %lu starts purge test\n", thr_no);
-
- for (i = 0; i < 2; i++) {
- test10_1(arg);
-
- sync_print();
-
- fsp_validate(0);
-
- test10_2_r(arg);
- sync_print();
-
- test10_2(arg);
- sync_print();
-
- lock_validate();
-
- test10_3(arg);
- sync_print();
- }
-
- printf("Thread %lu ends purge test\n", thr_no);
-
- return(0);
-}
-
-/*********************************************************************
-Purge test. */
-
-ulint
-test10_4(
-/*=====*/
- void* arg)
-{
- ulint i;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.4. PURGE TEST\n");
-
- for (i = 0; i < 30; i++) {
- trx_purge();
-
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- os_thread_sleep(5000000);
- }
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to test insert buffer merge. */
-
-ulint
-test_ibuf_merge(
-/*============*/
- void* arg)
-{
- ulint sum_sizes;
- ulint volume;
-
- ut_ad(arg);
-
- printf("Starting ibuf merge\n");
-
- sum_sizes = 0;
- volume = 1;
-
- while (volume) {
- volume = ibuf_contract(FALSE);
-
- sum_sizes += volume;
- }
-
- printf("Ibuf merged %lu bytes\n", sum_sizes);
-
- os_thread_sleep(5000000);
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint count;
-
- ut_ad(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
- count = 0;
-
- for (j = 0; j < 100; j++) {
-
- os_thread_sleep(10000);
-
- if ((&(buf_pool->mutex))->lock_word) {
-
- count++;
- }
- }
-
- printf("Mutex reserved %lu of %lu peeks\n", count, j);
- }
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint n5000 = 500;
- ulint err;
-
- oldtm = ut_clock();
-
-/* buf_debug_prints = TRUE; */
- log_do_write = TRUE;
- log_debug_writes = FALSE;
-/* btr_search_use_hash = FALSE; */
-
- srv_boot("initfile");
- os_aio_init(576, 9, 100);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
- lock_sys_create(1024);
-
- create_files();
- create_log_files();
-
- sess_sys_init_at_db_start();
-
- mem_validate();
-
- /* Tests crash recovery: */
-/*
- err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
- ut_dulint_max);
- ut_a(err == DB_SUCCESS);
-
- recv_compare_spaces_low(0, 4, 100);
-
- trx_sys_init_at_db_start();
-
- dict_boot();
-
- recv_recovery_from_checkpoint_finish();
-*/
- /* Tests archive recovery: */
-
- err = recv_recovery_from_archive_start(ut_dulint_max,
- "ib_arch_log_0_0000000000");
- ut_a(err == DB_SUCCESS);
-
- recv_compare_spaces_low(0, 4, 500);
-
- trx_sys_init_at_db_start();
-
- dict_boot();
-
- recv_recovery_from_archive_finish();
-
-/* test4_2(); */
-
- log_make_checkpoint_at(ut_dulint_max);
-
-/* dict_table_print_by_name("SYS_TABLES");
-
- dict_table_print_by_name("SYS_COLUMNS");
-
- dict_table_print_by_name("SYS_INDEXES"); */
-
- dict_table_print_by_name("TS_TABLE1");
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tsrecv97.c b/innobase/btr/ts/tsrecv97.c
deleted file mode 100644
index 0f30fcd94f1..00000000000
--- a/innobase/btr/ts/tsrecv97.c
+++ /dev/null
@@ -1,4909 +0,0 @@
-/************************************************************************
-Test for the B-tree
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "log0recv.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "row0del.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 3 /* must be >= 2 */
-#define N_FILES 1
-#define FILE_SIZE 512 /* must be > 512 */
-#define POOL_SIZE 1000
-#define IBUF_SIZE 200
-#define COUNTER_OFFSET 1500
-
-#define N_LOG_GROUPS 2
-#define N_LOG_FILES 3
-#define LOG_FILE_SIZE 500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-#define COUNT 1
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-ulint dummy = 0;
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- ulint i;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates or opens the log files. */
-
-void
-create_log_files(void)
-/*==================*/
-{
- bool ret;
- ulint i, k;
- char name[20];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open log files\n");
-
- strcpy(name, "logfile00");
-
- for (k = 0; k < N_LOG_GROUPS; k++) {
- for (i = 0; i < N_LOG_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_AIO,
- &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * LOG_FILE_SIZE, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k + 100, FIL_LOG);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, LOG_FILE_SIZE, k + 100);
- }
-
- fil_space_create(name, k + 200, FIL_LOG);
-
- log_group_init(k, N_LOG_FILES, LOG_FILE_SIZE * UNIV_PAGE_SIZE,
- k + 100, k + 200);
- }
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < 2 * N_SPACES; k += 2) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_AIO, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- if (k == 1) {
- ut_a(os_file_set_size(files[i],
- 8192 * IBUF_SIZE, 0));
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * FILE_SIZE, 0));
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, FIL_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0,
- DICT_UNIQUE | DICT_CLUSTERED, 1);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* CREATE YET ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND4", 0, 0, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-#endif
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE2", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE2", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_6(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.6. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE3", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE3", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_7(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.7. CREATE TABLE WITH 12 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE4", 0, 12);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL4", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL5", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL6", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL7", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL8", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL9", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL10", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL11", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- dict_mem_table_add_col(table, "COL12", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE4", "IND1", 0,
- DICT_CLUSTERED | DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for inserts. */
-
-ulint
-test2(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- dict_index_t* index;
-/* ulint size; */
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. MASSIVE INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- /* MASSIVE RANDOM INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd,
- DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
- printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print();
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-/*
- for (i = 0; i < 10; i++) {
- size = ibuf_contract(TRUE);
-
- printf("%lu bytes will be contracted\n", size);
-
- os_thread_sleep(1000000);
- }
-*/
- index = dict_table_get_next_index(dict_table_get_first_index(table));
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- index = dict_table_get_next_index(index);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- btr_search_print_info();
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 7857641) % 200000;
- dtuple_gen_search_tuple3(entry, rnd, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
-/* btr_print_tree(tree, 5); */
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- btr_validate_tree(tree);
-
-/* btr_search_print_info();
- dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_1(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ins_node_t* node;
- ulint count = 0;
- ulint rnd;
- dtuple_t* row;
-/* dict_tree_t* tree;
- dict_index_t* index;
- dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr; */
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1. MASSIVE ASCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- rnd = 0;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND3500, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 5000 == 0) {
- /* ibuf_print(); */
- /* buf_print(); */
-
- /* buf_print_io(); */
-
- tm = ut_clock();
- /*
- printf("Wall time for %lu inserts %lu milliseconds\n",
- i, tm - oldtm); */
- }
-
- rnd = rnd + 1;
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- ibuf_print();
-
- index = dict_table_get_first_index(table);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
- index = dict_table_get_next_index(index);
-
- btr_search_index_print_info(index);
-
- btr_validate_tree(dict_index_get_tree(index));
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- /* Check inserted entries */
-
- btr_search_print_info();
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-#endif
-#ifdef notdefined
- /*-------------------------------------*/
- /* ROLLBACK */
-
-/* btr_validate_tree(tree); */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_search_print_info();
-
-#endif
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
- /*-------------------------------------*/
-
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 5) {
- goto loop;
- }
-
- mem_heap_free(heap);
-
- return(0);
-}
-
-/*********************************************************************
-Another test for inserts. */
-
-ulint
-test2_2(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2. MASSIVE DESCENDING INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = *((ulint*)arg) + 1;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- if (i % 1000 == 0) {
-/* printf(
- "********************************Inserted %lu rows\n", i);
- ibuf_print(); */
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < *((ulint*)arg); i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i + 1, buf);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- btr_validate_tree(tree);
-/* dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(1000000);
-
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
-
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- btr_validate_tree(tree);
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for random inserts. */
-
-ulint
-test2mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2MT. MULTITHREADED RANDOM INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
- rnd = 78675;
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- if (i % 100 == 0) {
-/* buf_print(); */
-/* ibuf_print(); */
- }
-
- rnd = (rnd + 7857641) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_1mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.1MT. MULTITHREADED ASCENDING INSERT\n");
-
- rnd = 8757677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 98667501;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for multithreaded sequential inserts. */
-
-ulint
-test2_2mt(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2.2MT. MULTITHREADED DESCENDING INSERT\n");
-
- rnd = 87677;
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- rnd += 78667;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd - 1) % 500;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(3000000);
- /*-------------------------------------*/
-#ifdef notdefined
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-#endif
- /*-------------------------------------*/
- count++;
-
- mem_print_info();
-
- if (count < COUNT) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for updates. */
-
-ulint
-test3(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
- ulint err;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 3. UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 3; i++) {
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_RND30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_RND30, buf);
-
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-#ifdef notdefined
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Init for update test. */
-
-ulint
-test4_1(void)
-/*=========*/
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.1. UPDATE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*************************************************************************
-Checks that the multithreaded update test has rolled back its updates. */
-
-void
-test4_2(void)
-/*=========*/
-{
- dtuple_t* entry;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- mtr_t mtr;
- byte buf[32];
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- btr_pcur_t pcur;
- rec_t* rec;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4.2. CHECK UPDATE RESULT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*------------------------------------------*/
-
- table = dict_table_get("TS_TABLE1", trx);
-
- index = dict_table_get_first_index(table);
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
- ut_a(btr_pcur_is_before_first_in_tree(&pcur, &mtr));
-
- for (i = 0; i < 200; i++) {
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- dtuple_gen_search_tuple3(entry, i, buf);
-
- rec = btr_pcur_get_rec(&pcur);
-
- ut_a(0 == cmp_dtuple_rec(entry, rec));
-
- heap2 = mem_heap_create(200);
-
- row = row_build(ROW_COPY_DATA, index, rec, heap2);
-
- ut_a(30 == dfield_get_len(dtuple_get_nth_field(row, 2)));
- ut_a(0 == ut_memcmp(
- dfield_get_data(dtuple_get_nth_field(row, 2)),
- "12345678901234567890123456789", 30));
-
- mem_heap_free(heap2);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-}
-
-/*********************************************************************
-Test for massive updates. */
-
-ulint
-test4mt(
-/*====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4. MULTITHREADED UPDATES\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 300; i++) {
-
- rnd += 874681;
- tuple_no = (rnd % 40) * 5 + thr_no;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 3000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- btr_validate_tree(tree);
-
- ut_a(trx->conc_state != TRX_ACTIVE);
- ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
-
- count++;
-
- if (count < 2) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for join. */
-
-ulint
-test6(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- byte buf[100];
- ulint count = 0;
- dtuple_t* entry;
- dict_index_t* index;
- dict_tree_t* tree;
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- ulint rnd;
- ulint latch_mode;
-
- printf("-------------------------------------------------\n");
- printf("TEST 6. MASSIVE EQUIJOIN\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*--------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
- /*--------------*/
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /* Check inserted entries */
-
- entry = dtuple_create(heap, 1);
- dtuple_gen_search_tuple3(entry, 0, buf);
-
- mtr_start(&mtr);
-
- table = dict_table_get("TS_TABLE1", trx);
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- oldtm = ut_clock();
-
- btr_pcur_open(index, entry, PAGE_CUR_L, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IS, thr));
-
- rnd = 98651;
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- btr_pcur_store_position(&pcur, &mtr);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-
- btr_pcur_commit_specify_mtr(&pcur, &mtr);
-
- if (i % 1211 == 0) {
- dummy++;
- }
-
- rnd = 55321;
-
- dtuple_gen_search_tuple3(entry, rnd % *((ulint*)arg), buf);
-
-/* if (i == 0) { */
- latch_mode = BTR_SEARCH_LEAF;
-/* } else {
- latch_mode = BTR_SEARCH_LEAF | BTR_GUESS_LATCH;
- } */
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, latch_mode,
- &pcur2, &mtr2);
-
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur2),
- index));
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur2)));
-
- mtr_commit(&mtr2);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
- }
-
- ut_a(!btr_pcur_move_to_next(&pcur, &mtr));
- ut_a(btr_pcur_is_after_last_in_tree(&pcur, &mtr));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for join of %lu rows %lu milliseconds\n",
- i, tm - oldtm);
- btr_search_index_print_info(index);
- /*-------------------------------------*/
- /* COMMIT */
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-/* printf("Wall time for commit %lu milliseconds\n", tm - oldtm); */
-
- /*-------------------------------------*/
- count++;
-/* btr_validate_tree(tree); */
-
- if (count < 3) {
- goto loop;
- }
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for lock wait. Requires Test 4.1 first. */
-
-ulint
-test7(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- trx_t* trx2;
- ulint rnd;
- dtuple_t* entry;
- dtuple_t* row;
- byte buf[100];
- byte buf2[4000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 7. LOCK WAIT\n");
-
- thr_no = *((ulint*)arg);
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx2 = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- /* UPDATE by trx */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- ut_a(trx_start(trx2, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- rnd += 874681;
- tuple_no = 3;
-
- dtuple_gen_search_tuple3(entry, tuple_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 2, table);
- dfield_set_data(&(ufield->new_val), buf2, rnd % 1500);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* INSERT by trx2 */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx2;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx2);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx2->sess);
-
- trx2->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- dtuple_gen_test_tuple3(row, 2, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- /* Insert should be left to wait until trx releases the row lock */
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- lock_validate();
-
- lock_print_info();
-
- /*-------------------------------------*/
- /* COMMIT of trx */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
-
- /*-------------------------------------*/
- os_thread_sleep(1000000);
-
- printf(
- "trx2 can now continue to do the insert, after trx committed.\n");
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
- lock_validate();
-
- lock_print_info();
-
- dict_table_print_by_name("TS_TABLE1");
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-A. */
-
-ulint
-test8A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- dict_index_t* index;
- dict_tree_t* tree;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
- btr_pcur_t pcur;
- mtr_t mtr;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 8A. 1000 INSERTS FOR TPC-A\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE2", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_test_tuple_TPC_A(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < 1000; i++) {
- dtuple_gen_search_tuple_TPC_A(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE2"); */
-
- mem_heap_free(heap);
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-A transaction. */
-
-ulint
-test8(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 8. TPC-A %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE2", trx);
-
- update = upd_create(1, heap);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-
-loop:
-/* printf("Round %lu\n", count); */
-
- /*-------------------------------------*/
- /* INSERT */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-------------------------------------*/
- /* 3 UPDATES */
-
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
- for (i = 0; i < 3; i++) {
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_A(entry, rnd % 1000, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
-/* ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur))); */
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- tm = ut_clock();
- printf("Wall time for TPC-A %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-
-
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Inserts for TPC-C. */
-
-ulint
-test9A(
-/*===*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-/* dtuple_t* entry;
- btr_pcur_t pcur;
- mtr_t mtr;
- dict_index_t* index;
- dict_tree_t* tree;
-*/
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 9A. INSERTS FOR TPC-C\n");
-
-#define TPC_C_TABLE_SIZE 15000
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- btr_search_print_info();
-
- /*-------------------------------------*/
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE4", trx);
-
- row = dtuple_create(heap, 12 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_test_tuple_TPC_C(row, rnd, buf);
-
- rnd = rnd + 1;
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
- btr_validate_tree(tree);
-
- /* Check inserted entries */
- rnd = 0;
-
- entry = dtuple_create(heap, 1);
-
- for (i = 0; i < TPC_C_TABLE_SIZE; i++) {
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd, buf);
-
- rnd = rnd + 1;
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur,
- &mtr);
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- btr_pcur_close(&pcur);
- mtr_commit(&mtr);
- }
-
- btr_validate_tree(tree);
-#endif
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
-
-/* dict_table_print_by_name("TS_TABLE4"); */
-
-/* mem_heap_free(heap); */
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-C transaction. Test 9A must be run first to populate table. */
-
-ulint
-test9(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint j;
- ulint i;
- byte* ptr;
- ulint len;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
- ulint rnd = 0;
- byte buf2[240];
- rec_t* rec;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 9. TPC-C %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE4", trx);
-
- update = upd_create(3, heap);
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table2);
- ufield = upd_get_nth_field(update, 2);
-
- upd_field_set_col_no(ufield, 1, table2);
-
- entry = dtuple_create(heap, 1);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-loop:
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IS, thr));
- ut_a(DB_SUCCESS == lock_table(0, table2, LOCK_IX, thr));
-
-/* printf("Round %lu\n", count); */
-
-for (j = 0; j < 13; j++) {
-
- /*-------------------------------------*/
- /* SELECT FROM 'ITEM' */
-
- rnd += 876751;
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_S, thr);
- ut_a(err == DB_SUCCESS);
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 5; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
- mtr_commit(&mtr);
-
- /*-------------------------------------*/
- /* UPDATE 'STOCK' */
-
- rnd += 876751;
-
- if (count % 1231 == 0) {
- dummy++;
- }
-
- dtuple_gen_search_tuple_TPC_C(entry, rnd % TPC_C_TABLE_SIZE, buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_LEAF, &pcur, &mtr);
-
- ut_a(0 == cmp_dtuple_rec(entry, btr_pcur_get_rec(&pcur)));
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- rec = btr_pcur_get_rec(&pcur);
-
- for (i = 0; i < 10; i++) {
- ptr = rec_get_nth_field(rec, i + 2, &len);
-
- ut_memcpy(buf2 + i * 24, ptr, len);
- }
-
-/* btr_pcur_commit(&pcur); */
-
-/* err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr); */
- ut_a(DB_SUCCESS == lock_clust_rec_cons_read_check(
- btr_pcur_get_rec(&pcur),
- index));
-/* ut_a(err == DB_SUCCESS); */
-
- ufield = upd_get_nth_field(update, 0);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 1);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- ufield = upd_get_nth_field(update, 2);
-
- dfield_set_data(&(ufield->new_val), "1234", 5);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- btr_pcur_close(&pcur);
- /*-------------------------------------*/
- /* INSERT INTO 'ORDERLINE' */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count * 13 + j, DTUPLE_TEST_FIXED30, buf);
-
- ins_node_reset(inode);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-}
- /*-------------------------------------*/
- /* COMMIT */
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
- count++;
-
- if (count < *((ulint*)arg)) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
- tm = ut_clock();
- printf("Wall time for TPC-C %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- btr_search_index_print_info(index);
- btr_search_index_print_info(dict_table_get_first_index(table));
-
-/* mem_print_info(); */
- /*-------------------------------------*/
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/*********************************************************************
-Init for purge test. */
-
-ulint
-test10_1(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.1. PURGE INIT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200; i++) {
-
- dtuple_gen_test_tuple3(row, i * 100 + thr_no,
- DTUPLE_TEST_FIXED30, buf);
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 200);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_2_r(
-/*=======*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- byte buf2[1000];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.2. PURGE TEST UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- update = upd_create(2, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 87607651;
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- tuple_no = i;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- upd_field_set_col_no(ufield, 0, table);
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- dfield_set_data(&(ufield->new_val), dfield_get_data(
- dtuple_get_nth_field(entry, 0)),
- dfield_get_len(
- dtuple_get_nth_field(entry, 0)));
- ufield = upd_get_nth_field(update, 1);
-
- upd_field_set_col_no(ufield, 1, table);
-
- rnd += 98326761;
-
- dfield_set_data(&(ufield->new_val), buf2, rnd % 2000);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- fsp_validate(0);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
- mem_pool_print_info(mem_comm_pool);
-
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-
- os_thread_sleep(2000000);
-
- count++;
-
- if (count < 1) {
-
- goto loop;
- }
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_3(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.3. PURGE TEST DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 200; i++) {
-
- rnd = i;
- tuple_no = rnd;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-/*********************************************************************
-Test for purge. */
-
-ulint
-test10_5(
-/*=====*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* entry;
- byte buf[100];
- btr_pcur_t pcur;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- del_node_t* node;
- ulint err;
- ulint thr_no;
- ulint tuple_no;
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.5. PURGE TEST UNCOMMITTED DELETES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- /*-------------------------------------*/
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- node = del_node_create(fork, thr, table, &pcur, heap);
- thr->child = node;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- entry = dtuple_create(heap, 1);
-
- oldtm = ut_clock();
-
- thr_no = *((ulint*)arg);
-
- ut_a(DB_SUCCESS == lock_table(0, table, LOCK_IX, thr));
-
- for (i = 0; i < 50; i++) {
-
- rnd = i;
- tuple_no = rnd % 100;
-
- dtuple_gen_search_tuple3(entry, tuple_no * 100 + 10 + thr_no, buf);
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
-/* printf("Thread %lu to update row %lu\n", thr_no, tuple_no); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- tm = ut_clock();
- printf("Wall time for %lu delete markings %lu milliseconds\n",
- i, tm - oldtm);
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- printf("Validating tree\n");
- btr_validate_tree(tree);
- printf("Validated\n");
-
-/* lock_print_info(); */
-
-/* mem_print_info(); */
-
- return(0);
-}
-
-/*********************************************************************
-Multithreaded test for purge. */
-
-ulint
-test10mt(
-/*=====*/
- void* arg)
-{
- ulint i;
- ulint thr_no;
-
- thr_no = *((ulint*)arg);
-
- printf("Thread %lu starts purge test\n", thr_no);
-
- for (i = 0; i < 2; i++) {
- test10_1(arg);
-
- sync_print();
-
- fsp_validate(0);
-
- test10_2_r(arg);
- sync_print();
-
- test10_2(arg);
- sync_print();
-
- lock_validate();
-
- test10_3(arg);
- sync_print();
- }
-
- printf("Thread %lu ends purge test\n", thr_no);
-
- return(0);
-}
-
-/*********************************************************************
-Purge test. */
-
-ulint
-test10_4(
-/*=====*/
- void* arg)
-{
- ulint i;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 10.4. PURGE TEST\n");
-
- for (i = 0; i < 30; i++) {
- trx_purge();
-
- printf("%lu pages purged\n", purge_sys->n_pages_handled);
-
- os_thread_sleep(5000000);
- }
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to test insert buffer merge. */
-
-ulint
-test_ibuf_merge(
-/*============*/
- void* arg)
-{
- ulint sum_sizes;
- ulint volume;
-
- ut_ad(arg);
-
- printf("Starting ibuf merge\n");
-
- sum_sizes = 0;
- volume = 1;
-
- while (volume) {
- volume = ibuf_contract(FALSE);
-
- sum_sizes += volume;
- }
-
- printf("Ibuf merged %lu bytes\n", sum_sizes);
-
- os_thread_sleep(5000000);
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint count;
-
- ut_ad(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
- count = 0;
-
- for (j = 0; j < 100; j++) {
-
- os_thread_sleep(10000);
-
- if ((&(buf_pool->mutex))->lock_word) {
-
- count++;
- }
- }
-
- printf("Mutex reserved %lu of %lu peeks\n", count, j);
- }
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint n5000 = 500;
- ulint err;
-
- oldtm = ut_clock();
-
-/* buf_debug_prints = TRUE; */
- log_do_write = TRUE;
- log_debug_writes = FALSE;
-/* btr_search_use_hash = FALSE; */
-
- srv_boot("initfile");
- os_aio_init(576, 9, 100);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
- lock_sys_create(1024);
-
- create_files();
- create_log_files();
-
- sess_sys_init_at_db_start();
-
- mem_validate();
-
- /* Tests crash recovery: */
-/*
- err = recv_recovery_from_checkpoint_start(LOG_CHECKPOINT,
- ut_dulint_max);
- ut_a(err == DB_SUCCESS);
-
- recv_compare_spaces_low(0, 4, 100);
-
- trx_sys_init_at_db_start();
-
- dict_boot();
-
- recv_recovery_from_checkpoint_finish();
-*/
- /* Tests archive recovery: */
-
- err = recv_recovery_from_archive_start(ut_dulint_max,
- "ib_arch_log_0_0000000000");
- ut_a(err == DB_SUCCESS);
-
- recv_compare_spaces_low(0, 4, 500);
-
- trx_sys_init_at_db_start();
-
- dict_boot();
-
- recv_recovery_from_archive_finish();
-
-/* test4_2(); */
-
- log_make_checkpoint_at(ut_dulint_max);
-
-/* dict_table_print_by_name("SYS_TABLES");
-
- dict_table_print_by_name("SYS_COLUMNS");
-
- dict_table_print_by_name("SYS_INDEXES"); */
-
- dict_table_print_by_name("TS_TABLE1");
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/btr/ts/tss.c b/innobase/btr/ts/tss.c
deleted file mode 100644
index 4af3fda4415..00000000000
--- a/innobase/btr/ts/tss.c
+++ /dev/null
@@ -1,397 +0,0 @@
-/************************************************************************
-Test for the server
-
-(c) 1996-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "buf0flu.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "log0recv.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0sel.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-#include "pars0pars.h"
-#include "btr0sea.h"
-
-bool measure_cont = FALSE;
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte rnd_buf[67000];
-
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- ulint i;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates or opens the log files. */
-
-void
-create_log_files(void)
-/*==================*/
-{
- bool ret;
- ulint i, k;
- char name[20];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open log files\n");
-
- strcpy(name, "logfile00");
-
- for (k = 0; k < srv_n_log_groups; k++) {
-
- for (i = 0; i < srv_n_log_files; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_AIO,
- &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * srv_log_file_size, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k + 100, FIL_LOG);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, srv_log_file_size, k + 100);
- }
-
- fil_space_create(name, k + 200, FIL_LOG);
-
- log_group_init(k, srv_n_log_files,
- srv_log_file_size * UNIV_PAGE_SIZE,
- k + 100, k + 200);
- }
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < 2 * srv_n_spaces; k += 2) {
- for (i = 0; i < srv_n_files; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_NORMAL, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_NORMAL, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- UNIV_PAGE_SIZE * srv_file_size, 0));
- /* Initialize the file contents to a random value */
- /*
- for (j = 0; j < srv_file_size; j++) {
-
- for (c = 0; c < UNIV_PAGE_SIZE; c++) {
-
- rnd_buf[c] = 0xFF;
- }
-
- os_file_write(files[i], rnd_buf,
- UNIV_PAGE_SIZE * j, 0,
- UNIV_PAGE_SIZE);
- }
- */
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, FIL_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, srv_file_size, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- /* Create i/o-handler threads: */
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space. */
-
-void
-init_spaces(void)
-/*=============*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- fsp_header_init(0, srv_file_size * srv_n_files, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j, k;
- ulint count[8];
- ulint lcount[8];
- ulint lscount;
- ulint lkcount;
- ulint pcount, kcount, scount;
-
- UT_NOT_USED(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
-
- for (k = 0; k < 8; k++) {
- count[k] = 0;
- lcount[k] = 0;
- }
-
- pcount = 0;
- kcount = 0;
- scount = 0;
- lscount = 0;
- lkcount = 0;
-
- for (j = 0; j < 100; j++) {
-
- if (srv_measure_by_spin) {
- ut_delay(ut_rnd_interval(0, 20000));
- } else {
- os_thread_sleep(20000);
- }
-
- if (kernel_mutex.lock_word) {
- kcount++;
- }
-
- if (lock_kernel_reserved) {
- lkcount++;
- }
-
- if (buf_pool->mutex.lock_word) {
- pcount++;
- }
-
- if (btr_search_mutex.lock_word) {
- scount++;
- }
-
- for (k = 0; k < 8; k++) {
-
- if (btr_search_sys->
- hash_index->mutexes[k].lock_word) {
-
- count[k]++;
- }
- }
-
- for (k = 0; k < 2; k++) {
-
- if (lock_sys->rec_hash->mutexes[k].lock_word) {
-
- lcount[k]++;
- }
- }
-
- if (kernel_mutex.lock_word
- || lock_sys->rec_hash->mutexes[0].lock_word
- || lock_sys->rec_hash->mutexes[1].lock_word) {
-
- lscount++;
- }
- }
-
- printf(
-"Mutex res. p %lu, k %lu %lu, %lu %lu %lu s %lu, %lu %lu %lu %lu %lu %lu %lu %lu of %lu\n",
- pcount, kcount, lkcount, lcount[0], lcount[1], lscount, scount,
- count[0], count[1], count[2], count[3],
- count[4], count[5], count[6], count[7], j);
-
- sync_print_wait_info();
-
- printf("N log i/os %lu, n non sea %lu, n sea succ %lu\n",
- log_sys->n_log_ios, btr_cur_n_non_sea,
- btr_search_n_succ);
- }
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- os_thread_id_t thread_id;
-
- log_do_write = TRUE;
-/* yydebug = TRUE; */
-
- srv_boot("srv_init");
-
- os_aio_init(576, 9, 100);
-
- fil_init(25);
-
- buf_pool_init(srv_pool_size, srv_pool_size);
-
- fsp_init();
- log_init();
-
- lock_sys_create(srv_lock_table_size);
-
- create_files();
- create_log_files();
-
- init_spaces();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- dict_create();
-
- log_make_checkpoint_at(ut_dulint_max);
-
- if (srv_measure_contention) {
- os_thread_create(&test_measure_cont, NULL, &thread_id);
- }
-
- if (!srv_log_archive_on) {
-
- ut_a(DB_SUCCESS == log_archive_noarchivelog());
- }
-
- srv_master_thread();
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-
- os_process_exit(0);
-}
diff --git a/innobase/btr/ts/tssrv.c b/innobase/btr/ts/tssrv.c
deleted file mode 100644
index 78d247968d5..00000000000
--- a/innobase/btr/ts/tssrv.c
+++ /dev/null
@@ -1,535 +0,0 @@
-/************************************************************************
-Test for the server
-
-(c) 1996-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "os0proc.h"
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "mem0pool.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "buf0flu.h"
-#include "os0file.h"
-#include "os0thread.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "log0recv.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "btr0cur.h"
-#include "btr0sea.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "trx0purge.h"
-#include "row0ins.h"
-#include "row0sel.h"
-#include "row0upd.h"
-#include "row0row.h"
-#include "lock0lock.h"
-#include "ibuf0ibuf.h"
-#include "pars0pars.h"
-#include "btr0sea.h"
-
-bool measure_cont = FALSE;
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte rnd_buf[67000];
-
-ulint glob_var1 = 0;
-ulint glob_var2 = 0;
-
-mutex_t mutex2;
-
-mutex_t test_mutex1;
-mutex_t test_mutex2;
-
-mutex_t* volatile mutexes;
-
-bool always_false = FALSE;
-
-ulint* test_array;
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- ulint i;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- fil_aio_wait(segment);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates or opens the log files. */
-
-void
-create_log_files(void)
-/*==================*/
-{
- bool ret;
- ulint i, k;
- char name[20];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open log files\n");
-
- strcpy(name, "logfile00");
-
- for (k = 0; k < srv_n_log_groups; k++) {
-
- for (i = 0; i < srv_n_log_files; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_AIO,
- &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_AIO, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- 8192 * srv_log_file_size, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k + 100, FIL_LOG);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, srv_log_file_size, k + 100);
- }
-
- fil_space_create(name, k + 200, FIL_LOG);
-
- log_group_init(k, srv_n_log_files,
- srv_log_file_size * UNIV_PAGE_SIZE,
- k + 100, k + 200);
- }
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to the file
-system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[10];
- os_thread_id_t id[10];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < 2 * srv_n_spaces; k += 2) {
- for (i = 0; i < srv_n_files; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_NORMAL, &ret);
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN, OS_FILE_NORMAL, &ret);
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i],
- UNIV_PAGE_SIZE * srv_file_size, 0));
- /* Initialize the file contents to a random value */
- /*
- for (j = 0; j < srv_file_size; j++) {
-
- for (c = 0; c < UNIV_PAGE_SIZE; c++) {
-
- rnd_buf[c] = 0xFF;
- }
-
- os_file_write(files[i], rnd_buf,
- UNIV_PAGE_SIZE * j, 0,
- UNIV_PAGE_SIZE);
- }
- */
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, FIL_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, srv_file_size, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
- mutex_set_level(&ios_mutex, SYNC_NO_ORDER_CHECK);
-
- /* Create i/o-handler threads: */
-
- for (i = 0; i < 9; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space. */
-
-void
-init_spaces(void)
-/*=============*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- fsp_header_init(0, srv_file_size * srv_n_files, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-This thread is used to measure contention of latches. */
-
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint pcount, kcount, s_scount, s_xcount, s_mcount, lcount;
- ulint t1count;
- ulint t2count;
-
- UT_NOT_USED(arg);
-
- printf("Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
-
- pcount = 0;
- kcount = 0;
- s_scount = 0;
- s_xcount = 0;
- s_mcount = 0;
- lcount = 0;
- t1count = 0;
- t2count = 0;
-
- for (j = 0; j < 100; j++) {
-
- if (srv_measure_by_spin) {
- ut_delay(ut_rnd_interval(0, 20000));
- } else {
- os_thread_sleep(20000);
- }
-
- if (kernel_mutex.lock_word) {
- kcount++;
- }
-
- if (buf_pool->mutex.lock_word) {
- pcount++;
- }
-
- if (log_sys->mutex.lock_word) {
- lcount++;
- }
-
- if (btr_search_latch.reader_count) {
- s_scount++;
- }
-
- if (btr_search_latch.writer != RW_LOCK_NOT_LOCKED) {
- s_xcount++;
- }
-
- if (btr_search_latch.mutex.lock_word) {
- s_mcount++;
- }
-
- if (test_mutex1.lock_word) {
- t1count++;
- }
-
- if (test_mutex2.lock_word) {
- t2count++;
- }
- }
-
- printf(
- "Mutex res. l %lu, p %lu, k %lu s x %lu s s %lu s mut %lu of %lu\n",
- lcount, pcount, kcount, s_xcount, s_scount, s_mcount, j);
-
- sync_print_wait_info();
-
- printf(
- "log i/o %lu n non sea %lu n succ %lu n h fail %lu\n",
- log_sys->n_log_ios, btr_cur_n_non_sea,
- btr_search_n_succ, btr_search_n_hash_fail);
- }
-
- return(0);
-}
-
-/*********************************************************************
-This thread is used to test contention of latches. */
-
-ulint
-test_sync(
-/*======*/
- void* arg)
-{
- ulint tm, oldtm;
- ulint i, j;
- ulint sum;
- ulint rnd = ut_rnd_gen_ulint();
- ulint mut_ind;
- byte* ptr;
-
- UT_NOT_USED(arg);
-
- printf("Starting mutex reservation test\n");
-
- oldtm = ut_clock();
-
- sum = 0;
- rnd = 87354941;
-
- for (i = 0; i < srv_test_n_loops; i++) {
-
- for (j = 0; j < srv_test_n_free_rnds; j++) {
- rnd += 423087123;
-
- sum += test_array[rnd % (256 * srv_test_array_size)];
- }
-
- rnd += 43605677;
-
- mut_ind = rnd % srv_test_n_mutexes;
-
- mutex_enter(mutexes + mut_ind);
-
- for (j = 0; j < srv_test_n_reserved_rnds; j++) {
- rnd += 423087121;
-
- sum += test_array[rnd % (256 * srv_test_array_size)];
- }
-
- mutex_exit(mutexes + mut_ind);
-
- if (srv_test_cache_evict) {
- ptr = (byte*)(mutexes + mut_ind);
-
- for (j = 0; j < 4; j++) {
- ptr += 256 * 1024;
- sum += *((ulint*)ptr);
- }
- }
- }
-
- if (always_false) {
- printf("%lu", sum);
- }
-
- tm = ut_clock();
-
- printf("Wall time for res. test %lu milliseconds\n", tm - oldtm);
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- os_thread_id_t thread_ids[1000];
- ulint tm, oldtm;
- ulint rnd;
- ulint i, sum;
- byte* ptr;
-/* mutex_t mutex; */
-
- log_do_write = TRUE;
-/* yydebug = TRUE; */
-
- srv_boot("srv_init");
-
- os_aio_init(576, 9, 100);
-
- fil_init(25);
-
- buf_pool_init(srv_pool_size, srv_pool_size);
-
- fsp_init();
- log_init();
-
- lock_sys_create(srv_lock_table_size);
-
- create_files();
- create_log_files();
-
- init_spaces();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- dict_create();
-
- log_make_checkpoint_at(ut_dulint_max);
-
- printf("Hotspot semaphore addresses k %lx, p %lx, l %lx, s %lx\n",
- &kernel_mutex, &(buf_pool->mutex),
- &(log_sys->mutex), &btr_search_latch);
-
- if (srv_measure_contention) {
- os_thread_create(&test_measure_cont, NULL, thread_ids + 999);
- }
-
- if (!srv_log_archive_on) {
-
- ut_a(DB_SUCCESS == log_archive_noarchivelog());
- }
-
-/*
- mutex_create(&mutex);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 2000000; i++) {
-
- mutex_enter(&mutex);
-
- mutex_exit(&mutex);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu mutex enter %lu milliseconds\n",
- i, tm - oldtm);
-*/
- if (srv_test_sync) {
- if (srv_test_nocache) {
- mutexes = os_mem_alloc_nocache(srv_test_n_mutexes
- * sizeof(mutex_t));
- } else {
- mutexes = mem_alloc(srv_test_n_mutexes
- * sizeof(mutex_t));
- }
-
- sum = 0;
-
- rnd = 492314896;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4000000; i++) {
-
- rnd += 85967944;
-
- ptr = ((byte*)(mutexes)) + (rnd % (srv_test_n_mutexes
- * sizeof(mutex_t)));
- sum += *((ulint*)ptr);
- }
-
- tm = ut_clock();
-
- printf(
- "Wall clock time for %lu random access %lu milliseconds\n",
- i, tm - oldtm);
- if (always_false) {
- printf("%lu", sum);
- }
-
- test_array = mem_alloc(4 * 256 * srv_test_array_size);
-
- for (i = 0; i < srv_test_n_mutexes; i++) {
-
- mutex_create(mutexes + i);
- }
-
- for (i = 0; i < srv_test_n_threads; i++) {
- os_thread_create(&test_sync, NULL, thread_ids + i);
- }
- }
-
- srv_master_thread(NULL);
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-
- os_process_exit(0);
-}
diff --git a/innobase/buf/buf0buf.c b/innobase/buf/buf0buf.c
index cbf12c9e55d..844880238fa 100644
--- a/innobase/buf/buf0buf.c
+++ b/innobase/buf/buf0buf.c
@@ -476,11 +476,11 @@ buf_block_init(
rw_lock_create(&(block->lock));
ut_ad(rw_lock_validate(&(block->lock)));
-
+
#ifdef UNIV_SYNC_DEBUG
rw_lock_create(&(block->debug_latch));
rw_lock_set_level(&(block->debug_latch), SYNC_NO_ORDER_CHECK);
-#endif
+#endif /* UNIV_SYNC_DEBUG */
}
/************************************************************************
@@ -1106,13 +1106,13 @@ loop:
buf_read_page(space, offset);
- #ifdef UNIV_DEBUG
+#ifdef UNIV_DEBUG
buf_dbg_counter++;
if (buf_dbg_counter % 37 == 0) {
ut_ad(buf_validate());
}
- #endif
+#endif
goto loop;
}
@@ -1325,9 +1325,9 @@ buf_page_optimistic_get_func(
}
if (!UT_DULINT_EQ(modify_clock, block->modify_clock)) {
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(block->frame, SYNC_NO_ORDER_CHECK);
-
+#endif /* UNIV_SYNC_DEBUG */
if (rw_latch == RW_S_LATCH) {
rw_lock_s_unlock(&(block->lock));
} else {
@@ -1527,7 +1527,9 @@ buf_page_init(
in units of a page */
buf_block_t* block) /* in: block to init */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state != BUF_BLOCK_FILE_PAGE);
/* Set the state of the block */
@@ -1813,21 +1815,6 @@ buf_page_io_complete(
"InnoDB: Error: page n:o stored in the page read in is %lu, should be %lu!\n",
(ulong) read_page_no, (ulong) block->offset);
}
-#ifdef notdefined
- if (block->offset != 0 && read_page_no == 0) {
- /* Check that the page is really uninited */
-
- for (i = 0; i < UNIV_PAGE_SIZE; i++) {
-
- if (*((block->frame) + i) != '\0') {
- fprintf(stderr,
-"InnoDB: Error: page n:o in the page read in is 0, but page %lu is inited!\n",
- block->offset);
- break;
- }
- }
- }
-#endif
/* From version 3.23.38 up we store the page checksum
to the 4 first bytes of the page end lsn field */
diff --git a/innobase/buf/buf0flu.c b/innobase/buf/buf0flu.c
index cdea764971e..c568d5925fa 100644
--- a/innobase/buf/buf0flu.c
+++ b/innobase/buf/buf0flu.c
@@ -48,7 +48,9 @@ buf_flush_insert_into_flush_list(
/*=============================*/
buf_block_t* block) /* in: block which is modified */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
@@ -76,7 +78,9 @@ buf_flush_insert_sorted_into_flush_list(
buf_block_t* prev_b;
buf_block_t* b;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
prev_b = NULL;
b = UT_LIST_GET_FIRST(buf_pool->flush_list);
@@ -108,7 +112,9 @@ buf_flush_ready_for_replace(
buf_block_t* block) /* in: buffer control block, must be in state
BUF_BLOCK_FILE_PAGE and in the LRU list */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
if ((ut_dulint_cmp(block->oldest_modification, ut_dulint_zero) > 0)
@@ -132,7 +138,9 @@ buf_flush_ready_for_flush(
BUF_BLOCK_FILE_PAGE */
ulint flush_type)/* in: BUF_FLUSH_LRU or BUF_FLUSH_LIST */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
if ((ut_dulint_cmp(block->oldest_modification, ut_dulint_zero) > 0)
@@ -163,8 +171,9 @@ buf_flush_write_complete(
buf_block_t* block) /* in: pointer to the block in question */
{
ut_ad(block);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
block->oldest_modification = ut_dulint_zero;
@@ -248,7 +257,7 @@ buf_flush_buffered_writes(void)
"InnoDB: files.\n",
(ulong) block->offset, (ulong) block->space);
- ut_a(0);
+ ut_error;
}
}
diff --git a/innobase/buf/buf0lru.c b/innobase/buf/buf0lru.c
index 23f399503c8..c5faec17890 100644
--- a/innobase/buf/buf0lru.c
+++ b/innobase/buf/buf0lru.c
@@ -299,7 +299,7 @@ buf_LRU_get_free_block(void)
buf_block_t* block = NULL;
ibool freed;
ulint n_iterations = 1;
- ibool mon_value_was = 0; /* remove bug */
+ ibool mon_value_was = FALSE;
ibool started_monitor = FALSE;
loop:
mutex_enter(&(buf_pool->mutex));
@@ -310,20 +310,26 @@ loop:
fprintf(stderr,
" InnoDB: ERROR: over 9 / 10 of the buffer pool is occupied by\n"
-"InnoDB: lock heaps or the adaptive hash index!\n"
+"InnoDB: lock heaps or the adaptive hash index! Check that your\n"
+"InnoDB: transactions do not set too many row locks.\n"
+"InnoDB: Your buffer pool size is %lu MB. Maybe you should make\n"
+"InnoDB: the buffer pool bigger?\n"
"InnoDB: We intentionally generate a seg fault to print a stack trace\n"
-"InnoDB: on Linux!\n");
+"InnoDB: on Linux!\n",
+ (ulong)(buf_pool->curr_size / (1024 * 1024 / UNIV_PAGE_SIZE)));
- ut_a(0);
+ ut_error;
} else if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->max_size / 5) {
+ if (!srv_print_innodb_monitor) {
- /* Over 80 % of the buffer pool is occupied by lock heaps
- or the adaptive hash index. This may be a memory leak! */
+ /* Over 80 % of the buffer pool is occupied by lock
+ heaps or the adaptive hash index. This may be a memory
+ leak! */
- ut_print_timestamp(stderr);
- fprintf(stderr,
+ ut_print_timestamp(stderr);
+ fprintf(stderr,
" InnoDB: WARNING: over 4 / 5 of the buffer pool is occupied by\n"
"InnoDB: lock heaps or the adaptive hash index! Check that your\n"
"InnoDB: transactions do not set too many row locks.\n"
@@ -333,8 +339,9 @@ loop:
"InnoDB: lock heap and hash index sizes.\n",
(ulong) (buf_pool->curr_size / (1024 * 1024 / UNIV_PAGE_SIZE)));
- srv_print_innodb_monitor = TRUE;
-
+ srv_print_innodb_monitor = TRUE;
+ os_event_set(srv_lock_timeout_thread_event);
+ }
} else if (!recv_recovery_on && UT_LIST_GET_LEN(buf_pool->free)
+ UT_LIST_GET_LEN(buf_pool->LRU) < buf_pool->max_size / 4) {
@@ -423,6 +430,7 @@ loop:
mon_value_was = srv_print_innodb_monitor;
started_monitor = TRUE;
srv_print_innodb_monitor = TRUE;
+ os_event_set(srv_lock_timeout_thread_event);
}
/* No free block was found: try to flush the LRU list */
@@ -467,7 +475,9 @@ buf_LRU_old_adjust_len(void)
ulint new_len;
ut_a(buf_pool->LRU_old);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(3 * (BUF_LRU_OLD_MIN_LEN / 8) > BUF_LRU_OLD_TOLERANCE + 5);
for (;;) {
@@ -540,7 +550,9 @@ buf_LRU_remove_block(
{
ut_ad(buf_pool);
ut_ad(block);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(block->in_LRU_list);
@@ -604,7 +616,9 @@ buf_LRU_add_block_to_end_low(
ut_ad(buf_pool);
ut_ad(block);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
@@ -667,7 +681,9 @@ buf_LRU_add_block_low(
ut_ad(buf_pool);
ut_ad(block);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
ut_a(!block->in_LRU_list);
@@ -768,7 +784,9 @@ buf_LRU_block_free_non_file_page(
/*=============================*/
buf_block_t* block) /* in: block, must not contain a file page */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(block);
ut_a((block->state == BUF_BLOCK_MEMORY)
@@ -805,7 +823,9 @@ buf_LRU_block_remove_hashed_page(
be in a state where it can be freed; there
may or may not be a hash index to the page */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(block);
ut_a(block->state == BUF_BLOCK_FILE_PAGE);
@@ -859,7 +879,9 @@ buf_LRU_block_free_hashed_page(
buf_block_t* block) /* in: block, must contain a file page and
be in a state where it can be freed */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(block->state == BUF_BLOCK_REMOVE_HASH);
block->state = BUF_BLOCK_MEMORY;
diff --git a/innobase/buf/ts/makefile b/innobase/buf/ts/makefile
deleted file mode 100644
index 5886d06d7fa..00000000000
--- a/innobase/buf/ts/makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-doall: tsbuf
-
-tsbuf: ..\buf.lib tsbuf.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\buf.lib ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsbuf.c $(LFL)
-
-tsos: ..\buf.lib tsos.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\buf.lib ..\..\mach.lib ..\..\fil.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsos.c $(LFL)
-
-
-
-
-
-
-
-
diff --git a/innobase/buf/ts/tsbuf.c b/innobase/buf/ts/tsbuf.c
deleted file mode 100644
index fd6ae69653f..00000000000
--- a/innobase/buf/ts/tsbuf.c
+++ /dev/null
@@ -1,885 +0,0 @@
-/************************************************************************
-The test module for the file system and buffer manager
-
-(c) 1995 Innobase Oy
-
-Created 11/16/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "string.h"
-
-#include "os0thread.h"
-#include "os0file.h"
-#include "ut0ut.h"
-#include "ut0byte.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "fil0fil.h"
-#include "mtr0mtr.h"
-#include "mtr0log.h"
-#include "log0log.h"
-#include "mach0data.h"
-#include "..\buf0buf.h"
-#include "..\buf0flu.h"
-#include "..\buf0lru.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-#define N_SPACES 1
-#define N_FILES 1
-#define FILE_SIZE 4000
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_frame_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-This thread reports the status of sync system. */
-
-ulint
-info_thread(
-/*========*/
- void* arg)
-{
- ulint segment;
-
- segment = *((ulint*)arg);
-
- for (;;) {
- sync_print();
- os_aio_print();
- printf("Debug stop threads == %lu\n", ut_dbg_stop_threads);
- os_thread_sleep(30000000);
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
- ulint err;
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[9] = (char)((ulint)'0' + k);
- name[10] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- err = os_file_get_last_error();
- if (err != OS_FILE_ALREADY_EXISTS) {
- printf("OS error %lu in file creation\n", err);
- ut_error;
- }
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-/*
- n[9] = 9;
- os_thread_create(info_thread, n + 9, id);
-*/
-}
-
-/************************************************************************
-Creates the test database files. */
-
-void
-create_db(void)
-/*===========*/
-{
- ulint i;
- byte* frame;
- ulint j;
- ulint tm, oldtm;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("Write database pages\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < N_SPACES; i++) {
- for (j = 0; j < FILE_SIZE * N_FILES; j++) {
- mtr_start(&mtr);
- mtr_set_log_mode(&mtr, MTR_LOG_NONE);
-
- frame = buf_page_create(i, j, &mtr);
- buf_page_get(i, j, RW_X_LATCH, &mtr);
-
- if (j > FILE_SIZE * N_FILES - 64 * 2 - 1) {
- mlog_write_ulint(frame + FIL_PAGE_PREV, j - 5,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_NEXT, j - 7,
- MLOG_4BYTES, &mtr);
- } else {
- mlog_write_ulint(frame + FIL_PAGE_PREV, j - 1,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_NEXT, j + 1,
- MLOG_4BYTES, &mtr);
- }
-
- mlog_write_ulint(frame + FIL_PAGE_OFFSET, j,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_SPACE, i,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + COUNTER_OFFSET, 0,
- MLOG_4BYTES, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1 A. Test of page creation when page resides in buffer\n");
- for (i = 0; i < N_SPACES; i++) {
- for (j = FILE_SIZE * N_FILES - 200;
- j < FILE_SIZE * N_FILES; j++) {
- mtr_start(&mtr);
- mtr_set_log_mode(&mtr, MTR_LOG_NONE);
-
- frame = buf_page_create(i, j, &mtr);
- buf_page_get(i, j, RW_X_LATCH, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_PREV,
- j - 1, MLOG_4BYTES, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_NEXT,
- j + 1, MLOG_4BYTES, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_OFFSET, j,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_SPACE, i,
- MLOG_4BYTES, &mtr);
- mtr_commit(&mtr);
- }
- }
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1 B. Flush pages\n");
-
- buf_flush_batch(BUF_FLUSH_LIST, POOL_SIZE / 2);
- buf_validate();
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1 C. Allocate POOL_SIZE blocks to flush pages\n");
-
- buf_validate();
- /* Flush the pool of dirty pages */
- for (i = 0; i < POOL_SIZE; i++) {
-
- bl_arr[i] = buf_frame_alloc();
- }
- buf_validate();
- buf_LRU_print();
-
- for (i = 0; i < POOL_SIZE; i++) {
-
- buf_frame_free(bl_arr[i]);
- }
-
- buf_validate();
- ut_a(buf_all_freed());
-
- mtr_start(&mtr);
- frame = buf_page_get(0, 313, RW_S_LATCH, &mtr);
-#ifdef UNIV_ASYNC_IO
- ut_a(buf_page_io_query(buf_block_align(frame)) == TRUE);
-#endif
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i, j, k, c;
- byte* frame;
- ulint tm, oldtm;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1 D. Read linearly database files\n");
-
- oldtm = ut_clock();
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < N_SPACES; i++) {
- for (j = 0; j < N_FILES * FILE_SIZE; j++) {
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
-
- mtr_commit(&mtr);
- }
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu pages %lu milliseconds\n",
- k * i * j, tm - oldtm);
- buf_validate();
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1 E. Read linearly downward database files\n");
-
- oldtm = ut_clock();
-
- c = 0;
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < N_SPACES; i++) {
- for (j = ut_min(1000, FILE_SIZE - 1); j > 0; j--) {
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
- c++;
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
-
-
- ut_a(buf_page_io_query(buf_block_align(frame))
- == FALSE);
-
- mtr_commit(&mtr);
- }
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu pages %lu milliseconds\n",
- c, tm - oldtm);
- buf_validate();
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test2(void)
-/*=======*/
-{
- ulint i, j, k;
- byte* frame;
- ulint tm, oldtm;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("TEST 2. Read randomly database files\n");
-
- oldtm = ut_clock();
-
- for (k = 0; k < 100; k++) {
- i = ut_rnd_gen_ulint() % N_SPACES;
- j = ut_rnd_gen_ulint() % (N_FILES * FILE_SIZE);
-
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall clock time for random %lu read %lu milliseconds\n",
- k, tm - oldtm);
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test3(void)
-/*=======*/
-{
- ulint i, j, k;
- byte* frame;
- ulint tm, oldtm;
- ulint rnd;
- mtr_t mtr;
-
- if (FILE_SIZE < POOL_SIZE + 3050 + ut_dbg_zero) {
- return;
- }
-
- printf("Flush the pool of high-offset pages\n");
-
- /* Flush the pool of high-offset pages */
- for (i = 0; i < POOL_SIZE; i++) {
-
- mtr_start(&mtr);
-
- frame = buf_page_get(0, i, RW_S_LATCH, &mtr);
-
- mtr_commit(&mtr);
- }
- buf_validate();
-
- printf("--------------------------------------------------------\n");
- printf("TEST 3. Read randomly database pages, no read-ahead\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 400; k++) {
- rnd += 23477;
-
- i = 0;
- j = POOL_SIZE + 10 + rnd % 3000;
-
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random no read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-
- buf_validate();
- printf("Flush the pool of high-offset pages\n");
- /* Flush the pool of high-offset pages */
- for (i = 0; i < POOL_SIZE; i++) {
-
- mtr_start(&mtr);
-
- frame = buf_page_get(0, i, RW_S_LATCH, &mtr);
-
- mtr_commit(&mtr);
- }
-
- buf_validate();
- printf("--------------------------------------------------------\n");
- printf("TEST 3 B. Read randomly database pages, random read-ahead\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
- for (k = 0; k < 400; k++) {
- rnd += 23477;
-
- i = 0;
- j = POOL_SIZE + 10 + rnd % 400;
-
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-}
-
-/************************************************************************
-Tests speed of CPU algorithms. */
-
-void
-test4(void)
-/*=======*/
-{
- ulint i, j;
- ulint tm, oldtm;
- mtr_t mtr;
- buf_frame_t* frame;
-
- os_thread_sleep(2000000);
-
- printf("--------------------------------------------------------\n");
- printf("TEST 4. Speed of CPU algorithms\n");
-
- oldtm = ut_clock();
-
- for (j = 0; j < 1000; j++) {
-
- mtr_start(&mtr);
- for (i = 0; i < 20; i++) {
-
- frame = buf_page_get(0, i, RW_S_LATCH, &mtr);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu page get-release %lu milliseconds\n",
- i * j, tm - oldtm);
-
- buf_validate();
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000; i++) {
- frame = buf_frame_alloc();
- buf_frame_free(frame);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu block alloc-free %lu milliseconds\n",
- i, tm - oldtm);
-
- ha_print_info(buf_pool->page_hash);
- buf_print();
-}
-
-/************************************************************************
-Tests various points of code. */
-
-void
-test5(void)
-/*=======*/
-{
- buf_frame_t* frame;
- fil_addr_t addr;
- ulint space;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("TEST 5. Various tests \n");
-
- mtr_start(&mtr);
-
- frame = buf_page_get(0, 313, RW_S_LATCH, &mtr);
-
- ut_a(buf_frame_get_space_id(frame) == 0);
- ut_a(buf_frame_get_page_no(frame) == 313);
-
- ut_a(buf_frame_align(frame + UNIV_PAGE_SIZE - 1) == frame);
- ut_a(buf_frame_align(frame) == frame);
-
- ut_a(buf_block_align(frame + UNIV_PAGE_SIZE - 1) ==
- buf_block_align(frame));
-
- buf_ptr_get_fsp_addr(frame + UNIV_PAGE_SIZE - 1, &space, &addr);
-
- ut_a(addr.page == 313)
- ut_a(addr.boffset == UNIV_PAGE_SIZE - 1);
- ut_a(space == 0);
-
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Random test thread function. */
-
-ulint
-random_thread(
-/*===========*/
- void* arg)
-{
- ulint n;
- ulint i, j, r, t, p, sp, count;
- ulint s;
- buf_frame_t* arr[POOL_SIZE / N_THREADS];
- buf_frame_t* frame;
- mtr_t mtr;
- mtr_t mtr2;
-
- n = *((ulint*)arg);
-
- printf("Random test thread %lu starts\n", os_thread_get_curr_id());
-
- for (i = 0; i < 30; i++) {
- t = ut_rnd_gen_ulint() % 10;
- r = ut_rnd_gen_ulint() % 100;
- s = ut_rnd_gen_ulint() % (POOL_SIZE / N_THREADS);
- p = ut_rnd_gen_ulint();
- sp = ut_rnd_gen_ulint() % N_SPACES;
-
- if (i % 100 == 0) {
- printf("Thr %lu tst %lu starts\n", os_thread_get_curr_id(), t);
- }
- ut_a(buf_validate());
-
- mtr_start(&mtr);
- if (t == 6) {
- /* Allocate free blocks */
- for (j = 0; j < s; j++) {
- arr[j] = buf_frame_alloc();
- ut_a(arr[j]);
- }
- for (j = 0; j < s; j++) {
- buf_frame_free(arr[j]);
- }
- } else if (t == 9) {
-/* buf_flush_batch(BUF_FLUSH_LIST, 30); */
-
- } else if (t == 7) {
- /* x-lock many blocks */
- for (j = 0; j < s; j++) {
- arr[j] = buf_page_get(sp, (p + j)
- % (N_FILES * FILE_SIZE),
- RW_X_LATCH,
- &mtr);
- ut_a(arr[j]);
- if (j > 0) {
- ut_a(arr[j] != arr[j - 1]);
- }
- }
- ut_a(buf_validate());
- } else if (t == 8) {
- /* s-lock many blocks */
- for (j = 0; j < s; j++) {
- arr[j] = buf_page_get(sp, (p + j)
- % (N_FILES * FILE_SIZE),
- RW_S_LATCH,
- &mtr);
- ut_a(arr[j]);
- if (j > 0) {
- ut_a(arr[j] != arr[j - 1]);
- }
- }
- } else if (t <= 2) {
- for (j = 0; j < r; j++) {
- /* Read pages */
- mtr_start(&mtr2);
- frame = buf_page_get(sp,
- p % (N_FILES * FILE_SIZE),
- RW_S_LATCH, &mtr2);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr2)
- == p % (N_FILES * FILE_SIZE));
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr2)
- == sp);
- mtr_commit(&mtr2);
- if (t == 0) {
- p++; /* upward */
- } else if (t == 1) {
- p--; /* downward */
- } else if (t == 2) {
- p = ut_rnd_gen_ulint(); /* randomly */
- }
- }
- } else if (t <= 5) {
- for (j = 0; j < r; j++) {
- /* Write pages */
- mtr_start(&mtr2);
- frame = buf_page_get(sp, p % (N_FILES * FILE_SIZE),
- RW_X_LATCH, &mtr2);
- count = 1 + mtr_read_ulint(frame + COUNTER_OFFSET,
- MLOG_4BYTES, &mtr2);
- mutex_enter(&incs_mutex);
- incs++;
- mutex_exit(&incs_mutex);
- mlog_write_ulint(frame + COUNTER_OFFSET, count,
- MLOG_4BYTES, &mtr2);
- mtr_commit(&mtr2);
- if (t == 3) {
- p++; /* upward */
- } else if (t == 4) {
- p--; /* downward */
- } else if (t == 5) {
- p = ut_rnd_gen_ulint(); /* randomly */
- }
- }
- } /* if t = */
-
- mtr_commit(&mtr);
-/* printf("Thr %lu tst %lu ends ", os_thread_get_curr_id(), t); */
- ut_a(buf_validate());
- } /* for i */
- printf("\nRandom test thread %lu exits\n", os_thread_get_curr_id());
- return(0);
-}
-
-/************************************************************************
-Random test thread function which reports the rw-lock list. */
-
-ulint
-rw_list_thread(
-/*===========*/
- void* arg)
-{
- ulint n;
- ulint i;
-
- n = *((ulint*)arg);
-
- printf("\nRw list test thread %lu starts\n", os_thread_get_curr_id());
-
- for (i = 0; i < 10; i++) {
- os_thread_sleep(3000000);
- rw_lock_list_print_info();
- buf_validate();
- }
-
- return(0);
-}
-
-/*************************************************************************
-Performs random operations on the buffer with several threads. */
-
-void
-test6(void)
-/*=======*/
-{
- ulint i, j;
- os_thread_t thr[N_THREADS + 1];
- os_thread_id_t id[N_THREADS + 1];
- ulint n[N_THREADS + 1];
- ulint count = 0;
- buf_frame_t* frame;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("TEST 6. Random multi-thread test on the buffer \n");
-
- incs = 0;
- mutex_create(&incs_mutex);
-
- for (i = 0; i < N_THREADS; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(random_thread, n + i, id + i);
- }
-/*
- n[N_THREADS] = N_THREADS;
-
- thr[N_THREADS] = os_thread_create(rw_list_thread, n + N_THREADS,
- id + N_THREADS);
-*/
- for (i = 0; i < N_THREADS; i++) {
- os_thread_wait(thr[i]);
- }
-
-/* os_thread_wait(thr[N_THREADS]); */
-
- for (i = 0; i < N_SPACES; i++) {
- for (j = 0; j < N_FILES * FILE_SIZE; j++) {
- mtr_start(&mtr);
-
- frame = buf_page_get(i, j, RW_S_LATCH, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
-
- count += mtr_read_ulint(frame + COUNTER_OFFSET,
- MLOG_4BYTES, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- printf("Count %lu incs %lu\n", count, incs);
- ut_a(count == incs);
-}
-
-/************************************************************************
-Frees the spaces in the file system. */
-
-void
-free_system(void)
-/*=============*/
-{
- ulint i;
-
- for (i = 0; i < N_SPACES; i++) {
- fil_space_free(i);
- }
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
-/* buf_debug_prints = TRUE; */
-
- oldtm = ut_clock();
-
- os_aio_init(160, 5);
- sync_init();
- mem_init(1500000);
- fil_init(26); /* Allow 25 open files at a time */
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- log_init();
-
- buf_validate();
-
- ut_a(fil_validate());
-
- create_files();
-
- create_db();
-
- buf_validate();
-
- test1();
- buf_validate();
-
- test2();
- buf_validate();
-
- test3();
- buf_validate();
-
- test4();
-
- test5();
-
- buf_validate();
-
- test6();
-
- buf_validate();
-
- buf_print();
-
- buf_flush_batch(BUF_FLUSH_LIST, POOL_SIZE + 1);
- buf_print();
- buf_validate();
-
- os_thread_sleep(1000000);
-
- buf_print();
- buf_all_freed();
-
- free_system();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/buf/ts/tsos.c b/innobase/buf/ts/tsos.c
deleted file mode 100644
index c1cc3f27172..00000000000
--- a/innobase/buf/ts/tsos.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/************************************************************************
-The test module for the operating system interface
-
-(c) 1995 Innobase Oy
-
-Created 9/27/1995 Heikki Tuuri
-*************************************************************************/
-
-
-#include "../os0thread.h"
-#include "../os0shm.h"
-#include "../os0proc.h"
-#include "../os0sync.h"
-#include "../os0file.h"
-#include "ut0ut.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-
-ulint last_thr = 1;
-
-byte global_buf[1000000];
-
-os_file_t file;
-os_file_t file2;
-
-os_event_t gl_ready;
-
-mutex_t ios_mutex;
-ulint ios;
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = os_aio_wait(segment, &mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- ut_a(ret);
-/* printf("Message for thread %lu %lu\n", segment,
- (ulint)mess); */
- if ((ulint)mess == 3333) {
- os_event_set(gl_ready);
- }
- }
-
- return(0);
-}
-
-/************************************************************************
-Test of io-handler threads */
-
-void
-test4(void)
-/*=======*/
-{
- ulint i;
- bool ret;
- void* buf;
- ulint rnd;
- ulint tm, oldtm;
-
- os_thread_t thr[5];
- os_thread_id_t id[5];
- ulint n[5];
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 4. Test of asynchronous file io\n");
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- gl_ready = os_event_create(NULL);
- ios = 0;
-
- sync_init();
- mem_init();
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4096; i++) {
- ret = os_aio_read(file, (byte*)buf + 8192 * (rnd % 100),
- 8192 * (rnd % 4096), 0,
- 8192, (void*)i);
- ut_a(ret);
- rnd += 1;
- }
-
- ret = os_aio_read(file, buf, 8192 * (rnd % 1024), 0, 8192,
- (void*)3333);
- ut_a(ret);
-
- ut_a(!os_aio_all_slots_free());
-
- tm = ut_clock();
-
- printf("All ios queued! N ios: %lu\n", ios);
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_event_wait(gl_ready);
-
- tm = ut_clock();
- printf("N ios: %lu\n", ios);
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_thread_sleep(2000000);
-
- printf("N ios: %lu\n", ios);
-
- ut_a(os_aio_all_slots_free());
-}
-
-/*************************************************************************
-Initializes the asyncronous io system for tests. */
-
-void
-init_aio(void)
-/*==========*/
-{
- bool ret;
- void* buf;
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- os_aio_init(160, 5);
- file = os_file_create("j:\\tsfile4", OS_FILE_CREATE, OS_FILE_TABLESPACE,
- &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() == OS_FILE_ALREADY_EXISTS);
-
- file = os_file_create("j:\\tsfile4", OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- init_aio();
-
- test4();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/com/Makefile.am b/innobase/com/Makefile.am
deleted file mode 100644
index a3d2f8a76c6..00000000000
--- a/innobase/com/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-# & Innobase Oy
-#
-# 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; either version 2 of the License, or
-# (at your option) any later version.
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-include ../include/Makefile.i
-
-noinst_LIBRARIES = libcom.a
-
-libcom_a_SOURCES = com0com.c com0shm.c
-
-EXTRA_PROGRAMS =
diff --git a/innobase/com/com0com.c b/innobase/com/com0com.c
deleted file mode 100644
index 94585d9f269..00000000000
--- a/innobase/com/com0com.c
+++ /dev/null
@@ -1,345 +0,0 @@
-/******************************************************
-The communication primitives
-
-(c) 1995 Innobase Oy
-
-Created 9/23/1995 Heikki Tuuri
-*******************************************************/
-
-#include "com0com.h"
-#ifdef UNIV_NONINL
-#include "com0com.ic"
-#endif
-
-#include "mem0mem.h"
-#include "com0shm.h"
-
-/*
- IMPLEMENTATION OF COMMUNICATION PRIMITIVES
- ==========================================
-
-The primitives provide a uniform function interface for
-use in communication. The primitives have been modeled
-after the Windows Sockets interface. Below this uniform
-API, the precise methods of communication, for example,
-shared memory or Berkeley sockets, can be implemented
-as subroutines.
-*/
-
-struct com_endpoint_struct{
- ulint type; /* endpoint type */
- void* par; /* type-specific data structures */
- ibool bound; /* TRUE if the endpoint has been
- bound to an address */
-};
-
-/*************************************************************************
-Accessor functions for an endpoint */
-UNIV_INLINE
-ulint
-com_endpoint_get_type(
-/*==================*/
- com_endpoint_t* ep)
-{
- ut_ad(ep);
- return(ep->type);
-}
-
-UNIV_INLINE
-void
-com_endpoint_set_type(
-/*==================*/
- com_endpoint_t* ep,
- ulint type)
-{
- ut_ad(ep);
- ut_ad(type == COM_SHM);
-
- ep->type = type;
-}
-
-UNIV_INLINE
-void*
-com_endpoint_get_par(
-/*=================*/
- com_endpoint_t* ep)
-{
- ut_ad(ep);
- return(ep->par);
-}
-
-UNIV_INLINE
-void
-com_endpoint_set_par(
-/*=================*/
- com_endpoint_t* ep,
- void* par)
-{
- ut_ad(ep);
- ut_ad(par);
-
- ep->par = par;
-}
-
-UNIV_INLINE
-ibool
-com_endpoint_get_bound(
-/*===================*/
- com_endpoint_t* ep)
-{
- ut_ad(ep);
- return(ep->bound);
-}
-
-UNIV_INLINE
-void
-com_endpoint_set_bound(
-/*===================*/
- com_endpoint_t* ep,
- ibool bound)
-{
- ut_ad(ep);
-
- ep->bound = bound;
-}
-
-
-/*************************************************************************
-Creates a communications endpoint. */
-
-com_endpoint_t*
-com_endpoint_create(
-/*================*/
- /* out, own: communications endpoint, NULL if
- did not succeed */
- ulint type) /* in: communication type of endpoint:
- only COM_SHM supported */
-{
- com_endpoint_t* ep;
- void* par;
-
- ep = mem_alloc(sizeof(com_endpoint_t));
-
- com_endpoint_set_type(ep, type);
- com_endpoint_set_bound(ep, FALSE);
-
- if (type == COM_SHM) {
- par = com_shm_endpoint_create();
- com_endpoint_set_par(ep, par);
- } else {
- par = NULL;
- ut_error;
- }
-
- if (par != NULL) {
- return(ep);
- } else {
- mem_free(ep);
- return(NULL);
- }
-}
-
-/*************************************************************************
-Frees a communications endpoint. */
-
-ulint
-com_endpoint_free(
-/*==============*/
- /* out: O if succeed, else error number */
- com_endpoint_t* ep) /* in, own: communications endpoint */
-{
- ulint type;
- ulint ret;
- void* par;
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_endpoint_free((com_shm_endpoint_t*)par);
- } else {
- ret = 0;
- ut_error;
- }
-
- if (ret) {
- return(ret);
- } else {
- mem_free(ep);
- return(0);
- }
-}
-
-/*************************************************************************
-Sets an option, like the maximum datagram size for an endpoint.
-The options may vary depending on the endpoint type. */
-
-ulint
-com_endpoint_set_option(
-/*====================*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: endpoint */
- ulint optno, /* in: option number, only
- COM_OPT_MAX_DGRAM_SIZE currently supported */
- byte* optval, /* in: pointer to a buffer containing the
- option value to set */
- ulint optlen) /* in: option value buffer length */
-{
- ulint type;
- ulint ret;
- void* par;
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_endpoint_set_option((com_shm_endpoint_t*)par,
- optno, optval, optlen);
- } else {
- ret = 0;
- ut_error;
- }
-
- return(ret);
-}
-
-/*************************************************************************
-Binds a communications endpoint to the specified address. */
-
-ulint
-com_bind(
-/*=====*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len) /* in: name length */
-{
- ulint type;
- ulint ret;
- void* par;
-
- ut_ad(len <= COM_MAX_ADDR_LEN);
-
- if (com_endpoint_get_bound(ep)) {
- return(COM_ERR_ALREADY_BOUND);
- }
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_bind((com_shm_endpoint_t*)par, name, len);
- } else {
- ret = 0;
- ut_error;
- }
-
- if (ret == 0) {
- com_endpoint_set_bound(ep, TRUE);
- }
-
- return(ret);
-}
-
-/*************************************************************************
-Waits for a datagram to arrive at an endpoint. */
-
-ulint
-com_recvfrom(
-/*=========*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* out: datagram buffer; the buffer is
- supplied by the caller */
- ulint buf_len,/* in: datagram buffer length */
- ulint* len, /* out: datagram length */
- char* from, /* out: address name buffer; the buffer is
- supplied by the caller */
- ulint from_len,/* in: address name buffer length */
- ulint* addr_len)/* out: address name length */
-{
- ulint type;
- ulint ret;
- void* par;
-
- if (!com_endpoint_get_bound(ep)) {
-
- return(COM_ERR_NOT_BOUND);
- }
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_recvfrom((com_shm_endpoint_t*)par,
- buf, buf_len, len, from, from_len,
- addr_len);
- } else {
- ret = 0;
-
- ut_error;
- }
-
- return(ret);
-}
-
-/*************************************************************************
-Sends a datagram to the specified destination. */
-
-ulint
-com_sendto(
-/*=======*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* in: datagram buffer */
- ulint len, /* in: datagram length */
- char* to, /* in: address name buffer */
- ulint tolen) /* in: address name length */
-{
- ulint type;
- ulint ret;
- void* par;
-
- if (!com_endpoint_get_bound(ep)) {
- return(COM_ERR_NOT_BOUND);
- }
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_sendto((com_shm_endpoint_t*)par, buf, len,
- to, tolen);
- } else {
- ret = 0;
- ut_error;
- }
-
- return(ret);
-}
-
-/*************************************************************************
-Gets the maximum datagram size for an endpoint. */
-
-ulint
-com_endpoint_get_max_size(
-/*======================*/
- /* out: maximum size */
- com_endpoint_t* ep) /* in: endpoint */
-{
- ulint type;
- ulint ret;
- void* par;
-
- type = com_endpoint_get_type(ep);
- par = com_endpoint_get_par(ep);
-
- if (type == COM_SHM) {
- ret = com_shm_endpoint_get_size((com_shm_endpoint_t*)par);
- } else {
- ret = 0;
- ut_error;
- }
-
- return(ret);
-}
diff --git a/innobase/com/com0shm.c b/innobase/com/com0shm.c
deleted file mode 100644
index 834ba3a5220..00000000000
--- a/innobase/com/com0shm.c
+++ /dev/null
@@ -1,1163 +0,0 @@
-/******************************************************
-The communication through shared memory
-
-(c) 1995 Innobase Oy
-
-Created 9/25/1995 Heikki Tuuri
-*******************************************************/
-
-#include "com0shm.h"
-#ifdef UNIV_NONINL
-#include "com0shm.ic"
-#endif
-
-#include "mem0mem.h"
-#include "ut0mem.h"
-#include "com0com.h"
-#include "os0shm.h"
-#include "sync0sync.h"
-#include "sync0ipm.h"
-#include "hash0hash.h"
-
-/*
- IMPLEMENTATION OF COMMUNICATION PRIMITIVES
- ==========================================
-
-When bind is called for an endpoint, a shared memory area of
-a size specified by com_shm_set_option is created with the
-name of the address given concatenated to "_IBSHM".
-Also a mutex is created for controlling the access to the
-shared memory area. The name of the mutex is address + "_IBSHM_MTX".
-An event with name address + "_IBSHM_EV_NE" is created. This event
-is in signaled state when the shared memory area is not empty, i.e.,
-there is a datagram to read. An event address + "_IBSHM_EV_EM"
-is signaled, when the area is empty, i.e., a datagram can be
-written to it.
-
-The shared memory area consists of an info struct
-at the beginning, containing fields telling:
-if the area is valid, i.e., is anybody going to
-read it, whether it currently contains a datagram, the
-length of the address from which the datagram was received,
-the length of the datagram, and the maximum allowed length of
-a datagram.
-After the info struct, there is a string of bytes
-containing the sender address and the data
-of the datagram.
-*/
-
-/* The following is set TRUE when the first endpoint is created. */
-
-ibool com_shm_initialized = FALSE;
-
-/* When a datagram is sent, the shared memory area
-corresponding to the destination address is mapped
-to the address space of this (sender) process.
-We preserve it and keep the relevant info in the
-following list. We can save a lot of CPU time
-if the destination can be found on the list. The list is
-protected by the mutex below. */
-
-mutex_t com_shm_destination_mutex;
-hash_table_t* com_shm_destination_cache;
-UT_LIST_BASE_NODE_T(com_shm_endpoint_t)
- com_shm_destination_list;
-
-/* The number of successfully bound endpoints in this process. When this
-number drops to 0, the destination cache is freed. This variable is protected
-by com_shm_destination_mutex above. */
-
-ulint com_shm_bind_count = 0;
-
-/* The performance of communication in NT depends on how
-many times a system call is made (excluding os_thread_yield,
-as that is the fastest way to switch thread).
-The following variable counts such events. */
-
-ulint com_shm_system_call_count = 0;
-
-/* The info struct at the beginning of a shared memory area */
-
-typedef struct com_shm_info_struct com_shm_info_t;
-
-/* An area of shared memory consists of an info struct followed
-by a string of bytes. */
-
-typedef com_shm_info_t com_shm_t;
-
-struct com_shm_endpoint_struct{
- ibool owns_shm; /* This is true if the shared memory
- area is owned by this endpoint structure
- (it may also be opened for this endpoint,
- not created, in which case does not own it) */
- char* addr; /* pointer to address the endpoint is bound
- to, NULL if not bound */
- ulint addr_len; /* address length */
- ulint size; /* maximum allowed datagram size, initialized
- to 0 at creation */
- os_shm_t shm; /* operating system handle of the shared
- memory area */
- com_shm_t* map; /* pointer to the start address of the shared
- memory area */
- os_event_t not_empty; /* this is in the signaled state if
- the area currently may contain a datagram;
- NOTE: automatic event */
- os_event_t empty; /* this is in the signaled state if the area
- currently may be empty; NOTE: automatic
- event */
- ip_mutex_hdl_t* ip_mutex; /* handle to the interprocess mutex
- protecting the shared memory */
- UT_LIST_NODE_T(com_shm_endpoint_t) list; /* If the endpoint struct
- is inserted into a list, this contains
- pointers to next and prev */
- com_shm_endpoint_t* addr_hash;
- /* hash table link */
-};
-
-struct com_shm_info_struct{
- ulint valid; /* This is COM_SHM_VALID if the creator
- of the shared memory area has it still
- mapped to its address space. Otherwise,
- we may conclude that the datagram cannot
- be delivered. */
- ibool not_empty; /* TRUE if the area currently contains
- a datagram */
- ulint empty_waiters; /* Count of (writer) threads which are
- waiting for the empty-event */
- ulint max_len;/* maximum allowed length for a datagram */
- ulint addr_len;/* address length for the sender address */
- ulint data_len;/* datagram length */
- ip_mutex_t ip_mutex;/* fast interprocess mutex protecting
- the shared memory area */
-};
-
-#define COM_SHM_VALID 76640
-
-/*************************************************************************
-Accessor functions for a shared memory endpoint */
-
-UNIV_INLINE
-ibool
-com_shm_endpoint_get_owns_shm(
-/*==========================*/
- com_shm_endpoint_t* ep)
-{
- ut_ad(ep);
- return(ep->owns_shm);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_owns_shm(
-/*==========================*/
- com_shm_endpoint_t* ep,
- ibool flag)
-{
- ut_ad(ep);
-
- ep->owns_shm = flag;
-}
-
-UNIV_INLINE
-char*
-com_shm_endpoint_get_addr(
-/*======================*/
- com_shm_endpoint_t* ep)
-{
- ut_ad(ep);
- return(ep->addr);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_addr(
-/*======================*/
- com_shm_endpoint_t* ep,
- char* addr)
-{
- ut_ad(ep);
-
- ep->addr = addr;
-}
-
-UNIV_INLINE
-ulint
-com_shm_endpoint_get_addr_len(
-/*==========================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->addr_len);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_addr_len(
-/*==========================*/
- com_shm_endpoint_t* ep,
- ulint len)
-{
- ut_ad(ep);
- ut_ad(len > 0);
-
- ep->addr_len = len;
-}
-
-ulint
-com_shm_endpoint_get_size(
-/*======================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->size);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_size(
-/*======================*/
- com_shm_endpoint_t* ep,
- ulint size)
-{
- ut_ad(ep);
-
- ep->size = size;
-}
-
-UNIV_INLINE
-os_shm_t
-com_shm_endpoint_get_shm(
-/*=====================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->shm);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_shm(
-/*=====================*/
- com_shm_endpoint_t* ep,
- os_shm_t shm)
-{
- ut_ad(ep);
- ut_ad(shm);
-
- ep->shm = shm;
-}
-
-UNIV_INLINE
-com_shm_t*
-com_shm_endpoint_get_map(
-/*=====================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->map);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_map(
-/*=====================*/
- com_shm_endpoint_t* ep,
- com_shm_t* map)
-{
- ut_ad(ep);
- ut_ad(map);
-
- ep->map = map;
-}
-
-UNIV_INLINE
-os_event_t
-com_shm_endpoint_get_empty(
-/*=======================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->empty);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_empty(
-/*=======================*/
- com_shm_endpoint_t* ep,
- os_event_t event)
-{
- ut_ad(ep);
- ut_ad(event);
-
- ep->empty = event;
-}
-
-UNIV_INLINE
-os_event_t
-com_shm_endpoint_get_not_empty(
-/*===========================*/
- com_shm_endpoint_t* ep)
-{
- return(ep->not_empty);
-}
-
-UNIV_INLINE
-void
-com_shm_endpoint_set_not_empty(
-/*===========================*/
- com_shm_endpoint_t* ep,
- os_event_t event)
-{
- ut_ad(ep);
- ut_ad(event);
-
- ep->not_empty = event;
-}
-
-/************************************************************************
-Accessor functions for the shared memory area info struct. */
-UNIV_INLINE
-ulint
-com_shm_get_valid(
-/*==============*/
- com_shm_info_t* info)
-{
- return(info->valid);
-}
-
-UNIV_INLINE
-void
-com_shm_set_valid(
-/*==============*/
- com_shm_info_t* info,
- ulint flag)
-{
- ut_ad(info);
-
- info->valid = flag;
-}
-
-UNIV_INLINE
-ibool
-com_shm_get_not_empty(
-/*==================*/
- com_shm_info_t* info)
-{
- return(info->not_empty);
-}
-
-UNIV_INLINE
-void
-com_shm_set_not_empty(
-/*==================*/
- com_shm_info_t* info,
- ibool flag)
-{
- ut_ad(info);
-
- info->not_empty = flag;
-}
-
-UNIV_INLINE
-ulint
-com_shm_get_empty_waiters(
-/*======================*/
- com_shm_info_t* info)
-{
- ut_ad(info->empty_waiters < 1000);
-
- return(info->empty_waiters);
-}
-
-UNIV_INLINE
-void
-com_shm_set_empty_waiters(
-/*======================*/
- com_shm_info_t* info,
- ulint count)
-{
- ut_ad(info);
- ut_ad(count < 1000);
-
- info->empty_waiters = count;
-}
-
-UNIV_INLINE
-ulint
-com_shm_get_max_len(
-/*================*/
- com_shm_info_t* info)
-{
- return(info->max_len);
-}
-
-UNIV_INLINE
-void
-com_shm_set_max_len(
-/*================*/
- com_shm_info_t* info,
- ulint len)
-{
- ut_ad(info);
- ut_ad(len > 0);
-
- info->max_len = len;
-}
-
-UNIV_INLINE
-ulint
-com_shm_get_addr_len(
-/*=================*/
- com_shm_info_t* info)
-{
- return(info->addr_len);
-}
-
-UNIV_INLINE
-void
-com_shm_set_addr_len(
-/*=================*/
- com_shm_info_t* info,
- ulint len)
-{
- ut_ad(info);
- ut_ad(len > 0);
-
- info->addr_len = len;
-}
-
-UNIV_INLINE
-ulint
-com_shm_get_data_len(
-/*=================*/
- com_shm_info_t* info)
-{
- return(info->data_len);
-}
-
-UNIV_INLINE
-void
-com_shm_set_data_len(
-/*=================*/
- com_shm_info_t* info,
- ulint len)
-{
- ut_ad(info);
- ut_ad(len > 0);
-
- info->data_len = len;
-}
-
-UNIV_INLINE
-ip_mutex_t*
-com_shm_get_ip_mutex(
-/*=================*/
- com_shm_info_t* info)
-{
- return(&(info->ip_mutex));
-}
-
-/*************************************************************************
-Accessor functions for the address and datagram fields inside a
-shared memory area. */
-
-UNIV_INLINE
-char*
-com_shm_get_addr(
-/*=============*/
- com_shm_t* area)
-{
- return((char*)area + sizeof(com_shm_info_t));
-}
-
-UNIV_INLINE
-byte*
-com_shm_get_data(
-/*=============*/
- com_shm_t* area)
-{
- return((byte*)com_shm_get_addr(area) + com_shm_get_addr_len(area));
-}
-
-/*************************************************************************
-Initializes the shared memory communication system for this
-process. */
-UNIV_INLINE
-void
-com_shm_init(void)
-/*==============*/
-{
- mutex_create(&com_shm_destination_mutex);
-
- mutex_set_level(&com_shm_destination_mutex, SYNC_ANY_LATCH);
-
- com_shm_destination_cache = hash_create(1000);
-
- UT_LIST_INIT(com_shm_destination_list);
-
- com_shm_initialized = TRUE;
-}
-
-/*************************************************************************
-Reserves the ip mutex of the shared memory area of an endpoint. */
-UNIV_INLINE
-void
-com_shm_enter(
-/*==========*/
- com_shm_endpoint_t* ep)
-{
- ulint ret;
-
- ret = ip_mutex_enter(ep->ip_mutex, 10000000);
-
- if (ret != 0) {
- mutex_list_print_info();
-
- ut_error;
- }
-}
-
-/*************************************************************************
-Releases the ip mutex of the shared memory area of an endpoint. */
-UNIV_INLINE
-void
-com_shm_exit(
-/*=========*/
- com_shm_endpoint_t* ep)
-{
- ip_mutex_exit(ep->ip_mutex);
-}
-
-/*************************************************************************
-Looks for the given address in the cached destination addresses. */
-UNIV_INLINE
-com_shm_endpoint_t*
-com_shm_destination_cache_search(
-/*=============================*/
- /* out: cached endpoint structure if found, else NULL */
- char* addr, /* in: destination address */
- ulint len) /* in: address length */
-{
- com_shm_endpoint_t* ep;
- ulint fold;
-
- fold = ut_fold_binary((byte*)addr, len);
-/*
- printf("Searching dest. cache %s %lu fold %lu\n", addr, len, fold);
-*/
- mutex_enter(&com_shm_destination_mutex);
-
- HASH_SEARCH(addr_hash, com_shm_destination_cache, fold, ep,
- ((ep->addr_len == len)
- && (0 == ut_memcmp(addr, ep->addr, len))));
-
- mutex_exit(&com_shm_destination_mutex);
-
- return(ep);
-}
-
-/*************************************************************************
-Inserts the given endpoint structure in the cached destination addresses. */
-static
-void
-com_shm_destination_cache_insert(
-/*=============================*/
- com_shm_endpoint_t* ep) /* in: endpoint struct to insert */
-{
- ulint fold;
-
- fold = ut_fold_binary((byte*)(ep->addr), ep->addr_len);
-
- mutex_enter(&com_shm_destination_mutex);
-
- /* Add to hash table */
- HASH_INSERT(com_shm_endpoint_t,
- addr_hash, com_shm_destination_cache, fold, ep);
-
- UT_LIST_ADD_LAST(list, com_shm_destination_list, ep);
-
-/* printf("Inserting to dest. cache %s %lu fold %lu\n", ep->addr,
- ep->addr_len, fold);
-*/
- mutex_exit(&com_shm_destination_mutex);
-}
-
-/*************************************************************************
-Frees the endpoint structs in the destination cache if the bind count is zero.
-If it is not, some send operation may just be using a cached endpoint and it
-cannot be freed. */
-static
-void
-com_shm_destination_cache_no_binds(void)
-/*====================================*/
-{
- com_shm_endpoint_t* ep;
- ulint fold;
-
- mutex_enter(&com_shm_destination_mutex);
-
- if (com_shm_bind_count != 0) {
- mutex_exit(&com_shm_destination_mutex);
-
- return;
- }
-
- while (UT_LIST_GET_LEN(com_shm_destination_list) != 0) {
-
- ep = UT_LIST_GET_FIRST(com_shm_destination_list);
-
- UT_LIST_REMOVE(list, com_shm_destination_list, ep);
-
- fold = ut_fold_binary((byte*)ep->addr, ep->addr_len);
-/*
- printf("Deleting from dest. cache %s %lu fold %lu\n",
- ep->addr,
- ep->addr_len, fold);
-*/
- HASH_DELETE(com_shm_endpoint_t, addr_hash,
- com_shm_destination_cache, fold, ep);
-
- com_shm_endpoint_free(ep);
- }
-
- mutex_exit(&com_shm_destination_mutex);
-}
-
-/***********************************************************************
-Unbinds an endpoint at the time of freeing. */
-static
-void
-com_shm_unbind(
-/*===========*/
- com_shm_endpoint_t* ep) /* in: endpoint */
-{
- com_shm_t* map;
-
- map = com_shm_endpoint_get_map(ep);
-
- /* Mark the shared memory area invalid */
-
- com_shm_set_valid(map, 0);
-
- /* Decrement the count of bindings */
-
- mutex_enter(&com_shm_destination_mutex);
-
- com_shm_bind_count--;
-
- mutex_exit(&com_shm_destination_mutex);
-
- /* If there are no binds left, free the cached endpoints */
-
- com_shm_destination_cache_no_binds();
-}
-
-/*************************************************************************
-Creates a communications endpoint. */
-
-com_shm_endpoint_t*
-com_shm_endpoint_create(void)
-/*=========================*/
- /* out, own: communications endpoint, NULL if
- did not succeed */
-{
- com_shm_endpoint_t* ep;
-
- if (!com_shm_initialized) {
-
- com_shm_init();
- }
-
- ep = mem_alloc(sizeof(com_shm_endpoint_t));
-
- com_shm_endpoint_set_owns_shm(ep, FALSE);
- com_shm_endpoint_set_addr(ep, NULL);
- com_shm_endpoint_set_size(ep, 0);
-
- return(ep);
-}
-
-/*************************************************************************
-Frees a communications endpoint. */
-
-ulint
-com_shm_endpoint_free(
-/*==================*/
- /* out: O if succeed, else error number */
- com_shm_endpoint_t* ep) /* in, own: communications endpoint */
-{
- com_shm_t* map;
-
- ut_ad(ep);
-
- if (com_shm_endpoint_get_addr(ep) != NULL) {
-
- map = com_shm_endpoint_get_map(ep);
-
- if (com_shm_endpoint_get_owns_shm(ep)) {
-
- com_shm_unbind(ep);
- }
-
- /* We do not destroy the data structures in the shared memory
- area, because we cannot be sure that there is currently no
- process accessing it. Therefore we just close the ip_mutex
- residing in the area. */
-
- ip_mutex_close(ep->ip_mutex);
-
- os_event_free(com_shm_endpoint_get_not_empty(ep));
- os_event_free(com_shm_endpoint_get_empty(ep));
-
- os_shm_unmap(map);
- os_shm_free(com_shm_endpoint_get_shm(ep));
-
- mem_free(com_shm_endpoint_get_addr(ep));
- }
-
- mem_free(ep);
-
- return(0);
-}
-
-/*************************************************************************
-Sets an option, like the maximum datagram size for an endpoint.
-The options may vary depending on the endpoint type. */
-
-ulint
-com_shm_endpoint_set_option(
-/*========================*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: endpoint */
- ulint optno, /* in: option number, only
- COM_OPT_MAX_DGRAM_SIZE currently supported */
- byte* optval, /* in: pointer to a buffer containing the
- option value to set */
- ulint optlen) /* in: option value buffer length */
-{
- ulint size;
-
- UT_NOT_USED(optlen);
-
- ut_ad(ep);
- ut_a(optno == COM_OPT_MAX_DGRAM_SIZE);
- ut_ad(NULL == com_shm_endpoint_get_addr(ep));
-
- size = *((ulint*)optval);
-
- ut_ad(size > 0);
-
- com_shm_endpoint_set_size(ep, size);
-
- return(0);
-}
-
-/*************************************************************************
-This function is used either to create a new shared memory area or open an
-existing one, but this does not do the operations necessary with the ip mutex.
-They are performed in com_shm_bind or com_shm_open which call this function. */
-static
-ulint
-com_shm_create_or_open(
-/*===================*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len) /* in: address name length */
-{
- os_shm_t shm;
- com_shm_t* map;
- os_event_t event_ne;
- os_event_t event_em;
- char* buf;
-
- ut_ad(ep);
- ut_ad(name);
- ut_ad(len > 0);
-
- buf = mem_alloc(COM_MAX_ADDR_LEN + 20);
-
- ut_memcpy(buf, name, len);
-
- ut_strcpy(buf + len, (char*)"_IBSHM");
-
- shm = os_shm_create(sizeof(com_shm_info_t) + COM_MAX_ADDR_LEN +
- com_shm_endpoint_get_size(ep), buf);
- if (shm == NULL) {
-
- return(COM_ERR_NOT_SPECIFIED);
- }
-
- map = os_shm_map(shm);
-
- if (map == NULL) {
- os_shm_free(shm);
-
- return(COM_ERR_NOT_SPECIFIED);
- }
-
- ut_strcpy(buf + len, (char*)"_IBSHM_EV_NE"),
-
- event_ne = os_event_create(buf);
-
- ut_ad(event_ne);
-
- ut_strcpy(buf + len, (char*)"_IBSHM_EV_EM"),
-
- event_em = os_event_create(buf);
-
- ut_ad(event_em);
-
- ut_a(0); /* event_ne and event_em should be auto events! */
-
- com_shm_endpoint_set_shm(ep, shm);
- com_shm_endpoint_set_map(ep, map);
-
- com_shm_endpoint_set_not_empty(ep, event_ne);
- com_shm_endpoint_set_empty(ep, event_em);
-
- com_shm_endpoint_set_addr(ep, buf);
- com_shm_endpoint_set_addr_len(ep, len);
-
- return(0);
-}
-
-/*************************************************************************
-Opens a shared memory area for communication. */
-static
-ulint
-com_shm_open(
-/*=========*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len) /* in: address name length */
-{
- ip_mutex_hdl_t* ip_hdl;
- com_shm_t* map;
- ulint ret;
- char buf[COM_MAX_ADDR_LEN + 20];
-
- ret = com_shm_create_or_open(ep, name, len);
-
- if (ret != 0) {
-
- return(ret);
- }
-
- map = com_shm_endpoint_get_map(ep);
-
- /* Open the interprocess mutex to protect the shared memory area */
-
- ut_memcpy(buf, name, len);
- ut_strcpy(buf + len, (char*)"_IBSHM_MTX");
-
- ret = ip_mutex_open(com_shm_get_ip_mutex(map), buf, &ip_hdl);
-
- if (ret != 0) {
-
- return(COM_ERR_NOT_SPECIFIED);
- }
-
- ep->ip_mutex = ip_hdl;
-
- return(0);
-}
-
-/*************************************************************************
-Creates a shared memory area for communication. */
-
-ulint
-com_shm_bind(
-/*=========*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len) /* in: address name length */
-{
- com_shm_t* map;
- ulint ret;
- char buf[COM_MAX_ADDR_LEN + 20];
- ip_mutex_hdl_t* ip_hdl;
-
- if (com_shm_endpoint_get_size(ep) == 0) {
-
- return(COM_ERR_MAX_DATAGRAM_SIZE_NOT_SET);
- }
-
- ret = com_shm_create_or_open(ep, name, len);
-
- if (ret != 0) {
-
- return(ret);
- }
-
- map = com_shm_endpoint_get_map(ep);
-
- /* Create the interprocess mutex to protect the shared memory area */
-
- ut_memcpy(buf, name, len);
- ut_strcpy(buf + len, (char*)"_IBSHM_MTX");
-
- ret = ip_mutex_create(com_shm_get_ip_mutex(map), buf, &ip_hdl);
-
- if (ret != 0) {
-
- return(COM_ERR_NOT_SPECIFIED);
- }
-
- /* This endpoint structure owns the shared memory area */
-
- com_shm_endpoint_set_owns_shm(ep, TRUE);
- ep->ip_mutex = ip_hdl;
-
- mutex_enter(&com_shm_destination_mutex);
-
- /* Increment the count of successful bindings */
-
- com_shm_bind_count++;
-
- mutex_exit(&com_shm_destination_mutex);
-
- com_shm_set_not_empty(map, FALSE);
- com_shm_set_empty_waiters(map, 0);
- com_shm_set_max_len(map, com_shm_endpoint_get_size(ep));
-
- com_shm_set_valid(map, COM_SHM_VALID);
-
- os_event_set(com_shm_endpoint_get_empty(ep));
-
- return(0);
-}
-
-/*************************************************************************
-Waits for a datagram to arrive at an endpoint. */
-
-ulint
-com_shm_recvfrom(
-/*=============*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* out: datagram buffer; the buffer is
- supplied by the caller */
- ulint buf_len,/* in: datagram buffer length */
- ulint* len, /* out: datagram length */
- char* from, /* out: address name buffer; the buffer is
- supplied by the caller */
- ulint from_len,/* in: address name buffer length */
- ulint* addr_len)/* out: address name length */
-{
- com_shm_t* map;
- ulint loop_count;
-
- map = com_shm_endpoint_get_map(ep);
-
- loop_count = 0;
-loop:
- com_shm_system_call_count++;
-
- /* NOTE: automatic event */
-
- os_event_wait(com_shm_endpoint_get_not_empty(ep));
-
- loop_count++;
-
- if (loop_count > 1) {
- printf("!!!!!!!!COM_SHM loop count %lu\n", (ulong) loop_count);
- }
-
- ut_ad(loop_count < 2);
-
-#ifdef notdefined
- if (!com_shm_get_not_empty(map)) {
-
- /* There was no datagram, give up the time slice
- for some writer thread to insert a datagram */
-
- com_shm_exit(ep);
-
- os_thread_yield();
-
- com_shm_enter(ep);
- }
-#endif
- com_shm_enter(ep);
-
- if (!com_shm_get_not_empty(map)) {
- /* There was no datagram, wait for the event */
-
- com_shm_exit(ep);
-
- goto loop;
- }
-
- if (com_shm_get_data_len(map) > buf_len) {
-
- com_shm_exit(ep);
-
- return(COM_ERR_DATA_BUFFER_TOO_SMALL);
- }
-
- if (com_shm_get_addr_len(map) > from_len) {
-
- com_shm_exit(ep);
-
- return(COM_ERR_ADDR_BUFFER_TOO_SMALL);
- }
-
- *len = com_shm_get_data_len(map);
- *addr_len = com_shm_get_addr_len(map);
-
- ut_memcpy(buf, com_shm_get_data(map), *len);
- ut_memcpy(from, com_shm_get_addr(map), *addr_len);
-
- com_shm_set_not_empty(map, FALSE);
-
- /* If there may be writers queuing to insert the datagram, signal the
- empty-event */
-
- if (com_shm_get_empty_waiters(map) != 0) {
-
- com_shm_system_call_count++;
-
- os_event_set(com_shm_endpoint_get_empty(ep));
- }
-
- com_shm_exit(ep);
-
- return(0);
-}
-
-/*************************************************************************
-Sends a datagram to the specified destination. */
-
-ulint
-com_shm_sendto(
-/*===========*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* in: datagram buffer */
- ulint len, /* in: datagram length */
- char* to, /* in: address name buffer */
- ulint tolen) /* in: address name length */
-{
- com_shm_endpoint_t* ep2;
- com_shm_t* map;
- ulint sender_len;
- ulint ret;
- ulint loop_count;
-
- /* Try first to find from the cached destination addresses */
-
- ep2 = com_shm_destination_cache_search(to, tolen);
-
- if (ep2 == NULL) {
- /* Did not find it in the cache */
- ep2 = com_shm_endpoint_create();
-
- ret = com_shm_open(ep2, to, tolen);
-
- if (ret != 0) {
- com_shm_endpoint_free(ep2);
-
- return(ret);
- }
-
- /* Insert into the cached destination addresses */
-
- com_shm_destination_cache_insert(ep2);
- }
-
- map = com_shm_endpoint_get_map(ep2);
-
- if (com_shm_get_valid(map) != COM_SHM_VALID) {
-
- com_shm_exit(ep2);
-
- return(COM_ERR_DGRAM_NOT_DELIVERED);
- }
-
- if (com_shm_get_max_len(map) < len) {
-
- com_shm_exit(ep2);
-
- return(COM_ERR_DATA_TOO_LONG);
- }
-
- /* Optimistically, we first go to see if the datagram area is empty,
- without waiting for the empty-event */
-
- loop_count = 0;
-loop:
- loop_count++;
-
- if (loop_count > 5) {
- printf("!!!!!!COM_SHM Notempty loop count %lu\n",
- (ulong) loop_count);
- }
-
- ut_ad(loop_count < 100);
-
- com_shm_enter(ep2);
-
- if (com_shm_get_not_empty(map)) {
-
- /* Not empty, we cannot insert a datagram */
-
- com_shm_set_empty_waiters(map,
- 1 + com_shm_get_empty_waiters(map));
- com_shm_exit(ep2);
-
- com_shm_system_call_count++;
-
- /* Wait for the area to become empty */
- /* NOTE: automatic event */
-
- ret = os_event_wait_time(com_shm_endpoint_get_empty(ep2),
- 10000000);
- ut_a(ret == 0);
-
- com_shm_enter(ep2);
-
- com_shm_set_empty_waiters(map,
- com_shm_get_empty_waiters(map) - 1);
- com_shm_exit(ep2);
-
- goto loop;
- }
-
- sender_len = com_shm_endpoint_get_addr_len(ep);
-
- com_shm_set_data_len(map, len);
- com_shm_set_addr_len(map, sender_len);
-
- ut_memcpy(com_shm_get_data(map), buf, len);
- ut_memcpy(com_shm_get_addr(map), com_shm_endpoint_get_addr(ep),
- sender_len);
- com_shm_set_not_empty(map, TRUE);
-#ifdef notdefined
- com_shm_exit(ep2);
-
- /* Now we give up our time slice voluntarily to give some reader
- thread chance to fetch the datagram */
-
- os_thread_yield();
-
- com_shm_enter(ep2);
-
- if (com_shm_get_not_empty(map)) {
-#endif
- com_shm_system_call_count++;
-
- com_shm_exit(ep2);
-
- /* Signal the event */
-
- os_event_set(com_shm_endpoint_get_not_empty(ep2));
-
- return(0);
-
-#ifdef notdefined
- }
-
- com_shm_exit(ep2);
-
- return(0);
-#endif
-}
diff --git a/innobase/com/makefilewin b/innobase/com/makefilewin
deleted file mode 100644
index 0d2d6d45952..00000000000
--- a/innobase/com/makefilewin
+++ /dev/null
@@ -1,12 +0,0 @@
-include ..\include\makefile.i
-
-com.lib: com0com.obj com0shm.obj
- lib -out:..\libs\com.lib com0com.obj com0shm.obj
-
-com0com.obj: com0com.c
- $(CCOM) $(CFL) -c com0com.c
-
-com0shm.obj: com0shm.c
- $(CCOM) $(CFL) -c com0shm.c
-
-
diff --git a/innobase/com/ts/makefile b/innobase/com/ts/makefile
deleted file mode 100644
index 01c14737c78..00000000000
--- a/innobase/com/ts/makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-doall: tscom tscli
-
-tscom: ..\com.lib tscom.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\com.lib ..\..\ut.lib ..\..\mem.lib ..\..\sync.lib ..\..\os.lib tscom.c $(LFL)
-
-tscli: ..\com.lib tscli.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\com.lib ..\..\ut.lib ..\..\mem.lib ..\..\sync.lib ..\..\os.lib tscli.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/com/ts/tscli.c b/innobase/com/ts/tscli.c
deleted file mode 100644
index 27a787a0e5c..00000000000
--- a/innobase/com/ts/tscli.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/************************************************************************
-The test module for communication
-
-(c) 1995 Innobase Oy
-
-Created 9/26/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "../com0com.h"
-#include "../com0shm.h"
-#include "ut0ut.h"
-#include "mem0mem.h"
-#include "os0thread.h"
-#include "sync0ipm.h"
-#include "sync0sync.h"
-
-byte buf[10000];
-char addr[150];
-
-void
-test1(void)
-/*=======*/
-{
- com_endpoint_t* ep;
- ulint ret;
- ulint size;
- ulint len;
- ulint addr_len;
- ulint i;
-
- ep = com_endpoint_create(COM_SHM);
-
- ut_a(ep);
-
- size = 8192;
-
- ret = com_endpoint_set_option(ep, COM_OPT_MAX_DGRAM_SIZE,
- (byte*)&size, 0);
-
- ut_a(ret == 0);
-
- ret = com_bind(ep, "CLI", 3);
-
- ut_a(ret == 0);
-
- printf("Client endpoint created!\n");
-
- for (i = 0; i < 10000; i++) {
-
- ret = com_sendto(ep, (byte*)"Hello from client!\n", 18, "SRV", 3);
-
- ut_a(ret == 0);
-
- ret = com_recvfrom(ep, buf, 10000, &len, addr, 150, &addr_len);
-
- ut_a(ret == 0);
-
- buf[len] = '\0';
- addr[addr_len] = '\0';
-/*
- printf(
- "Message of len %lu\n%s \nreceived from address %s of len %lu\n",
- len, buf, addr, addr_len);
-*/
- }
-
- ret = com_endpoint_free(ep);
-
- ut_ad(ret == 0);
-
-
- printf("Count of extra system calls in com_shm %lu\n",
- com_shm_system_call_count);
- printf("Count of extra system calls in ip_mutex %lu\n",
- ip_mutex_system_call_count);
-}
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
-
- oldtm = ut_clock();
-
- test1();
-
- ut_ad(mem_all_freed());
-
- tm = ut_clock();
- printf("Wall clock time for test %ld milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/com/ts/tscom.c b/innobase/com/ts/tscom.c
deleted file mode 100644
index a02db40efa7..00000000000
--- a/innobase/com/ts/tscom.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/************************************************************************
-The test module for communication
-
-(c) 1995 Innobase Oy
-
-Created 9/26/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "../com0com.h"
-#include "../com0shm.h"
-#include "ut0ut.h"
-#include "mem0mem.h"
-#include "os0thread.h"
-#include "sync0ipm.h"
-#include "sync0sync.h"
-
-byte buf[10000];
-char addr[150];
-
-void
-test1(void)
-/*=======*/
-{
- com_endpoint_t* ep;
- ulint ret;
- ulint size;
- ulint len;
- ulint addr_len;
- ulint i;
-
- ep = com_endpoint_create(COM_SHM);
-
- ut_a(ep);
-
- size = 8192;
-
- ret = com_endpoint_set_option(ep, COM_OPT_MAX_DGRAM_SIZE,
- (byte*)&size, 0);
-
- ut_a(ret == 0);
-
- ret = com_bind(ep, "SRV", 3);
-
- ut_a(ret == 0);
-
- printf("Server endpoint created!\n");
-
- for (i = 0; i < 50000; i++) {
-
- ret = com_recvfrom(ep, buf, 10000, &len, addr, 150, &addr_len);
-
- ut_a(ret == 0);
-
- buf[len] = '\0';
- addr[addr_len] = '\0';
-/*
- printf(
- "Message of len %lu\n%s \nreceived from address %s of len %lu\n",
- len, buf, addr, addr_len);
-*/
- ret = com_sendto(ep, (byte*)"Hello from server!\n", 18, "CLI", 3);
-
- ut_a(ret == 0);
- }
-
- ret = com_endpoint_free(ep);
-
- ut_ad(ret == 0);
-
- printf("Count of extra system calls in com_shm %lu\n",
- com_shm_system_call_count);
- printf("Count of extra system calls in ip_mutex %lu\n",
- ip_mutex_system_call_count);
-}
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
-
- oldtm = ut_clock();
-
- test1();
-
- ut_ad(mem_all_freed());
-
- tm = ut_clock();
- printf("Wall clock time for test %ld milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/configure.in b/innobase/configure.in
index 9d57a0f2d91..652291f1f38 100644
--- a/innobase/configure.in
+++ b/innobase/configure.in
@@ -34,6 +34,7 @@ CXXFLAGS="$CXXFLAGS "
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_INSTALL
+AC_PROG_LIBTOOL
AC_CHECK_HEADERS(aio.h sched.h)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)
@@ -112,12 +113,12 @@ case "$target" in
esac
AC_OUTPUT(Makefile os/Makefile ut/Makefile btr/Makefile dnl
- buf/Makefile com/Makefile data/Makefile dnl
+ buf/Makefile data/Makefile dnl
dict/Makefile dyn/Makefile dnl
eval/Makefile fil/Makefile fsp/Makefile fut/Makefile dnl
ha/Makefile ibuf/Makefile include/Makefile dnl
lock/Makefile log/Makefile dnl
- mach/Makefile mem/Makefile mtr/Makefile odbc/Makefile dnl
+ mach/Makefile mem/Makefile mtr/Makefile dnl
page/Makefile pars/Makefile que/Makefile dnl
read/Makefile rem/Makefile row/Makefile dnl
srv/Makefile sync/Makefile thr/Makefile trx/Makefile dnl
diff --git a/innobase/cry/makefilewin b/innobase/cry/makefilewin
deleted file mode 100644
index 9e791b8d073..00000000000
--- a/innobase/cry/makefilewin
+++ /dev/null
@@ -1,12 +0,0 @@
-include ..\include\makefile.i
-
-doall: cr.exe dcr.exe wro.exe
-
-cr.exe: cry0cry.c
- $(CCOM) $(CFLW) -o cr.exe -I.. cry0cry.c ..\ut.lib ..\os.lib
-
-dcr.exe: cry0dcr.c
- $(CCOM) $(CFLW) -o dcr.exe -I.. cry0dcr.c ..\ut.lib ..\os.lib
-
-wro.exe: cry0wro.c
- $(CCOM) $(CFLW) -o wro.exe -I.. cry0wro.c ..\ut.lib ..\os.lib
diff --git a/innobase/data/data0data.c b/innobase/data/data0data.c
index 78cee31a29d..0ed0efeb160 100644
--- a/innobase/data/data0data.c
+++ b/innobase/data/data0data.c
@@ -114,8 +114,8 @@ dtuple_datas_are_ordering_equal(
ulint i;
ut_ad(tuple1 && tuple2);
- ut_ad(tuple1->magic_n = DATA_TUPLE_MAGIC_N);
- ut_ad(tuple2->magic_n = DATA_TUPLE_MAGIC_N);
+ ut_ad(tuple1->magic_n == DATA_TUPLE_MAGIC_N);
+ ut_ad(tuple2->magic_n == DATA_TUPLE_MAGIC_N);
ut_ad(dtuple_check_typed(tuple1));
ut_ad(dtuple_check_typed(tuple2));
@@ -263,7 +263,7 @@ dfield_check_typed(
(ulong) dfield_get_type(field)->mtype,
(ulong) dfield_get_len(field));
- ut_a(0);
+ ut_error;
}
return(TRUE);
@@ -308,7 +308,7 @@ dtuple_validate(
ulint i;
ulint j;
- ut_a(tuple->magic_n = DATA_TUPLE_MAGIC_N);
+ ut_ad(tuple->magic_n == DATA_TUPLE_MAGIC_N);
n_fields = dtuple_get_n_fields(tuple);
@@ -727,416 +727,3 @@ dtuple_big_rec_free(
{
mem_heap_free(vector->heap);
}
-
-#ifdef notdefined
-
-/******************************************************************
-Generates random numbers, where 10/16 is uniformly
-distributed between 0 and n1, 5/16 between 0 and n2,
-and 1/16 between 0 and n3. */
-static
-ulint
-dtuple_gen_rnd_ulint(
-/*=================*/
- /* out: random ulint */
- ulint n1,
- ulint n2,
- ulint n3)
-{
- ulint m;
- ulint n;
-
- m = ut_rnd_gen_ulint() % 16;
-
- if (m < 10) {
- n = n1;
- } else if (m < 15) {
- n = n2;
- } else {
- n = n3;
- }
-
- m = ut_rnd_gen_ulint();
-
- return(m % n);
-}
-
-/***************************************************************
-Generates a random tuple. */
-
-dtuple_t*
-dtuple_gen_rnd_tuple(
-/*=================*/
- /* out: pointer to the tuple */
- mem_heap_t* heap) /* in: memory heap where generated */
-{
- ulint n_fields;
- dfield_t* field;
- ulint len;
- dtuple_t* tuple;
- ulint i;
- ulint j;
- byte* ptr;
-
- n_fields = dtuple_gen_rnd_ulint(5, 30, 300) + 1;
-
- tuple = dtuple_create(heap, n_fields);
-
- for (i = 0; i < n_fields; i++) {
-
- if (n_fields < 7) {
- len = dtuple_gen_rnd_ulint(5, 30, 400);
- } else {
- len = dtuple_gen_rnd_ulint(7, 5, 17);
- }
-
- field = dtuple_get_nth_field(tuple, i);
-
- if (len == 0) {
- dfield_set_data(field, NULL, UNIV_SQL_NULL);
- } else {
- ptr = mem_heap_alloc(heap, len);
- dfield_set_data(field, ptr, len - 1);
-
- for (j = 0; j < len; j++) {
- *ptr = (byte)(65 +
- dtuple_gen_rnd_ulint(22, 22, 22));
- ptr++;
- }
- }
-
- dtype_set(dfield_get_type(field), DATA_VARCHAR,
- DATA_ENGLISH, 500, 0);
- }
-
- ut_a(dtuple_validate(tuple));
-
- return(tuple);
-}
-
-/*******************************************************************
-Generates a test tuple for sort and comparison tests. */
-
-void
-dtuple_gen_test_tuple(
-/*==================*/
- dtuple_t* tuple, /* in/out: a tuple with 3 fields */
- ulint i) /* in: a number < 512 */
-{
- ulint j;
- dfield_t* field;
- void* data = NULL;
- ulint len = 0;
-
- for (j = 0; j < 3; j++) {
- switch (i % 8) {
- case 0:
- data = ""; len = 0; break;
- case 1:
- data = "A"; len = 1; break;
- case 2:
- data = "AA"; len = 2; break;
- case 3:
- data = "AB"; len = 2; break;
- case 4:
- data = "B"; len = 1; break;
- case 5:
- data = "BA"; len = 2; break;
- case 6:
- data = "BB"; len = 2; break;
- case 7:
- len = UNIV_SQL_NULL; break;
- }
-
- field = dtuple_get_nth_field(tuple, 2 - j);
-
- dfield_set_data(field, data, len);
- dtype_set(dfield_get_type(field), DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
-
- i = i / 8;
- }
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_test_tuple3(
-/*===================*/
- dtuple_t* tuple, /* in/out: a tuple with >= 3 fields */
- ulint i, /* in: a number < 1000000 */
- ulint type, /* in: DTUPLE_TEST_FIXED30, ... */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
- ulint third_size;
-
- ut_ad(tuple && buf);
- ut_ad(i < 1000000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- ut_strcpy((char*)buf, "0000000");
-
- buf[1] = (byte)('0' + (i / 100000) % 10);
- buf[2] = (byte)('0' + (i / 10000) % 10);
- buf[3] = (byte)('0' + (i / 1000) % 10);
- buf[4] = (byte)('0' + (i / 100) % 10);
- buf[5] = (byte)('0' + (i / 10) % 10);
- buf[6] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 8);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
-
- i = i % 1000; /* ut_rnd_gen_ulint() % 1000000; */
-
- ut_strcpy((char*)buf + 8, "0000000");
-
- buf[9] = (byte)('0' + (i / 100000) % 10);
- buf[10] = (byte)('0' + (i / 10000) % 10);
- buf[11] = (byte)('0' + (i / 1000) % 10);
- buf[12] = (byte)('0' + (i / 100) % 10);
- buf[13] = (byte)('0' + (i / 10) % 10);
- buf[14] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf + 8, 8);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- field = dtuple_get_nth_field(tuple, 2);
-
- data_rnd += 8757651;
-
- if (type == DTUPLE_TEST_FIXED30) {
- third_size = 30;
- } else if (type == DTUPLE_TEST_RND30) {
- third_size = data_rnd % 30;
- } else if (type == DTUPLE_TEST_RND3500) {
- third_size = data_rnd % 3500;
- } else if (type == DTUPLE_TEST_FIXED2000) {
- third_size = 2000;
- } else if (type == DTUPLE_TEST_FIXED3) {
- third_size = 3;
- } else {
- ut_error;
- }
-
- if (type == DTUPLE_TEST_FIXED30) {
- dfield_set_data(field,
- "12345678901234567890123456789", third_size);
- } else {
- dfield_set_data(field, data_buf, third_size);
- }
-
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple3(
-/*=====================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 or 2 fields */
- ulint i, /* in: a number < 1000000 */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
-
- ut_ad(tuple && buf);
- ut_ad(i < 1000000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- ut_strcpy((char*)buf, "0000000");
-
- buf[1] = (byte)('0' + (i / 100000) % 10);
- buf[2] = (byte)('0' + (i / 10000) % 10);
- buf[3] = (byte)('0' + (i / 1000) % 10);
- buf[4] = (byte)('0' + (i / 100) % 10);
- buf[5] = (byte)('0' + (i / 10) % 10);
- buf[6] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 8);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- if (dtuple_get_n_fields(tuple) == 1) {
-
- return;
- }
-
- field = dtuple_get_nth_field(tuple, 1);
-
- i = (i * 1000) % 1000000;
-
- ut_strcpy((char*)buf + 8, "0000000");
-
- buf[9] = (byte)('0' + (i / 100000) % 10);
- buf[10] = (byte)('0' + (i / 10000) % 10);
- buf[11] = (byte)('0' + (i / 1000) % 10);
- buf[12] = (byte)('0' + (i / 100) % 10);
- buf[13] = (byte)('0' + (i / 10) % 10);
- buf[14] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf + 8, 8);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for TPC-A speed test. */
-
-void
-dtuple_gen_test_tuple_TPC_A(
-/*========================*/
- dtuple_t* tuple, /* in/out: a tuple with >= 3 fields */
- ulint i, /* in: a number < 10000 */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
- ulint third_size;
-
- ut_ad(tuple && buf);
- ut_ad(i < 10000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- ut_strcpy((char*)buf, "0000");
-
- buf[0] = (byte)('0' + (i / 1000) % 10);
- buf[1] = (byte)('0' + (i / 100) % 10);
- buf[2] = (byte)('0' + (i / 10) % 10);
- buf[3] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
-
- dfield_set_data(field, buf + 8, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- field = dtuple_get_nth_field(tuple, 2);
-
- third_size = 90;
-
- dfield_set_data(field, data_buf, third_size);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple_TPC_A(
-/*==========================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 field */
- ulint i, /* in: a number < 10000 */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
-
- ut_ad(tuple && buf);
- ut_ad(i < 10000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- ut_strcpy((char*)buf, "0000");
-
- buf[0] = (byte)('0' + (i / 1000) % 10);
- buf[1] = (byte)('0' + (i / 100) % 10);
- buf[2] = (byte)('0' + (i / 10) % 10);
- buf[3] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for TPC-C speed test. */
-
-void
-dtuple_gen_test_tuple_TPC_C(
-/*========================*/
- dtuple_t* tuple, /* in/out: a tuple with >= 12 fields */
- ulint i, /* in: a number < 100000 */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
- ulint size;
- ulint j;
-
- ut_ad(tuple && buf);
- ut_ad(i < 100000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- buf[0] = (byte)('0' + (i / 10000) % 10);
- buf[1] = (byte)('0' + (i / 1000) % 10);
- buf[2] = (byte)('0' + (i / 100) % 10);
- buf[3] = (byte)('0' + (i / 10) % 10);
- buf[4] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
-
- dfield_set_data(field, buf, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- for (j = 0; j < 10; j++) {
-
- field = dtuple_get_nth_field(tuple, 2 + j);
-
- size = 24;
-
- dfield_set_data(field, data_buf, size);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH,
- 100, 0);
- }
-
- ut_ad(dtuple_validate(tuple));
-}
-
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple_TPC_C(
-/*==========================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 field */
- ulint i, /* in: a number < 100000 */
- byte* buf) /* in: a buffer of size >= 16 bytes */
-{
- dfield_t* field;
-
- ut_ad(tuple && buf);
- ut_ad(i < 100000);
-
- field = dtuple_get_nth_field(tuple, 0);
-
- buf[0] = (byte)('0' + (i / 10000) % 10);
- buf[1] = (byte)('0' + (i / 1000) % 10);
- buf[2] = (byte)('0' + (i / 100) % 10);
- buf[3] = (byte)('0' + (i / 10) % 10);
- buf[4] = (byte)('0' + (i % 10));
-
- dfield_set_data(field, buf, 5);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 100, 0);
-
- ut_ad(dtuple_validate(tuple));
-}
-
-#endif /* notdefined */
diff --git a/innobase/data/data0type.c b/innobase/data/data0type.c
index f505cdfb0a2..71ce5ff3d58 100644
--- a/innobase/data/data0type.c
+++ b/innobase/data/data0type.c
@@ -12,10 +12,99 @@ Created 1/16/1996 Heikki Tuuri
#include "data0type.ic"
#endif
-dtype_t dtype_binary_val = {DATA_BINARY, 0, 0, 0, 0};
+/* At the database startup we store the default-charset collation number of
+this MySQL installation to this global variable. If we have < 4.1.2 format
+column definitions, or records in the insert buffer, we use this
+charset-collation code for them. */
+
+ulint data_mysql_default_charset_coll = 99999999;
+ulint data_mysql_latin1_swedish_charset_coll = 99999999;
+
+dtype_t dtype_binary_val = {DATA_BINARY, 0, 0, 0};
dtype_t* dtype_binary = &dtype_binary_val;
/*************************************************************************
+Checks if a data main type is a string type. Also a BLOB is considered a
+string type. */
+
+ibool
+dtype_is_string_type(
+/*=================*/
+ /* out: TRUE if string type */
+ ulint mtype) /* in: InnoDB main data type code: DATA_CHAR, ... */
+{
+ if (mtype <= DATA_BLOB
+ || mtype == DATA_MYSQL
+ || mtype == DATA_VARMYSQL) {
+
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+/*************************************************************************
+Checks if a type is a binary string type. Note that for tables created with
+< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
+those DATA_BLOB columns this function currently returns FALSE. */
+
+ibool
+dtype_is_binary_string_type(
+/*========================*/
+ /* out: TRUE if binary string type */
+ ulint mtype, /* in: main data type */
+ ulint prtype) /* in: precise type */
+{
+ if ((mtype == DATA_FIXBINARY)
+ || (mtype == DATA_BINARY)
+ || (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {
+
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+/*************************************************************************
+Checks if a type is a non-binary string type. That is, dtype_is_string_type is
+TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
+with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
+For those DATA_BLOB columns this function currently returns TRUE. */
+
+ibool
+dtype_is_non_binary_string_type(
+/*============================*/
+ /* out: TRUE if non-binary string type */
+ ulint mtype, /* in: main data type */
+ ulint prtype) /* in: precise type */
+{
+ if (dtype_is_string_type(mtype) == TRUE
+ && dtype_is_binary_string_type(mtype, prtype) == FALSE) {
+
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+/*************************************************************************
+Forms a precise type from the < 4.1.2 format precise type plus the
+charset-collation code. */
+
+ulint
+dtype_form_prtype(
+/*==============*/
+ ulint old_prtype, /* in: the MySQL type code and the flags
+ DATA_BINARY_TYPE etc. */
+ ulint charset_coll) /* in: MySQL charset-collation code */
+{
+ ut_a(old_prtype < 256 * 256);
+ ut_a(charset_coll < 256);
+
+ return(old_prtype + (charset_coll << 16));
+}
+
+/*************************************************************************
Validates a data type structure. */
ibool
diff --git a/innobase/dict/dict0boot.c b/innobase/dict/dict0boot.c
index 76c94d1a918..46cf6c7788d 100644
--- a/innobase/dict/dict0boot.c
+++ b/innobase/dict/dict0boot.c
@@ -39,8 +39,9 @@ dict_hdr_get(
header = DICT_HDR + buf_page_get(DICT_HDR_SPACE, DICT_HDR_PAGE_NO,
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(header, SYNC_DICT_HEADER);
-
+#endif /* UNIV_SYNC_DEBUG */
return(header);
}
@@ -64,7 +65,7 @@ dict_hdr_get_new_id(
dict_hdr = dict_hdr_get(&mtr);
- id = mtr_read_dulint(dict_hdr + type, MLOG_8BYTES, &mtr);
+ id = mtr_read_dulint(dict_hdr + type, &mtr);
/* Add some dummy code here because otherwise pgcc seems to
compile wrong */
@@ -75,7 +76,7 @@ dict_hdr_get_new_id(
id = ut_dulint_add(id, 1);
- mlog_write_dulint(dict_hdr + type, id, MLOG_8BYTES, &mtr);
+ mlog_write_dulint(dict_hdr + type, id, &mtr);
mtr_commit(&mtr);
@@ -94,7 +95,9 @@ dict_hdr_flush_row_id(void)
dulint id;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
id = dict_sys->row_id;
@@ -102,7 +105,7 @@ dict_hdr_flush_row_id(void)
dict_hdr = dict_hdr_get(&mtr);
- mlog_write_dulint(dict_hdr + DICT_HDR_ROW_ID, id, MLOG_8BYTES, &mtr);
+ mlog_write_dulint(dict_hdr + DICT_HDR_ROW_ID, id, &mtr);
mtr_commit(&mtr);
}
@@ -138,20 +141,16 @@ dict_hdr_create(
/* Start counting row, table, index, and tree ids from
DICT_HDR_FIRST_ID */
mlog_write_dulint(dict_header + DICT_HDR_ROW_ID,
- ut_dulint_create(0, DICT_HDR_FIRST_ID),
- MLOG_8BYTES, mtr);
+ ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr);
mlog_write_dulint(dict_header + DICT_HDR_TABLE_ID,
- ut_dulint_create(0, DICT_HDR_FIRST_ID),
- MLOG_8BYTES, mtr);
+ ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr);
mlog_write_dulint(dict_header + DICT_HDR_INDEX_ID,
- ut_dulint_create(0, DICT_HDR_FIRST_ID),
- MLOG_8BYTES, mtr);
+ ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr);
mlog_write_dulint(dict_header + DICT_HDR_MIX_ID,
- ut_dulint_create(0, DICT_HDR_FIRST_ID),
- MLOG_8BYTES, mtr);
+ ut_dulint_create(0, DICT_HDR_FIRST_ID), mtr);
/* Create the B-tree roots for the clustered indexes of the basic
system tables */
@@ -247,7 +246,7 @@ dict_boot(void)
dict_sys->row_id = ut_dulint_add(
ut_dulint_align_up(
mtr_read_dulint(dict_hdr + DICT_HDR_ROW_ID,
- MLOG_8BYTES, &mtr),
+ &mtr),
DICT_HDR_ROW_ID_WRITE_MARGIN),
DICT_HDR_ROW_ID_WRITE_MARGIN);
diff --git a/innobase/dict/dict0crea.c b/innobase/dict/dict0crea.c
index 038e4803441..6a951317d47 100644
--- a/innobase/dict/dict0crea.c
+++ b/innobase/dict/dict0crea.c
@@ -25,6 +25,11 @@ Created 1/8/1996 Heikki Tuuri
#include "trx0roll.h"
#include "usr0sess.h"
+/* Maximum lengths of identifiers in MySQL, in bytes */
+#define MAX_TABLE_NAME_LEN 64
+#define MAX_COLUMN_NAME_LEN 64
+#define MAX_IDENTIFIER_LEN 255
+
/*********************************************************************
Based on a table object, this function builds the entry to be inserted
in the SYS_TABLES system table. */
@@ -153,7 +158,7 @@ dict_create_sys_tables_tuple(
if (table->type == DICT_TABLE_CLUSTER_MEMBER) {
dfield_set_data(dfield, table->cluster_name,
ut_strlen(table->cluster_name));
- ut_a(0); /* Oracle-style clusters are not supported yet */
+ ut_error; /* Oracle-style clusters are not supported yet */
} else {
dfield_set_data(dfield, NULL, UNIV_SQL_NULL);
}
@@ -267,9 +272,10 @@ dict_build_table_def_step(
ulint error;
mtr_t mtr;
- UT_NOT_USED(thr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
+
table = node->table;
table->id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
@@ -344,33 +350,6 @@ dict_build_col_def_step(
return(DB_SUCCESS);
}
-#ifdef notdefined
-/*************************************************************************
-Creates the single index for a cluster: it contains all the columns of
-the cluster definition in the order they were defined. */
-static
-void
-dict_create_index_for_cluster_step(
-/*===============================*/
- tab_node_t* node) /* in: table create node */
-{
- dict_index_t* index;
- ulint i;
- dict_col_t* col;
-
- index = dict_mem_index_create(table->name, "IND_DEFAULT_CLUSTERED",
- table->space, DICT_CLUSTERED,
- table->n_cols);
-
- for (i = 0; i < table->n_cols; i++) {
- col = dict_table_get_nth_col(table, i);
- dict_mem_index_add_field(index, col->name, 0, 0);
- }
-
- (node->cluster)->index = index;
-}
-#endif
-
/*********************************************************************
Based on an index object, this function builds the entry to be inserted
in the SYS_INDEXES system table. */
@@ -391,7 +370,9 @@ dict_create_sys_indexes_tuple(
byte* ptr;
UT_NOT_USED(trx);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(index && heap);
sys_indexes = dict_sys->sys_indexes;
@@ -584,8 +565,9 @@ dict_build_index_def_step(
dict_index_t* index;
dtuple_t* row;
- UT_NOT_USED(thr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
index = node->index;
@@ -657,8 +639,10 @@ dict_create_index_tree_step(
dtuple_t* search_tuple;
btr_pcur_t pcur;
mtr_t mtr;
-
+
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
UT_NOT_USED(thr);
index = node->index;
@@ -723,7 +707,9 @@ dict_drop_index_tree(
byte* ptr;
ulint len;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ptr = rec_get_nth_field(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len);
@@ -766,26 +752,6 @@ dict_drop_index_tree(
page_rec_write_index_page_no(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD,
FIL_NULL, mtr);
}
-
-#ifdef notdefined
-/*************************************************************************
-Creates the default clustered index for a table: the records are ordered
-by row id. */
-
-void
-dict_create_default_index(
-/*======================*/
- dict_table_t* table, /* in: table */
- trx_t* trx) /* in: transaction handle */
-{
- dict_index_t* index;
-
- index = dict_mem_index_create(table->name, "IND_DEFAULT_CLUSTERED",
- table->space, DICT_CLUSTERED, 0);
-
- dict_create_index(index, trx);
-}
-#endif
/*************************************************************************
Creates a table create graph. */
@@ -873,8 +839,10 @@ dict_create_table_step(
trx_t* trx;
ut_ad(thr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
+
trx = thr_get_trx(thr);
node = thr->run_node;
@@ -981,7 +949,9 @@ dict_create_index_step(
trx_t* trx;
ut_ad(thr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx = thr_get_trx(thr);
@@ -1170,7 +1140,7 @@ dict_create_or_check_foreign_constraint_tables(void)
graph->fork_type = QUE_FORK_MYSQL_INTERFACE;
- ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0));
+ ut_a(thr = que_fork_start_command(graph));
que_run_threads(thr);
@@ -1210,26 +1180,42 @@ dict_create_or_check_foreign_constraint_tables(void)
}
/************************************************************************
-Adds foreign key definitions to data dictionary tables in the database. */
+Adds foreign key definitions to data dictionary tables in the database. We
+look at table->foreign_list, and also generate names to constraints that were
+not named by the user. A generated constraint has a name of the format
+databasename/tablename_ibfk_<number>, where the numbers start from 1, and are
+given locally for this table, that is, the number is not global, as in the
+old format constraints < 4.0.18 it used to be. */
ulint
dict_create_add_foreigns_to_dictionary(
/*===================================*/
/* out: error code or DB_SUCCESS */
+ ulint start_id,/* in: if we are actually doing ALTER TABLE
+ ADD CONSTRAINT, we want to generate constraint
+ numbers which are bigger than in the table so
+ far; we number the constraints from
+ start_id + 1 up; start_id should be set to 0 if
+ we are creating a new table, or if the table
+ so far has no constraints for which the name
+ was generated here */
dict_table_t* table, /* in: table */
trx_t* trx) /* in: transaction */
{
dict_foreign_t* foreign;
que_thr_t* thr;
que_t* graph;
- dulint id;
+ ulint number = start_id + 1;
ulint len;
+ ulint namelen;
ulint error;
+ char* ebuf = dict_foreign_err_buf;
ulint i;
- char buf2[50];
char buf[10000];
- ut_ad(mutex_own(&(dict_sys->mutex)));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (NULL == dict_table_get_low((char *) "SYS_FOREIGN")) {
fprintf(stderr,
@@ -1254,34 +1240,43 @@ loop:
"PROCEDURE ADD_FOREIGN_DEFS_PROC () IS\n"
"BEGIN\n");
- /* We allocate the new id from the sequence of table id's */
- id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
+ namelen = strlen(table->name);
+ ut_a(namelen < MAX_TABLE_NAME_LEN);
+
+ if (foreign->id == NULL) {
+ /* Generate a new constraint id */
+ foreign->id = mem_heap_alloc(foreign->heap, namelen + 20);
+ /* no overflow if number < 1e13 */
+ sprintf(foreign->id, "%s_ibfk_%lu", table->name, (ulong) number);
+ number++;
+ }
+
+ ut_a(strlen(foreign->id) < MAX_IDENTIFIER_LEN);
+ ut_a(len < (sizeof buf)
+ - 46 - 2 * MAX_TABLE_NAME_LEN - MAX_IDENTIFIER_LEN - 20);
- sprintf(buf2, "%lu_%lu", (ulong) ut_dulint_get_high(id),
- (ulong) ut_dulint_get_low(id));
- foreign->id = mem_heap_alloc(foreign->heap, ut_strlen(buf2) + 1);
- ut_memcpy(foreign->id, buf2, ut_strlen(buf2) + 1);
-
len += sprintf(buf + len,
- "INSERT INTO SYS_FOREIGN VALUES('%lu_%lu', '%s', '%s', %lu);\n",
- (ulong) ut_dulint_get_high(id),
- (ulong) ut_dulint_get_low(id),
+ "INSERT INTO SYS_FOREIGN VALUES('%s', '%s', '%s', %lu);\n",
+ foreign->id,
table->name,
foreign->referenced_table_name,
(ulong) (foreign->n_fields
+ (foreign->type << 24)));
for (i = 0; i < foreign->n_fields; i++) {
+ ut_a(len < (sizeof buf)
+ - 51 - 2 * MAX_COLUMN_NAME_LEN
+ - MAX_IDENTIFIER_LEN - 20);
len += sprintf(buf + len,
- "INSERT INTO SYS_FOREIGN_COLS VALUES('%lu_%lu', %lu, '%s', '%s');\n",
- (ulong) ut_dulint_get_high(id),
- (ulong) ut_dulint_get_low(id),
+ "INSERT INTO SYS_FOREIGN_COLS VALUES('%s', %lu, '%s', '%s');\n",
+ foreign->id,
(ulong) i,
foreign->foreign_col_names[i],
foreign->referenced_col_names[i]);
}
+ ut_a(len < (sizeof buf) - 19);
len += sprintf(buf + len,"COMMIT WORK;\nEND;\n");
graph = pars_sql(buf);
@@ -1293,7 +1288,7 @@ loop:
graph->fork_type = QUE_FORK_MYSQL_INTERFACE;
- ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0));
+ ut_a(thr = que_fork_start_command(graph));
que_run_threads(thr);
@@ -1301,30 +1296,33 @@ loop:
que_graph_free(graph);
+ if (error == DB_DUPLICATE_KEY) {
+ mutex_enter(&dict_foreign_err_mutex);
+ ut_sprintf_timestamp(ebuf);
+ ut_a(strlen(ebuf) < DICT_FOREIGN_ERR_BUF_LEN
+ - MAX_TABLE_NAME_LEN - MAX_IDENTIFIER_LEN - 201);
+ sprintf(ebuf + strlen(ebuf),
+" Error in foreign key constraint creation for table %s.\n"
+"A foreign key constraint of name %s\n"
+"already exists (note that internally InnoDB adds 'databasename/'\n"
+"in front of the user-defined constraint name).\n", table->name, foreign->id);
+
+ mutex_exit(&dict_foreign_err_mutex);
+
+ return(error);
+ }
+
if (error != DB_SUCCESS) {
fprintf(stderr,
"InnoDB: Foreign key constraint creation failed:\n"
"InnoDB: internal error number %lu\n", (ulong) error);
- if (error == DB_DUPLICATE_KEY) {
- fprintf(stderr,
- "InnoDB: Duplicate key error in system table %s index %s\n",
- ((dict_index_t*)trx->error_info)->table_name,
- ((dict_index_t*)trx->error_info)->name);
-
- fprintf(stderr, "%s\n", buf);
-
- fprintf(stderr,
- "InnoDB: Maybe the internal data dictionary of InnoDB is\n"
- "InnoDB: out-of-sync from the .frm files of your tables.\n"
- "InnoDB: See section 15.1 Troubleshooting data dictionary operations\n"
- "InnoDB: at http://www.innodb.com/ibman.html\n");
- }
-
mutex_enter(&dict_foreign_err_mutex);
- ut_sprintf_timestamp(buf);
- sprintf(buf + strlen(buf),
-" Internal error in foreign key constraint creation for table %.500s.\n"
+ ut_sprintf_timestamp(ebuf);
+ ut_a(strlen(ebuf) < DICT_FOREIGN_ERR_BUF_LEN
+ - MAX_TABLE_NAME_LEN - 124);
+ sprintf(ebuf + strlen(ebuf),
+" Internal error in foreign key constraint creation for table %s.\n"
"See the MySQL .err log in the datadir for more information.\n", table->name);
mutex_exit(&dict_foreign_err_mutex);
diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c
index da5ffaecf41..cf4b0482aa2 100644
--- a/innobase/dict/dict0dict.c
+++ b/innobase/dict/dict0dict.c
@@ -52,7 +52,7 @@ rw_lock_t dict_operation_lock; /* table create, drop, etc. reserve
hash table fixed size in bytes */
#define DICT_POOL_PER_VARYING 4 /* buffer pool max size per data
dictionary varying size in bytes */
-
+
/**************************************************************************
Adds a column to the data dictionary hash table. */
static
@@ -209,7 +209,7 @@ dict_tables_have_same_db(
}
}
- ut_a(0);
+ ut_error;
return(FALSE);
}
@@ -232,10 +232,33 @@ dict_remove_db_name(
}
}
- ut_a(0);
+ ut_error;
return(NULL);
}
+
+/************************************************************************
+Get the database name length in a table name. */
+
+ulint
+dict_get_db_name_len(
+/*=================*/
+ /* out: database name length */
+ char* name) /* in: table name in the form dbname '/' tablename */
+{
+ ulint i;
+
+ for (i = 0; i < 100000 ; i++) {
+ if (name[i] == '/') {
+
+ return(i);
+ }
+ }
+
+ ut_error;
+
+ return(0);
+}
/************************************************************************
Reserves the dictionary system mutex for MySQL. */
@@ -593,7 +616,9 @@ dict_table_get_on_id(
if we are doing a rollback to handle an error in TABLE
CREATE, for example, we already have the mutex! */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
return(dict_table_get_on_id_low(table_id, trx));
}
@@ -608,7 +633,7 @@ dict_table_get_on_id(
}
/************************************************************************
-Looks for column n postion in the clustered index. */
+Looks for column n position in the clustered index. */
ulint
dict_table_get_nth_col_pos(
@@ -622,6 +647,44 @@ dict_table_get_nth_col_pos(
n));
}
+/************************************************************************
+Checks if a column is in the ordering columns of the clustered index of a
+table. Column prefixes are treated like whole columns. */
+
+ibool
+dict_table_col_in_clustered_key(
+/*============================*/
+ /* out: TRUE if the column, or its prefix, is
+ in the clustered key */
+ dict_table_t* table, /* in: table */
+ ulint n) /* in: column number */
+{
+ dict_index_t* index;
+ dict_field_t* field;
+ dict_col_t* col;
+ ulint pos;
+ ulint n_fields;
+
+ ut_ad(table);
+
+ col = dict_table_get_nth_col(table, n);
+
+ index = dict_table_get_first_index(table);
+
+ n_fields = dict_index_get_n_unique(index);
+
+ for (pos = 0; pos < n_fields; pos++) {
+ field = dict_index_get_nth_field(index, pos);
+
+ if (col == field->col) {
+
+ return(TRUE);
+ }
+ }
+
+ return(FALSE);
+}
+
/**************************************************************************
Inits the data dictionary module. */
@@ -739,7 +802,9 @@ dict_table_add_to_cache(
ulint i;
ut_ad(table);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->n_def == table->n_cols - DATA_N_SYS_COLS);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
ut_ad(table->cached == FALSE);
@@ -870,12 +935,15 @@ dict_table_rename_in_cache(
ulint fold;
ulint old_size;
char* name_buf;
+ char* old_name;
ibool success;
ulint i;
ut_ad(table);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
+
old_size = mem_heap_get_size(table->heap);
fold = ut_fold_string(new_name);
@@ -916,6 +984,9 @@ dict_table_rename_in_cache(
/* Remove table from the hash tables of tables */
HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
ut_fold_string(table->name), table);
+ old_name = mem_heap_alloc(table->heap, ut_strlen(table->name) + 1);
+
+ ut_strcpy(old_name, table->name);
name_buf = mem_heap_alloc(table->heap, ut_strlen(new_name) + 1);
@@ -972,7 +1043,9 @@ dict_table_rename_in_cache(
return(TRUE);
}
- /* Update the table name fields in foreign constraints */
+ /* Update the table name fields in foreign constraints, and update also
+ the constraint id of new format >= 4.0.18 constraints. Note that at
+ this point we have already changed table->name to the new name. */
foreign = UT_LIST_GET_FIRST(table->foreign_list);
@@ -981,14 +1054,68 @@ dict_table_rename_in_cache(
ut_strlen(table->name)) {
/* Allocate a longer name buffer;
TODO: store buf len to save memory */
+
foreign->foreign_table_name = mem_heap_alloc(
foreign->heap,
ut_strlen(table->name) + 1);
}
- ut_memcpy(foreign->foreign_table_name, table->name,
- ut_strlen(table->name) + 1);
- foreign->foreign_table_name[ut_strlen(table->name)] = '\0';
+ sprintf(foreign->foreign_table_name, "%s", table->name);
+
+ if (ut_str_contains(foreign->id, '/')) {
+ ulint db_len;
+ char old_id[2000];
+
+ /* This is a >= 4.0.18 format id */
+
+ ut_a(ut_strlen(foreign->id) < 1999);
+
+ ut_strcpy(old_id, foreign->id);
+
+ if (ut_strlen(foreign->id) > ut_strlen(old_name)
+ + ut_strlen("_ibfk_")
+ && 0 == ut_memcmp(foreign->id, old_name,
+ ut_strlen(old_name))
+ && 0 == ut_memcmp(
+ foreign->id + ut_strlen(old_name),
+ (char*)"_ibfk_", ut_strlen("_ibfk_"))) {
+
+ /* This is a generated >= 4.0.18 format id */
+
+ if (ut_strlen(table->name)
+ > ut_strlen(old_name)) {
+ foreign->id = mem_heap_alloc(
+ foreign->heap,
+ ut_strlen(table->name)
+ + ut_strlen(old_id) + 1);
+ }
+
+ /* Replace the prefix 'databasename/tablename'
+ with the new names */
+ sprintf(foreign->id, "%s%s", table->name,
+ old_id + ut_strlen(old_name));
+ } else {
+ /* This is a >= 4.0.18 format id where the user
+ gave the id name */
+ db_len = dict_get_db_name_len(table->name) + 1;
+
+ if (dict_get_db_name_len(table->name)
+ > dict_get_db_name_len(foreign->id)) {
+
+ foreign->id = mem_heap_alloc(
+ foreign->heap,
+ db_len + ut_strlen(old_id) + 1);
+ }
+
+ /* Replace the database prefix in id with the
+ one from table->name */
+
+ ut_memcpy(foreign->id, table->name, db_len);
+
+ sprintf(foreign->id + db_len, "%s",
+ dict_remove_db_name(old_id));
+ }
+ }
foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
}
@@ -1000,14 +1127,13 @@ dict_table_rename_in_cache(
ut_strlen(table->name)) {
/* Allocate a longer name buffer;
TODO: store buf len to save memory */
+
foreign->referenced_table_name = mem_heap_alloc(
foreign->heap,
ut_strlen(table->name) + 1);
}
- ut_memcpy(foreign->referenced_table_name, table->name,
- ut_strlen(table->name) + 1);
- foreign->referenced_table_name[ut_strlen(table->name)] = '\0';
+ sprintf(foreign->referenced_table_name, "%s", table->name);
foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
}
@@ -1054,7 +1180,9 @@ dict_table_remove_from_cache(
ulint i;
ut_ad(table);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
/* printf("Removing table %s from dictionary cache\n", table->name); */
@@ -1123,9 +1251,11 @@ dict_table_LRU_trim(void)
dict_table_t* table;
dict_table_t* prev_table;
- ut_a(0);
+ ut_error;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
table = UT_LIST_GET_LAST(dict_sys->table_LRU);
@@ -1154,7 +1284,9 @@ dict_col_add_to_cache(
ulint fold;
ut_ad(table && col);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
fold = ut_fold_ulint_pair(ut_fold_string(table->name),
@@ -1185,7 +1317,9 @@ dict_col_remove_from_cache(
ulint fold;
ut_ad(table && col);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
fold = ut_fold_ulint_pair(ut_fold_string(table->name),
@@ -1208,7 +1342,9 @@ dict_col_reposition_in_cache(
ulint fold;
ut_ad(table && col);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
fold = ut_fold_ulint_pair(ut_fold_string(table->name),
@@ -1242,7 +1378,9 @@ dict_index_add_to_cache(
ulint i;
ut_ad(index);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(index->n_def == index->n_fields);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
@@ -1368,7 +1506,9 @@ dict_index_remove_from_cache(
ut_ad(table && index);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(UT_LIST_GET_LEN((index->tree)->tree_indexes) == 1);
dict_tree_free(index->tree);
@@ -1412,7 +1552,9 @@ dict_index_find_cols(
ut_ad(table && index);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < index->n_fields; i++) {
field = dict_index_get_nth_field(index, i);
@@ -1553,7 +1695,9 @@ dict_index_build_internal_clust(
ut_ad(table && index);
ut_ad(index->type & DICT_CLUSTERED);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
/* Create a new index object with certainly enough fields */
@@ -1722,7 +1866,9 @@ dict_index_build_internal_non_clust(
ut_ad(table && index);
ut_ad(0 == (index->type & DICT_CLUSTERED));
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
/* The clustered index should be the first in the list of indexes */
@@ -1805,6 +1951,24 @@ dict_index_build_internal_non_clust(
/*====================== FOREIGN KEY PROCESSING ========================*/
/*************************************************************************
+Checks if a table is referenced by foreign keys. */
+
+ibool
+dict_table_referenced_by_foreign_key(
+/*=================================*/
+ /* out: TRUE if table is referenced by a
+ foreign key */
+ dict_table_t* table) /* in: InnoDB table */
+{
+ if (UT_LIST_GET_LEN(table->referenced_list) > 0) {
+
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+/*************************************************************************
Frees a foreign key struct. */
static
void
@@ -1823,7 +1987,9 @@ dict_foreign_remove_from_cache(
/*===========================*/
dict_foreign_t* foreign) /* in, own: foreign constraint */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(foreign);
if (foreign->referenced_table) {
@@ -1852,7 +2018,9 @@ dict_foreign_find(
{
dict_foreign_t* foreign;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
foreign = UT_LIST_GET_FIRST(table->foreign_list);
@@ -1961,7 +2129,9 @@ dict_foreign_add_to_cache(
ibool added_to_referenced_list = FALSE;
char* buf = dict_foreign_err_buf;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
for_table = dict_table_check_if_in_cache_low(
foreign->foreign_table_name);
@@ -2083,7 +2253,7 @@ static
char*
dict_scan_to(
/*=========*/
-
+ /* out: scanned up to this */
char* ptr, /* in: scan from */
const char *string) /* in: look for this */
{
@@ -2150,6 +2320,68 @@ dict_accept(
}
/*************************************************************************
+Scans an id. For the lexical definition of an 'id', see the code below.
+Strips backquotes or double quotes from around the id. */
+static
+char*
+dict_scan_id(
+/*=========*/
+ /* out: scanned to */
+ char* ptr, /* in: scanned to */
+ char** start, /* out: start of the id; NULL if no id was
+ scannable */
+ ulint* len, /* out: length of the id */
+ ibool accept_also_dot)/* in: TRUE if also a dot can appear in a
+ non-quoted id; in a quoted id it can appear
+ always */
+{
+ char quote = '\0';
+
+ *start = NULL;
+
+ while (isspace(*ptr)) {
+ ptr++;
+ }
+
+ if (*ptr == '\0') {
+
+ return(ptr);
+ }
+
+ if (*ptr == '`' || *ptr == '"') {
+ quote = *ptr++;
+ }
+
+ *start = ptr;
+
+ if (quote) {
+ while (*ptr != quote && *ptr != '\0') {
+ ptr++;
+ }
+ } else {
+ while (!isspace(*ptr) && *ptr != '(' && *ptr != ')'
+ && (accept_also_dot || *ptr != '.')
+ && *ptr != ',' && *ptr != '\0') {
+
+ ptr++;
+ }
+ }
+
+ *len = (ulint) (ptr - *start);
+
+ if (quote) {
+ if (*ptr == quote) {
+ ptr++;
+ } else {
+ /* Syntax error */
+ *start = NULL;
+ }
+ }
+
+ return(ptr);
+}
+
+/*************************************************************************
Tries to scan a column name. */
static
char*
@@ -2165,46 +2397,29 @@ dict_scan_col(
ulint* column_name_len)/* out: column name length */
{
dict_col_t* col;
- char* old_ptr;
ulint i;
*success = FALSE;
- while (isspace(*ptr)) {
- ptr++;
- }
-
- if (*ptr == '\0') {
-
- return(ptr);
- }
-
- if (*ptr == '`') {
- ptr++;
- }
+ ptr = dict_scan_id(ptr, column_name, column_name_len, TRUE);
- old_ptr = ptr;
-
- while (!isspace(*ptr) && *ptr != ',' && *ptr != ')' && *ptr != '`'
- && *ptr != '\0') {
+ if (column_name == NULL) {
- ptr++;
+ return(ptr); /* Syntax error */
}
- *column_name_len = (ulint)(ptr - old_ptr);
-
if (table == NULL) {
*success = TRUE;
*column = NULL;
- *column_name = old_ptr;
} else {
for (i = 0; i < dict_table_get_n_cols(table); i++) {
col = dict_table_get_nth_col(table, i);
- if (ut_strlen(col->name) == (ulint)(ptr - old_ptr)
- && 0 == ut_cmp_in_lower_case(col->name, old_ptr,
- (ulint)(ptr - old_ptr))) {
+ if (ut_strlen(col->name) == *column_name_len
+ && 0 == ut_cmp_in_lower_case(col->name,
+ *column_name,
+ *column_name_len)) {
/* Found */
*success = TRUE;
@@ -2216,10 +2431,6 @@ dict_scan_col(
}
}
- if (*ptr == '`') {
- ptr++;
- }
-
return(ptr);
}
@@ -2238,144 +2449,112 @@ dict_scan_table_name(
the referenced table name; must be at least
2500 bytes */
{
- char* dot_ptr = NULL;
- char* old_ptr;
+ char* database_name = NULL;
+ ulint database_name_len = 999999999; /* init to a dummy value to
+ suppress a compiler warning */
+ char* table_name = NULL;
+ ulint table_name_len;
+ char* scanned_id;
+ ulint scanned_id_len;
ulint i;
*success = FALSE;
*table = NULL;
+
+ ptr = dict_scan_id(ptr, &scanned_id, &scanned_id_len, FALSE);
- while (isspace(*ptr)) {
- ptr++;
+ if (scanned_id == NULL) {
+
+ return(ptr); /* Syntax error */
}
- if (*ptr == '\0') {
+ if (*ptr == '.') {
+ /* We scanned the database name; scan also the table name */
- return(ptr);
- }
-
- if (*ptr == '`') {
ptr++;
- }
- old_ptr = ptr;
-
- while (!isspace(*ptr) && *ptr != '(' && *ptr != '`' && *ptr != '\0') {
- if (*ptr == '.') {
- dot_ptr = ptr;
- }
+ database_name = scanned_id;
+ database_name_len = scanned_id_len;
- ptr++;
- }
+ ptr = dict_scan_id(ptr, &table_name, &table_name_len, FALSE);
- if (ptr - old_ptr > 2000) {
- return(old_ptr);
- }
-
- if (dot_ptr == NULL) {
- /* Copy the database name from 'name' to the start */
- for (i = 0;; i++) {
- second_table_name[i] = name[i];
- if (name[i] == '/') {
- i++;
- break;
- }
- }
-#ifdef __WIN__
- ut_cpy_in_lower_case(second_table_name + i, old_ptr,
- ptr - old_ptr);
-#else
- if (srv_lower_case_table_names) {
- ut_cpy_in_lower_case(second_table_name + i, old_ptr,
- ptr - old_ptr);
- } else {
- ut_memcpy(second_table_name + i, old_ptr,
- ptr - old_ptr);
+ if (table_name == NULL) {
+
+ return(ptr); /* Syntax error */
}
-#endif
- second_table_name[i + (ptr - old_ptr)] = '\0';
} else {
-#ifdef __WIN__
- ut_cpy_in_lower_case(second_table_name, old_ptr,
- ptr - old_ptr);
-#else
- if (srv_lower_case_table_names) {
- ut_cpy_in_lower_case(second_table_name, old_ptr,
- ptr - old_ptr);
- } else {
- ut_memcpy(second_table_name, old_ptr, ptr - old_ptr);
+ /* To be able to read table dumps made with InnoDB-4.0.17 or
+ earlier, we must allow the dot separator between the database
+ name and the table name also to appear within a quoted
+ identifier! InnoDB used to print a constraint as:
+ ... REFERENCES `databasename.tablename` ...
+ starting from 4.0.18 it is
+ ... REFERENCES `databasename`.`tablename` ... */
+
+ for (i = 0; i < scanned_id_len; i++) {
+ if (scanned_id[i] == '.') {
+ database_name = scanned_id;
+ database_name_len = i;
+
+ scanned_id = scanned_id + i + 1;
+ scanned_id_len -= i + 1;
+ }
}
-#endif
- second_table_name[dot_ptr - old_ptr] = '/';
- second_table_name[ptr - old_ptr] = '\0';
- }
- *success = TRUE;
-
- *table = dict_table_get_low(second_table_name);
-
- if (*ptr == '`') {
- ptr++;
+ table_name = scanned_id;
+ table_name_len = scanned_id_len;
}
- return(ptr);
-}
+ if (database_name == NULL) {
+ /* Use the database name of the foreign key table */
-/*************************************************************************
-Scans an id. For the lexical definition of an 'id', see the code below.
-Strips backquotes from around the id. */
-static
-char*
-dict_scan_id(
-/*=========*/
- /* out: scanned to */
- char* ptr, /* in: scanned to */
- char** start, /* out: start of the id; NULL if no id was
- scannable */
- ulint* len) /* out: length of the id */
-{
- ibool scanned_backquote = FALSE;
-
- *start = NULL;
-
- while (isspace(*ptr)) {
- ptr++;
+ database_name = name;
+
+ database_name_len = dict_get_db_name_len(name);
}
- if (*ptr == '\0') {
-
- return(ptr);
- }
+ if (table_name_len + database_name_len > 2000) {
- if (*ptr == '`') {
- scanned_backquote = TRUE;
- ptr++;
+ return(ptr); /* Too long name */
}
- *start = ptr;
-
- while (!isspace(*ptr) && *ptr != ',' && *ptr != '(' && *ptr != ')'
- && *ptr != '\0' && *ptr != '`') {
-
- ptr++;
+#ifdef __WIN__
+ ut_cpy_in_lower_case(second_table_name, database_name,
+ database_name_len);
+#else
+ if (srv_lower_case_table_names) {
+ ut_cpy_in_lower_case(second_table_name, database_name,
+ database_name_len);
+ } else {
+ ut_memcpy(second_table_name, database_name,
+ database_name_len);
}
+#endif
+ second_table_name[database_name_len] = '/';
- *len = (ulint) (ptr - *start);
-
- if (scanned_backquote) {
- if (*ptr == '`') {
- ptr++;
- } else {
- /* Syntax error */
- *start = NULL;
- }
+#ifdef __WIN__
+ ut_cpy_in_lower_case(second_table_name + database_name_len + 1,
+ table_name, table_name_len);
+#else
+ if (srv_lower_case_table_names) {
+ ut_cpy_in_lower_case(second_table_name + database_name_len + 1,
+ table_name, table_name_len);
+ } else {
+ ut_memcpy(second_table_name + database_name_len + 1,
+ table_name, table_name_len);
}
+#endif
+ second_table_name[database_name_len + 1 + table_name_len] = '\0';
+
+ *success = TRUE;
+
+ *table = dict_table_get_low(second_table_name);
return(ptr);
}
/*************************************************************************
-Skips one id. */
+Skips one id. The id is allowed to contain also '.'. */
static
char*
dict_skip_word(
@@ -2390,7 +2569,7 @@ dict_skip_word(
*success = FALSE;
- ptr = dict_scan_id(ptr, &start, &len);
+ ptr = dict_scan_id(ptr, &start, &len, TRUE);
if (start) {
*success = TRUE;
@@ -2506,6 +2685,52 @@ scan_more:
}
/*************************************************************************
+Finds the highest <number> for foreign key constraints of the table. Looks
+only at the >= 4.0.18-format id's, which are of the form
+databasename/tablename_ibfk_<number>. */
+static
+ulint
+dict_table_get_highest_foreign_id(
+/*==============================*/
+ /* out: highest number, 0 if table has no new
+ format foreign key constraints */
+ dict_table_t* table) /* in: table in the dictionary memory cache */
+{
+ dict_foreign_t* foreign;
+ char* endp;
+ ulint biggest_id = 0;
+ ulint id;
+
+ ut_a(table);
+
+ foreign = UT_LIST_GET_FIRST(table->foreign_list);
+
+ while (foreign) {
+ if (ut_strlen(foreign->id) > ut_strlen("_ibfk_")
+ + ut_strlen(table->name)
+ && 0 == ut_memcmp(foreign->id, table->name,
+ ut_strlen(table->name))
+ && 0 == ut_memcmp(foreign->id + ut_strlen(table->name),
+ (char*)"_ibfk_", ut_strlen("_ibfk_"))) {
+ /* It is of the >= 4.0.18 format */
+
+ id = strtoul(foreign->id + ut_strlen(table->name)
+ + ut_strlen("_ibfk_"),
+ &endp, 10);
+ ut_a(id != biggest_id);
+
+ if (id > biggest_id) {
+ biggest_id = id;
+ }
+ }
+
+ foreign = UT_LIST_GET_NEXT(foreign_list, foreign);
+ }
+
+ return(biggest_id);
+}
+
+/*************************************************************************
Reports a simple foreign key create clause syntax error. */
static
void
@@ -2547,19 +2772,26 @@ dict_create_foreign_constraints_low(
FOREIGN KEY (a, b) REFERENCES table2(c, d),
table2 can be written also with the database
name before it: test.table2; the default
- database id the database of parameter name */
+ database is the database of parameter name */
char* name) /* in: table full name in the normalized form
database_name/table_name */
{
dict_table_t* table;
dict_table_t* referenced_table;
+ dict_table_t* table_to_alter;
+ ulint highest_id_so_far = 0;
dict_index_t* index;
dict_foreign_t* foreign;
char* ptr = sql_string;
char* start_of_latest_foreign = sql_string;
char* buf = dict_foreign_err_buf;
+ char* constraint_name; /* this is NOT a null-
+ terminated string */
+ ulint constraint_name_len;
ibool success;
ulint error;
+ char* ptr1;
+ char* ptr2;
ulint i;
ulint j;
ibool is_on_delete;
@@ -2570,7 +2802,9 @@ dict_create_foreign_constraints_low(
ulint column_name_lens[500];
char referenced_table_name[2500];
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
table = dict_table_get_low(name);
@@ -2586,16 +2820,89 @@ dict_create_foreign_constraints_low(
return(DB_ERROR);
}
+
+ /* First check if we are actually doing an ALTER TABLE, and in that
+ case look for the table being altered */
+
+ ptr = dict_accept(ptr, (char*) "ALTER", &success);
+
+ if (!success) {
+
+ goto loop;
+ }
+
+ ptr = dict_accept(ptr, (char*) "TABLE", &success);
+
+ if (!success) {
+
+ goto loop;
+ }
+
+ /* We are doing an ALTER TABLE: scan the table name we are altering;
+ in the call below we use the buffer 'referenced_table_name' as a dummy
+ buffer */
+
+ ptr = dict_scan_table_name(ptr, &table_to_alter, name,
+ &success, referenced_table_name);
+ if (!success) {
+ fprintf(stderr,
+"InnoDB: Error: could not find the table being ALTERED in:\n%s\n", sql_string);
+
+ return(DB_ERROR);
+ }
+
+ /* Starting from 4.0.18 and 4.1.2, we generate foreign key id's in the
+ format databasename/tablename_ibfk_<number>, where <number> is local
+ to the table; look for the highest <number> for table_to_alter, so
+ that we can assign to new constraints higher numbers. */
+
+ /* If we are altering a temporary table, the table name after ALTER
+ TABLE does not correspond to the internal table name, and
+ table_to_alter is NULL. TODO: should we fix this somehow? */
+
+ if (table_to_alter == NULL) {
+ highest_id_so_far = 0;
+ } else {
+ highest_id_so_far = dict_table_get_highest_foreign_id(
+ table_to_alter);
+ }
+
+ /* Scan for foreign key declarations in a loop */
loop:
- ptr = dict_scan_to(ptr, (char *) "FOREIGN");
+ /* Scan either to "CONSTRAINT" or "FOREIGN", whichever is closer */
- if (*ptr == '\0') {
+ ptr1 = dict_scan_to(ptr, (char *) "CONSTRAINT");
+ ptr2 = dict_scan_to(ptr, (char *) "FOREIGN");
+
+ constraint_name = NULL;
+
+ if (ptr1 < ptr2) {
+ /* The user has specified a constraint name. Pick it so
+ that we can store 'databasename/constraintname' as the id of
+ the id of the constraint to system tables. */
+ ptr = ptr1;
+
+ ptr = dict_accept(ptr, (char *) "CONSTRAINT", &success);
+ ut_a(success);
+
+ if (!isspace(*ptr)) {
+ goto loop;
+ }
+
+ ptr = dict_scan_id(ptr, &constraint_name, &constraint_name_len,
+ FALSE);
+ } else {
+ ptr = ptr2;
+ }
+
+ if (*ptr == '\0') {
+ /**********************************************************/
/* The following call adds the foreign key constraints
to the data dictionary system tables on disk */
- error = dict_create_add_foreigns_to_dictionary(table, trx);
-
+ error = dict_create_add_foreigns_to_dictionary(
+ highest_id_so_far, table, trx);
return(error);
}
@@ -2703,6 +3010,28 @@ col_loop1:
foreign = dict_mem_foreign_create();
+ if (constraint_name) {
+ ulint db_len;
+
+ /* Catenate 'databasename/' to the constraint name specified
+ by the user: we conceive the constraint as belonging to the
+ same MySQL 'database' as the table itself. We store the name
+ to foreign->id. */
+
+ db_len = dict_get_db_name_len(table->name);
+
+ foreign->id = mem_heap_alloc(foreign->heap,
+ db_len + 1 + constraint_name_len + 1);
+
+ ut_memcpy(foreign->id, table->name, db_len);
+
+ foreign->id[db_len] = '/';
+
+ ut_memcpy(foreign->id + db_len + 1, constraint_name,
+ constraint_name_len);
+ foreign->id[db_len + 1 + constraint_name_len] = '\0';
+ }
+
foreign->foreign_table = table;
foreign->foreign_table_name = table->name;
foreign->foreign_index = index;
@@ -3004,7 +3333,7 @@ dict_create_foreign_constraints(
FOREIGN KEY (a, b) REFERENCES table2(c, d),
table2 can be written also with the database
name before it: test.table2; the default
- database id the database of parameter name */
+ database is the database of parameter name */
char* name) /* in: table full name in the normalized form
database_name/table_name */
{
@@ -3055,7 +3384,9 @@ dict_foreign_parse_drop_constraints(
str = dict_strip_comments(*(trx->mysql_query_str));
ptr = str;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
loop:
ptr = dict_scan_to(ptr, (char *) "DROP");
@@ -3088,7 +3419,7 @@ loop:
goto syntax_error;
}
- ptr = dict_scan_id(ptr, &start, &len);
+ ptr = dict_scan_id(ptr, &start, &len, TRUE);
if (start == NULL) {
@@ -3106,8 +3437,10 @@ loop:
foreign = UT_LIST_GET_FIRST(table->foreign_list);
while (foreign != NULL) {
- if (0 == ut_strcmp(foreign->id, id)) {
-
+ if (0 == ut_strcmp(foreign->id, id)
+ || (ut_str_contains(foreign->id, '/')
+ && 0 == ut_strcmp(id,
+ dict_remove_db_name(foreign->id)))) {
/* Found */
break;
}
@@ -3120,8 +3453,8 @@ loop:
ut_sprintf_timestamp(buf);
sprintf(buf + strlen(buf),
" Error in dropping of a foreign key constraint of table %.500s,\n"
-"just before:\n%s\n in SQL command\n%s\nCannot find a constraint with the\n"
-"given id %s.\n", table->name, ptr, str, id);
+"in SQL command\n%s\nCannot find a constraint with the\n"
+"given id %s.\n", table->name, str, id);
ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN);
mutex_exit(&dict_foreign_err_mutex);
@@ -3193,7 +3526,9 @@ dict_procedure_reserve_parsed_copy(
que_t* graph;
proc_node_t* proc_node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(dict_sys->mutex));
@@ -3241,7 +3576,9 @@ dict_procedure_release_parsed_copy(
{
proc_node_t* proc_node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(dict_sys->mutex));
@@ -3318,9 +3655,9 @@ dict_tree_create(
tree->id = index->id;
UT_LIST_INIT(tree->tree_indexes);
-
+#ifdef UNIV_DEBUG
tree->magic_n = DICT_TREE_MAGIC_N;
-
+#endif /* UNIV_DEBUG */
rw_lock_create(&(tree->lock));
rw_lock_set_level(&(tree->lock), SYNC_INDEX_TREE);
@@ -3337,7 +3674,7 @@ dict_tree_free(
dict_tree_t* tree) /* in, own: index tree */
{
ut_a(tree);
- ut_a(tree->magic_n == DICT_TREE_MAGIC_N);
+ ut_ad(tree->magic_n == DICT_TREE_MAGIC_N);
rw_lock_free(&(tree->lock));
mem_free(tree);
@@ -3731,7 +4068,9 @@ dict_foreign_print_low(
{
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
printf(" FOREIGN KEY CONSTRAINT %s: %s (", foreign->id,
foreign->foreign_table_name);
@@ -3796,7 +4135,9 @@ dict_table_print_low(
dict_foreign_t* foreign;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
dict_update_statistics_low(table, TRUE);
@@ -3850,7 +4191,9 @@ dict_col_print_low(
{
dtype_t* type;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
type = dict_col_get_type(col);
printf("%s: ", col->name);
@@ -3870,7 +4213,9 @@ dict_index_print_low(
ib_longlong n_vals;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
tree = index->tree;
@@ -3916,7 +4261,9 @@ dict_field_print_low(
/*=================*/
dict_field_t* field) /* in: field */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
printf(" %s", field->name);
@@ -3937,10 +4284,20 @@ dict_print_info_on_foreign_key_in_create_format(
char* buf) /* in: buffer of at least 5000 bytes */
{
char* buf2 = buf;
+ char* stripped_id;
+ ulint cpy_len;
ulint i;
+ if (ut_str_contains(foreign->id, '/')) {
+ /* Strip the preceding database name from the constraint id */
+ stripped_id = foreign->id + 1
+ + dict_get_db_name_len(foreign->id);
+ } else {
+ stripped_id = foreign->id;
+ }
+
buf2 += sprintf(buf2, ",\n CONSTRAINT `%s` FOREIGN KEY (",
- foreign->id);
+ stripped_id);
for (i = 0; i < foreign->n_fields; i++) {
if ((ulint)(buf2 - buf) >= 4000) {
@@ -3956,24 +4313,31 @@ dict_print_info_on_foreign_key_in_create_format(
if (dict_tables_have_same_db(foreign->foreign_table_name,
foreign->referenced_table_name)) {
- /* Do not print the database name of the referenced
- table */
+ /* Do not print the database name of the referenced table */
buf2 += sprintf(buf2, ") REFERENCES `%.500s` (",
dict_remove_db_name(
foreign->referenced_table_name));
} else {
- buf2 += sprintf(buf2, ") REFERENCES `%.500s` (",
- foreign->referenced_table_name);
- /* Change the '/' in the table name to '.' */
-
- for (i = ut_strlen(buf); i > 0; i--) {
- if (buf[i] == '/') {
+ buf2 += sprintf(buf2, ") REFERENCES `");
+
+ /* Look for the '/' in the table name */
- buf[i] = '.';
+ i = 0;
+ while (foreign->referenced_table_name[i] != '/') {
+ i++;
+ }
+
+ cpy_len = i;
- break;
- }
+ if (cpy_len > 500) {
+ cpy_len = 500;
}
+
+ memcpy(buf2, foreign->referenced_table_name, cpy_len);
+ buf2 += cpy_len;
+
+ buf2 += sprintf(buf2, "`.`%.500s` (",
+ foreign->referenced_table_name + i + 1);
}
for (i = 0; i < foreign->n_fields; i++) {
diff --git a/innobase/dict/dict0load.c b/innobase/dict/dict0load.c
index e9076db08f3..c6a8ebc4b55 100644
--- a/innobase/dict/dict0load.c
+++ b/innobase/dict/dict0load.c
@@ -43,7 +43,9 @@ dict_get_first_table_name_in_db(
char* table_name;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
heap = mem_heap_create(1000);
@@ -307,7 +309,9 @@ dict_load_columns(
ulint i;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
@@ -360,6 +364,15 @@ dict_load_columns(
field = rec_get_nth_field(rec, 6, &len);
prtype = mach_read_from_4(field);
+ if (dtype_is_non_binary_string_type(mtype, prtype)
+ && dtype_get_charset_coll(prtype) == 0) {
+ /* This is a non-binary string type, and the table
+ was created with < 4.1.2. Use the default charset. */
+
+ prtype = dtype_form_prtype(prtype,
+ data_mysql_default_charset_coll);
+ }
+
field = rec_get_nth_field(rec, 7, &len);
col_len = mach_read_from_4(field);
@@ -405,7 +418,9 @@ dict_load_fields(
ulint i;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
UT_NOT_USED(table);
@@ -517,7 +532,9 @@ dict_load_indexes(
dulint id;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if ((ut_dulint_get_high(table->id) == 0)
&& (ut_dulint_get_low(table->id) < DICT_HDR_FIRST_ID)) {
@@ -691,7 +708,9 @@ dict_load_table(
ulint err;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
heap = mem_heap_create(1000);
@@ -782,7 +801,7 @@ dict_load_table(
table->type = mach_read_from_4(field);
if (table->type == DICT_TABLE_CLUSTER_MEMBER) {
- ut_a(0);
+ ut_error;
field = rec_get_nth_field(rec, 6, &len);
table->mix_id = mach_read_from_8(field);
@@ -863,7 +882,9 @@ dict_load_table_on_id(
char* name;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
/* NOTE that the operation of this function is protected by
the dictionary mutex, and therefore no deadlocks can occur
@@ -948,7 +969,9 @@ dict_load_sys_table(
{
mem_heap_t* heap;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
heap = mem_heap_create(1000);
@@ -979,7 +1002,9 @@ dict_load_foreign_cols(
ulint i;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
foreign->foreign_col_names = mem_heap_alloc(foreign->heap,
foreign->n_fields * sizeof(void*));
@@ -1060,7 +1085,9 @@ dict_load_foreign(
ulint err;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
heap2 = mem_heap_create(1000);
@@ -1192,7 +1219,9 @@ dict_load_foreigns(
ulint err;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
sys_foreign = dict_table_get_low((char *) "SYS_FOREIGN");
diff --git a/innobase/dict/dict0mem.c b/innobase/dict/dict0mem.c
index aed44eb246c..c49738a0960 100644
--- a/innobase/dict/dict0mem.c
+++ b/innobase/dict/dict0mem.c
@@ -92,9 +92,9 @@ dict_mem_table_create(
mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX);
table->autoinc_inited = FALSE;
-
+#ifdef UNIV_DEBUG
table->magic_n = DICT_TABLE_MAGIC_N;
-
+#endif /* UNIV_DEBUG */
return(table);
}
@@ -219,7 +219,9 @@ dict_mem_index_create(
index->stat_n_diff_key_vals = NULL;
index->cached = FALSE;
+#ifdef UNIV_DEBUG
index->magic_n = DICT_INDEX_MAGIC_N;
+#endif /* UNIV_DEBUG */
return(index);
}
diff --git a/innobase/dict/ts/makefile b/innobase/dict/ts/makefile
deleted file mode 100644
index d1a24e90a89..00000000000
--- a/innobase/dict/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsdict: ..\dict.lib tsdict.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\dict.lib ..\..\data.lib ..\..\buf.lib ..\..\mach.lib ..\..\fil.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsdict.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/dict/ts/tsdict.c b/innobase/dict/ts/tsdict.c
deleted file mode 100644
index fa41a6b9112..00000000000
--- a/innobase/dict/ts/tsdict.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/************************************************************************
-The test module for the data dictionary
-
-(c) 1996 Innobase Oy
-
-Created 1/13/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "buf0buf.h"
-#include "data0type.h"
-#include "..\dict0dict.h"
-
-/************************************************************************
-Basic test of data dictionary. */
-
-void
-test1(void)
-/*=======*/
-{
- dict_table_t* table;
- dict_index_t* index;
-
- table = dict_table_create("TS_TABLE1", 3);
-
- dict_table_add_col(table, "COL1", DATA_INT, 3, 4, 5);
- dict_table_add_col(table, "COL2", DATA_INT, 3, 4, 5);
- dict_table_add_col(table, "COL3", DATA_INT, 3, 4, 5);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE1", "IND1",
- DICT_UNIQUE | DICT_CLUSTERED | DICT_MIX, 2, 1);
-
- dict_index_add_field(index, "COL2", DICT_DESCEND);
- dict_index_add_field(index, "COL1", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- dict_table_print(table);
-
- dict_table_free(table);
-
- ut_a(dict_all_freed());
-
- dict_free_all();
-
- ut_a(dict_all_freed());
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- sync_init();
- mem_init();
- buf_pool_init(100, 100);
- dict_init();
-
- test1();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/dyn/ts/makefile b/innobase/dyn/ts/makefile
deleted file mode 100644
index b4b5ad5eadf..00000000000
--- a/innobase/dyn/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsdyn: ..\dyn.lib tsdyn.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\dyn.lib ..\..\mem.lib ..\..\ut.lib ..\..\mach.lib ..\..\sync.lib ..\..\os.lib tsdyn.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/dyn/ts/tsdyn.c b/innobase/dyn/ts/tsdyn.c
deleted file mode 100644
index 4c21583d9d8..00000000000
--- a/innobase/dyn/ts/tsdyn.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/************************************************************************
-The test module for dynamic array
-
-(c) 1996 Innobase Oy
-
-Created 2/5/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "../dyn0dyn.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-
-/****************************************************************
-Basic test. */
-
-void
-test1(void)
-/*=======*/
-{
- dyn_array_t dyn;
- ulint i;
- ulint* ulint_ptr;
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Basic test\n");
-
- dyn_array_create(&dyn);
-
- for (i = 0; i < 1000; i++) {
- ulint_ptr = dyn_array_push(&dyn, sizeof(ulint));
- *ulint_ptr = i;
- }
-
- ut_a(dyn_array_get_n_elements(&dyn) == 1000);
-
- for (i = 0; i < 1000; i++) {
- ulint_ptr = dyn_array_get_nth_element(&dyn, i, sizeof(ulint));
- ut_a(*ulint_ptr == i);
- }
-
- dyn_array_free(&dyn);
-}
-
-void
-main(void)
-{
- sync_init();
- mem_init();
-
- test1();
-
- ut_ad(sync_all_freed());
-
- ut_ad(mem_all_freed());
-
- printf("TEST SUCCESSFULLY COMPLETED!\n");
-}
diff --git a/innobase/fil/fil0fil.c b/innobase/fil/fil0fil.c
index ee63df08744..768dda4eedc 100644
--- a/innobase/fil/fil0fil.c
+++ b/innobase/fil/fil0fil.c
@@ -534,7 +534,9 @@ fil_node_close_file(
ibool ret;
ut_ad(node && system);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(system->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(node->open);
ut_a(node->n_pending == 0);
ut_a(node->n_pending_flushes == 0);
@@ -742,7 +744,9 @@ fil_node_free(
fil_space_t* space) /* in: space where the file node is chained */
{
ut_ad(node && system && space);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(system->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(node->magic_n == FIL_NODE_MAGIC_N);
ut_a(node->n_pending == 0);
@@ -3383,7 +3387,9 @@ fil_node_prepare_for_io(
fil_space_t* space) /* in: space */
{
ut_ad(node && system && space);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(system->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (system->n_open > system->max_n_open + 5) {
ut_print_timestamp(stderr);
@@ -3427,7 +3433,9 @@ fil_node_complete_io(
{
ut_ad(node);
ut_ad(system);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(system->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(node->n_pending > 0);
@@ -3561,7 +3569,7 @@ fil_io(
space->name, (ulong) byte_offset, (ulong) len,
(ulong) type);
- ut_a(0);
+ ut_error;
}
if (node->size > block_offset) {
@@ -3726,7 +3734,7 @@ fil_aio_wait(
ret = os_aio_posix_handle(segment, &fil_node, &message);
#else
ret = 0; /* Eliminate compiler warning */
- ut_a(0);
+ ut_error;
#endif
} else {
srv_io_thread_op_info[segment] =(char *)"handle simulated aio";
diff --git a/innobase/fil/ts/makefile b/innobase/fil/ts/makefile
deleted file mode 100644
index 41911104bc6..00000000000
--- a/innobase/fil/ts/makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsfil: ..\fil.lib tsfil.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\fil.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsfil.c $(LFL)
-
-
-
-
-
-
-
-
diff --git a/innobase/fil/ts/tsfil.c b/innobase/fil/ts/tsfil.c
deleted file mode 100644
index 61fdefe28af..00000000000
--- a/innobase/fil/ts/tsfil.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/************************************************************************
-The test module for the file system
-
-(c) 1995 Innobase Oy
-
-Created 10/29/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "os0thread.h"
-#include "os0file.h"
-#include "ut0ut.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "..\fil0fil.h"
-
-ulint last_thr = 1;
-
-byte global_buf[10000000];
-byte global_buf2[20000];
-
-os_file_t files[1000];
-
-os_event_t gl_ready;
-
-mutex_t ios_mutex;
-ulint ios;
-
-/*********************************************************************
-Test for synchronous file io. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i, j;
- void* mess;
- bool ret;
- void* buf;
- ulint rnd, rnd3;
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("FIL-TEST 1. Test of synchronous file io\n");
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- rnd = ut_time();
- rnd3 = ut_time();
-
- rnd = rnd * 3416133;
- rnd3 = rnd3 * 6576681;
-
- oldtm = ut_clock();
-
- for (j = 0; j < 300; j++) {
- for (i = 0; i < (rnd3 % 15); i++) {
- fil_read((rnd % 1000) / 100, rnd % 100, 0, 8192, buf, NULL);
-
- ut_a(fil_validate());
-
- ret = fil_aio_wait(0, &mess);
- ut_a(ret);
-
- ut_a(fil_validate());
-
- ut_a(*((ulint*)buf) == rnd % 1000);
-
- rnd += 1;
- }
- rnd = rnd + 3416133;
- rnd3 = rnd3 + 6576681;
- }
-
- tm = ut_clock();
- printf("Wall clock time for synchr. io %lu milliseconds\n",
- tm - oldtm);
-
-}
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- void* buf;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- printf("Thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- if ((ulint)mess == 3333) {
- os_event_set(gl_ready);
- } else {
- ut_a((ulint)mess ==
- *((ulint*)((byte*)buf + 8192 * (ulint)mess)));
- }
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- ut_a(ret);
-/* printf("Message for thread %lu %lu\n", segment,
- (ulint)mess); */
- }
-
- return(0);
-}
-
-/************************************************************************
-Test of io-handler threads */
-
-void
-test2(void)
-/*=======*/
-{
- ulint i;
- ulint j;
- void* buf;
- ulint rnd, rnd3;
- ulint tm, oldtm;
- os_thread_t thr[5];
- os_thread_id_t id[5];
- ulint n[5];
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- gl_ready = os_event_create(NULL);
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-
- printf("-------------------------------------------\n");
- printf("FIL-TEST 2. Test of asynchronous file io\n");
-
- rnd = ut_time();
- rnd3 = ut_time();
-
- rnd = rnd * 3416133;
- rnd3 = rnd3 * 6576681;
-
- oldtm = ut_clock();
-
- for (j = 0; j < 300; j++) {
- for (i = 0; i < (rnd3 % 15); i++) {
- fil_read((rnd % 1000) / 100, rnd % 100, 0, 8192,
- (void*)((byte*)buf + 8192 * (rnd % 1000)),
- (void*)(rnd % 1000));
-
- rnd += 1;
- }
- ut_a(fil_validate());
- rnd = rnd + 3416133;
- rnd3 = rnd3 + 6576681;
- }
-
- ut_a(!os_aio_all_slots_free());
-
- tm = ut_clock();
- printf("Wall clock time for asynchr. io %lu milliseconds\n",
- tm - oldtm);
-
- fil_read(5, 25, 0, 8192,
- (void*)((byte*)buf + 8192 * 1000),
- (void*)3333);
-
- tm = ut_clock();
-
- ut_a(fil_validate());
-
- printf("All ios queued! N ios: %lu\n", ios);
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_event_wait(gl_ready);
-
- tm = ut_clock();
- printf("N ios: %lu\n", ios);
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_thread_sleep(2000000);
-
- printf("N ios: %lu\n", ios);
-
- ut_a(fil_validate());
- ut_a(os_aio_all_slots_free());
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, j, k, n;
- void* buf;
- void* mess;
- char name[10];
-
- buf = (void*)(((ulint)global_buf2 + 6300) & (~0xFFF));
-
- name[0] = 't';
- name[1] = 's';
- name[2] = 'f';
- name[3] = 'i';
- name[4] = 'l';
- name[5] = 'e';
- name[8] = '\0';
-
- for (k = 0; k < 10; k++) {
- for (i = 0; i < 20; i++) {
-
- name[6] = (char)(k + (ulint)'a');
- name[7] = (char)(i + (ulint)'a');
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- } else {
-
- for (j = 0; j < 5; j++) {
- for (n = 0; n < 8192 / sizeof(ulint); n++) {
- *((ulint*)buf + n) =
- k * 100 + i * 5 + j;
- }
-
- ret = os_aio_write(files[i], buf, 8192 * j,
- 0, 8192, NULL);
- ut_a(ret);
-
- ret = os_aio_wait(0, &mess);
-
- ut_a(ret);
- ut_a(mess == NULL);
- }
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create("noname", k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, 5, k);
- }
- }
-}
-
-/************************************************************************
-Frees the spaces in the file system. */
-
-void
-free_system(void)
-/*=============*/
-{
- ulint i;
-
- for (i = 0; i < 10; i++) {
- fil_space_free(i);
- }
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- os_aio_init(160, 5);
- sync_init();
- mem_init();
- fil_init(2); /* Allow only 2 open files at a time */
-
- ut_a(fil_validate());
-
- create_files();
-
- test1();
-
- test2();
-
- free_system();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/fsp/fsp0fsp.c b/innobase/fsp/fsp0fsp.c
index 9d76387c6cb..77535e4c524 100644
--- a/innobase/fsp/fsp0fsp.c
+++ b/innobase/fsp/fsp0fsp.c
@@ -327,9 +327,9 @@ fsp_get_space_header(
ut_ad(mtr);
header = FSP_HEADER_OFFSET + buf_page_get(id, 0, RW_X_LATCH, mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(header, SYNC_FSP_PAGE);
-
+#endif /* UNIV_SYNC_DEBUG */
return(header);
}
@@ -684,7 +684,9 @@ xdes_get_descriptor_with_space_hdr(
} else {
descr_page = buf_page_get(space, descr_page_no, RW_X_LATCH,
mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(descr_page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
}
return(descr_page + XDES_ARR_OFFSET
@@ -714,8 +716,9 @@ xdes_get_descriptor(
sp_header = FSP_HEADER_OFFSET
+ buf_page_get(space, 0, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(sp_header, SYNC_FSP_PAGE);
-
+#endif /* UNIV_SYNC_DEBUG */
return(xdes_get_descriptor_with_space_hdr(sp_header, space, offset,
mtr));
}
@@ -790,19 +793,12 @@ fsp_init_file_page_low(
byte* ptr) /* in: pointer to a page */
{
page_t* page;
-#ifdef UNIV_BASIC_LOG_DEBUG
- ulint i;
-#endif
page = buf_frame_align(ptr);
buf_block_align(page)->check_index_page_at_flush = FALSE;
-
-#ifdef UNIV_BASIC_LOG_DEBUG
-/* printf("In log debug version: Erase the contents of the file page\n");
-*/
- for (i = 0; i < UNIV_PAGE_SIZE; i++) {
- page[i] = (byte)0xFF;
- }
+
+#ifdef UNIV_BASIC_LOG_DEBUG
+ memset(page, 0xff, UNIV_PAGE_SIZE);
#endif
mach_write_to_8(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM,
ut_dulint_zero);
@@ -812,6 +808,7 @@ fsp_init_file_page_low(
/***************************************************************
Inits a file page whose prior contents should be ignored. */
+static
void
fsp_init_file_page(
/*===============*/
@@ -885,9 +882,10 @@ fsp_header_init(
mtr_x_lock(fil_space_get_latch(space), mtr);
page = buf_page_create(space, 0, mtr);
-
buf_page_get(space, 0, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
/* The prior contents of the file page should be ignored */
@@ -908,8 +906,7 @@ fsp_header_init(
flst_init(header + FSP_SEG_INODES_FULL, mtr);
flst_init(header + FSP_SEG_INODES_FREE, mtr);
- mlog_write_dulint(header + FSP_SEG_ID, ut_dulint_create(0, 1),
- MLOG_8BYTES, mtr);
+ mlog_write_dulint(header + FSP_SEG_ID, ut_dulint_create(0, 1), mtr);
if (space == 0) {
fsp_fill_free_list(FALSE, space, header, mtr);
btr_create(DICT_CLUSTERED | DICT_UNIVERSAL | DICT_IBUF, space,
@@ -1250,8 +1247,10 @@ fsp_fill_free_list(
if (i > 0) {
descr_page = buf_page_create(space, i, mtr);
buf_page_get(space, i, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(descr_page,
SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
fsp_init_file_page(descr_page, mtr);
}
@@ -1264,11 +1263,11 @@ fsp_fill_free_list(
ibuf_page = buf_page_create(space,
i + FSP_IBUF_BITMAP_OFFSET, &ibuf_mtr);
-
buf_page_get(space, i + FSP_IBUF_BITMAP_OFFSET,
RW_X_LATCH, &ibuf_mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(ibuf_page, SYNC_FSP_PAGE);
-
+#endif /* UNIV_SYNC_DEBUG */
fsp_init_file_page(ibuf_page, &ibuf_mtr);
ibuf_bitmap_page_init(ibuf_page, &ibuf_mtr);
@@ -1429,7 +1428,7 @@ fsp_alloc_free_page(
ut_print_buf(((byte*)descr) - 500, 1000);
- ut_a(0);
+ ut_error;
}
page_no = xdes_get_offset(descr) + free;
@@ -1484,8 +1483,9 @@ fsp_alloc_free_page(
buf_page_create(space, page_no, mtr);
page = buf_page_get(space, page_no, RW_X_LATCH, mtr);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
/* Prior contents of the page should be ignored */
fsp_init_file_page(page, mtr);
@@ -1535,7 +1535,7 @@ fsp_free_page(
return;
}
- ut_a(0);
+ ut_error;
}
if (xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)
@@ -1605,7 +1605,7 @@ fsp_free_extent(
ut_print_buf(((byte*)descr) - 500, 1000);
- ut_a(0);
+ ut_error;
}
xdes_init(descr, mtr);
@@ -1720,15 +1720,15 @@ fsp_alloc_seg_inode_page(
buf_block_align(page)->check_index_page_at_flush = FALSE;
fil_page_set_type(page, FIL_PAGE_INODE);
-
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < FSP_SEG_INODES_PER_PAGE; i++) {
inode = fsp_seg_inode_page_get_nth_inode(page, i, mtr);
- mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero,
- MLOG_8BYTES, mtr);
+ mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero, mtr);
}
flst_add_last(space_header + FSP_SEG_INODES_FREE,
@@ -1768,7 +1768,9 @@ fsp_alloc_seg_inode(
page = buf_page_get(buf_frame_get_space_id(space_header), page_no,
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
n = fsp_seg_inode_page_find_free(page, 0, mtr);
@@ -1821,7 +1823,7 @@ fsp_free_seg_inode(
page + FSEG_INODE_PAGE_NODE, mtr);
}
- mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero, MLOG_8BYTES, mtr);
+ mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero, mtr);
mlog_write_ulint(inode + FSEG_MAGIC_N, 0, MLOG_4BYTES, mtr);
if (ULINT_UNDEFINED == fsp_seg_inode_page_find_used(page, mtr)) {
@@ -2020,9 +2022,11 @@ fseg_create_general(
mtr);
}
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
latch = fil_space_get_latch(space);
mtr_x_lock(latch, mtr);
@@ -2056,12 +2060,12 @@ fseg_create_general(
/* Read the next segment id from space header and increment the
value in space header */
- seg_id = mtr_read_dulint(space_header + FSP_SEG_ID, MLOG_8BYTES, mtr);
+ seg_id = mtr_read_dulint(space_header + FSP_SEG_ID, mtr);
mlog_write_dulint(space_header + FSP_SEG_ID, ut_dulint_add(seg_id, 1),
- MLOG_8BYTES, mtr);
+ mtr);
- mlog_write_dulint(inode + FSEG_ID, seg_id, MLOG_8BYTES, mtr);
+ mlog_write_dulint(inode + FSEG_ID, seg_id, mtr);
mlog_write_ulint(inode + FSEG_NOT_FULL_N_USED, 0, MLOG_4BYTES, mtr);
flst_init(inode + FSEG_FREE, mtr);
@@ -2176,9 +2180,11 @@ fseg_n_reserved_pages(
space = buf_frame_get_space_id(header);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
mtr_x_lock(fil_space_get_latch(space), mtr);
inode = fseg_inode_get(header, mtr);
@@ -2241,8 +2247,8 @@ fseg_fill_free_list(
xdes_set_state(descr, XDES_FSEG, mtr);
- seg_id = mtr_read_dulint(inode + FSEG_ID, MLOG_8BYTES, mtr);
- mlog_write_dulint(descr + XDES_ID, seg_id, MLOG_8BYTES, mtr);
+ seg_id = mtr_read_dulint(inode + FSEG_ID, mtr);
+ mlog_write_dulint(descr + XDES_ID, seg_id, mtr);
flst_add_last(inode + FSEG_FREE, descr + XDES_FLST_NODE, mtr);
hint += FSP_EXTENT_SIZE;
@@ -2283,10 +2289,10 @@ fseg_alloc_free_extent(
return(NULL);
}
- seg_id = mtr_read_dulint(inode + FSEG_ID, MLOG_8BYTES, mtr);
+ seg_id = mtr_read_dulint(inode + FSEG_ID, mtr);
xdes_set_state(descr, XDES_FSEG, mtr);
- mlog_write_dulint(descr + XDES_ID, seg_id, MLOG_8BYTES, mtr);
+ mlog_write_dulint(descr + XDES_ID, seg_id, mtr);
flst_add_last(inode + FSEG_FREE, descr + XDES_FLST_NODE, mtr);
/* Try to fill the segment free list */
@@ -2336,7 +2342,7 @@ fseg_alloc_free_page_low(
ut_ad((direction >= FSP_UP) && (direction <= FSP_NO_DIR));
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) ==
FSEG_MAGIC_N_VALUE);
- seg_id = mtr_read_dulint(seg_inode + FSEG_ID, MLOG_8BYTES, mtr);
+ seg_id = mtr_read_dulint(seg_inode + FSEG_ID, mtr);
ut_ad(ut_dulint_cmp(seg_id, ut_dulint_zero) > 0);
@@ -2357,8 +2363,7 @@ fseg_alloc_free_page_low(
/*-------------------------------------------------------------*/
if ((xdes_get_state(descr, mtr) == XDES_FSEG)
&& (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
- MLOG_8BYTES, mtr),
- seg_id))
+ mtr), seg_id))
&& (xdes_get_bit(descr, XDES_FREE_BIT,
hint % FSP_EXTENT_SIZE, mtr) == TRUE)) {
@@ -2380,8 +2385,7 @@ fseg_alloc_free_page_low(
ut_a(ret_descr == descr);
xdes_set_state(ret_descr, XDES_FSEG, mtr);
- mlog_write_dulint(ret_descr + XDES_ID, seg_id, MLOG_8BYTES,
- mtr);
+ mlog_write_dulint(ret_descr + XDES_ID, seg_id, mtr);
flst_add_last(seg_inode + FSEG_FREE,
ret_descr + XDES_FLST_NODE, mtr);
@@ -2410,8 +2414,7 @@ fseg_alloc_free_page_low(
/*-------------------------------------------------------------*/
} else if ((xdes_get_state(descr, mtr) == XDES_FSEG)
&& (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
- MLOG_8BYTES, mtr),
- seg_id))
+ mtr), seg_id))
&& (!xdes_is_full(descr, mtr))) {
/* 4. We can take the page from the same extent as the
@@ -2512,7 +2515,9 @@ fseg_alloc_free_page_low(
ut_a(page == buf_page_get(space, ret_page, RW_X_LATCH, mtr));
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_FSP_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
/* The prior contents of the page should be ignored */
fsp_init_file_page(page, mtr);
@@ -2566,9 +2571,11 @@ fseg_alloc_free_page_general(
space = buf_frame_get_space_id(seg_header);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
latch = fil_space_get_latch(space);
mtr_x_lock(latch, mtr);
@@ -2714,9 +2721,11 @@ fsp_reserve_free_extents(
ulint n_pages_added;
ut_ad(mtr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
*n_reserved = n_ext;
latch = fil_space_get_latch(space);
@@ -2814,8 +2823,9 @@ fsp_get_available_space_in_free_extents(
rw_lock_t* latch;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
-
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
latch = fil_space_get_latch(space);
@@ -2969,7 +2979,7 @@ fseg_free_page_low(
fprintf(stderr,
"InnoDB: If the InnoDB recovery crashes here, see section 6.1\n"
"InnoDB: of http://www.innodb.com/ibman.html about forcing recovery.\n");
- ut_a(0);
+ ut_error;
}
state = xdes_get_state(descr, mtr);
@@ -2994,8 +3004,8 @@ fseg_free_page_low(
/* If we get here, the page is in some extent of the segment */
- descr_id = mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES, mtr);
- seg_id = mtr_read_dulint(seg_inode + FSEG_ID, MLOG_8BYTES, mtr);
+ descr_id = mtr_read_dulint(descr + XDES_ID, mtr);
+ seg_id = mtr_read_dulint(seg_inode + FSEG_ID, mtr);
/*
fprintf(stderr,
"InnoDB: InnoDB is freeing space %lu page %lu,\n"
@@ -3028,7 +3038,7 @@ fseg_free_page_low(
fprintf(stderr,
"InnoDB: If the InnoDB recovery crashes here, see section 6.1\n"
"InnoDB: of http://www.innodb.com/ibman.html about forcing recovery.\n");
- ut_a(0);
+ ut_error;
}
not_full_n_used = mtr_read_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
@@ -3072,9 +3082,11 @@ fseg_free_page(
{
fseg_inode_t* seg_inode;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
mtr_x_lock(fil_space_get_latch(space), mtr);
seg_inode = fseg_inode_get(seg_header, mtr);
@@ -3109,8 +3121,8 @@ fseg_free_extent(
ut_a(xdes_get_state(descr, mtr) == XDES_FSEG);
ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES, mtr),
- mtr_read_dulint(seg_inode + FSEG_ID, MLOG_8BYTES, mtr)));
+ mtr_read_dulint(descr + XDES_ID, mtr),
+ mtr_read_dulint(seg_inode + FSEG_ID, mtr)));
first_page_in_extent = page - (page % FSP_EXTENT_SIZE);
@@ -3181,9 +3193,11 @@ fseg_free_step(
space = buf_frame_get_space_id(header);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
mtr_x_lock(fil_space_get_latch(space), mtr);
descr = xdes_get_descriptor(space, buf_frame_get_page_no(header), mtr);
@@ -3254,9 +3268,11 @@ fseg_free_step_not_header(
space = buf_frame_get_space_id(header);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex)
|| mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
+#endif /* UNIV_SYNC_DEBUG */
mtr_x_lock(fil_space_get_latch(space), mtr);
inode = fseg_inode_get(header, mtr);
@@ -3398,7 +3414,7 @@ fseg_validate_low(
space = buf_frame_get_space_id(inode);
- seg_id = mtr_read_dulint(inode + FSEG_ID, MLOG_8BYTES, mtr2);
+ seg_id = mtr_read_dulint(inode + FSEG_ID, mtr2);
n_used = mtr_read_ulint(inode + FSEG_NOT_FULL_N_USED,
MLOG_4BYTES, mtr2);
flst_validate(inode + FSEG_FREE, mtr2);
@@ -3417,8 +3433,7 @@ fseg_validate_low(
ut_a(xdes_get_n_used(descr, &mtr) == 0);
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
+ mtr_read_dulint(descr + XDES_ID, &mtr), seg_id));
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
mtr_commit(&mtr);
@@ -3438,8 +3453,7 @@ fseg_validate_low(
ut_a(xdes_get_n_used(descr, &mtr) < FSP_EXTENT_SIZE);
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
+ mtr_read_dulint(descr + XDES_ID, &mtr), seg_id));
n_used2 += xdes_get_n_used(descr, &mtr);
@@ -3460,8 +3474,7 @@ fseg_validate_low(
ut_a(xdes_get_n_used(descr, &mtr) == FSP_EXTENT_SIZE);
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
+ mtr_read_dulint(descr + XDES_ID, &mtr), seg_id));
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
mtr_commit(&mtr);
@@ -3526,7 +3539,7 @@ fseg_print_low(
reserved = fseg_n_reserved_pages_low(inode, &used, mtr);
- d_var = mtr_read_dulint(inode + FSEG_ID, MLOG_8BYTES, mtr);
+ d_var = mtr_read_dulint(inode + FSEG_ID, mtr);
seg_id_low = ut_dulint_get_low(d_var);
seg_id_high = ut_dulint_get_high(d_var);
@@ -3844,7 +3857,7 @@ fsp_print(
n_free_frag = flst_get_len(header + FSP_FREE_FRAG, &mtr);
n_full_frag = flst_get_len(header + FSP_FULL_FRAG, &mtr);
- d_var = mtr_read_dulint(header + FSP_SEG_ID, MLOG_8BYTES, &mtr);
+ d_var = mtr_read_dulint(header + FSP_SEG_ID, &mtr);
seg_id_low = ut_dulint_get_low(d_var);
seg_id_high = ut_dulint_get_high(d_var);
diff --git a/innobase/fsp/trash/FSP0FSP.C b/innobase/fsp/trash/FSP0FSP.C
deleted file mode 100644
index b0add437bff..00000000000
--- a/innobase/fsp/trash/FSP0FSP.C
+++ /dev/null
@@ -1,3100 +0,0 @@
-/**********************************************************************
-File-space management
-
-(c) 1995 Innobase Oy
-
-Created 11/29/1995 Heikki Tuuri
-***********************************************************************/
-
-#include "fsp0fsp.h"
-
-#include "buf0buf.h"
-#include "fil0fil.h"
-#include "sync0sync.h"
-#include "mtr0log.h"
-#include "fut0fut.h"
-#include "ut0byte.h"
-
-/* The data structures in files are defined just as byte strings in C */
-typedef byte fsp_header_t;
-typedef byte xdes_t;
-typedef byte fseg_page_header_t;
-
-/* Rw-latch protecting the whole file space system */
-rw_lock_t fsp_latch;
-
-
-/* SPACE HEADER
- ============
-
-File space header data structure: this data structure
-is contained in the first page of a space. The space for this header
-is reserved in every extent descriptor page, but used only in the first. */
-#define FSP_HEADER_OFFSET FIL_PAGE_DATA /* Offset of the space header
- within a file page */
-/*-------------------------------------*/
-#define FSP_SIZE 0 /* Current
- size of the space in pages */
-#define FSP_FREE_LIMIT 4 /* Minimum page number for which
- the free list has not been initialized:
- the pages >= this limit are, by
- definition, free */
-#define FSP_LOWEST_NO_WRITE 8 /* The lowest page offset for which
- the page has not been written to disk
- (if it has been written, we know
- that the OS has really reserved
- the physical space for the page) */
-#define FSP_FRAG_N_USED 12 /* number of used pages in
- the FSP_FREE_FRAG list */
-#define FSP_FREE 16 /* list of free extents */
-#define FSP_FREE_FRAG (16 + FLST_BASE_NODE_SIZE)
- /* list of partially free extents not
- belonging to any segment */
-#define FSP_FULL_FRAG (16 + 2 * FLST_BASE_NODE_SIZE)
- /* list of full extents not belonging
- to any segment */
-#define FSP_SEG_ID (16 + 3 * FLST_BASE_NODE_SIZE)
- /* 8 bytes which give the first
-#define FSP_SEG_HDRS_FULL (24 + 3 * FLST_BASE_NODE_SIZE)
- /* list of pages containing segment
- headers, where all the segment header
- slots are reserved */
-#define FSP_SEG_HDRS_FREE (24 + 4 * FLST_BASE_NODE_SIZE)
- /* list of pages containing segment
- headers, where not all the segment
- header slots are reserved */
-/*-------------------------------------*/
-/* File space header size */
-#define FSP_HEADER_SIZE (24 + 4 * FLST_BASE_NODE_SIZE)
-
-#define FSP_FREE_ADD 4 /* this many free extents are added
- to the free list from above
- FSP_FREE_LIMIT at a time */
-
-
-/* SEGMENT HEADER
- ==============
-
-Segment header which is created for each segment in a tablespace, on a
-page of its own. NOTE: in purge we assume that a segment having only one
-currently used page can be freed in a few steps, so that the freeing cannot
-fill the file buffer with bufferfixed file pages. */
-
-#define FSEG_HDR_PAGE_NODE FSEG_PAGE_DATA
- /* the list node for linking
- segment header pages */
-
-#define FSEG_ARR_OFFSET (FSEG_PAGE_DATA + FLST_NODE_SIZE)
-/*-------------------------------------*/
-#define FSEG_ID 0 /* 8 bytes of segment id: if this is
- ut_dulint_zero, it means that the
- header is unused */
-#define FSEG_NOT_FULL_N_USED 8
- /* number of used segment pages in
- the FSEG_NOT_FULL list */
-#define FSEG_FREE 12
- /* list of free extents of this
- segment */
-#define FSEG_NOT_FULL (12 + FLST_BASE_NODE_SIZE)
- /* list of partially free extents */
-#define FSEG_FULL (12 + 2 * FLST_BASE_NODE_SIZE)
- /* list of full extents */
-#define FSEG_MAGIC_N (12 + 3 * FLST_BASE_NODE_SIZE)
- /* magic number used in debugging */
-#define FSEG_FRAG_ARR (16 + 3 * FLST_BASE_NODE_SIZE)
- /* array of individual pages
- belonging to this segment in fsp
- fragment extent lists */
-#define FSEG_FRAG_ARR_N_SLOTS (FSP_EXTENT_SIZE / 2)
- /* number of slots in the array for
- the fragment pages */
-#define FSEG_FRAG_SLOT_SIZE 4 /* a fragment page slot contains its
- page number within space, FIL_NULL
- means that the slot is not in use */
-/*-------------------------------------*/
-#define FSEG_HEADER_SIZE (16 + 3 * FLST_BASE_NODE_SIZE +\
- FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE)
-
-#define FSP_SEG_HDRS_PER_PAGE ((UNIV_PAGE_SIZE - FSEG_ARR_OFFSET - 10)\
- / FSEG_HEADER_SIZE)
- /* Number of segment headers which fit on a
- single page */
-
-#define FSEG_MAGIC_N_VALUE 97937874
-
-#define FSEG_FILLFACTOR 8 /* If this value is x, then if
- the number of unused but reserved
- pages in a segment is less than
- reserved pages * 1/x, and there are
- at least FSEG_FRAG_LIMIT used pages,
- then we allow a new empty extent to
- be added to the segment in
- fseg_alloc_free_page. Otherwise, we
- use unused pages of the segment. */
-
-#define FSEG_FRAG_LIMIT FSEG_FRAG_N_ARR_SLOTS
- /* If the segment has >= this many
- used pages, it may be expanded by
- allocating extents to the segment;
- until that only individual fragment
- pages are allocated from the space */
-
-#define FSEG_FREE_LIST_LIMIT 40 /* If the reserved size of a segment
- is at least this many extents, we
- allow extents to be put to the free
- list of the extent: at most
- FSEG_FREE_LIST_MAX_LEN many */
-#define FSEG_FREE_LIST_MAX_LEN 4
-
-
-/* EXTENT DESCRIPTOR
- =================
-
-File extent descriptor data structure: contains bits to tell
-which pages in the extent are free and which contain old tuple
-version to clean. */
-
-/*-------------------------------------*/
-#define XDES_ID 0 /* The identifier of the segment
- to which this extent belongs */
-#define XDES_FLST_NODE 8 /* The list node data structure
- for the descriptors */
-#define XDES_STATE (FLST_NODE_SIZE + 8)
- /* contains state information
- of the extent */
-#define XDES_BITMAP (FLST_NODE_SIZE + 12)
- /* Descriptor bitmap of the pages
- in the extent*/
-/*-------------------------------------*/
-
-#define XDES_BITS_PER_PAGE 2 /* How many bits are there per page */
-#define XDES_FREE_BIT 0 /* Index of the bit which tells if
- the page is free */
-#define XDES_CLEAN_BIT 1 /* Index of the bit which tells if
- there are old versions of tuples
- on the page */
-/* States of a descriptor */
-#define XDES_FREE 1 /* extent is in free list of space */
-#define XDES_FREE_FRAG 2 /* extent is in free fragment list of
- space */
-#define XDES_FULL_FRAG 3 /* extent is in full fragment list of
- space */
-#define XDES_FSEG 4 /* extent belongs to a segment*/
-
-/* Number of pages described in a single descriptor page:
-currently each page description takes less than
-1 byte. */
-#define XDES_DESCRIBED_PER_PAGE UNIV_PAGE_SIZE
-
-/* File extent data structure size in bytes. The "+ 7 ) / 8"
-part in the definition rounds the number of bytes upward. */
-#define XDES_SIZE (XDES_BITMAP +\
- (FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE + 7) / 8)
-
-/* Offset of the descriptor array on a descriptor page */
-#define XDES_ARR_OFFSET (FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
-
-/**************************************************************************
-Returns an extent to the free list of a space. */
-static
-void
-fsp_free_extent(
-/*============*/
- ulint space, /* in: space id */
- ulint page, /* in: page offset in the extent */
- mtr_t* mtr); /* in: mtr */
-/**************************************************************************
-Frees an extent of a segment to the space free list. */
-static
-void
-fseg_free_extent(
-/*=============*/
- fseg_header_t* seg_header, /* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset in the extent */
- mtr_t* mtr); /* in: mtr handle */
-/**************************************************************************
-Calculates the number of pages reserved by a segment, and how
-many pages are currently used. */
-static
-ulint
-fseg_n_reserved_pages_low(
-/*======================*/
- /* out: number of reserved pages */
- fseg_header_t* header, /* in: segment header */
- ulint* used, /* out: number of pages used (<= reserved) */
- mtr_t* mtr); /* in: mtr handle */
-/************************************************************************
-Marks a page used. The page must reside within the extents of the given
-segment. */
-static
-void
-fseg_mark_page_used(
-/*================*/
- fseg_header_t* seg_header,/* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr); /* in: mtr */
-/**************************************************************************
-Frees a single page of a segment. */
-static
-void
-fseg_free_page_low(
-/*===============*/
- fseg_header_t* seg_header, /* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr); /* in: mtr handle */
-/**************************************************************************
-Returns the first extent descriptor for a segment. We think of the extent
-lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
--> FSEG_FREE. */
-static
-xdes_t*
-fseg_get_first_extent(
-/*==================*/
- /* out: the first extent descriptor, or NULL if
- none */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr); /* in: mtr */
-/**************************************************************************
-Puts new extents to the free list if
-there are free extents above the free limit. If an extent happens
-to contain an extent descriptor page, the extent is put to
-the FSP_FREE_FRAG list with the page marked as used. */
-static
-void
-fsp_fill_free_list(
-/*===============*/
- ulint space, /* in: space */
- fsp_header_t* header, /* in: space header */
- mtr_t* mtr); /* in: mtr */
-
-/**************************************************************************
-Gets a descriptor bit of a page. */
-UNIV_INLINE
-bool
-xdes_get_bit(
-/*=========*/
- /* out: TRUE if free */
- xdes_t* descr, /* in: descriptor */
- ulint bit, /* in: XDES_FREE_BIT or XDES_CLEAN_BIT */
- ulint offset, /* in: page offset within extent:
- 0 ... FSP_EXTENT_SIZE - 1 */
- mtr_t* mtr) /* in: mtr */
-{
- ulint index;
- ulint byte_index;
- ulint bit_index;
-
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
- ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT));
- ut_ad(offset < FSP_EXTENT_SIZE);
-
- index = bit + XDES_BITS_PER_PAGE * offset;
-
- byte_index = index / 8;
- bit_index = index % 8;
-
- return(ut_bit_get_nth(
- mtr_read_ulint(descr + XDES_BITMAP + byte_index,
- MLOG_1BYTE, mtr),
- bit_index));
-}
-
-/**************************************************************************
-Sets a descriptor bit of a page. */
-UNIV_INLINE
-void
-xdes_set_bit(
-/*=========*/
- xdes_t* descr, /* in: descriptor */
- ulint bit, /* in: XDES_FREE_BIT or XDES_CLEAN_BIT */
- ulint offset, /* in: page offset within extent:
- 0 ... FSP_EXTENT_SIZE - 1 */
- bool val, /* in: bit value */
- mtr_t* mtr) /* in: mtr */
-{
- ulint index;
- ulint byte_index;
- ulint bit_index;
- ulint descr_byte;
-
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
- ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT));
- ut_ad(offset < FSP_EXTENT_SIZE);
-
- index = bit + XDES_BITS_PER_PAGE * offset;
-
- byte_index = index / 8;
- bit_index = index % 8;
-
- descr_byte = mtr_read_ulint(descr + XDES_BITMAP + byte_index,
- MLOG_1BYTE, mtr);
-
- descr_byte = ut_bit_set_nth(descr_byte, bit_index, val);
-
- mlog_write_ulint(descr + XDES_BITMAP + byte_index,
- descr_byte, MLOG_1BYTE, mtr);
-}
-
-/**************************************************************************
-Looks for a descriptor bit having the desired value. Starts from hint
-and scans upward; at the end of the extent the search is wrapped to
-the start of the extent. */
-UNIV_INLINE
-ulint
-xdes_find_bit(
-/*==========*/
- /* out: bit index of the bit,
- ULINT_UNDEFINED if not found */
- xdes_t* descr, /* in: descriptor */
- ulint bit, /* in: XDES_FREE_BIT or XDES_CLEAN_BIT */
- bool val, /* in: desired bit value */
- ulint hint, /* in: hint of which bit position would be
- desirable */
- mtr_t* mtr) /* in: mtr */
-{
- ulint i;
-
- ut_ad(descr && mtr);
- ut_ad(val <= TRUE);
- ut_ad(hint < FSP_EXTENT_SIZE);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- for (i = hint; i < FSP_EXTENT_SIZE; i++) {
- if (val == xdes_get_bit(descr, bit, i, mtr)) {
- return(i);
- }
- }
-
- for (i = 0; i < hint; i++) {
- if (val == xdes_get_bit(descr, bit, i, mtr)) {
- return(i);
- }
- }
-
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Looks for a descriptor bit having the desired value. Scans the extent in
-a direction opposite to xdes_find_bit. */
-UNIV_INLINE
-ulint
-xdes_find_bit_downward(
-/*===================*/
- /* out: bit index of the bit,
- ULINT_UNDEFINED if not found */
- xdes_t* descr, /* in: descriptor */
- ulint bit, /* in: XDES_FREE_BIT or XDES_CLEAN_BIT */
- bool val, /* in: desired bit value */
- ulint hint, /* in: hint of which bit position would be
- desirable */
- mtr_t* mtr) /* in: mtr */
-{
- ulint i;
-
- ut_ad(descr && mtr);
- ut_ad(val <= TRUE);
- ut_ad(hint < FSP_EXTENT_SIZE);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- for (i = hint + 1; i > 0; i--) {
- if (val == xdes_get_bit(descr, bit, i - 1, mtr)) {
- return(i - 1);
- }
- }
-
- for (i = FSP_EXTENT_SIZE - 1; i > hint; i--) {
- if (val == xdes_get_bit(descr, bit, i, mtr)) {
- return(i);
- }
- }
-
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Returns the number of used pages in a descriptor. */
-UNIV_INLINE
-ulint
-xdes_get_n_used(
-/*============*/
- /* out: number of pages used */
- xdes_t* descr, /* in: descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- ulint i;
- ulint count = 0;
-
- ut_ad(descr && mtr);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- for (i = 0; i < FSP_EXTENT_SIZE; i++) {
- if (FALSE == xdes_get_bit(descr, XDES_FREE_BIT, i, mtr)) {
- count++;
- }
- }
-
- return(count);
-}
-
-/**************************************************************************
-Returns true if extent contains no used pages. */
-UNIV_INLINE
-bool
-xdes_is_free(
-/*=========*/
- /* out: TRUE if totally free */
- xdes_t* descr, /* in: descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- if (0 == xdes_get_n_used(descr, mtr)) {
- return(TRUE);
- } else {
- return(FALSE);
- }
-}
-
-/**************************************************************************
-Returns true if extent contains no free pages. */
-UNIV_INLINE
-bool
-xdes_is_full(
-/*=========*/
- /* out: TRUE if full */
- xdes_t* descr, /* in: descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- if (FSP_EXTENT_SIZE == xdes_get_n_used(descr, mtr)) {
- return(TRUE);
- } else {
- return(FALSE);
- }
-}
-
-/**************************************************************************
-Sets the state of an xdes. */
-UNIV_INLINE
-void
-xdes_set_state(
-/*===========*/
- xdes_t* descr, /* in: descriptor */
- ulint state, /* in: state to set */
- mtr_t* mtr) /* in: mtr handle */
-{
- ut_ad(descr && mtr);
- ut_ad(state >= XDES_FREE);
- ut_ad(state <= XDES_FSEG);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- mlog_write_ulint(descr + XDES_STATE, state, MLOG_4BYTES, mtr);
-}
-
-/**************************************************************************
-Gets the state of an xdes. */
-UNIV_INLINE
-ulint
-xdes_get_state(
-/*===========*/
- /* out: state */
- xdes_t* descr, /* in: descriptor */
- mtr_t* mtr) /* in: mtr handle */
-{
- ut_ad(descr && mtr);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- return(mtr_read_ulint(descr + XDES_STATE, MLOG_4BYTES, mtr));
-}
-
-/**************************************************************************
-Inits an extent descriptor to free and clean state. */
-UNIV_INLINE
-void
-xdes_init(
-/*======*/
- xdes_t* descr, /* in: descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- ulint i;
-
- ut_ad(descr && mtr);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(descr),
- MTR_MEMO_PAGE_X_LOCK));
-
- for (i = 0; i < FSP_EXTENT_SIZE; i++) {
- xdes_set_bit(descr, XDES_FREE_BIT, i, TRUE, mtr);
- xdes_set_bit(descr, XDES_CLEAN_BIT, i, TRUE, mtr);
- }
-
- xdes_set_state(descr, XDES_FREE, mtr);
-}
-
-/************************************************************************
-Calculates the page where the descriptor of a page resides. */
-UNIV_INLINE
-ulint
-xdes_calc_descriptor_page(
-/*======================*/
- /* out: descriptor page offset */
- ulint offset) /* in: page offset */
-{
- ut_ad(UNIV_PAGE_SIZE > XDES_ARR_OFFSET
- + (XDES_DESCRIBED_PER_PAGE / FSP_EXTENT_SIZE) * XDES_SIZE);
-
- return(ut_2pow_round(offset, XDES_DESCRIBED_PER_PAGE));
-}
-
-/************************************************************************
-Calculates the descriptor index within a descriptor page. */
-UNIV_INLINE
-ulint
-xdes_calc_descriptor_index(
-/*=======================*/
- /* out: descriptor index */
- ulint offset) /* in: page offset */
-{
- return(ut_2pow_remainder(offset, XDES_DESCRIBED_PER_PAGE) /
- FSP_EXTENT_SIZE);
-}
-
-/************************************************************************
-Gets pointer to a the extent descriptor of a page. The page where the
-extent descriptor resides is x-locked. If the page offset is equal to the free
-limit of the space, adds new extents from above the free limit
-to the space free list, if not free limit == space size. This adding
-is necessary to make the descriptor defined, as they are uninitialized
-above the free limit. */
-UNIV_INLINE
-xdes_t*
-xdes_get_descriptor_with_space_hdr(
-/*===============================*/
- /* out: pointer to the extent descriptor,
- NULL if the page does not exist in the
- space or if offset > free limit */
- fsp_header_t* sp_header,/* in: space header, x-latched */
- ulint space, /* in: space id */
- ulint offset, /* in: page offset;
- if equal to the free limit,
- we try to add new extents to
- the space free list */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint limit;
- ulint size;
- buf_block_t* buf_page;
- ulint descr_page_no;
- page_t* descr_page;
-
- ut_ad(mtr);
- ut_ad(mtr_memo_contains(mtr, &fsp_latch, MTR_MEMO_X_LOCK));
-
- /* Read free limit and space size */
- limit = mtr_read_ulint(sp_header + FSP_FREE_LIMIT, MLOG_4BYTES, mtr);
- size = mtr_read_ulint(sp_header + FSP_SIZE, MLOG_4BYTES, mtr);
-
- /* If offset is >= size or > limit, return NULL */
- if ((offset >= size) || (offset > limit)) {
- return(NULL);
- }
-
- /* If offset is == limit, fill free list of the space. */
- if (offset == limit) {
- fsp_fill_free_list(space, sp_header, mtr);
- }
-
- descr_page_no = xdes_calc_descriptor_page(offset);
-
- if (descr_page_no == 0) {
- /* It is on the space header page */
-
- descr_page = buf_frame_align(sp_header);
- } else {
-
- buf_page = buf_page_get(space, descr_page_no, mtr);
- buf_page_x_lock(buf_page, mtr);
- descr_page = buf_block_get_frame(buf_page);
- }
-
- return(descr_page + XDES_ARR_OFFSET
- + XDES_SIZE * xdes_calc_descriptor_index(offset));
-}
-
-/************************************************************************
-Gets pointer to a the extent descriptor of a page. The page where the
-extent descriptor resides is x-locked. If the page offset is equal to the free
-limit of the space, adds new extents from above the free limit
-to the space free list, if not free limit == space size. This adding
-is necessary to make the descriptor defined, as they are uninitialized
-above the free limit. */
-static
-xdes_t*
-xdes_get_descriptor(
-/*================*/
- /* out: pointer to the extent descriptor,
- NULL if the page does not exist in the
- space or if offset > free limit */
- ulint space, /* in: space id */
- ulint offset, /* in: page offset;
- if equal to the free limit,
- we try to add new extents to
- the space free list */
- mtr_t* mtr) /* in: mtr handle */
-{
- fsp_header_t* sp_header;
- buf_block_t* block;
-
- block = buf_page_get(space, 0, mtr); /* get space header */
- sp_header = FSP_HEADER_OFFSET + buf_block_get_frame(block);
- buf_page_x_lock(block, mtr);
-
- return(xdes_get_descriptor_with_space_hdr(sp_header, space, offset,
- mtr));
-}
-
-/************************************************************************
-Gets pointer to a the extent descriptor if the file address
-of the descriptor list node is known. The page where the
-extent descriptor resides is x-locked. */
-UNIV_INLINE
-xdes_t*
-xdes_lst_get_descriptor(
-/*====================*/
- /* out: pointer to the extent descriptor */
- ulint space, /* in: space id */
- fil_addr_t lst_node,/* in: file address of the list node
- contained in the descriptor */
- mtr_t* mtr) /* in: mtr handle */
-{
- xdes_t* descr;
-
- ut_ad(mtr);
- ut_ad(mtr_memo_contains(mtr, &fsp_latch, MTR_MEMO_X_LOCK));
-
- descr = fut_get_ptr_x_lock(space, lst_node, mtr) - XDES_FLST_NODE;
-
- return(descr);
-}
-
-/************************************************************************
-Gets pointer to the next descriptor in a descriptor list and x-locks
-its page. */
-UNIV_INLINE
-xdes_t*
-xdes_lst_get_next(
-/*==============*/
- xdes_t* descr, /* in: pointer to a descriptor */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint space;
-
- ut_ad(mtr && descr);
-
- space = buf_page_get_space(buf_block_align(descr));
-
- return(xdes_lst_get_descriptor(space,
- flst_get_next_addr(descr + XDES_FLST_NODE, mtr), mtr));
-}
-
-/************************************************************************
-Returns page offset of the first page in extent described by a descriptor.
-*/
-UNIV_INLINE
-ulint
-xdes_get_offset(
-/*============*/
- /* out: offset of the first page in extent */
- xdes_t* descr) /* in: extent descriptor */
-{
- buf_block_t* buf_page;
-
- ut_ad(descr);
-
- buf_page = buf_block_align(descr);
-
- return(buf_page_get_offset(buf_page)
- + ((descr - buf_frame_align(descr) - XDES_ARR_OFFSET)
- / XDES_SIZE)
- * FSP_EXTENT_SIZE);
-}
-
-/**************************************************************************
-Gets a pointer to the space header and x-locks its page. */
-UNIV_INLINE
-fsp_header_t*
-fsp_get_space_header(
-/*=================*/
- /* out: pointer to the space header, page x-locked */
- ulint id, /* in: space id */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
-
- ut_ad(mtr);
-
- block = buf_page_get(id, 0, mtr);
-
- buf_page_x_lock(block, mtr);
-
- return(FSP_HEADER_OFFSET + buf_block_get_frame(block));
-}
-
-/**************************************************************************
-Initializes the file space system mutex. */
-
-void
-fsp_init(void)
-/*==========*/
-{
- rw_lock_create(&fsp_latch);
-}
-
-/**************************************************************************
-Initializes the space header of a new created space. */
-
-void
-fsp_header_init(
-/*============*/
- ulint space, /* in: space id */
- ulint size, /* in: current size in blocks */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- fsp_header_t* header;
-
- ut_ad(mtr);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr);
- mlog_write_ulint(header + FSP_FREE_LIMIT, 0, MLOG_4BYTES, mtr);
- mlog_write_ulint(header + FSP_LOWEST_NO_WRITE, 0, MLOG_4BYTES, mtr);
- mlog_write_ulint(header + FSP_FRAG_N_USED, 0, MLOG_4BYTES, mtr);
-
- flst_init(header + FSP_FREE, mtr);
- flst_init(header + FSP_FREE_FRAG, mtr);
- flst_init(header + FSP_FULL_FRAG, mtr);
- flst_init(header + FSP_SEG_HDRS_FULL, mtr);
- flst_init(header + FSP_SEG_HDRS_FREE, mtr);
-
- mlog_write_dulint(header + FSP_SEG_ID, ut_dulint_create(0, 1),
- MLOG_8BYTES, mtr);
-}
-
-/**************************************************************************
-Increases the space size field of a space. */
-
-void
-fsp_header_inc_size(
-/*================*/
- ulint space, /* in: space id */
- ulint size_inc,/* in: size increment in pages */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- fsp_header_t* header;
- ulint size;
-
- ut_ad(mtr);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
- mlog_write_ulint(header + FSP_SIZE, size + size_inc, MLOG_4BYTES, mtr);
-}
-
-/**************************************************************************
-Puts new extents to the free list if there are free extents above the free
-limit. If an extent happens to contain an extent descriptor page, the extent
-is put to the FSP_FREE_FRAG list with the page marked as used. */
-static
-void
-fsp_fill_free_list(
-/*===============*/
- ulint space, /* in: space */
- fsp_header_t* header, /* in: space header */
- mtr_t* mtr) /* in: mtr */
-{
- ulint limit;
- ulint size;
- ulint i;
- xdes_t* descr;
- ulint count = 0;
- ulint frag_n_used;
-
- ut_ad(header && mtr);
-
- /* Check if we can fill free list from above the free list limit */
- size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
- limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES, mtr);
-
- i = limit;
- while ((i + FSP_EXTENT_SIZE <= size) && (count < FSP_FREE_ADD)) {
- mlog_write_ulint(header + FSP_FREE_LIMIT,
- i + FSP_EXTENT_SIZE, MLOG_4BYTES, mtr);
-
- descr = xdes_get_descriptor_with_space_hdr(header, space, i,
- mtr);
- xdes_init(descr, mtr);
-
- ut_ad(XDES_DESCRIBED_PER_PAGE % FSP_EXTENT_SIZE == 0);
-
- if (0 == i % XDES_DESCRIBED_PER_PAGE) {
- /* The first page in the extent is a descriptor page:
- mark it used */
- xdes_set_bit(descr, XDES_FREE_BIT, 0, FALSE, mtr);
- xdes_set_state(descr, XDES_FREE_FRAG, mtr);
- flst_add_last(header + FSP_FREE_FRAG,
- descr + XDES_FLST_NODE, mtr);
- frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
- MLOG_4BYTES, mtr);
- mlog_write_ulint(header + FSP_FRAG_N_USED,
- frag_n_used + 1,
- MLOG_4BYTES, mtr);
- } else {
- flst_add_last(header + FSP_FREE,
- descr + XDES_FLST_NODE, mtr);
- count++;
- }
- i += FSP_EXTENT_SIZE;
- }
-}
-
-/**************************************************************************
-Allocates a new free extent. */
-static
-xdes_t*
-fsp_alloc_free_extent(
-/*==================*/
- /* out: extent descriptor, NULL if cannot
- be allocated */
- ulint space, /* in: space id */
- ulint hint, /* in: hint of which extent would be
- desirable: any page offset in the extent
- goes; the hint must not be > FSP_FREE_LIMIT */
- mtr_t* mtr) /* in: mtr */
-{
- fsp_header_t* header;
- fil_addr_t first;
- xdes_t* descr;
-
- ut_ad(mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr);
-
- if (descr && (xdes_get_state(descr, mtr) == XDES_FREE)) {
- /* Ok, we can take this extent */
- } else {
- /* Take the first extent in the free list */
- first = flst_get_first(header + FSP_FREE, mtr);
-
- if (fil_addr_is_null(first)) {
- fsp_fill_free_list(space, header, mtr);
- first = flst_get_first(header + FSP_FREE, mtr);
- }
-
- if (fil_addr_is_null(first)) {
- return(NULL); /* No free extents left */
- }
-
- descr = xdes_lst_get_descriptor(space, first, mtr);
- }
-
- flst_remove(header + FSP_FREE, descr + XDES_FLST_NODE, mtr);
-
- return(descr);
-}
-
-/**************************************************************************
-Allocates a single free page from a space. The page is marked as used. */
-static
-ulint
-fsp_alloc_free_page(
-/*================*/
- /* out: the page offset, FIL_NULL
- if no page could be allocated */
- ulint space, /* in: space id */
- ulint hint, /* in: hint of which page would be desirable */
- mtr_t* mtr) /* in: mtr handle */
-{
- fsp_header_t* header;
- fil_addr_t first;
- xdes_t* descr;
- ulint free;
- ulint frag_n_used;
-
- ut_ad(mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- /* Get the hinted descriptor */
- descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr);
-
- if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) {
- /* Ok, we can take this extent */
- } else {
- /* Else take the first extent in free_frag list */
- first = flst_get_first(header + FSP_FREE_FRAG, mtr);
-
- if (fil_addr_is_null(first)) {
- /* There are no partially full fragments: allocate
- a free extent and add it to the FREE_FRAG
- list. NOTE that the allocation may have as a
- side-effect that an extent containing a descriptor
- page is added to the FREE_FRAG list. But we will
- allocate our page from the allocated free extent. */
-
- descr = fsp_alloc_free_extent(space, hint, mtr);
-
- if (descr == NULL) {
- /* No free space left */
- return(FIL_NULL);
- }
-
- xdes_set_state(descr, XDES_FREE_FRAG, mtr);
- flst_add_last(header + FSP_FREE_FRAG,
- descr + XDES_FLST_NODE, mtr);
- } else {
- descr = xdes_lst_get_descriptor(space, first, mtr);
- }
-
- /* Reset the hint */
- hint = 0;
- }
-
- /* Now we have in descr an extent with at least one free page.
- Look for a free page in the extent. */
- free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE,
- hint % FSP_EXTENT_SIZE, mtr);
- ut_a(free != ULINT_UNDEFINED);
-
- xdes_set_bit(descr, XDES_FREE_BIT, free, FALSE, mtr);
-
- /* Update the FRAG_N_USED field */
- frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
- MLOG_4BYTES, mtr);
- frag_n_used++;
- mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used,
- MLOG_4BYTES, mtr);
-
- if (xdes_is_full(descr, mtr)) {
- /* The fragment is full: move it to another list */
- flst_remove(header + FSP_FREE_FRAG,
- descr + XDES_FLST_NODE, mtr);
- xdes_set_state(descr, XDES_FULL_FRAG, mtr);
- flst_add_last(header + FSP_FULL_FRAG,
- descr + XDES_FLST_NODE, mtr);
- mlog_write_ulint(header + FSP_FRAG_N_USED,
- frag_n_used - FSP_EXTENT_SIZE,
- MLOG_4BYTES, mtr);
- }
- return(xdes_get_offset(descr) + free);
-}
-
-/**************************************************************************
-Frees a single page of a space. The page is marked as free and clean. */
-static
-void
-fsp_free_page(
-/*==========*/
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr) /* in: mtr handle */
-{
- fsp_header_t* header;
- xdes_t* descr;
- ulint state;
- ulint frag_n_used;
-
- ut_ad(mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- descr = xdes_get_descriptor_with_space_hdr(header, space, page, mtr);
-
- state = xdes_get_state(descr, mtr);
-
- ut_a((state == XDES_FREE_FRAG) || (state == XDES_FULL_FRAG));
-
- ut_a(xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)
- == FALSE);
-
- xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
- xdes_set_bit(descr, XDES_CLEAN_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
-
- frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
- MLOG_4BYTES, mtr);
-
- if (state == XDES_FULL_FRAG) {
- /* The fragment was full: move it to another list */
- flst_remove(header + FSP_FULL_FRAG,
- descr + XDES_FLST_NODE, mtr);
- xdes_set_state(descr, XDES_FREE_FRAG, mtr);
- flst_add_last(header + FSP_FREE_FRAG,
- descr + XDES_FLST_NODE, mtr);
- mlog_write_ulint(header + FSP_FRAG_N_USED,
- frag_n_used + FSP_EXTENT_SIZE - 1,
- MLOG_4BYTES, mtr);
- } else {
- ut_a(frag_n_used > 0);
- mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used - 1,
- MLOG_4BYTES, mtr);
- }
-
- if (xdes_is_free(descr, mtr)) {
- /* The extent has become free: move it to another list */
- flst_remove(header + FSP_FREE_FRAG,
- descr + XDES_FLST_NODE, mtr);
- fsp_free_extent(space, page, mtr);
- }
-}
-
-/**************************************************************************
-Returns an extent to the free list of a space. */
-static
-void
-fsp_free_extent(
-/*============*/
- ulint space, /* in: space id */
- ulint page, /* in: page offset in the extent */
- mtr_t* mtr) /* in: mtr */
-{
- fsp_header_t* header;
- xdes_t* descr;
-
- ut_ad(mtr);
-
- header = fsp_get_space_header(space, mtr);
-
- descr = xdes_get_descriptor_with_space_hdr(header, space, page, mtr);
-
- ut_a(xdes_get_state(descr, mtr) != XDES_FREE);
-
- xdes_init(descr, mtr);
-
- flst_add_last(header + FSP_FREE, descr + XDES_FLST_NODE, mtr);
-}
-
-/**************************************************************************
-Looks for an unused segment header on a segment header page. */
-UNIV_INLINE
-fseg_header_t*
-fsp_seg_hdr_page_get_nth_hdr(
-/*=========================*/
- /* out: segment header */
- page_t* page, /* in: segment header page */
- ulint i, /* in: search forward starting from this index */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- ut_ad(i < FSP_SEG_HDRS_PER_PAGE);
- ut_ad(mtr_memo_contains(mtr, page, MTR_MEMO_PAGE_X_LOCK));
-
- return(page + FSEG_ARR_OFFSET + FSEG_HEADER_SIZE * i);
-}
-
-/**************************************************************************
-Looks for a used segment header on a segment header page. */
-static
-ulint
-fsp_seg_hdr_page_find_used(
-/*=======================*/
- /* out: segment header index, or ULINT_UNDEFINED
- if not found */
- page_t* page, /* in: segment header page */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- ulint i;
- fseg_header_t* header;
-
- for (i = 0; i < FSP_SEG_HDRS_PER_PAGE; i++) {
-
- header = fsp_seg_hdr_page_get_nth_hdr(page, i, mtr);
-
- if (ut_dulint_cmp(mach_read_from_8(header + FSEG_ID),
- ut_dulint_zero) != 0) {
- /* This is used */
-
- return(i);
- }
- }
-
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Looks for an unused segment header on a segment header page. */
-static
-ulint
-fsp_seg_hdr_page_find_free(
-/*=======================*/
- /* out: segment header index, or ULINT_UNDEFINED
- if not found */
- page_t* page, /* in: segment header page */
- ulint j, /* in: search forward starting from this index */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- ulint i;
- fseg_header_t* header;
-
- for (i = j; i < FSP_SEG_HDRS_PER_PAGE; i++) {
-
- header = fsp_seg_hdr_page_get_nth_hdr(page, i, mtr);
-
- if (ut_dulint_cmp(mach_read_from_8(header + FSEG_ID),
- ut_dulint_zero) == 0) {
- /* This is unused */
-
- return(i);
- }
- }
-
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Allocates a new file segment header page. */
-static
-bool
-fsp_alloc_seg_hdr_page(
-/*===================*/
- /* out: TRUE if could be allocated */
- fsp_header_t* space_header, /* in: space header */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- buf_block_t* block;
- ulint page_no;
- page_t* page;
- fseg_header_t* header;
- ulint i;
-
- page_no = fsp_alloc_free_page(buf_frame_get_space(space_header),
- 0, mtr);
- if (page_no == FIL_NULL) {
-
- return(FALSE);
- }
-
- block = buf_page_get(buf_frame_get_space(space_header), page_no, mtr);
-
- buf_page_x_lock(block, mtr);
-
- page = buf_block_get_frame(block);
-
- for (i = 0; i < FSP_SEG_HDRS_PER_PAGE; i++) {
-
- header = fsp_seg_hdr_page_get_nth_hdr(page, i, mtr);
-
- mlog_write_dulint(header + FSEG_ID, ut_dulint_zero,
- MLOG_8BYTES, mtr);
- }
-
- flst_add_last(space_header + FSP_SEG_HDRS_FREE,
- page + FSEG_HDR_PAGE_NODE, mtr);
- return(TRUE);
-}
-
-/**************************************************************************
-Allocates a new file segment header. */
-static
-fseg_header_t*
-fsp_alloc_seg_header(
-/*=================*/
- /* out: segment header, or NULL if
- not enough space */
- fsp_header_t* space_header, /* in: space header */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- buf_block_t* block;
- ulint page_no;
- page_t* page;
- fseg_header_t* header;
- ulint n;
- bool success;
-
- if (flst_get_len(space_header + FSP_SEG_HDRS_FREE, mtr) == 0) {
- /* Allocate a new segment header page */
-
- success = fsp_alloc_seg_hdr_page(space_header, mtr);
-
- if (!success) {
-
- return(NULL);
- }
- }
-
- page_no = flst_get_first(space_header + FSP_SEG_HDRS_FREE, mtr).page;
-
- block = buf_page_get(buf_frame_get_space(space_header), page_no, mtr);
-
- buf_page_x_lock(block, mtr);
-
- page = buf_block_get_frame(block);
-
- n = fsp_seg_hdr_page_find_free(page, 0, mtr);
-
- ut_a(n != ULINT_UNDEFINED);
-
- header = fsp_seg_hdr_page_get_nth_hdr(page, n, mtr);
-
- if (ULINT_UNDEFINED == fsp_seg_hdr_page_find_free(page, n + 1, mtr)) {
-
- /* There are no other unused headers left on the page: move it
- to another list */
-
- flst_remove(space_header + FSP_SEG_HDRS_FREE,
- page + FSEG_HDR_PAGE_NODE, mtr);
-
- flst_add_last(space_header + FSP_SEG_HDRS_FULL,
- page + FSEG_HDR_PAGE_NODE, mtr);
- }
-
- return(header);
-}
-
-/**************************************************************************
-Frees a file segment header. */
-static
-void
-fsp_free_seg_header(
-/*================*/
- ulint space, /* in: space id */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mini-transaction handle */
-{
- page_t* page;
- fsp_header_t* space_header;
-
- page = buf_frame_align(header);
-
- space_header = fsp_get_space_header(space, mtr);
-
- ut_ad(mach_read_from_4(header + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
-
- if (ULINT_UNDEFINED == fsp_seg_hdr_page_find_free(page, mtr)) {
-
- /* Move the page to another list */
-
- flst_remove(space_header + FSP_SEG_HDRS_FULL,
- page + FSEG_HDR_PAGE_NODE, mtr);
-
- flst_add_last(space_header + FSP_SEG_HDRS_FREE,
- page + FSEG_HDR_PAGE_NODE, mtr);
- }
-
- mlog_write_dulint(header + FSEG_ID, ut_dulint_zero, MLOG_8BYTES, mtr);
- mlog_write_ulint(header + FSEG_MAGIC_N, 0, MLOG_4BYTES, mtr);
-
- if (ULINT_UNDEFINED == fsp_seg_hdr_page_find_used(page, mtr)) {
-
- /* There are no other used headers left on the page: free it */
-
- flst_remove(space_header + FSP_SEG_HDRS_FREE,
- page + FSEG_HDR_PAGE_NODE, mtr);
-
- fsp_free_page(space, page_no, mtr);
- }
-}
-
-/**************************************************************************
-Gets the page number from the nth fragment page slot. */
-UNIV_INLINE
-ulint
-fseg_get_nth_frag_page_no(
-/*======================*/
- /* out: page number, FIL_NULL if not in use */
- fseg_header_t* header, /* in: segment header */
- ulint n, /* in: slot index */
- mtr_t* mtr) /* in: mtr handle */
-{
- ut_ad(header && mtr);
- ut_ad(n < FSEG_FRAG_ARR_N_SLOTS);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(header),
- MTR_MEMO_PAGE_X_LOCK));
-
- return(mach_read_from_4(header + FSEG_FRAG_ARR
- + n * FSEG_FRAG_SLOT_SIZE));
-}
-
-/**************************************************************************
-Sets the page number in the nth fragment page slot. */
-UNIV_INLINE
-void
-fseg_set_nth_frag_page_no(
-/*======================*/
- fseg_header_t* header, /* in: segment header */
- ulint n, /* in: slot index */
- ulint page_no,/* in: page number to set */
- mtr_t* mtr) /* in: mtr handle */
-{
- ut_ad(header && mtr);
- ut_ad(n < FSEG_FRAG_ARR_N_SLOTS);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(header),
- MTR_MEMO_PAGE_X_LOCK));
-
- mlog_write_ulint(header + FSEG_FRAG_ARR + n * FSEG_FRAG_SLOT_SIZE,
- page_no, MLOG_4BYTES, mtr);
-}
-
-/**************************************************************************
-Finds a fragment page slot which is free. */
-static
-ulint
-fseg_find_free_frag_page_slot(
-/*==========================*/
- /* out: slot index; ULINT_UNDEFINED if none
- found */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint i;
- ulint page_no;
-
- ut_ad(header && mtr);
-
- for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
- page_no = fseg_get_nth_frag_page_no(header, i, mtr);
-
- if (page_no == FIL_NULL) {
-
- return(i);
- }
- }
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Finds a fragment page slot which is used and last in the array. */
-static
-ulint
-fseg_find_last_used_frag_page_slot(
-/*===============================*/
- /* out: slot index; ULINT_UNDEFINED if none
- found */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint i;
- ulint page_no;
-
- ut_ad(header && mtr);
-
- for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
- page_no = fseg_get_nth_frag_page_no(header,
- FSEG_ARR_N_SLOTS - i - 1, mtr);
-
- if (page_no != FIL_NULL) {
-
- return(i);
- }
- }
- return(ULINT_UNDEFINED);
-}
-
-/**************************************************************************
-Calculates reserved fragment page slots. */
-static
-ulint
-fseg_get_n_frag_pages(
-/*==================*/
- /* out: number of fragment pages */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint i;
- ulint count = 0;
-
- ut_ad(header && mtr);
-
- for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
- if (FIL_NULL != fseg_get_nth_frag_page_no(header, i, mtr)) {
- count++;
- }
- }
- return(count);
-}
-
-/**************************************************************************
-Creates a new segment. */
-
-ulint
-fseg_create(
-/*========*/
- /* out: the page number where the segment header is
- placed, FIL_NULL if could not create segment because
- lack of space */
- ulint space, /* in: space id */
- ulint* offset, /* out: byte offset of the segment header on its
- page */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- buf_frame_t* frame;
- fsp_header_t* space_header;
- fseg_header_t* header;
- dulint seg_id;
- ulint i;
-
- ut_ad(mtr);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- space_header = fsp_get_space_header(space, mtr);
-
- header = fsp_alloc_seg_header(space_header, mtr);
-
- if (header == NULL) {
-
- return(FIL_NULL);
- }
-
- /* Read the next segment id from space header and increment the
- value in space header */
-
- seg_id = mtr_read_dulint(space_header + FSP_SEG_ID, MLOG_8BYTES, mtr);
-
- mlog_write_dulint(space_header + FSP_SEG_ID, ut_dulint_add(seg_id, 1),
- MLOG_8BYTES, mtr);
-
- mlog_write_dulint(header + FSEG_ID, seg_id, MLOG_8BYTES, mtr);
- mlog_write_ulint(header + FSEG_NOT_FULL_N_USED, 0, MLOG_4BYTES, mtr);
-
- flst_init(header + FSEG_FREE, mtr);
- flst_init(header + FSEG_NOT_FULL, mtr);
- flst_init(header + FSEG_FULL, mtr);
-
- mlog_write_ulint(header + FSEG_MAGIC_N, FSEG_MAGIC_N_VALUE,
- MLOG_4BYTES, mtr);
- for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
- fseg_set_nth_frag_page_no(header, i, FIL_NULL, mtr);
- }
-
- *offset = header - buf_frame_align(header);
- return(buf_frame_get_page(buf_frame_align(header)));
-}
-
-/**************************************************************************
-Calculates the number of pages reserved by a segment, and how
-many pages are currently used. */
-
-ulint
-fseg_n_reserved_pages(
-/*==================*/
- /* out: number of reserved pages */
- fseg_header_t* header, /* in: segment header */
- ulint* used, /* out: number of pages used (<= reserved) */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint ret;
-
- mtr_x_lock(&fsp_latch, mtr);
-
- ret = fseg_n_reserved_pages_low(header, used, mtr);
-
- return(ret);
-}
-
-/**************************************************************************
-Calculates the number of pages reserved by a segment, and how
-many pages are currently used. */
-static
-ulint
-fseg_n_reserved_pages_low(
-/*======================*/
- /* out: number of reserved pages */
- fseg_header_t* header, /* in: segment header */
- ulint* used, /* out: number of pages used (<= reserved) */
- mtr_t* mtr) /* in: mtr handle */
-{
- ulint ret;
-
- ut_ad(header && used && mtr);
- ut_ad(mtr_memo_contains(mtr, buf_block_align(header),
- MTR_MEMO_BUF_FIX));
-
- buf_page_x_lock(buf_block_align(header), mtr);
-
- *used = mtr_read_ulint(header + FSEG_NOT_FULL_N_USED, MLOG_4BYTES, mtr)
- + FSP_EXTENT_SIZE * flst_get_len(header + FSEG_FULL, mtr)
- + fseg_get_n_frag_pages(header, mtr);
-
- ret = fseg_get_n_frag_pages(header, mtr)
- + FSP_EXTENT_SIZE * flst_get_len(header + FSEG_FREE, mtr)
- + FSP_EXTENT_SIZE * flst_get_len(header + FSEG_NOT_FULL, mtr)
- + FSP_EXTENT_SIZE * flst_get_len(header + FSEG_FULL, mtr);
-
- return(ret);
-}
-
-/*************************************************************************
-Tries to fill the free list of a segment with consecutive free extents.
-This happens if the segment is big enough to allowextents in the free list,
-the free list is empty, and the extents can be allocated consecutively from
-the hint onward. */
-static
-void
-fseg_fill_free_list(
-/*================*/
- fseg_header_t* header, /* in: segment header */
- ulint space, /* in: space id */
- ulint hint, /* in: hint which extent would be good as
- the first extent */
- mtr_t* mtr) /* in: mtr */
-{
- xdes_t* descr;
- ulint i;
- dulint seg_id;
- ulint reserved;
- ulint used;
-
- ut_ad(header && mtr);
-
- buf_page_x_lock(buf_block_align(header), mtr);
-
- reserved = fseg_n_reserved_pages_low(header, &used, mtr);
-
- if (reserved < FSEG_FREE_LIST_LIMIT * FSP_EXTENT_SIZE) {
- /* The segment is too small to allow extents in free list */
-
- return;
- }
-
- if (flst_get_len(header + FSEG_FREE, mtr) > 0) {
- /* Free list is not empty */
-
- return;
- }
-
- for (i = 0; i < FSEG_FREE_LIST_MAX_LEN; i++) {
- descr = xdes_get_descriptor(space, hint, mtr);
-
- if ((descr == NULL) ||
- (XDES_FREE != xdes_get_state(descr, mtr))) {
- /* We cannot allocate the desired extent: stop */
-
- return;
- }
-
- descr = fsp_alloc_free_extent(space, hint, mtr);
-
- xdes_set_state(descr, XDES_FSEG, mtr);
-
- seg_id = mtr_read_dulint(header + FSEG_ID, MLOG_8BYTES, mtr);
- mlog_write_dulint(descr + XDES_ID, seg_id, MLOG_8BYTES, mtr);
-
- flst_add_last(header + FSEG_FREE, descr + XDES_FLST_NODE, mtr);
- hint += FSP_EXTENT_SIZE;
- }
-}
-
-/*************************************************************************
-Allocates a free extent for the segment: looks first in the
-free list of the segment, then tries to allocate from the space free
-list. NOTE that the extent returned is still placed in the segment free
-list, not taken off it! */
-static
-xdes_t*
-fseg_alloc_free_extent(
-/*===================*/
- /* out: allocated extent, still placed in the
- segment free list, NULL if could
- not be allocated */
- fseg_header_t* header, /* in: segment header */
- ulint space, /* in: space id */
- mtr_t* mtr) /* in: mtr */
-{
- xdes_t* descr;
- dulint seg_id;
- fil_addr_t first;
-
- buf_page_x_lock(buf_block_align(header), mtr);
-
- if (flst_get_len(header + FSEG_FREE, mtr) > 0) {
- /* Segment free list is not empty, allocate from it */
-
- first = flst_get_first(header + FSEG_FREE, mtr);
-
- descr = xdes_lst_get_descriptor(space, first, mtr);
- } else {
- /* Segment free list was empty, allocate from space */
- descr = fsp_alloc_free_extent(space, 0, mtr);
-
- if (descr == NULL) {
- return(NULL);
- }
-
- seg_id = mtr_read_dulint(header + FSEG_ID, MLOG_8BYTES, mtr);
-
- xdes_set_state(descr, XDES_FSEG, mtr);
- mlog_write_dulint(descr + XDES_ID, seg_id, MLOG_8BYTES, mtr);
- flst_add_last(header + FSEG_FREE,
- descr + XDES_FLST_NODE, mtr);
-
- /* Try to fill the segment free list */
- fseg_fill_free_list(header, space,
- xdes_get_offset(descr) + FSP_EXTENT_SIZE, mtr);
- }
-
- return(descr);
-}
-
-/**************************************************************************
-Allocates a single free page from a segment. This function implements
-the intelligent allocation strategy which tries to minimize file space
-fragmentation. */
-
-ulint
-fseg_alloc_free_page(
-/*=================*/
- /* out: the allocated page offset
- FIL_NULL if no page could be allocated */
- fseg_header_t* seg_header, /* in: segment header */
- ulint hint, /* in: hint of which page would be desirable */
- byte direction, /* in: if the new page is needed because
- of an index page split, and records are
- inserted there in order, into which
- direction they go alphabetically: FSP_DOWN,
- FSP_UP, FSP_NO_DIR */
- mtr_t* mtr) /* in: mtr handle */
-{
- buf_block_t* block;
- dulint seg_id;
- fseg_page_header_t* page_header;
- ulint space;
- ulint used;
- ulint reserved;
- fil_addr_t first;
- xdes_t* descr; /* extent of the hinted page */
- ulint ret_page; /* the allocated page offset, FIL_NULL
- if could not be allocated */
- buf_block_t* ret_buf_page;
- buf_frame_t* ret_frame;
- xdes_t* ret_descr; /* the extent of the allocated page */
- ulint n;
- bool frag_page_allocated = FALSE;
-
- ut_ad(seg_header && mtr);
- ut_ad((direction >= FSP_UP) && (direction <= FSP_NO_DIR));
-
- mtr_x_lock(&fsp_latch, mtr);
-
- block = buf_block_align(seg_header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- seg_id = mtr_read_dulint(seg_header + FSEG_ID, MLOG_8BYTES, mtr);
-
- ut_ad(ut_dulint_cmp(seg_id, ut_dulint_zero) > 0);
-
- reserved = fseg_n_reserved_pages_low(seg_header, &used, mtr);
-
- descr = xdes_get_descriptor(space, hint, mtr);
-
- if (descr == NULL) {
- /* Hint outside space or too high above free limit:
- reset hint */
- hint = 0;
- descr = xdes_get_descriptor(space, hint, mtr);
- }
-
- /* In the big if-else below we look for ret_page and ret_descr */
- /*-------------------------------------------------------------*/
- if ((xdes_get_state(descr, mtr) == XDES_FSEG)
- && (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
- MLOG_8BYTES, mtr),
- seg_id))
- && (xdes_get_bit(descr, XDES_FREE_BIT,
- hint % FSP_EXTENT_SIZE, mtr) == TRUE)) {
-
- /* 1. We can take the hinted page
- =================================*/
- ret_descr = descr;
- ret_page = hint;
- /*-------------------------------------------------------------*/
- } else if ((xdes_get_state(descr, mtr) == XDES_FREE)
- && ((reserved - used) < reserved / FSEG_FILLFACTOR)
- && (used >= FSEG_FRAG_LIMIT)) {
-
- /* 2. We allocate the free extent from space and can take
- =========================================================
- the hinted page
- ===============*/
- ret_descr = fsp_alloc_free_extent(space, hint, mtr);
-
- ut_a(ret_descr == descr);
-
- xdes_set_state(ret_descr, XDES_FSEG, mtr);
- mlog_write_dulint(ret_descr + XDES_ID, seg_id, MLOG_8BYTES,
- mtr);
- flst_add_last(seg_header + FSEG_FREE,
- ret_descr + XDES_FLST_NODE, mtr);
-
- /* Try to fill the segment free list */
- fseg_fill_free_list(seg_header, space,
- hint + FSP_EXTENT_SIZE, mtr);
- ret_page = hint;
- /*-------------------------------------------------------------*/
- } else if ((direction != FSP_NO_DIR)
- && ((reserved - used) < reserved / FSEG_FILLFACTOR)
- && (used >= FSEG_FRAG_LIMIT)
- && (NULL != (ret_descr =
- fseg_alloc_free_extent(seg_header, space, mtr)))) {
-
- /* 3. We take any free extent (which was already assigned above
- ===============================================================
- in the if-condition to ret_descr) and take the lowest or
- ========================================================
- highest page in it, depending on the direction
- ==============================================*/
- ret_page = xdes_get_offset(ret_descr);
- if (direction == FSP_DOWN) {
- ret_page += FSP_EXTENT_SIZE - 1;
- }
- /*-------------------------------------------------------------*/
- } else if ((xdes_get_state(descr, mtr) == XDES_FSEG)
- && (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
- MLOG_8BYTES, mtr),
- seg_id))
- && (!xdes_is_full(descr, mtr))) {
-
- /* 4. We can take the page from the same extent as the
- ======================================================
- hinted page (and the extent already belongs to the
- ==================================================
- segment)
- ========*/
- ret_descr = descr;
- ret_page = xdes_get_offset(ret_descr) +
- xdes_find_bit(ret_descr, XDES_FREE_BIT, TRUE,
- hint % FSP_EXTENT_SIZE, mtr);
- /*-------------------------------------------------------------*/
- } else if (reserved - used > 0) {
- /* 5. We take any unused page from the segment
- ==============================================*/
- if (flst_get_len(seg_header + FSEG_NOT_FULL, mtr) > 0) {
- first = flst_get_first(seg_header + FSEG_NOT_FULL,
- mtr);
- } else if (flst_get_len(seg_header + FSEG_FREE, mtr) > 0) {
- first = flst_get_first(seg_header + FSEG_FREE, mtr);
- } else {
- ut_error;
- }
-
- ret_descr = xdes_lst_get_descriptor(space, first, mtr);
- ret_page = xdes_get_offset(ret_descr) +
- xdes_find_bit(ret_descr, XDES_FREE_BIT, TRUE,
- 0, mtr);
- /*-------------------------------------------------------------*/
- } else if (used < FSEG_FRAG_LIMIT) {
- /* 6. We allocate an individual page from the space
- ===================================================*/
- ret_page = fsp_alloc_free_page(space, hint, mtr);
- ret_descr = NULL;
-
- frag_page_allocated = TRUE;
-
- if (ret_page != FIL_NULL) {
- /* Put the page in the fragment page array of the
- segment */
- n = fseg_find_free_frag_page_slot(seg_header, mtr);
- ut_a(n != FIL_NULL);
-
- fseg_set_nth_frag_page_no(seg_header, n, ret_page,
- mtr);
- }
- /*-------------------------------------------------------------*/
- } else {
- /* 7. We allocate a new extent and take its first page
- ======================================================*/
- ret_descr = fseg_alloc_free_extent(seg_header, space, mtr);
-
- if (ret_descr == NULL) {
- ret_page = FIL_NULL;
- } else {
- ret_page = xdes_get_offset(ret_descr);
- }
- }
-
- if (ret_page == FIL_NULL) {
- /* Page could not be allocated */
-
- return(FIL_NULL);
- }
-
- /* Initialize the allocated page to buffer pool, so that it can be
- obtained immediately with buf_page_get without need for disk read */
-
- ret_buf_page = buf_page_create(space, ret_page, mtr);
-
- if (!frag_page_allocated) {
- /* At this point we know the extent and the page offset.
- The extent is still in the appropriate list (FSEG_NOT_FULL or
- FSEG_FREE), and the page is not yet marked as used. */
-
- ut_ad(xdes_get_descriptor(space, ret_page, mtr) == ret_descr);
- ut_ad(xdes_get_bit(ret_descr, XDES_FREE_BIT,
- ret_page % FSP_EXTENT_SIZE, mtr) == TRUE);
-
- fseg_mark_page_used(seg_header, space, ret_page, mtr);
- }
-
- return(ret_page);
-}
-
-/************************************************************************
-Marks a page used. The page must reside within the extents of the given
-segment. */
-static
-void
-fseg_mark_page_used(
-/*================*/
- fseg_header_t* seg_header,/* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr) /* in: mtr */
-{
- xdes_t* descr;
- ulint not_full_n_used;
-
- ut_ad(seg_header && mtr);
-
- descr = xdes_get_descriptor(space, page, mtr);
-
- ut_ad(mtr_read_ulint(seg_header + FSEG_ID, MLOG_4BYTES, mtr) ==
- mtr_read_ulint(descr + XDES_ID, MLOG_4BYTES, mtr));
-
- if (xdes_is_free(descr, mtr)) {
- /* We move the extent from the free list to the
- NOT_FULL list */
- flst_remove(seg_header + FSEG_FREE,
- descr + XDES_FLST_NODE, mtr);
- flst_add_last(seg_header + FSEG_NOT_FULL,
- descr + XDES_FLST_NODE, mtr);
- }
-
- ut_ad(xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)
- == TRUE);
-
- /* We mark the page as used */
- xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, FALSE, mtr);
-
- not_full_n_used = mtr_read_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- MLOG_4BYTES, mtr);
-
- not_full_n_used++;
- mlog_write_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- not_full_n_used, MLOG_4BYTES, mtr);
-
- if (xdes_is_full(descr, mtr)) {
- /* We move the extent from the NOT_FULL list to the
- FULL list */
- flst_remove(seg_header + FSEG_NOT_FULL,
- descr + XDES_FLST_NODE, mtr);
- flst_add_last(seg_header + FSEG_FULL,
- descr + XDES_FLST_NODE, mtr);
-
- mlog_write_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- not_full_n_used - FSP_EXTENT_SIZE,
- MLOG_4BYTES, mtr);
- }
-}
-
-/**************************************************************************
-Frees a single page of a segment. */
-
-void
-fseg_free_page(
-/*===========*/
- fseg_header_t* seg_header, /* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr) /* in: mtr handle */
-{
- mtr_x_lock(&fsp_latch, mtr);
-
- fseg_free_page_low(seg_header, space, page, mtr);
-}
-
-/**************************************************************************
-Frees a single page of a segment. */
-static
-void
-fseg_free_page_low(
-/*===============*/
- fseg_header_t* seg_header, /* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset */
- mtr_t* mtr) /* in: mtr handle */
-{
- buf_block_t* block;
- xdes_t* descr;
- ulint used;
- ulint not_full_n_used;
- ulint state;
- buf_block_t* buf_page;
- buf_frame_t* buf_frame;
- ulint i;
-
- ut_ad(seg_header && mtr);
-
- block = buf_block_align(seg_header);
- buf_page_x_lock(block, mtr);
-
- descr = xdes_get_descriptor(space, page, mtr);
-
- ut_a(descr);
- ut_a(xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)
- == FALSE);
-
- state = xdes_get_state(descr, mtr);
-
- if (state != XDES_FSEG) {
- /* The page is in the fragment pages of the segment */
-
- for (i = 0;; i++) {
- if (fseg_get_nth_frag_page_no(seg_header, i, mtr)
- == page) {
-
- fseg_set_nth_frag_page_no(seg_header, i,
- FIL_NULL, mtr);
- break;
- }
- }
-
- fsp_free_page(space, page, mtr);
-
- return;
- }
-
- /* If we get here, the page is in some extent of the segment */
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES, mtr),
- mtr_read_dulint(seg_header + FSEG_ID, MLOG_8BYTES, mtr)));
-
- not_full_n_used = mtr_read_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- MLOG_4BYTES, mtr);
- if (xdes_is_full(descr, mtr)) {
- /* The fragment is full: move it to another list */
- flst_remove(seg_header + FSEG_FULL,
- descr + XDES_FLST_NODE, mtr);
- flst_add_last(seg_header + FSEG_NOT_FULL,
- descr + XDES_FLST_NODE, mtr);
- mlog_write_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- not_full_n_used + FSP_EXTENT_SIZE - 1,
- MLOG_4BYTES, mtr);
- } else {
- ut_a(not_full_n_used > 0);
- mlog_write_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- not_full_n_used - 1,
- MLOG_4BYTES, mtr);
- }
-
- xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
- xdes_set_bit(descr, XDES_CLEAN_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
-
- if (xdes_is_free(descr, mtr)) {
- /* The extent has become free: free it to space */
- flst_remove(seg_header + FSEG_NOT_FULL,
- descr + XDES_FLST_NODE, mtr);
- fsp_free_extent(space, page, mtr);
- }
-}
-
-/**************************************************************************
-Frees an extent of a segment to the space free list. */
-static
-void
-fseg_free_extent(
-/*=============*/
- fseg_header_t* seg_header, /* in: segment header */
- ulint space, /* in: space id */
- ulint page, /* in: page offset in the extent */
- mtr_t* mtr) /* in: mtr handle */
-{
- buf_block_t* block;
- xdes_t* descr;
- ulint not_full_n_used;
- ulint descr_n_used;
-
- ut_ad(seg_header && mtr);
-
- block = buf_block_align(seg_header);
- buf_page_x_lock(block, mtr);
-
- descr = xdes_get_descriptor(space, page, mtr);
-
- ut_a(xdes_get_state(descr, mtr) == XDES_FSEG);
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES, mtr),
- mtr_read_dulint(seg_header + FSEG_ID, MLOG_8BYTES, mtr)));
-
- if (xdes_is_full(descr, mtr)) {
- flst_remove(seg_header + FSEG_FULL,
- descr + XDES_FLST_NODE, mtr);
- } else if (xdes_is_free(descr, mtr)) {
- flst_remove(seg_header + FSEG_FREE,
- descr + XDES_FLST_NODE, mtr);
- } else {
- flst_remove(seg_header + FSEG_NOT_FULL,
- descr + XDES_FLST_NODE, mtr);
-
- not_full_n_used = mtr_read_ulint(
- seg_header + FSEG_NOT_FULL_N_USED,
- MLOG_4BYTES, mtr);
-
- descr_n_used = xdes_get_n_used(descr, mtr);
- ut_a(not_full_n_used >= descr_n_used);
- mlog_write_ulint(seg_header + FSEG_NOT_FULL_N_USED,
- not_full_n_used - descr_n_used,
- MLOG_4BYTES, mtr);
- }
- fsp_free_extent(space, page, mtr);
-}
-
-/**************************************************************************
-Frees part of a segment. This function can be used to free a segment
-by repeatedly calling this function in different mini-transactions.
-Doing the freeing in a single mini-transaction might result in too big
-a mini-transaction. */
-
-bool
-fseg_free_step(
-/*===========*/
- /* out: TRUE if freeing completed */
- ulint space, /* in: segment space id */
- ulint page_no,/* in: segment header page number */
- ulint offset, /* in: segment header byte offset on page */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- ulint n;
- ulint page;
- xdes_t* descr;
- fseg_header_t* header;
- fil_addr_t header_addr;
-
- header_addr.page = page_no;
- header_addr.boffset = offset;
-
- mtr_x_lock(&fsp_latch, mtr);
-
- header = fut_get_ptr_x_lock(space, header_addr, mtr);
-
- descr = fseg_get_first_extent(header, mtr);
-
- if (descr != NULL) {
- /* Free the extent held by the segment */
- page = xdes_get_offset(descr);
-
- fseg_free_extent(header, space, page, mtr);
-
- return(FALSE);
- }
-
- /* Free a frag page */
-
- n = fseg_get_last_used_frag_page_slot(header, mtr);
-
- if (n == ULINT_UNDEFINED) {
- /* Freeing completed: free the segment header */
- fsp_free_seg_header(space, header, mtr);
-
- return(TRUE);
- }
-
- fseg_free_page_low(header, space,
- fseg_get_nth_frag_page_no(header, n, mtr), mtr);
-
- return(FALSE);
-}
-
-/***********************************************************************
-Frees a segment. The freeing is performed in several mini-transactions,
-so that there is no danger of bufferfixing too many buffer pages. */
-
-void
-fseg_free(
-/*======*/
- ulint space, /* in: space id */
- ulint page_no,/* in: page number where the segment header is
- placed */
- ulint offset) /* in: byte offset of the segment header on that
- page */
-{
- mtr_t mtr;
- buf_block_t* block;
- bool finished;
-
- for (;;) {
- mtr_start(&mtr);
-
- block = buf_page_get(space, page_no, &mtr);
-
- finished = fseg_free_step(space, page_no, offset, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-}
-
-/**************************************************************************
-Returns the first extent descriptor for a segment. We think of the extent
-lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
--> FSEG_FREE. */
-static
-xdes_t*
-fseg_get_first_extent(
-/*==================*/
- /* out: the first extent descriptor, or NULL if
- none */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- fil_addr_t first;
- ulint space;
- xdes_t* descr;
-
- ut_ad(header && mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- first = fil_addr_null;
-
- if (flst_get_len(header + FSEG_FULL, mtr) > 0) {
- first = flst_get_first(header + FSEG_FULL, mtr);
- } else if (flst_get_len(header + FSEG_NOT_FULL, mtr) > 0) {
- first = flst_get_first(header + FSEG_NOT_FULL, mtr);
- } else if (flst_get_len(header + FSEG_FREE, mtr) > 0) {
- first = flst_get_first(header + FSEG_FREE, mtr);
- }
-
- if (first.page == FIL_NULL) {
- return(NULL);
- } else {
- descr = xdes_lst_get_descriptor(space, first, mtr);
- return(descr);
- }
-}
-
-#ifdef notdefined
-
-/**************************************************************************
-Returns the last non-free extent descriptor for a segment. We think of
-the extent lists of the segment catenated in the order FSEG_FULL ->
-FSEG_NOT_FULL -> FSEG_FREE. */
-static
-xdes_t*
-fseg_get_last_non_free_extent(
-/*==========================*/
- /* out: the last extent descriptor, or NULL if
- none */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- fil_addr_t last;
- ulint space;
- xdes_t* descr;
-
- ut_ad(header && mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- last = fil_addr_null;
-
- if (flst_get_len(header + FSEG_NOT_FULL, mtr) > 0) {
- last = flst_get_last(header + FSEG_NOT_FULL, mtr);
- } else if (flst_get_len(header + FSEG_FULL, mtr) > 0) {
- last = flst_get_last(header + FSEG_FULL, mtr);
- }
-
- if (last.page == FIL_NULL) {
- return(NULL);
- } else {
- descr = xdes_lst_get_descriptor(space, last, mtr);
- return(descr);
- }
-}
-
-/**************************************************************************
-Returns the next extent descriptor for a segment. We think of the extent
-lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
--> FSEG_FREE. */
-static
-xdes_t*
-fseg_get_next_extent(
-/*=================*/
- /* out: next extent descriptor, or NULL if
- none */
- fseg_header_t* header, /* in: segment header */
- xdes_t* descr, /* in: previous extent descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- fil_addr_t next_addr;
- buf_block_t* block;
- ulint space;
-
- ut_ad(header && descr && mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- next_addr = flst_get_next_addr(descr + XDES_FLST_NODE, mtr);
-
- if (next_addr.page == FIL_NULL) {
- /* This is the last extent in the list. */
- if (xdes_is_full(descr, mtr)) {
- /* descr is in FSEG_FULL list */
- if (flst_get_len(header + FSEG_NOT_FULL, mtr) > 0) {
- next_addr = flst_get_first(header
- + FSEG_NOT_FULL, mtr);
- } else if (flst_get_len(header + FSEG_FREE, mtr) > 0) {
- next_addr = flst_get_first(header
- + FSEG_FREE, mtr);
- }
- } else if (!xdes_is_full(descr, mtr)
- && !xdes_is_free(descr, mtr)) {
- /* descr is in FSEG_NOT_FULL list */
- if (flst_get_len(header + FSEG_FREE, mtr) > 0) {
- next_addr = flst_get_first(header
- + FSEG_FREE, mtr);
- }
- }
- }
-
- if (next_addr.page != FIL_NULL) {
- descr = xdes_lst_get_descriptor(space, next_addr, mtr);
- ut_ad(descr);
- return(descr);
- } else {
- return(NULL);
- }
-}
-
-/**************************************************************************
-Returns the previous extent descriptor for a segment. We think of the extent
-lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
--> FSEG_FREE. */
-static
-xdes_t*
-fseg_get_prev_extent(
-/*=================*/
- /* out: previous extent descriptor, or NULL if
- none */
- fseg_header_t* header, /* in: segment header */
- xdes_t* descr, /* in: extent descriptor */
- mtr_t* mtr) /* in: mtr */
-{
- fil_addr_t prev_addr;
- buf_block_t* block;
- ulint space;
-
- ut_ad(header && descr && mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- prev_addr = flst_get_prev_addr(descr + XDES_FLST_NODE, mtr);
-
- if (prev_addr.page == FIL_NULL) {
- /* This is the first extent in the list. */
- if (xdes_is_free(descr, mtr)) {
- /* descr is in FSEG_FREE list */
- if (flst_get_len(header + FSEG_NOT_FULL, mtr) > 0) {
- prev_addr = flst_get_last(header
- + FSEG_NOT_FULL, mtr);
- } else if (flst_get_len(header + FSEG_FULL, mtr) > 0) {
- prev_addr = flst_get_last(header
- + FSEG_FULL, mtr);
- }
- } else if (!xdes_is_full(descr, mtr)
- && !xdes_is_free(descr, mtr)) {
- /* descr is in FSEG_NOT_FULL list */
- if (flst_get_len(header + FSEG_FULL, mtr) > 0) {
- prev_addr = flst_get_last(header
- + FSEG_FULL, mtr);
- }
- }
- }
-
- if (prev_addr.page != FIL_NULL) {
- descr = xdes_lst_get_descriptor(space, prev_addr, mtr);
- ut_ad(descr);
- return(descr);
- } else {
- return(NULL);
- }
-}
-
-/*************************************************************************
-Gets the first used page number in the given extent assigned to a
-specific segment, or its successors, in the order defined in
-fsp_get_next_extent. */
-static
-ulint
-fseg_extent_get_next_page_no(
-/*=========================*/
- /* next used page number in the given extent
- or a successor of it, FIL_NULL if no page
- found */
- fseg_header_t* header, /* in: segment header */
- xdes_t* descr, /* in: extent descriptor, if this is NULL, the
- function returns FIL_NULL */
- mtr_t* mtr) /* in: mtr */
-{
- ulint bit;
-
- UT_NOT_USED(header);
- ut_ad((descr == NULL) || (xdes_get_state(descr, mtr) == XDES_FSEG));
-
- for (;;) {
- if (descr == NULL) {
- return(FIL_NULL);
- }
-
- bit = xdes_find_bit(descr, XDES_FREE_BIT, FALSE, 0, mtr);
-
- if (bit == ULINT_UNDEFINED) {
- /* No page found in this extent: the extent is in
- FSEG_FREE list, thus, no used page can be found
- in successors */
- return(FIL_NULL);
- } else {
- return(xdes_get_offset(descr) + bit);
- }
- }
-}
-
-/*************************************************************************
-Gets the last used page number in the given extent assigned to a
-specific segment, or its predecessor extents, in the order defined in
-fsp_get_next_extent. If the page cannot be found from the extents,
-the last page of the fragment list is returned, or FIL_NULL if it is
-empty.*/
-static
-ulint
-fseg_extent_get_prev_page_no(
-/*=========================*/
- /* previous used page number in the given
- extent or a predecessor, FIL_NULL
- if no page found */
- fseg_header_t* header, /* in: segment header */
- xdes_t* descr, /* in: extent descriptor, if this is NULL, the
- function returns the last page of the fragment
- list, if any */
- mtr_t* mtr) /* in: mtr */
-{
- ulint prev_page_no;
- ulint bit;
- fil_addr_t last_frag_page_addr;
-
- ut_ad((descr == NULL) || (xdes_get_state(descr, mtr) == XDES_FSEG));
-
- for (;;) {
- if (descr == NULL) {
- prev_page_no = FIL_NULL;
- break;
- }
-
- bit = xdes_find_bit_downward(descr, XDES_FREE_BIT, FALSE,
- FSP_EXTENT_SIZE - 1, mtr);
-
- if (bit == ULINT_UNDEFINED) {
- descr = fseg_get_prev_extent(header, descr, mtr);
- } else {
- prev_page_no = xdes_get_offset(descr) + bit;
- break;
- }
- }
-
- if (prev_page_no == FIL_NULL) {
- last_frag_page_addr = flst_get_last(header + FSEG_FRAG, mtr);
- prev_page_no = last_frag_page_addr.page;
- }
-
- return(prev_page_no);
-}
-
-/**************************************************************************
-Returns the page number of the first segment page. If no pages have been
-freed from the segment, and the pages were allocated with the hint page
-number always one greater than previous page, then it is guaranteed that
-this function returns the first allocated page. */
-
-ulint
-fseg_get_first_page_no(
-/*===================*/
- /* out: page number, FIL_NULL if no
- page found */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- ulint first_page_no;
- xdes_t* descr;
- fil_addr_t first_frag_page_addr;
-
- ut_ad(header);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- /* Find first page */
- first_frag_page_addr = flst_get_first(header + FSEG_FRAG, mtr);
- first_page_no = first_frag_page_addr.page;
-
- if (first_page_no == FIL_NULL) {
- descr = fseg_get_first_extent(header, mtr);
- first_page_no = fseg_extent_get_next_page_no(header, descr,
- mtr);
- }
-
- return(first_page_no);
-}
-
-/**************************************************************************
-Returns the page number of the last segment page. If no pages have been
-freed from the segment, and the pages were allocated with the hint page
-number always one greater than previous page, then it is guaranteed that
-this function returns the last allocated page. */
-
-ulint
-fseg_get_last_page_no(
-/*==================*/
- /* out: page number, FIL_NULL if no
- page found */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- ulint last_page_no;
- xdes_t* descr;
-
- ut_ad(header);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- descr = fseg_get_last_non_free_extent(header, mtr);
- last_page_no = fseg_extent_get_prev_page_no(header, descr, mtr);
-
- return(last_page_no);
-}
-
-/**************************************************************************
-Returns the page number of the next segment page. If no pages have been
-freed from the segment, and the pages were allocated with the hint page
-number always one greater than previous page, then it is guaranteed that
-this function steps the pages through in the order they were allocated
-to the segment. */
-
-ulint
-fseg_get_next_page_no(
-/*==================*/
- /* out: page number, FIL_NULL if no
- page left */
- fseg_header_t* header, /* in: segment header */
- ulint page_no,/* in: previous page number */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- buf_frame_t* frame;
- ulint space;
- ulint next_page_no;
- xdes_t* descr;
- ulint bit;
- fil_addr_t next_frag_page_addr;
- fseg_page_header_t* page_header;
-
- ut_ad(header);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- descr = xdes_get_descriptor(space, page_no, mtr);
- ut_ad(xdes_get_bit(descr, XDES_FREE_BIT,
- page_no % FSP_EXTENT_SIZE, mtr) == FALSE);
-
- if (xdes_get_state(descr, mtr) == XDES_FSEG) {
- /* The extent of the current page belongs to the segment */
- bit = xdes_find_bit(descr, XDES_FREE_BIT, FALSE,
- (page_no + 1) % FSP_EXTENT_SIZE,
- mtr);
- if ((bit == ULINT_UNDEFINED)
- || (bit <= (page_no % FSP_EXTENT_SIZE))) {
- /* No higher address pages in this extent */
- descr = fseg_get_next_extent(header, descr, mtr);
- next_page_no = fseg_extent_get_next_page_no(
- header, descr, mtr);
- } else {
- next_page_no = xdes_get_offset(descr) + bit;
- }
- } else {
- /* Current page is a fragment page */
- block = buf_page_get(space, page_no, mtr);
- buf_page_x_lock(block, mtr);
- frame = buf_block_get_frame(block);
- page_header = frame + FSEG_PAGE_HEADER_OFFSET;
- next_frag_page_addr = flst_get_next_addr(
- page_header + FSEG_PAGE_FRAG_NODE,
- mtr);
-
- next_page_no = next_frag_page_addr.page;
- if (next_page_no == FIL_NULL) {
- descr = fseg_get_first_extent(header, mtr);
- next_page_no = fseg_extent_get_next_page_no(
- header, descr, mtr);
- }
- }
- return(next_page_no);
-}
-
-/**************************************************************************
-Returns the page number of the previous segment page. If no pages have been
-freed from the segment, and the pages were allocated with the hint page
-number always one greater than the previous page, then it is guaranteed that
-this function steps through the pages in the order opposite to the allocation
-order of the pages. */
-
-ulint
-fseg_get_prev_page_no(
-/*==================*/
- /* out: page number, FIL_NULL if no page
- left */
- fseg_header_t* header, /* in: segment header */
- ulint page_no,/* in: page number */
- mtr_t* mtr) /* in: mtr */
-{
- buf_block_t* block;
- buf_frame_t* frame;
- ulint space;
- ulint prev_page_no;
- xdes_t* descr;
- ulint bit;
- fil_addr_t prev_frag_page_addr;
- fseg_page_header_t* page_header;
-
- ut_ad(header);
-
- mtr_x_lock(&fsp_latch, mtr);
-
- block = buf_block_align(header);
- buf_page_x_lock(block, mtr);
-
- space = buf_page_get_space(block);
-
- descr = xdes_get_descriptor(space, page_no, mtr);
- ut_ad(xdes_get_bit(descr, XDES_FREE_BIT,
- page_no % FSP_EXTENT_SIZE, mtr) == FALSE);
-
- if (xdes_get_state(descr, mtr) == XDES_FSEG) {
- /* The extent of the current page belongs to the segment */
- bit = xdes_find_bit_downward(descr, XDES_FREE_BIT, FALSE,
- (page_no - 1) % FSP_EXTENT_SIZE,
- mtr);
- if ((bit == ULINT_UNDEFINED)
- || (bit >= (page_no % FSP_EXTENT_SIZE))) {
- /* No lower address pages in this extent */
- descr = fseg_get_prev_extent(header, descr, mtr);
- prev_page_no = fseg_extent_get_prev_page_no(
- header, descr, mtr);
- } else {
- prev_page_no = xdes_get_offset(descr) + bit;
- }
- } else {
- /* Current page is a fragment page */
- block = buf_page_get(space, page_no, mtr);
- buf_page_x_lock(block, mtr);
- frame = buf_block_get_frame(block);
- page_header = frame + FSEG_PAGE_HEADER_OFFSET;
- prev_frag_page_addr = flst_get_prev_addr(
- page_header + FSEG_PAGE_FRAG_NODE,
- mtr);
-
- prev_page_no = prev_frag_page_addr.page;
- }
- return(prev_page_no);
-}
-
-#endif
-
-/***********************************************************************
-Validates a segment. */
-static
-bool
-fseg_validate_low(
-/*==============*/
- /* out: TRUE if ok */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr2) /* in: mtr */
-{
- ulint space;
- dulint seg_id;
- mtr_t mtr;
- xdes_t* descr;
- fil_addr_t node_addr;
- ulint n_used = 0;
- ulint n_used2 = 0;
- flst_node_t* node;
- buf_frame_t* frame;
- fseg_page_header_t* page_header;
-
- ut_ad(mtr_memo_contains(mtr2, buf_block_align(header),
- MTR_MEMO_BUF_FIX));
- buf_page_x_lock(buf_block_align(header), mtr2);
-
- space = buf_page_get_space(buf_block_align(header));
-
- seg_id = mtr_read_dulint(header + FSEG_ID, MLOG_8BYTES, mtr2);
- n_used = mtr_read_ulint(header + FSEG_NOT_FULL_N_USED,
- MLOG_4BYTES, mtr2);
-
- flst_validate(header + FSEG_FRAG, mtr2);
- flst_validate(header + FSEG_FREE, mtr2);
- flst_validate(header + FSEG_NOT_FULL, mtr2);
- flst_validate(header + FSEG_FULL, mtr2);
-
- /* Validate FSEG_FREE list */
- node_addr = flst_get_first(header + FSEG_FREE, mtr2);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) == 0);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
-
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
- mtr_commit(&mtr);
- }
-
- /* Validate FSEG_NOT_FULL list */
-
- node_addr = flst_get_first(header + FSEG_NOT_FULL, mtr2);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) > 0);
- ut_a(xdes_get_n_used(descr, &mtr) < FSP_EXTENT_SIZE);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
-
- n_used2 += xdes_get_n_used(descr, &mtr);
-
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
- mtr_commit(&mtr);
- }
-
- /* Validate FSEG_FULL list */
-
- node_addr = flst_get_first(header + FSEG_FULL, mtr2);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) == FSP_EXTENT_SIZE);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(descr + XDES_ID, MLOG_8BYTES,
- &mtr), seg_id));
-
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
- mtr_commit(&mtr);
- }
-
- /* Validate FSEG_FRAG list */
- node_addr = flst_get_first(header + FSEG_FRAG, mtr2);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- node = fut_get_ptr_x_lock(space, node_addr, &mtr);
- frame = buf_frame_align(node);
- page_header = frame + FSEG_PAGE_HEADER_OFFSET;
- ut_a(0 == ut_dulint_cmp(
- mtr_read_dulint(page_header + FSEG_PAGE_SEG_ID,
- MLOG_8BYTES, &mtr), seg_id));
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- ut_a(n_used == n_used2);
-
- return(TRUE);
-}
-
-/***********************************************************************
-Validates a segment. */
-
-bool
-fseg_validate(
-/*==========*/
- /* out: TRUE if ok */
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr2) /* in: mtr */
-{
- bool ret;
-
- mtr_x_lock(&fsp_latch, mtr2);
- ret = fseg_validate_low(header, mtr2);
-
- return(ret);
-}
-
-/***********************************************************************
-Writes info of a segment. */
-static
-void
-fseg_print_low(
-/*===========*/
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- ulint space;
- ulint seg_id_low;
- ulint seg_id_high;
- ulint n_used;
- ulint n_frag;
- ulint n_free;
- ulint n_not_full;
- ulint n_full;
- ulint reserved;
- ulint used;
- ulint page_no;
-
- ut_ad(mtr_memo_contains(mtr, buf_block_align(header),
- MTR_MEMO_BUF_FIX));
- buf_page_x_lock(buf_block_align(header), mtr);
-
- space = buf_page_get_space(buf_block_align(header));
- page_no = buf_page_get_offset(buf_block_align(header));
-
- reserved = fseg_n_reserved_pages_low(header, &used, mtr);
-
- seg_id_low = ut_dulint_get_low(mtr_read_dulint(header + FSEG_ID,
- MLOG_8BYTES, mtr));
- seg_id_high = ut_dulint_get_high(mtr_read_dulint(header + FSEG_ID,
- MLOG_8BYTES, mtr));
-
- n_used = mtr_read_ulint(header + FSEG_NOT_FULL_N_USED,
- MLOG_4BYTES, mtr);
-
- n_frag = flst_get_len(header + FSEG_FRAG, mtr);
- n_free = flst_get_len(header + FSEG_FREE, mtr);
- n_not_full = flst_get_len(header + FSEG_NOT_FULL, mtr);
- n_full = flst_get_len(header + FSEG_FULL, mtr);
-
- printf(
- "SEGMENT id %lu %lu space %lu; page %lu; res %lu used %lu; full ext %lu\n",
- seg_id_high, seg_id_low, space, page_no, reserved, used,
- n_full);
- printf(
- "fragm pages %lu; free extents %lu; not full extents %lu: pages %lu\n",
- n_frag, n_free, n_not_full, n_used);
-}
-
-/***********************************************************************
-Writes info of a segment. */
-
-void
-fseg_print(
-/*=======*/
- fseg_header_t* header, /* in: segment header */
- mtr_t* mtr) /* in: mtr */
-{
- mtr_x_lock(&fsp_latch, mtr);
-
- fseg_print_low(header, mtr);
-}
-
-/***********************************************************************
-Validates the file space system and its segments. */
-
-bool
-fsp_validate(
-/*=========*/
- /* out: TRUE if ok */
- ulint space) /* in: space id */
-{
- fsp_header_t* header;
- fseg_header_t* seg_header;
- ulint size;
- ulint free_limit;
- ulint frag_n_used;
- mtr_t mtr;
- mtr_t mtr2;
- xdes_t* descr;
- fil_addr_t node_addr;
- ulint descr_count = 0;
- ulint n_used = 0;
- ulint n_used2 = 0;
- ulint n_full_frag_pages;
-
- /* Start first a mini-transaction mtr2 to lock out all other threads
- from the fsp system */
- mtr_start(&mtr2);
- mtr_x_lock(&fsp_latch, &mtr2);
-
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
-
- size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, &mtr);
- free_limit = mtr_read_ulint(header + FSP_FREE_LIMIT,
- MLOG_4BYTES, &mtr);
- frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
- MLOG_4BYTES, &mtr);
-
- n_full_frag_pages = FSP_EXTENT_SIZE *
- flst_get_len(header + FSP_FULL_FRAG, &mtr);
-
- ut_a(free_limit <= size);
-
- flst_validate(header + FSP_FREE, &mtr);
- flst_validate(header + FSP_FREE_FRAG, &mtr);
- flst_validate(header + FSP_FULL_FRAG, &mtr);
- flst_validate(header + FSP_SEGS, &mtr);
-
- mtr_commit(&mtr);
-
- /* Validate FSP_FREE list */
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
- node_addr = flst_get_first(header + FSP_FREE, &mtr);
-
- mtr_commit(&mtr);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr_count++;
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) == 0);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FREE);
-
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
- mtr_commit(&mtr);
- }
-
- /* Validate FSP_FREE_FRAG list */
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
- node_addr = flst_get_first(header + FSP_FREE_FRAG, &mtr);
-
- mtr_commit(&mtr);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr_count++;
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) > 0);
- ut_a(xdes_get_n_used(descr, &mtr) < FSP_EXTENT_SIZE);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FREE_FRAG);
-
- n_used += xdes_get_n_used(descr, &mtr);
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
-
- mtr_commit(&mtr);
- }
-
- /* Validate FSP_FULL_FRAG list */
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
- node_addr = flst_get_first(header + FSP_FULL_FRAG, &mtr);
-
- mtr_commit(&mtr);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- descr_count++;
- descr = xdes_lst_get_descriptor(space, node_addr, &mtr);
-
- ut_a(xdes_get_n_used(descr, &mtr) == FSP_EXTENT_SIZE);
- ut_a(xdes_get_state(descr, &mtr) == XDES_FULL_FRAG);
-
- node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
- mtr_commit(&mtr);
- }
-
- /* Validate segments */
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
- node_addr = flst_get_first(header + FSP_SEGS, &mtr);
-
- mtr_commit(&mtr);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- seg_header = fut_get_ptr_x_lock(space, node_addr,
- &mtr) - FSEG_FLST_NODE;
- fseg_validate_low(seg_header, &mtr);
-
- descr_count += flst_get_len(seg_header + FSEG_FREE, &mtr);
- descr_count += flst_get_len(seg_header + FSEG_FULL, &mtr);
- descr_count += flst_get_len(seg_header + FSEG_NOT_FULL, &mtr);
-
- n_used2 += flst_get_len(seg_header + FSEG_FRAG, &mtr);
-
- node_addr = flst_get_next_addr(seg_header + FSEG_FLST_NODE,
- &mtr);
- mtr_commit(&mtr);
- }
-
- ut_a(descr_count * FSP_EXTENT_SIZE == free_limit);
- ut_a(n_used + n_full_frag_pages
- == n_used2 + (free_limit + XDES_DESCRIBED_PER_PAGE - 1)
- / XDES_DESCRIBED_PER_PAGE);
- ut_a(frag_n_used == n_used);
-
- mtr_commit(&mtr2);
- return(TRUE);
-}
-
-/***********************************************************************
-Prints info of a file space. */
-
-void
-fsp_print(
-/*======*/
- ulint space) /* in: space id */
-{
- fsp_header_t* header;
- fseg_header_t* seg_header;
- ulint size;
- ulint free_limit;
- ulint frag_n_used;
- mtr_t mtr;
- mtr_t mtr2;
- fil_addr_t node_addr;
- ulint n_free;
- ulint n_free_frag;
- ulint n_full_frag;
- ulint n_segs;
- ulint seg_id_low;
- ulint seg_id_high;
-
- /* Start first a mini-transaction mtr2 to lock out all other threads
- from the fsp system */
- mtr_start(&mtr2);
- mtr_x_lock(&fsp_latch, &mtr2);
-
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- header = fsp_get_space_header(space, &mtr);
-
- size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, &mtr);
- free_limit = mtr_read_ulint(header + FSP_FREE_LIMIT,
- MLOG_4BYTES, &mtr);
- frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
- MLOG_4BYTES, &mtr);
-
- n_free = flst_get_len(header + FSP_FREE, &mtr);
- n_free_frag = flst_get_len(header + FSP_FREE_FRAG, &mtr);
- n_full_frag = flst_get_len(header + FSP_FULL_FRAG, &mtr);
- n_segs = flst_get_len(header + FSP_SEGS, &mtr);
- seg_id_low = ut_dulint_get_low(mtr_read_dulint(header + FSP_SEG_ID,
- MLOG_8BYTES, &mtr));
- seg_id_high = ut_dulint_get_high(mtr_read_dulint(header + FSP_SEG_ID,
- MLOG_8BYTES, &mtr));
-
- printf("FILE SPACE INFO: id %lu\n", space);
-
- printf("size %lu, free limit %lu, free extents %lu\n",
- size, free_limit, n_free);
- printf(
- "not full frag extents %lu: used pages %lu, full frag extents %lu\n",
- n_free_frag, frag_n_used, n_full_frag);
-
- printf("number of segments %lu, first seg id not used %lu %lu\n",
- n_segs, seg_id_high, seg_id_low);
-
- /* Print segments */
- node_addr = flst_get_first(header + FSP_SEGS, &mtr);
-
- mtr_commit(&mtr);
-
- while (!fil_addr_is_null(node_addr)) {
- mtr_start(&mtr);
- mtr_x_lock(&fsp_latch, &mtr);
-
- seg_header = fut_get_ptr_x_lock(space, node_addr,
- &mtr) - FSEG_FLST_NODE;
- fseg_print_low(seg_header, &mtr);
-
- node_addr = flst_get_next_addr(seg_header + FSEG_FLST_NODE,
- &mtr);
- mtr_commit(&mtr);
- }
-
- mtr_commit(&mtr2);
-}
-
diff --git a/innobase/fsp/ts/del.c b/innobase/fsp/ts/del.c
deleted file mode 100644
index 885797bdc76..00000000000
--- a/innobase/fsp/ts/del.c
+++ /dev/null
@@ -1,891 +0,0 @@
-/************************************************************************
-The test module for the file system and buffer manager
-
-(c) 1995 Innobase Oy
-
-Created 11/16/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "string.h"
-
-#include "os0thread.h"
-#include "os0file.h"
-#include "ut0ut.h"
-#include "ut0byte.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "fil0fil.h"
-#include "..\buf0buf.h"
-#include "..\buf0buf.h1"
-#include "..\buf0buf.h2"
-#include "..\buf0flu.h"
-#include "..\buf0lru.h"
-#include "mtr0buf.h"
-#include "mtr0log.h"
-#include "fsp0fsp.h"
-#include "log0log.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[5];
-
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/************************************************************************
-Creates the test database files. */
-
-void
-create_db(void)
-/*===========*/
-{
- ulint i;
- buf_block_t* block;
- byte* frame;
- ulint j;
- ulint tm, oldtm;
- mtr_t mtr;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1; i++) {
- for (j = 0; j < 4096; j++) {
- mtr_start(&mtr);
- if (j == 0) {
- fsp_header_init(i, 4096, &mtr);
-
- block = mtr_page_get(i, j, NULL, &mtr);
- } else {
- block = mtr_page_create(i, j, &mtr);
- }
-
- frame = buf_block_get_frame(block);
-
- mtr_page_x_lock(block, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_PREV,
- j - 1, MLOG_4BYTES, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_NEXT,
- j + 1, MLOG_4BYTES, &mtr);
-
- mlog_write_ulint(frame + FIL_PAGE_OFFSET,
- j, MLOG_4BYTES, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- /* Flush the pool of dirty pages by reading low-offset pages */
- for (i = 0; i < 1000; i++) {
-
- mtr_start(&mtr);
- block = mtr_page_get(0, i, NULL, &mtr);
-
- frame = buf_block_get_frame(block);
-
- mtr_page_s_lock(block, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET, MLOG_4BYTES,
- &mtr) == i);
-
- mtr_commit(&mtr);
- }
-
- os_thread_sleep(1000000);
-
- ut_a(buf_all_freed());
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- strcpy(name, "j:\\tsfile1");
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < 4; i++) {
-
- name[9] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_set_size(files[i], 4096 * 8192, 0);
- ut_a(ret);
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create("noname", k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, 4096, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i, j, k;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- buf_flush_batch(BUF_FLUSH_LIST, 1000);
-
- os_thread_sleep(1000000);
-
- buf_all_freed();
-
- oldtm = ut_clock();
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < 1; i++) {
- for (j = 0; j < 409; j++) {
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test2(void)
-/*=======*/
-{
- ulint i, j, k, rnd;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 100; k++) {
- rnd += 23651;
- rnd = rnd % 4096;
-
- i = rnd / 4096;
- j = rnd % 2048;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf("Wall clock time for random read %lu milliseconds\n",
- tm - oldtm);
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test4(void)
-/*=======*/
-{
- ulint i, j, k, rnd;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- /* Flush the pool of high-offset pages */
- for (i = 0; i < 1000; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == i);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
-
- printf("Test starts\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 400; k++) {
-
- rnd += 4357;
-
- i = 0;
- j = 1001 + rnd % 3000;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random no read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-
- /* Flush the pool of high-offset pages */
- for (i = 0; i < 1000; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == i);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
-
- printf("Test starts\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 400; k++) {
-
- rnd += 4357;
-
- i = 0;
- j = 1001 + rnd % 400;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block);
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- buf_page_s_unlock(block);
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-
-}
-
-/************************************************************************
-Tests speed of CPU algorithms. */
-
-void
-test3(void)
-/*=======*/
-{
- ulint i, j;
- buf_block_t* block;
- ulint tm, oldtm;
-
- for (i = 0; i < 400; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- buf_page_release(block);
- }
-
- os_thread_sleep(2000000);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 500; j++) {
- for (i = 0; i < 200; i++) {
-
- block = buf_page_get(0, i, NULL);
-
-/*
- buf_page_s_lock(block);
-
- buf_page_s_unlock(block);
-*/
-
- buf_page_release(block);
-
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu page get-release %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 500; j++) {
- for (i = 0; i < 200; i++) {
-
- buf_page_get(0, i, NULL);
-/*
- buf_page_s_lock(block);
-
- buf_page_s_unlock(block);
-*/
- buf_page_release(block);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu block get-release %lu milliseconds\n",
- i * j, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000; i++) {
- block = buf_block_alloc();
- buf_block_free(block);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu block alloc-free %lu milliseconds\n",
- i, tm - oldtm);
-
- ha_print_info(buf_pool->page_hash);
-}
-
-/************************************************************************
-Frees the spaces in the file system. */
-
-void
-free_system(void)
-/*=============*/
-{
- ulint i;
-
- for (i = 0; i < 1; i++) {
- fil_space_free(i);
- }
-}
-
-/************************************************************************
-Test for file space management. */
-
-void
-test5(void)
-/*=======*/
-{
- mtr_t mtr;
- ulint seg_page;
- ulint new_page;
- ulint seg_page2;
- ulint new_page2;
- buf_block_t* block;
- bool finished;
- ulint i;
- ulint reserved;
- ulint used;
- ulint tm, oldtm;
-
- os_thread_sleep(1000000);
-
- buf_validate();
-
- buf_print();
-
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, 555, &mtr);
-
- mtr_commit(&mtr);
-
- os_thread_sleep(1000000);
- buf_validate();
- printf("Segment created: header page %lu\n", seg_page);
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- new_page = fseg_alloc_free_page(buf_block_get_frame(block) + 1000,
- 2, FSP_UP, &mtr);
-
- mtr_commit(&mtr);
-
- buf_validate();
- buf_print();
- printf("Segment page allocated %lu\n", new_page);
-
- finished = FALSE;
-
- while (!finished) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
- }
-
- /***********************************************/
- os_thread_sleep(1000000);
- buf_validate();
- buf_print();
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, 557, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page == 1);
-
- printf("Segment created: header page %lu\n", seg_page);
-
- new_page = seg_page;
- for (i = 0; i < 1023; i++) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
- if (i < FSP_EXTENT_SIZE - 1) {
- ut_a(new_page == 2 + i);
- } else {
- ut_a(new_page == i + FSP_EXTENT_SIZE + 1);
- }
-
- printf("%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
- }
-
- buf_print();
- buf_validate();
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- mtr_page_s_lock(block, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- ut_a(used == 1024);
- ut_a(reserved >= 1024);
-
- printf("Pages used in segment %lu reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- finished = FALSE;
-
- while (!finished) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
- }
-
- buf_print();
- buf_validate();
-
- /***********************************************/
-
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, 557, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page == 1);
-
- mtr_start(&mtr);
-
- seg_page2 = fseg_create(0, 0, 1000, 558, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page2 == 2);
-
- new_page = seg_page;
- new_page2 = seg_page2;
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
-
- printf("1:%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
-
- printf("1:%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page2, NULL, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page2 + 1, FSP_UP, &mtr);
-
- printf("2:%lu %lu; ", i, new_page2);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
-
- if (new_page2 == FIL_NULL) {
- break;
- }
- }
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- mtr_page_s_lock(block, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- printf("Pages used in segment 1 %lu, reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page2, NULL, &mtr);
-
- mtr_page_s_lock(block, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- printf("Pages used in segment 2 %lu, reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- block = mtr_page_get(0, seg_page2, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
- mtr_start(&mtr);
-
- seg_page2 = fseg_create(0, 0, 1000, 558, &mtr);
-
- mtr_commit(&mtr);
-
- i = 0;
- for (;;) {
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page2, NULL, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- 557, FSP_DOWN, &mtr);
-
- printf("%lu %lu; ", i, new_page2);
- mtr_commit(&mtr);
-
- if (new_page2 == FIL_NULL) {
- break;
- }
- i++;
- }
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page2, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
-
- /***************************************/
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000; i++) {
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, 555, &mtr);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- new_page = fseg_alloc_free_page(buf_block_get_frame(block) + 1000,
- 2, FSP_UP, &mtr);
-
- mtr_commit(&mtr);
-
- finished = FALSE;
-
- while (!finished) {
-
- mtr_start(&mtr);
-
- block = mtr_page_get(0, seg_page, NULL, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu seg crea+free %lu millisecs\n",
- i, tm - oldtm);
-
- buf_validate();
-
- buf_flush_batch(BUF_FLUSH_LIST, 500);
-
- os_thread_sleep(1000000);
-
- buf_all_freed();
-}
-
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint n;
-
- oldtm = ut_clock();
-
- os_aio_init(160, 5);
- sync_init();
- mem_init();
- fil_init(26); /* Allow 25 open files at a time */
- buf_pool_init(1000, 1000);
- log_init();
-
- buf_validate();
-
- ut_a(fil_validate());
-
- create_files();
-
- create_db();
-
- buf_validate();
-
- test5();
-/*
- test1();
-
- test3();
-
- test4();
-
- test2();
-*/
- buf_validate();
-
- n = buf_flush_batch(BUF_FLUSH_LIST, 500);
-
- os_thread_sleep(1000000);
-
- buf_all_freed();
-
- free_system();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/fsp/ts/makefile b/innobase/fsp/ts/makefile
deleted file mode 100644
index cd56e791b31..00000000000
--- a/innobase/fsp/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsfsp: ..\fsp.lib tsfsp.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsfsp.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/fsp/ts/tsfsp.c b/innobase/fsp/ts/tsfsp.c
deleted file mode 100644
index ba6a35ebc69..00000000000
--- a/innobase/fsp/ts/tsfsp.c
+++ /dev/null
@@ -1,1234 +0,0 @@
-/************************************************************************
-The test module for file space management
-
-(c) 1996 Innobase Oy
-
-Created 1/4/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "string.h"
-
-#include "os0thread.h"
-#include "os0file.h"
-#include "ut0ut.h"
-#include "ut0byte.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "fil0fil.h"
-#include "mach0data.h"
-#include "buf0buf.h"
-#include "buf0flu.h"
-#include "log0log.h"
-#include "fut0lst.h"
-#include "fut0fut.h"
-#include "mtr0mtr.h"
-#include "mtr0log.h"
-#include "..\fsp0fsp.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-ulint page_nos[10000];
-
-#define N_SPACES 1
-#define N_FILES 2
-#define FILE_SIZE 1000 /* must be > 512 */
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Creates the test database files. */
-
-void
-create_db(void)
-/*===========*/
-{
- ulint i;
- buf_block_t* block;
- byte* frame;
- ulint j;
- ulint tm, oldtm;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("Write database pages\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < N_SPACES; i++) {
- for (j = 0; j < FILE_SIZE * N_FILES; j++) {
- mtr_start(&mtr);
-
- block = buf_page_create(i, j, &mtr);
-
- frame = buf_block_get_frame(block);
-
- buf_page_x_lock(block, &mtr);
-
- if (j > FILE_SIZE * N_FILES
- - 64 * 2 - 1) {
- mlog_write_ulint(frame + FIL_PAGE_PREV, j - 5,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_NEXT, j - 7,
- MLOG_4BYTES, &mtr);
- } else {
- mlog_write_ulint(frame + FIL_PAGE_PREV, j - 1,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_NEXT, j + 1,
- MLOG_4BYTES, &mtr);
- }
-
- mlog_write_ulint(frame + FIL_PAGE_OFFSET, j,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + FIL_PAGE_SPACE, i,
- MLOG_4BYTES, &mtr);
- mlog_write_ulint(frame + COUNTER_OFFSET, 0,
- MLOG_4BYTES, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i, j, k;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
- mtr_t mtr;
-
- printf("--------------------------------------------------------\n");
- printf("TEST 1. Read linearly database files\n");
-
- oldtm = ut_clock();
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < N_SPACES; i++) {
- for (j = 0; j < N_FILES * FILE_SIZE; j++) {
- mtr_start(&mtr);
-
- block = buf_page_get(i, j, &mtr);
-
- frame = buf_block_get_frame(block);
-
- buf_page_s_lock(block, &mtr);
-
- ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET,
- MLOG_4BYTES, &mtr)
- == j);
- ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE,
- MLOG_4BYTES, &mtr)
- == i);
-
- mtr_commit(&mtr);
- }
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu pages %lu milliseconds\n",
- k * i * j, tm - oldtm);
- buf_validate();
-}
-
-/************************************************************************
-Test for file-based lists. */
-
-void
-test2(void)
-/*=======*/
-{
- mtr_t mtr;
- buf_frame_t* frame;
- buf_block_t* block;
- ulint i;
- flst_base_node_t* base1;
- fil_addr_t base_addr1;
- flst_base_node_t* base2;
- fil_addr_t base_addr2;
- flst_node_t* node;
- fil_addr_t node_addr;
- flst_node_t* node2;
- fil_addr_t node_addr2;
- flst_node_t* node3;
- fil_addr_t node_addr3;
-
-#define BPAGE 10
-#define BASE1 300
-#define BASE2 500
-#define NODE1 800
-#define NODE2 900
-#define NODE3 1000
-#define NODE4 1100
-#define INDEX 30
-
- buf_validate();
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, BPAGE, &mtr);
- frame = buf_block_get_frame(block);
-
- flst_init(frame + BASE1, &mtr);
- flst_init(frame + BASE2, &mtr);
-
- mtr_commit(&mtr);
-
- printf("-------------------------------------------\n");
- printf("TEST 2. Test of file-based two-way lists \n");
-
- base_addr1.page = BPAGE;
- base_addr1.boffset = BASE1;
-
- base_addr2.page = BPAGE;
- base_addr2.boffset = BASE2;
-
- printf(
- "Add 1000 elements in list1 in reversed order and in list2 in order\n");
- for (i = 0; i < 1000; i++) {
- mtr_start(&mtr);
-
- base1 = fut_get_ptr(0, base_addr1, &mtr);
- base2 = fut_get_ptr(0, base_addr2, &mtr);
-
- block = buf_page_get(0, i, &mtr);
- frame = buf_block_get_frame(block);
-
- buf_page_x_lock(block, &mtr);
-
- flst_add_first(base1, frame + NODE1, &mtr);
- mlog_write_ulint(frame + NODE1 + INDEX, i,
- MLOG_4BYTES, &mtr);
- flst_add_last(base2, frame + NODE2, &mtr);
- mlog_write_ulint(frame + NODE2 + INDEX, i,
- MLOG_4BYTES, &mtr);
-
- mtr_commit(&mtr);
- }
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr(0, base_addr1, &mtr);
- base2 = fut_get_ptr(0, base_addr2, &mtr);
-
- flst_validate(base1, &mtr);
- flst_validate(base2, &mtr);
-
- flst_print(base1, &mtr);
- flst_print(base2, &mtr);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_s_lock(0, base_addr1, &mtr);
-
- node_addr = flst_get_first(base1, &mtr);
-
- mtr_commit(&mtr);
-
- printf("Check order of elements in list1\n");
- for (i = 0; i < 1000; i++) {
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- ut_a(mtr_read_ulint(node + INDEX, MLOG_4BYTES, &mtr) ==
- 999 - i);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- ut_a(fil_addr_is_null(node_addr));
-
- mtr_start(&mtr);
-
- base2 = fut_get_ptr_s_lock(0, base_addr2, &mtr);
-
- node_addr = flst_get_first(base2, &mtr);
-
- mtr_commit(&mtr);
-
- printf("Check order of elements in list2\n");
- for (i = 0; i < 1000; i++) {
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- ut_a(mtr_read_ulint(node + INDEX, MLOG_4BYTES, &mtr)
- == i);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- ut_a(fil_addr_is_null(node_addr));
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr(0, base_addr1, &mtr);
- base2 = fut_get_ptr(0, base_addr2, &mtr);
-
- flst_validate(base1, &mtr);
- flst_validate(base2, &mtr);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_s_lock(0, base_addr1, &mtr);
-
- node_addr = flst_get_first(base1, &mtr);
-
- mtr_commit(&mtr);
-
- for (i = 0; i < 500; i++) {
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- printf("Add 200 elements to the middle of list1\n");
- for (i = 0; i < 100; i++) {
- mtr_start(&mtr);
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- node_addr2.page = i;
- node_addr2.boffset = NODE3;
- node2 = fut_get_ptr_x_lock(0, node_addr2, &mtr);
-
- node_addr3.page = i;
- node_addr3.boffset = NODE4;
- node3 = fut_get_ptr_x_lock(0, node_addr3, &mtr);
-
- mlog_write_ulint(node2 + INDEX, 99 - i, MLOG_4BYTES, &mtr);
-
- block = buf_page_get(0, BPAGE, &mtr);
- frame = buf_block_get_frame(block);
-
- base1 = frame + BASE1;
-
- flst_insert_after(base1, node, node2, &mtr);
- flst_insert_before(base1, node3, node, &mtr);
-
- if (i % 17 == 0) {
- flst_validate(base1, &mtr);
- }
- mtr_commit(&mtr);
- }
-
- printf("Check that 100 of the inserted nodes are in order\n");
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
-
- for (i = 0; i < 100; i++) {
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- ut_a(mtr_read_ulint(node + INDEX, MLOG_4BYTES, &mtr)
- == i);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- printf("Remove 899 elements from the middle of list1\n");
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_x_lock(0, base_addr1, &mtr);
-
- node_addr = flst_get_first(base1, &mtr);
-
- flst_print(base1, &mtr);
- mtr_commit(&mtr);
-
- for (i = 0; i < 300; i++) {
- mtr_start(&mtr);
- ut_a(!fil_addr_is_null(node_addr));
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- node_addr = flst_get_next_addr(node, &mtr);
- mtr_commit(&mtr);
- }
-
- for (i = 0; i < 899; i++) {
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_x_lock(0, base_addr1, &mtr);
-
- node_addr = flst_get_first(base1, &mtr);
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- node_addr = flst_get_next_addr(node, &mtr);
-
- ut_a(!fil_addr_is_null(node_addr));
-
- node2 = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- flst_remove(base1, node2, &mtr);
-
- if (i % 17 == 0) {
- flst_validate(base1, &mtr);
- }
-
- mtr_commit(&mtr);
- }
-
- printf("Remove 301 elements from the start of list1\n");
- for (i = 0; i < 301; i++) {
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_x_lock(0, base_addr1, &mtr);
-
- node_addr = flst_get_first(base1, &mtr);
-
- node = fut_get_ptr_x_lock(0, node_addr, &mtr);
-
- flst_remove(base1, node, &mtr);
-
- if (i % 17 == 0) {
- flst_validate(base1, &mtr);
- }
-
- mtr_commit(&mtr);
- }
-
- mtr_start(&mtr);
-
- base1 = fut_get_ptr_x_lock(0, base_addr1, &mtr);
-
- ut_a(flst_get_len(base1, &mtr) == 0);
- flst_print(base1, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Inits space header of space 0. */
-
-void
-init_space(void)
-/*============*/
-{
- mtr_t mtr;
-
- printf("Init space header\n");
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Test for file space management. */
-
-void
-test5(void)
-/*=======*/
-{
- mtr_t mtr;
- ulint seg_page;
- ulint new_page;
- ulint seg_page2;
- ulint new_page2;
- ulint seg_page3;
- buf_block_t* block;
- bool finished;
- ulint i;
- ulint reserved;
- ulint used;
- ulint tm, oldtm;
-
- buf_validate();
-
- fsp_validate(0);
- fsp_print(0);
-
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, &mtr);
-
- mtr_commit(&mtr);
-
- fsp_validate(0);
-
- buf_validate();
- printf("Segment created: header page %lu, byte offset %lu\n",
- seg_page, 1000);
- fsp_print(0);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- new_page = fseg_alloc_free_page(buf_block_get_frame(block) + 1000,
- 2, FSP_UP, &mtr);
-
- mtr_commit(&mtr);
-
- fsp_print(0);
- fsp_validate(0);
- buf_validate();
- printf("Segment page allocated %lu\n", new_page);
-
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- fseg_free_page(buf_block_get_frame(block) + 1000,
- 0, new_page, &mtr);
-
- mtr_commit(&mtr);
-
- fsp_validate(0);
- printf("Segment page freed %lu\n", new_page);
-
- finished = FALSE;
-
- while (!finished) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
- }
- fsp_validate(0);
-
- /***********************************************/
- buf_validate();
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page == 2);
-
- printf("Segment created: header page %lu\n", seg_page);
-
- new_page = seg_page;
- for (i = 0; i < 511; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
- printf("%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
-
- if (i % 117 == 0) {
- fsp_validate(0);
- }
- }
-
- fsp_validate(0);
- buf_validate();
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- ut_a(used == 512);
- ut_a(reserved >= 512);
-
- printf("Pages used in segment %lu reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- finished = FALSE;
-
- while (!finished) {
- i++;
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (i % 117 == 0) {
- fsp_validate(0);
- }
- }
-
- fsp_validate(0);
- buf_validate();
-
- /***********************************************/
-
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page == 2);
-
- mtr_start(&mtr);
-
- seg_page2 = fseg_create(0, 0, 1000, &mtr);
-
- mtr_commit(&mtr);
-
- ut_a(seg_page2 == 3);
-
- new_page = seg_page;
- new_page2 = seg_page2;
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
-
- printf("1:%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- new_page = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page + 1, FSP_UP, &mtr);
-
- printf("1:%lu %lu; ", i, new_page);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
-
- i++;
- if (i % 217 == 0) {
- fsp_validate(0);
- }
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page2, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page2 + 1, FSP_DOWN, &mtr);
-
- printf("2:%lu %lu; ", i, new_page2);
- if (i % 10 == 0) {
- printf("\n");
- }
-
- mtr_commit(&mtr);
-
- if (new_page2 == FIL_NULL) {
- break;
- }
- }
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- printf("Pages used in segment 1 %lu, reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
- fsp_validate(0);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page2, &mtr);
-
- reserved = fseg_n_reserved_pages(buf_block_get_frame(block) + 1000,
- &used, &mtr);
-
- printf("Pages used in segment 2 %lu, reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- fsp_print(0);
-
- for (;;) {
-
- i++;
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- block = buf_page_get(0, seg_page2, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
-
- if (i % 117 == 0) {
- fsp_validate(0);
- }
- }
-
- fsp_validate(0);
-
- mtr_start(&mtr);
-
- seg_page3 = fseg_create(0, 0, 1000, &mtr);
- page_nos[0] = seg_page3;
- new_page2 = seg_page3;
-
- mtr_commit(&mtr);
-
- for (i = 1; i < 250; i++) {
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page3, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page2 + 1, FSP_UP, &mtr);
- page_nos[i] = new_page2;
-
- mtr_commit(&mtr);
- }
-
- /*************************************************/
-
- mtr_start(&mtr);
-
- fseg_create(0, seg_page3, 1500, &mtr);
-
- mtr_commit(&mtr);
-
- for (i = 0; i < 250; i++) {
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page3, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1500,
- new_page2 + 1, FSP_UP, &mtr);
- page_nos[i] = new_page2;
-
- mtr_commit(&mtr);
- }
-
- printf("---------------------------------------------------------\n");
- printf("TEST 5A13. Test free_step.\n");
-
- fseg_free(0, seg_page3, 1500);
-
- printf("---------------------------------------------------------\n");
- printf("TEST 5A3. Test free_step.\n");
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page3, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
- /***************************************************/
-
- mtr_start(&mtr);
-
- seg_page2 = fseg_create(0, 0, 1000, &mtr);
- page_nos[0] = seg_page2;
- new_page2 = seg_page2;
-
- mtr_commit(&mtr);
-
- i = 1;
- for (;;) {
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page2, &mtr);
-
- new_page2 = fseg_alloc_free_page(
- buf_block_get_frame(block) + 1000,
- new_page2 + 1, FSP_UP, &mtr);
- page_nos[i] = new_page2;
-/*
- printf("%lu %lu; ", i, new_page2);
-*/
- mtr_commit(&mtr);
-
- if (new_page2 == FIL_NULL) {
- break;
- }
- i++;
- }
-
- printf("---------------------------------------------------------\n");
- printf("TEST 5D. Test free_step.\n");
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
- for (;;) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page2, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
-
- if (finished) {
- break;
- }
- }
-
-
- /***************************************/
-
- oldtm = ut_clock();
-
- fsp_validate(0);
-
- for (i = 0; i < 10; i++) {
- mtr_start(&mtr);
-
- seg_page = fseg_create(0, 0, 1000, &mtr);
-
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- new_page = fseg_alloc_free_page(buf_block_get_frame(block) + 1000,
- 3, FSP_UP, &mtr);
-
- mtr_commit(&mtr);
-
- finished = FALSE;
-
- while (!finished) {
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, seg_page, &mtr);
-
- finished = fseg_free_step(
- buf_block_get_frame(block) + 1000, &mtr);
-
- mtr_commit(&mtr);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu seg crea+free %lu millisecs\n",
- i, tm - oldtm);
-
- buf_validate();
- fsp_validate(0);
- fsp_print(0);
-
- buf_flush_batch(BUF_FLUSH_LIST, 2000);
- os_thread_sleep(3000000);
-
-/* buf_print(); */
- buf_all_freed();
-}
-
-/************************************************************************
-Random test thread function. */
-
-ulint
-random_thread(
-/*===========*/
- void* arg)
-{
- ulint n;
- ulint i, j, t, p, sp, d, b;
- ulint s;
- ulint arr[FILE_SIZE * N_FILES];
- ulint seg_page;
- fseg_header_t* seg_header;
- fil_addr_t seg_addr;
- byte dir;
- ulint k;
- mtr_t mtr;
- bool finished;
- ulint used;
- ulint reserved;
-
- n = *((ulint*)arg);
- n = os_thread_get_curr_id();
-
- printf("Random test thread %lu starts\n", n);
-
- for (i = 0; i < 30; i++) {
- t = ut_rnd_gen_ulint() % 10;
- s = ut_rnd_gen_ulint() % FILE_SIZE * N_FILES;
- p = 0;
- sp = ut_rnd_gen_ulint() % N_SPACES;
- d = ut_rnd_gen_ulint() % 3;
- b = ut_rnd_gen_ulint() % 3;
-
- if (i % 10 == 0) {
- printf("Thr %lu round %lu starts\n", n, i);
- }
- ut_a(buf_validate());
-
- if (t != 0) {
- do {
- mtr_start(&mtr);
- seg_page = fseg_create(sp, p, 1000, &mtr);
- mtr_commit(&mtr);
- } while (seg_page == FIL_NULL);
-
- seg_addr.page = seg_page;
- seg_addr.boffset = 1000;
-
- k = 0;
- j = 0;
- while (j < s) {
- j++;
- if (d == 0) {
- dir = FSP_DOWN;
- } else if (d == 1) {
- dir = FSP_NO_DIR;
- } else {
- dir = FSP_UP;
- }
- mtr_start(&mtr);
- seg_header = fut_get_ptr(sp, seg_addr, &mtr);
-
- if (b != 0) {
- arr[k] = fseg_alloc_free_page(seg_header,
- p, dir, &mtr);
- k++;
- } else if (k > 0) {
- fseg_free_page(seg_header, sp, arr[k - 1],
- &mtr);
- k--;
- }
-
- mtr_commit(&mtr);
- if ((k > 0) && (arr[k - 1] == FIL_NULL)) {
- k--;
- break;
- }
- if (p > 0) {
- p = arr[k - 1] + dir - 1;
- }
- if (j % 577 == 0) {
- if (k > 0) {
- p = arr[k / 2] + 1;
- } else {
- p = 0;
- }
- d = ut_rnd_gen_ulint() % 3;
- b = ut_rnd_gen_ulint() % 3;
- }
- }
- finished = FALSE;
- mtr_start(&mtr);
-
- seg_header = fut_get_ptr(sp, seg_addr, &mtr);
-
- reserved = fseg_n_reserved_pages(seg_header,
- &used, &mtr);
-
- printf("Pages used in segment %lu reserved by segment %lu \n",
- used, reserved);
-
- mtr_commit(&mtr);
-
- printf("Thread %lu starts releasing seg %lu size %lu\n", n,
- seg_addr.page, k);
- while (!finished) {
- mtr_start(&mtr);
- seg_header = fut_get_ptr(sp, seg_addr, &mtr);
-
- finished = fseg_free_step(seg_header, &mtr);
- mtr_commit(&mtr);
- }
- } else {
- fsp_print(sp);
- printf("Thread %lu validates fsp\n", n);
- fsp_validate(sp);
- buf_validate();
- }
- } /* for i */
- printf("\nRandom test thread %lu exits\n", os_thread_get_curr_id());
- return(0);
-}
-
-/*************************************************************************
-Performs random operations on the buffer with several threads. */
-
-void
-test6(void)
-/*=======*/
-{
- ulint i;
- os_thread_t thr[N_THREADS + 1];
- os_thread_id_t id[N_THREADS + 1];
- ulint n[N_THREADS + 1];
-
- printf("--------------------------------------------------------\n");
- printf("TEST 6. Random multi-thread test on the buffer \n");
-
- incs = 0;
- mutex_create(&incs_mutex);
-
- for (i = 0; i < N_THREADS; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(random_thread, n + i, id + i);
- }
-
- for (i = 0; i < N_THREADS; i++) {
- os_thread_wait(thr[i]);
- }
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- os_aio_init(160, 5);
- sync_init();
- mem_init();
- fil_init(26); /* Allow 25 open files at a time */
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- log_init();
- fsp_init();
-
- buf_validate();
-
- ut_a(fil_validate());
-
- create_files();
-
- create_db();
-
- buf_validate();
-
-/* test1(); */
-/* buf_validate(); */
-/*
- test2();
- buf_validate();
-*/
- init_space();
-
- test5();
- buf_validate();
-
-/* test6(); */
-
- buf_flush_batch(BUF_FLUSH_LIST, POOL_SIZE + 1);
-/* buf_print(); */
- buf_validate();
-
- os_thread_sleep(1000000);
-
-/* buf_print(); */
- buf_all_freed();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/ha/ha0ha.c b/innobase/ha/ha0ha.c
index 3f36879e80b..5e807406ce0 100644
--- a/innobase/ha/ha0ha.c
+++ b/innobase/ha/ha0ha.c
@@ -66,33 +66,6 @@ ha_create(
}
/*****************************************************************
-Checks that a hash table node is in the chain. */
-
-ibool
-ha_node_in_chain(
-/*=============*/
- /* out: TRUE if in chain */
- hash_cell_t* cell, /* in: hash table cell */
- ha_node_t* node) /* in: external chain node */
-{
- ha_node_t* node2;
-
- node2 = cell->node;
-
- while (node2 != NULL) {
-
- if (node2 == node) {
-
- return(TRUE);
- }
-
- node2 = node2->next;
- }
-
- return(FALSE);
-}
-
-/*****************************************************************
Inserts an entry into a hash table. If an entry with the same fold number
is found, its node is updated to point to the new data, and no new node
is inserted. */
@@ -116,8 +89,9 @@ ha_insert_for_fold(
ulint hash;
ut_ad(table && data);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
-
+#endif /* UNIV_SYNC_DEBUG */
hash = hash_calc_hash(fold, table);
cell = hash_get_nth_cell(table, hash);
@@ -213,8 +187,9 @@ ha_delete(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
-
+#endif /* UNIV_SYNC_DEBUG */
node = ha_search_with_data(table, fold, data);
ut_a(node);
@@ -264,8 +239,9 @@ ha_remove_all_nodes_to_page(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
-
+#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
while (node) {
diff --git a/innobase/ha/hash0hash.c b/innobase/ha/hash0hash.c
index facdea66198..372104e54b3 100644
--- a/innobase/ha/hash0hash.c
+++ b/innobase/ha/hash0hash.c
@@ -22,6 +22,7 @@ hash_mutex_enter(
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
mutex_enter(hash_get_mutex(table, fold));
}
@@ -34,41 +35,10 @@ hash_mutex_exit(
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
mutex_exit(hash_get_mutex(table, fold));
}
-/****************************************************************
-Reserves all the mutexes of a hash table, in an ascending order. */
-
-void
-hash_mutex_enter_all(
-/*=================*/
- hash_table_t* table) /* in: hash table */
-{
- ulint i;
-
- for (i = 0; i < table->n_mutexes; i++) {
-
- mutex_enter(table->mutexes + i);
- }
-}
-
-/****************************************************************
-Releases all the mutexes of a hash table. */
-
-void
-hash_mutex_exit_all(
-/*================*/
- hash_table_t* table) /* in: hash table */
-{
- ulint i;
-
- for (i = 0; i < table->n_mutexes; i++) {
-
- mutex_exit(table->mutexes + i);
- }
-}
-
/*****************************************************************
Creates a hash table with >= n array cells. The actual number of cells is
chosen to be a prime number slightly bigger than n. */
@@ -98,7 +68,9 @@ hash_create(
table->mutexes = NULL;
table->heaps = NULL;
table->heap = NULL;
+#ifdef UNIV_DEBUG
table->magic_n = HASH_TABLE_MAGIC_N;
+#endif /* UNIV_DEBUG */
/* Initialize the cell array */
@@ -119,6 +91,7 @@ hash_table_free(
/*============*/
hash_table_t* table) /* in, own: hash table */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_a(table->mutexes == NULL);
ut_free(table->array);
@@ -140,6 +113,7 @@ hash_create_mutexes(
ulint i;
ut_a(n_mutexes == ut_2_power_up(n_mutexes));
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
diff --git a/innobase/ha/ts/makefile b/innobase/ha/ts/makefile
deleted file mode 100644
index aea21f11141..00000000000
--- a/innobase/ha/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsha: ..\ha.lib tsha.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsha.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/ha/ts/tsha.c b/innobase/ha/ts/tsha.c
deleted file mode 100644
index fd9a2e12f6e..00000000000
--- a/innobase/ha/ts/tsha.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/************************************************************************
-The test module for hash table
-
-(c) 1994, 1995 Innobase Oy
-
-Created 1/25/1994 Heikki Tuuri
-*************************************************************************/
-
-#include "ut0ut.h"
-#include "ha0ha.h"
-#include "mem0mem.h"
-#include "sync0sync.h"
-
-ulint ulint_array[200000];
-
-void
-test1(void)
-{
- hash_table_t* table1;
- ulint i;
- ulint n313 = 313;
- ulint n414 = 414;
-
- printf("------------------------------------------------\n");
- printf("TEST 1. BASIC TEST\n");
-
- table1 = ha_create(50000);
-
- ha_insert_for_fold(table1, 313, &n313);
-
- ha_insert_for_fold(table1, 313, &n414);
-
- ut_a(ha_validate(table1));
-
- ha_delete(table1, 313, &n313);
- ha_delete(table1, 313, &n414);
-
- ut_a(ha_validate(table1));
-
- printf("------------------------------------------------\n");
- printf("TEST 2. TEST OF MASSIVE INSERTS AND DELETES\n");
-
- table1 = ha_create(10000);
-
- for (i = 0; i < 200000; i++) {
- ulint_array[i] = i;
- }
-
- for (i = 0; i < 50000; i++) {
- ha_insert_for_fold(table1, i * 7, ulint_array + i);
- }
-
- ut_a(ha_validate(table1));
-
- for (i = 0; i < 50000; i++) {
- ha_delete(table1, i * 7, ulint_array + i);
- }
-
- ut_a(ha_validate(table1));
-}
-
-void
-test2(void)
-{
- hash_table_t* table1;
- ulint i;
- ulint oldtm, tm;
- ha_node_t* node;
-
- printf("------------------------------------------------\n");
- printf("TEST 3. SPEED TEST\n");
-
- table1 = ha_create(300000);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200000; i++) {
- ha_insert_for_fold(table1, i * 27877, ulint_array + i);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu inserts %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200000; i++) {
- node = ha_search(table1, i * 27877);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu searches %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 200000; i++) {
- ha_delete(table1, i * 27877, ulint_array + i);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu deletes %lu millisecs\n",
- i, tm - oldtm);
-}
-
-void
-main(void)
-{
- sync_init();
- mem_init(1000000);
-
- test1();
-
- test2();
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c
index 805f08af361..42ca34e7f10 100644
--- a/innobase/ibuf/ibuf0ibuf.c
+++ b/innobase/ibuf/ibuf0ibuf.c
@@ -270,7 +270,9 @@ ibuf_header_page_get(
page = buf_page_get(space, FSP_IBUF_HEADER_PAGE_NO, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_IBUF_HEADER);
+#endif /* UNIV_SYNC_DEBUG */
return(page);
}
@@ -295,7 +297,9 @@ ibuf_tree_root_get(
page = buf_page_get(space, FSP_IBUF_TREE_ROOT_PAGE_NO, RW_X_LATCH,
mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
return(page);
}
@@ -407,7 +411,9 @@ ibuf_data_sizes_update(
{
ulint old_size;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&ibuf_mutex));
+#endif /* UNIV_SYNC_DEBUG */
old_size = data->size;
@@ -489,7 +495,9 @@ ibuf_data_init_for_space(
root = buf_page_get(space, FSP_IBUF_TREE_ROOT_PAGE_NO, RW_X_LATCH,
&mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(root, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
data->size = 0;
data->n_inserts = 0;
@@ -721,7 +729,9 @@ ibuf_bitmap_get_map_page(
page = buf_page_get(space, ibuf_bitmap_page_no_calc(page_no),
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_IBUF_BITMAP);
+#endif /* UNIV_SYNC_DEBUG */
return(page);
}
@@ -1446,7 +1456,9 @@ ibuf_data_enough_free_for_insert(
/* out: TRUE if enough free pages in list */
ibuf_data_t* data) /* in: ibuf data for the space */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&ibuf_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* We want a big margin of free pages, because a B-tree can sometimes
grow in size also if records are deleted from it, as the node pointers
@@ -1472,7 +1484,9 @@ ibuf_data_too_much_free(
/* out: TRUE if enough free pages in list */
ibuf_data_t* data) /* in: ibuf data for the space */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&ibuf_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (data->free_list_len >= 3 + data->size / 2 + 3 * data->height) {
@@ -1532,7 +1546,9 @@ ibuf_add_free_page(
page = buf_page_get(space, page_no, RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE_NEW);
+#endif /* UNIV_SYNC_DEBUG */
ibuf_enter();
@@ -1653,7 +1669,9 @@ ibuf_remove_free_page(
page = buf_page_get(space, page_no, RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
/* Remove the page from the free list and update the ibuf size data */
@@ -1694,14 +1712,16 @@ ibuf_free_excess_pages(
{
ibuf_data_t* ibuf_data;
ulint i;
-
+
if (space != 0) {
fprintf(stderr,
"InnoDB: Error: calling ibuf_free_excess_pages for space %lu\n", (ulong) space);
return;
}
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(fil_space_get_latch(space), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(rw_lock_get_x_lock_count(fil_space_get_latch(space)) == 1);
ut_ad(!ibuf_inside());
@@ -2208,7 +2228,9 @@ ibuf_get_volume_buffered(
prev_page = buf_page_get(0, prev_page_no, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(prev_page, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
rec = page_get_supremum_rec(prev_page);
rec = page_rec_get_prev(rec);
@@ -2269,7 +2291,9 @@ count_later:
next_page = buf_page_get(0, next_page_no, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(next_page, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
rec = page_get_infimum_rec(next_page);
rec = page_rec_get_next(rec);
@@ -3018,7 +3042,9 @@ loop:
IB__FILE__, __LINE__,
&mtr);
ut_a(success);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TREE_NODE);
+#endif /* UNIV_SYNC_DEBUG */
}
/* Position pcur in the insert buffer at the first entry for this
@@ -3261,7 +3287,9 @@ ibuf_validate_low(void)
ibuf_data_t* data;
ulint sum_sizes;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&ibuf_mutex));
+#endif /* UNIV_SYNC_DEBUG */
sum_sizes = 0;
diff --git a/innobase/include/Makefile.am b/innobase/include/Makefile.am
index 8664f6dfc17..2584357e24a 100644
--- a/innobase/include/Makefile.am
+++ b/innobase/include/Makefile.am
@@ -18,21 +18,20 @@
noinst_HEADERS = btr0btr.h btr0btr.ic btr0cur.h btr0cur.ic \
btr0pcur.h btr0pcur.ic btr0sea.h btr0sea.ic btr0types.h \
buf0buf.h buf0buf.ic buf0flu.h buf0flu.ic buf0lru.h \
- buf0lru.ic buf0rea.h buf0types.h com0com.h com0com.ic \
- com0shm.h com0shm.ic data0data.h data0data.ic data0type.h \
+ buf0lru.ic buf0rea.h buf0types.h data0data.h data0data.ic data0type.h \
data0type.ic data0types.h db0err.h dict0boot.h \
dict0boot.ic dict0crea.h dict0crea.ic dict0dict.h \
dict0dict.ic dict0load.h dict0load.ic dict0mem.h \
dict0mem.ic dict0types.h dyn0dyn.h dyn0dyn.ic eval0eval.h \
eval0eval.ic eval0proc.h eval0proc.ic fil0fil.h fsp0fsp.h \
fsp0fsp.ic fut0fut.h fut0fut.ic fut0lst.h fut0lst.ic \
- ha0ha.h ha0ha.ic hash0hash.h hash0hash.ic ib_odbc.h \
+ ha0ha.h ha0ha.ic hash0hash.h hash0hash.ic \
ibuf0ibuf.h ibuf0ibuf.ic ibuf0types.h lock0lock.h \
lock0lock.ic lock0types.h log0log.h log0log.ic log0recv.h \
log0recv.ic mach0data.h mach0data.ic makefilewin.i \
mem0dbg.h mem0dbg.ic mem0mem.h mem0mem.ic mem0pool.h \
mem0pool.ic mtr0log.h mtr0log.ic mtr0mtr.h mtr0mtr.ic \
- mtr0types.h odbc0odbc.h os0file.h os0proc.h os0proc.ic \
+ mtr0types.h os0file.h os0proc.h os0proc.ic \
os0shm.h os0shm.ic os0sync.h os0sync.ic os0thread.h \
os0thread.ic page0cur.h page0cur.ic page0page.h \
page0page.ic page0types.h pars0grm.h pars0opt.h \
@@ -50,7 +49,7 @@ noinst_HEADERS = btr0btr.h btr0btr.ic btr0cur.h btr0cur.ic \
thr0loc.h thr0loc.ic trx0purge.h trx0purge.ic trx0rec.h \
trx0rec.ic trx0roll.h trx0roll.ic trx0rseg.h trx0rseg.ic \
trx0sys.h trx0sys.ic trx0trx.h trx0trx.ic trx0types.h \
- trx0undo.h trx0undo.ic univ.i univold.i univoldmysql.i \
+ trx0undo.h trx0undo.ic univ.i \
usr0sess.h usr0sess.ic usr0types.h ut0byte.h ut0byte.ic \
ut0dbg.h ut0lst.h ut0mem.h ut0mem.ic ut0rnd.h ut0rnd.ic \
ut0sort.h ut0ut.h ut0ut.ic
diff --git a/innobase/include/btr0btr.ic b/innobase/include/btr0btr.ic
index 301a73b3444..b0aa0756307 100644
--- a/innobase/include/btr0btr.ic
+++ b/innobase/include/btr0btr.ic
@@ -45,8 +45,7 @@ btr_page_set_index_id(
dulint id, /* in: index id */
mtr_t* mtr) /* in: mtr */
{
- mlog_write_dulint(page + PAGE_HEADER + PAGE_INDEX_ID, id,
- MLOG_8BYTES, mtr);
+ mlog_write_dulint(page + PAGE_HEADER + PAGE_INDEX_ID, id, mtr);
}
/******************************************************************
diff --git a/innobase/include/btr0cur.h b/innobase/include/btr0cur.h
index 31aecef8104..f1334656d53 100644
--- a/innobase/include/btr0cur.h
+++ b/innobase/include/btr0cur.h
@@ -365,17 +365,6 @@ btr_cur_parse_update_in_place(
byte* ptr, /* in: buffer */
byte* end_ptr,/* in: buffer end */
page_t* page); /* in: page or NULL */
-/***************************************************************
-Parses a redo log record of updating a record, but not in-place. */
-
-byte*
-btr_cur_parse_opt_update(
-/*=====================*/
- /* out: end of log record or NULL */
- byte* ptr, /* in: buffer */
- byte* end_ptr,/* in: buffer end */
- page_t* page, /* in: page or NULL */
- mtr_t* mtr); /* in: mtr or NULL */
/********************************************************************
Parses the redo log record for delete marking or unmarking of a clustered
index record. */
@@ -446,16 +435,6 @@ btr_cur_mark_dtuple_inherited_extern(
ulint n_ext_vec, /* in: number of elements in ext_vec */
upd_t* update); /* in: update vector */
/***********************************************************************
-Marks all extern fields in a record as owned by the record. This function
-should be called if the delete mark of a record is removed: a not delete
-marked record always owns all its extern fields. */
-
-void
-btr_cur_unmark_extern_fields(
-/*=========================*/
- rec_t* rec, /* in: record in a clustered index */
- mtr_t* mtr); /* in: mtr */
-/***********************************************************************
Marks all extern fields in a dtuple as owned by the record. */
void
diff --git a/innobase/include/btr0sea.h b/innobase/include/btr0sea.h
index ee762a12221..ce4140ecf92 100644
--- a/innobase/include/btr0sea.h
+++ b/innobase/include/btr0sea.h
@@ -49,21 +49,6 @@ btr_search_info_update(
dict_index_t* index, /* in: index of the cursor */
btr_cur_t* cursor);/* in: cursor which was just positioned */
/**********************************************************************
-Tries to guess the right search position based on the search pattern info
-of the index. */
-
-ibool
-btr_search_guess_on_pattern(
-/*========================*/
- /* out: TRUE if succeeded */
- dict_index_t* index, /* in: index */
- btr_search_t* info, /* in: index search info */
- dtuple_t* tuple, /* in: logical record */
- ulint mode, /* in: PAGE_CUR_L, ... */
- ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */
- btr_cur_t* cursor, /* out: tree cursor */
- mtr_t* mtr); /* in: mtr */
-/**********************************************************************
Tries to guess the right search position based on the hash search info
of the index. Note that if mode is PAGE_CUR_LE, which is used in inserts,
and the function returns TRUE, then cursor->up_match and cursor->low_match
@@ -140,26 +125,6 @@ btr_search_update_hash_on_delete(
record to delete using btr_cur_search_...,
the record is not yet deleted */
/************************************************************************
-Prints info of the search system. */
-
-void
-btr_search_print_info(void);
-/*=======================*/
-/************************************************************************
-Prints info of searches on an index. */
-
-void
-btr_search_index_print_info(
-/*========================*/
- dict_index_t* index); /* in: index */
-/************************************************************************
-Prints info of searches on a table. */
-
-void
-btr_search_table_print_info(
-/*========================*/
- char* name); /* in: table name */
-/************************************************************************
Validates the search system. */
ibool
@@ -249,7 +214,9 @@ extern rw_lock_t* btr_search_latch_temp;
#define btr_search_latch (*btr_search_latch_temp)
+#ifdef UNIV_SEARCH_PERF_STAT
extern ulint btr_search_n_succ;
+#endif /* UNIV_SEARCH_PERF_STAT */
extern ulint btr_search_n_hash_fail;
/* After change in n_fields or n_bytes in info, this many rounds are waited
diff --git a/innobase/include/btr0sea.ic b/innobase/include/btr0sea.ic
index 63a3a658cf4..8a41042f713 100644
--- a/innobase/include/btr0sea.ic
+++ b/innobase/include/btr0sea.ic
@@ -44,8 +44,10 @@ btr_search_info_update(
{
btr_search_t* info;
- ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED)
- && !rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+ ut_ad(!rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
info = btr_search_get_info(index);
diff --git a/innobase/include/buf0buf.h b/innobase/include/buf0buf.h
index 3f2fd5bbbe0..3cab717546a 100644
--- a/innobase/include/buf0buf.h
+++ b/innobase/include/buf0buf.h
@@ -562,11 +562,11 @@ buf_awe_map_page_to_frame(
we need to map the page should also
add the block to the
awe_LRU_free_mapped list */
+#ifdef UNIV_SYNC_DEBUG
/*************************************************************************
Adds latch level info for the rw-lock protecting the buffer frame. This
should be called in the debug version after a successful latching of a
-page if we know the latching order level of the acquired latch. If
-UNIV_SYNC_DEBUG is not defined, compiles to an empty function. */
+page if we know the latching order level of the acquired latch. */
UNIV_INLINE
void
buf_page_dbg_add_level(
@@ -574,6 +574,7 @@ buf_page_dbg_add_level(
buf_frame_t* frame, /* in: buffer page where we have acquired
a latch */
ulint level); /* in: latching order level */
+#endif /* UNIV_SYNC_DEBUG */
/*************************************************************************
Gets a pointer to the memory frame of a block. */
UNIV_INLINE
diff --git a/innobase/include/buf0buf.ic b/innobase/include/buf0buf.ic
index eb22bae7ff0..cb54785128f 100644
--- a/innobase/include/buf0buf.ic
+++ b/innobase/include/buf0buf.ic
@@ -130,7 +130,9 @@ buf_pool_clock_tic(void)
/*====================*/
/* out: new clock value */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
buf_pool->ulint_clock++;
@@ -221,7 +223,7 @@ buf_block_align(
"InnoDB: how to force recovery.\n",
(long)ptr, (long)frame_zero,
(long)(buf_pool->high_end));
- ut_a(0);
+ ut_error;
}
block = *(buf_pool->blocks_of_frames + (((ulint)(ptr - frame_zero))
@@ -257,7 +259,7 @@ buf_frame_align(
"InnoDB: how to force recovery.\n",
(long)ptr, (long)(buf_pool->frame_zero),
(long)(buf_pool->high_end));
- ut_a(0);
+ ut_error;
}
return(frame);
@@ -447,8 +449,10 @@ buf_frame_modify_clock_inc(
block = buf_block_align(frame);
+#ifdef UNIV_SYNC_DEBUG
ut_ad((mutex_own(&(buf_pool->mutex)) && (block->buf_fix_count == 0))
|| rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
+#endif /*UNIV_SYNC_DEBUG */
UT_DULINT_INC(block->modify_clock);
@@ -466,8 +470,10 @@ buf_block_modify_clock_inc(
/* out: new value */
buf_block_t* block) /* in: block */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad((mutex_own(&(buf_pool->mutex)) && (block->buf_fix_count == 0))
|| rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
+#endif /* UNIV_SYNC_DEBUG */
UT_DULINT_INC(block->modify_clock);
@@ -490,12 +496,15 @@ buf_frame_get_modify_clock(
block = buf_block_align(frame);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
|| rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
+#endif /* UNIV_SYNC_DEBUG */
return(block->modify_clock);
}
+#ifdef UNIV_SYNC_DEBUG
/***********************************************************************
Increments the bufferfix count. */
UNIV_INLINE
@@ -515,7 +524,7 @@ buf_block_buf_fix_inc_debug(
#endif
block->buf_fix_count++;
}
-
+#else /* UNIV_SYNC_DEBUG */
/***********************************************************************
Increments the bufferfix count. */
UNIV_INLINE
@@ -526,7 +535,7 @@ buf_block_buf_fix_inc(
{
block->buf_fix_count++;
}
-
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Returns the control block of a file page, NULL if not found. */
UNIV_INLINE
@@ -541,7 +550,9 @@ buf_page_hash_get(
ulint fold;
ut_ad(buf_pool);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
/* Look for the page in the hash table */
@@ -641,6 +652,7 @@ buf_page_release(
}
}
+#ifdef UNIV_SYNC_DEBUG
/*************************************************************************
Adds latch level info for the rw-lock protecting the buffer frame. This
should be called in the debug version after a successful latching of a
@@ -655,7 +667,6 @@ buf_page_dbg_add_level(
ulint level __attribute__((unused))) /* in: latching order
level */
{
-#ifdef UNIV_SYNC_DEBUG
sync_thread_add_level(&(buf_block_align(frame)->lock), level);
-#endif
}
+#endif /* UNIV_SYNC_DEBUG */
diff --git a/innobase/include/buf0flu.ic b/innobase/include/buf0flu.ic
index e2faf773cab..d6dbdcc0865 100644
--- a/innobase/include/buf0flu.ic
+++ b/innobase/include/buf0flu.ic
@@ -40,8 +40,10 @@ buf_flush_note_modification(
ut_ad(block);
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
ut_ad(mutex_own(&(buf_pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(ut_dulint_cmp(mtr->start_lsn, ut_dulint_zero) != 0);
ut_ad(mtr->modifications);
@@ -76,7 +78,9 @@ buf_flush_recv_note_modification(
ut_ad(block);
ut_ad(block->state == BUF_BLOCK_FILE_PAGE);
ut_ad(block->buf_fix_count > 0);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(block->lock), RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(buf_pool->mutex));
diff --git a/innobase/include/com0com.h b/innobase/include/com0com.h
deleted file mode 100644
index 6f04b6a3f11..00000000000
--- a/innobase/include/com0com.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/******************************************************
-The communication primitives
-
-(c) 1995 Innobase Oy
-
-Created 9/23/1995 Heikki Tuuri
-*******************************************************/
-
-/* This module defines a standard datagram communication
-function interface for use in the database. We assume that
-the communication medium is reliable. */
-
-#ifndef com0com_h
-#define com0com_h
-
-#include "univ.i"
-
-/* The communications endpoint type definition */
-typedef struct com_endpoint_struct com_endpoint_t;
-
-/* Possible endpoint communication types */
-#define COM_SHM 1 /* communication through shared memory */
-
-/* Option numbers for endpoint */
-#define COM_OPT_MAX_DGRAM_SIZE 1
-
-/* Error numbers */
-#define COM_ERR_NOT_SPECIFIED 1
-#define COM_ERR_NOT_BOUND 2
-#define COM_ERR_ALREADY_BOUND 3
-#define COM_ERR_MAX_DATAGRAM_SIZE_NOT_SET 4
-#define COM_ERR_DATA_BUFFER_TOO_SMALL 5
-#define COM_ERR_ADDR_BUFFER_TOO_SMALL 6
-#define COM_ERR_DATA_TOO_LONG 7
-#define COM_ERR_ADDR_TOO_LONG 8
-#define COM_ERR_DGRAM_NOT_DELIVERED 9
-
-/* Maximum allowed address length in bytes */
-#define COM_MAX_ADDR_LEN 100
-
-/*************************************************************************
-Creates a communications endpoint. */
-
-com_endpoint_t*
-com_endpoint_create(
-/*================*/
- /* out, own: communications endpoint, NULL if
- did not succeed */
- ulint type); /* in: communication type of endpoint:
- only COM_SHM supported */
-/*************************************************************************
-Frees a communications endpoint. */
-
-ulint
-com_endpoint_free(
-/*==============*/
- /* out: O if succeed, else error number */
- com_endpoint_t* ep); /* in, own: communications endpoint */
-/*************************************************************************
-Sets an option, like the maximum datagram size for an endpoint.
-The options may vary depending on the endpoint type. */
-
-ulint
-com_endpoint_set_option(
-/*====================*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: endpoint */
- ulint optno, /* in: option number, only
- COM_OPT_MAX_DGRAM_SIZE currently supported */
- byte* optval, /* in: pointer to a buffer containing the
- option value to set */
- ulint optlen);/* in: option value buffer length */
-/*************************************************************************
-Binds a communications endpoint to a specified address. */
-
-ulint
-com_bind(
-/*=====*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len); /* in: name length */
-/*************************************************************************
-Waits for a datagram to arrive at an endpoint. */
-
-ulint
-com_recvfrom(
-/*=========*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* out: datagram buffer; the buffer must be
- supplied by the caller */
- ulint buf_len,/* in: datagram buffer length */
- ulint* len, /* out: datagram length */
- char* from, /* out: address name buffer; the buffer must be
- supplied by the caller */
- ulint from_len,/* in: address name buffer length */
- ulint* addr_len);/* out: address name length */
-/*************************************************************************
-Sends a datagram to a specified destination. */
-
-ulint
-com_sendto(
-/*=======*/
- /* out: 0 if succeed, else error number */
- com_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* in: datagram buffer */
- ulint len, /* in: datagram length */
- char* to, /* in: address name buffer */
- ulint tolen); /* in: address name length */
-/*************************************************************************
-Gets the maximum datagram size for an endpoint. */
-
-ulint
-com_endpoint_get_max_size(
-/*======================*/
- /* out: maximum size */
- com_endpoint_t* ep); /* in: endpoint */
-
-
-#ifndef UNIV_NONINL
-#include "com0com.ic"
-#endif
-
-#endif
diff --git a/innobase/include/com0com.ic b/innobase/include/com0com.ic
deleted file mode 100644
index cec1cb190cc..00000000000
--- a/innobase/include/com0com.ic
+++ /dev/null
@@ -1,7 +0,0 @@
-/******************************************************
-The communication primitives
-
-(c) 1995 Innobase Oy
-
-Created 9/23/1995 Heikki Tuuri
-*******************************************************/
diff --git a/innobase/include/com0shm.h b/innobase/include/com0shm.h
deleted file mode 100644
index 7de9c4ac2de..00000000000
--- a/innobase/include/com0shm.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/******************************************************
-The communication through shared memory
-
-(c) 1995 Innobase Oy
-
-Created 9/23/1995 Heikki Tuuri
-*******************************************************/
-
-#ifndef com0shm_h
-#define com0shm_h
-
-#include "univ.i"
-
-typedef struct com_shm_endpoint_struct com_shm_endpoint_t;
-
-/* The performance of communication in NT depends on how
-many times a system call is made (excluding os_thread_yield,
-as that is the fastest way to switch thread).
-The following variable counts such events. */
-
-extern ulint com_shm_system_call_count;
-
-
-/*************************************************************************
-Creates a communications endpoint. */
-
-com_shm_endpoint_t*
-com_shm_endpoint_create(void);
-/*=========================*/
- /* out, own: communications endpoint, NULL if
- did not succeed */
-/*************************************************************************
-Frees a communications endpoint. */
-
-ulint
-com_shm_endpoint_free(
-/*==================*/
- /* out: O if succeed, else error number */
- com_shm_endpoint_t* ep);/* in, own: communications endpoint */
-/*************************************************************************
-Sets an option, like the maximum datagram size for an endpoint.
-The options may vary depending on the endpoint type. */
-
-ulint
-com_shm_endpoint_set_option(
-/*========================*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: endpoint */
- ulint optno, /* in: option number, only
- COM_OPT_MAX_DGRAM_SIZE currently supported */
- byte* optval, /* in: pointer to a buffer containing the
- option value to set */
- ulint optlen);/* in: option value buffer length */
-/*************************************************************************
-Bind a communications endpoint to a specified address. */
-
-ulint
-com_shm_bind(
-/*=========*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- char* name, /* in: address name */
- ulint len); /* in: address name length */
-/*************************************************************************
-Waits for a datagram to arrive at an endpoint. */
-
-ulint
-com_shm_recvfrom(
-/*=============*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* out: datagram buffer; the buffer is
- supplied by the caller */
- ulint buf_len,/* in: datagram buffer length */
- ulint* len, /* out: datagram length */
- char* from, /* out: address name buffer; the buffer is
- supplied by the caller */
- ulint from_len,/* in: address name buffer length */
- ulint* addr_len);/* out: address name length */
-/*************************************************************************
-Sends a datagram to the specified destination. */
-
-ulint
-com_shm_sendto(
-/*===========*/
- /* out: 0 if succeed, else error number */
- com_shm_endpoint_t* ep, /* in: communications endpoint */
- byte* buf, /* in: datagram buffer */
- ulint len, /* in: datagram length */
- char* to, /* in: address name buffer */
- ulint tolen); /* in: address name length */
-
-ulint
-com_shm_endpoint_get_size(
-/*======================*/
- com_shm_endpoint_t* ep);
-
-
-#ifndef UNIV_NONINL
-#include "com0shm.ic"
-#endif
-
-#endif
diff --git a/innobase/include/com0shm.ic b/innobase/include/com0shm.ic
deleted file mode 100644
index e0d3cb26f69..00000000000
--- a/innobase/include/com0shm.ic
+++ /dev/null
@@ -1,7 +0,0 @@
-/******************************************************
-Communication through shared memory
-
-(c) 1995 Innobase Oy
-
-Created 9/23/1995 Heikki Tuuri
-*******************************************************/
diff --git a/innobase/include/data0data.h b/innobase/include/data0data.h
index 889d148d3fe..c4e93bec738 100644
--- a/innobase/include/data0data.h
+++ b/innobase/include/data0data.h
@@ -262,6 +262,14 @@ dtuple_set_types_binary(
/*====================*/
dtuple_t* tuple, /* in: data tuple */
ulint n); /* in: number of fields to set */
+/**************************************************************************
+Checks if a dtuple contains an SQL null value. */
+UNIV_INLINE
+ibool
+dtuple_contains_null(
+/*=================*/
+ /* out: TRUE if some field is SQL null */
+ dtuple_t* tuple); /* in: dtuple */
/**************************************************************
Checks that a data field is typed. Asserts an error if not. */
@@ -367,84 +375,6 @@ dtuple_big_rec_free(
/*================*/
big_rec_t* vector); /* in, own: big rec vector; it is
freed in this function */
-/***************************************************************
-Generates a random tuple. */
-
-dtuple_t*
-dtuple_gen_rnd_tuple(
-/*=================*/
- /* out: pointer to the tuple */
- mem_heap_t* heap); /* in: memory heap where generated */
-/*******************************************************************
-Generates a test tuple for sort and comparison tests. */
-
-void
-dtuple_gen_test_tuple(
-/*==================*/
- dtuple_t* tuple, /* in/out: a tuple with 3 fields */
- ulint i); /* in: a number, 0 <= i < 512 */
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_test_tuple3(
-/*===================*/
- dtuple_t* tuple, /* in/out: a tuple with 3 fields */
- ulint i, /* in: a number < 1000000 */
- ulint type, /* in: DTUPLE_TEST_FIXED30, ... */
- byte* buf); /* in: a buffer of size >= 8 bytes */
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple3(
-/*=====================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 or 2 fields */
- ulint i, /* in: a number < 1000000 */
- byte* buf); /* in: a buffer of size >= 8 bytes */
-/*******************************************************************
-Generates a test tuple for TPC-A speed test. */
-
-void
-dtuple_gen_test_tuple_TPC_A(
-/*========================*/
- dtuple_t* tuple, /* in/out: a tuple with >= 3 fields */
- ulint i, /* in: a number < 10000 */
- byte* buf); /* in: a buffer of size >= 16 bytes */
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple_TPC_A(
-/*==========================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 field */
- ulint i, /* in: a number < 10000 */
- byte* buf); /* in: a buffer of size >= 16 bytes */
-/*******************************************************************
-Generates a test tuple for TPC-C speed test. */
-
-void
-dtuple_gen_test_tuple_TPC_C(
-/*========================*/
- dtuple_t* tuple, /* in/out: a tuple with >= 12 fields */
- ulint i, /* in: a number < 100000 */
- byte* buf); /* in: a buffer of size >= 16 bytes */
-/*******************************************************************
-Generates a test tuple for B-tree speed tests. */
-
-void
-dtuple_gen_search_tuple_TPC_C(
-/*==========================*/
- dtuple_t* tuple, /* in/out: a tuple with 1 field */
- ulint i, /* in: a number < 100000 */
- byte* buf); /* in: a buffer of size >= 16 bytes */
-
-/* Types of the third field in dtuple_gen_test_tuple3 */
-#define DTUPLE_TEST_FIXED30 1
-#define DTUPLE_TEST_RND30 2
-#define DTUPLE_TEST_RND3500 3
-#define DTUPLE_TEST_FIXED2000 4
-#define DTUPLE_TEST_FIXED3 5
/*######################################################################*/
@@ -472,9 +402,11 @@ struct dtuple_struct {
UT_LIST_NODE_T(dtuple_t) tuple_list;
/* data tuples can be linked into a
list using this field */
- ulint magic_n;
-};
+#ifdef UNIV_DEBUG
+ ulint magic_n;
#define DATA_TUPLE_MAGIC_N 65478679
+#endif /* UNIV_DEBUG */
+};
/* A slot for a field in a big rec vector */
diff --git a/innobase/include/data0data.ic b/innobase/include/data0data.ic
index d356664df21..def80d3f430 100644
--- a/innobase/include/data0data.ic
+++ b/innobase/include/data0data.ic
@@ -406,3 +406,28 @@ data_write_sql_null(
data[j] = '\0';
}
}
+
+/**************************************************************************
+Checks if a dtuple contains an SQL null value. */
+UNIV_INLINE
+ibool
+dtuple_contains_null(
+/*=================*/
+ /* out: TRUE if some field is SQL null */
+ dtuple_t* tuple) /* in: dtuple */
+{
+ ulint n;
+ ulint i;
+
+ n = dtuple_get_n_fields(tuple);
+
+ for (i = 0; i < n; i++) {
+ if (dfield_get_len(dtuple_get_nth_field(tuple, i))
+ == UNIV_SQL_NULL) {
+
+ return(TRUE);
+ }
+ }
+
+ return(FALSE);
+}
diff --git a/innobase/include/data0type.h b/innobase/include/data0type.h
index f202230bb94..2b27ead5fac 100644
--- a/innobase/include/data0type.h
+++ b/innobase/include/data0type.h
@@ -11,6 +11,9 @@ Created 1/16/1996 Heikki Tuuri
#include "univ.i"
+extern ulint data_mysql_default_charset_coll;
+extern ulint data_mysql_latin1_swedish_charset_coll;
+
/* SQL data type struct */
typedef struct dtype_struct dtype_t;
@@ -18,31 +21,79 @@ typedef struct dtype_struct dtype_t;
data type */
extern dtype_t* dtype_binary;
-/* Data main types of SQL data */
-#define DATA_VARCHAR 1 /* character varying */
-#define DATA_CHAR 2 /* fixed length character */
+/*-------------------------------------------*/
+/* The 'MAIN TYPE' of a column */
+#define DATA_VARCHAR 1 /* character varying of the
+ latin1_swedish_ci charset-collation */
+#define DATA_CHAR 2 /* fixed length character of the
+ latin1_swedish_ci charset-collation */
#define DATA_FIXBINARY 3 /* binary string of fixed length */
#define DATA_BINARY 4 /* binary string */
-#define DATA_BLOB 5 /* binary large object, or a TEXT type; if
- prtype & DATA_NONLATIN1 != 0 the data must
- be compared by MySQL as a whole field; if
- prtype & DATA_BINARY_TYPE == 0, then this is
- actually a TEXT column */
+#define DATA_BLOB 5 /* binary large object, or a TEXT type;
+ if prtype & DATA_BINARY_TYPE == 0, then this is
+ actually a TEXT column (or a BLOB created
+ with < 4.0.14) */
#define DATA_INT 6 /* integer: can be any size 1 - 8 bytes */
#define DATA_SYS_CHILD 7 /* address of the child page in node pointer */
#define DATA_SYS 8 /* system column */
+
/* Data types >= DATA_FLOAT must be compared using the whole field, not as
binary strings */
+
#define DATA_FLOAT 9
#define DATA_DOUBLE 10
#define DATA_DECIMAL 11 /* decimal number stored as an ASCII string */
-#define DATA_VARMYSQL 12 /* non-latin1 varying length char */
-#define DATA_MYSQL 13 /* non-latin1 fixed length char */
+#define DATA_VARMYSQL 12 /* any charset varying length char */
+#define DATA_MYSQL 13 /* any charset fixed length char */
+ /* NOTE that 4.1.1 used DATA_MYSQL and
+ DATA_VARMYSQL for all character sets, and the
+ charset-collation for tables created with it
+ can also be latin1_swedish_ci */
#define DATA_MTYPE_MAX 63 /* dtype_store_for_order_and_null_size()
requires the values are <= 63 */
/*-------------------------------------------*/
-/* In the lowest byte in the precise type we store the MySQL type code
-(not applicable for system columns). */
+/* The 'PRECISE TYPE' of a column */
+/*
+Tables created by a MySQL user have the following convention:
+
+- In the least significant byte in the precise type we store the MySQL type
+code (not applicable for system columns).
+
+- In the second least significant byte we OR flags DATA_NOT_NULL,
+DATA_UNSIGNED, DATA_BINARY_TYPE.
+
+- In the third least significant byte of the precise type of string types we
+store the MySQL charset-collation code. In DATA_BLOB columns created with
+< 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there
+are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no
+problem, though.
+
+Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the
+precise type, since the charset was always the default charset of the MySQL
+installation. If the stored charset code is 0 in the system table SYS_COLUMNS
+of InnoDB, that means that the default charset of this MySQL installation
+should be used.
+
+When loading a table definition from the system tables to the InnoDB data
+dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check
+if the stored charset-collation is 0, and if that is the case and the type is
+a non-binary string, replace that 0 by the default charset-collation code of
+this MySQL installation. In short, in old tables, the charset-collation code
+in the system tables on disk can be 0, but in in-memory data structures
+(dtype_t), the charset-collation code is always != 0 for non-binary string
+types.
+
+In new tables, in binary string types, the charset-collation code is the
+MySQL code for the 'binary charset', that is, != 0.
+
+For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those
+DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci,
+InnoDB performs all comparisons internally, without resorting to the MySQL
+comparison functions. This is to save CPU time.
+
+InnoDB's own internal system tables have different precise types for their
+columns, and for them the precise type is usually not used at all.
+*/
#define DATA_ENGLISH 4 /* English language character string: this
is a relic from pre-MySQL time and only used
@@ -69,7 +120,7 @@ be less than 256 */
#define DATA_MIX_ID_LEN 9 /* maximum stored length for mix id (in a
compressed dulint form) */
#define DATA_N_SYS_COLS 4 /* number of system columns defined above */
-/*-------------------------------------------*/
+
/* Flags ORed to the precise data type */
#define DATA_NOT_NULL 256 /* this is ORed to the precise type when
the column is declared as NOT NULL */
@@ -79,20 +130,53 @@ be less than 256 */
string, this is ORed to the precise type:
this only holds for tables created with
>= MySQL-4.0.14 */
-#define DATA_NONLATIN1 2048 /* if the data type is a DATA_BLOB (actually
- TEXT) of a non-latin1 type, this is ORed to
- the precise type: this only holds for tables
- created with >= MySQL-4.0.14 */
+/* #define DATA_NONLATIN1 2048 This is a relic from < 4.1.2 and < 5.0.1.
+ In earlier versions this was set for some
+ BLOB columns.
+*/
/*-------------------------------------------*/
/* This many bytes we need to store the type information affecting the
alphabetical order for a single field and decide the storage size of an
SQL null*/
-#define DATA_ORDER_NULL_TYPE_BUF_SIZE 4
-/* In the >= 4.1.x storage format we need 2 bytes more for the charset */
+#define DATA_ORDER_NULL_TYPE_BUF_SIZE 4
+/* In the >= 4.1.x storage format we add 2 bytes more so that we can also
+store the charset-collation number; one byte is left unused, though */
#define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE 6
/*************************************************************************
+Checks if a data main type is a string type. Also a BLOB is considered a
+string type. */
+
+ibool
+dtype_is_string_type(
+/*=================*/
+ /* out: TRUE if string type */
+ ulint mtype); /* in: InnoDB main data type code: DATA_CHAR, ... */
+/*************************************************************************
+Checks if a type is a binary string type. Note that for tables created with
+< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
+those DATA_BLOB columns this function currently returns FALSE. */
+
+ibool
+dtype_is_binary_string_type(
+/*========================*/
+ /* out: TRUE if binary string type */
+ ulint mtype, /* in: main data type */
+ ulint prtype);/* in: precise type */
+/*************************************************************************
+Checks if a type is a non-binary string type. That is, dtype_is_string_type is
+TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
+with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
+For those DATA_BLOB columns this function currently returns TRUE. */
+
+ibool
+dtype_is_non_binary_string_type(
+/*============================*/
+ /* out: TRUE if non-binary string type */
+ ulint mtype, /* in: main data type */
+ ulint prtype);/* in: precise type */
+/*************************************************************************
Sets a data type structure. */
UNIV_INLINE
void
@@ -126,6 +210,23 @@ dtype_get_prtype(
/*=============*/
dtype_t* type);
/*************************************************************************
+Gets the MySQL charset-collation code for MySQL string types. */
+UNIV_INLINE
+ulint
+dtype_get_charset_coll(
+/*===================*/
+ ulint prtype);/* in: precise data type */
+/*************************************************************************
+Forms a precise type from the < 4.1.2 format precise type plus the
+charset-collation code. */
+
+ulint
+dtype_form_prtype(
+/*==============*/
+ ulint old_prtype, /* in: the MySQL type code and the flags
+ DATA_BINARY_TYPE etc. */
+ ulint charset_coll); /* in: MySQL charset-collation code */
+/*************************************************************************
Gets the type length. */
UNIV_INLINE
ulint
@@ -225,9 +326,8 @@ dtype_print(
struct dtype_struct{
ulint mtype; /* main data type */
ulint prtype; /* precise type; MySQL data type */
- ulint chrset; /* MySQL character set code */
- /* remaining two fields do not affect alphabetical ordering: */
+ /* the remaining two fields do not affect alphabetical ordering: */
ulint len; /* length */
ulint prec; /* precision */
diff --git a/innobase/include/data0type.ic b/innobase/include/data0type.ic
index 5d39b3e430b..946b646ffbf 100644
--- a/innobase/include/data0type.ic
+++ b/innobase/include/data0type.ic
@@ -27,7 +27,6 @@ dtype_set(
type->prtype = prtype;
type->len = len;
type->prec = prec;
- type->chrset = 0;
ut_ad(dtype_validate(type));
}
@@ -73,6 +72,17 @@ dtype_get_prtype(
}
/*************************************************************************
+Gets the MySQL charset-collation code for MySQL string types. */
+UNIV_INLINE
+ulint
+dtype_get_charset_coll(
+/*===================*/
+ ulint prtype) /* in: precise data type */
+{
+ return((prtype >> 16) & 0xFFUL);
+}
+
+/*************************************************************************
Gets the type length. */
UNIV_INLINE
ulint
@@ -147,20 +157,25 @@ dtype_new_store_for_order_and_null_size(
buf[0] = buf[0] | 128;
}
- if (type->prtype & DATA_NONLATIN1) {
- buf[0] = buf[0] | 64;
- }
+ /* In versions < 4.1.2 we had: if (type->prtype & DATA_NONLATIN1) {
+ buf[0] = buf[0] | 64;
+ }
+ */
buf[1] = (byte)(type->prtype & 0xFFUL);
mach_write_to_2(buf + 2, type->len & 0xFFFFUL);
- mach_write_to_2(buf + 4, type->chrset & 0xFFFFUL);
+ mach_write_to_2(buf + 4, dtype_get_charset_coll(type->prtype));
+
+ /* Note that the second last byte is left unused, because the
+ charset-collation code is always < 256 */
}
/**************************************************************************
Reads to a type the stored information which determines its alphabetical
-ordering and the storage size of an SQL NULL value. */
+ordering and the storage size of an SQL NULL value. This is the < 4.1.x
+storage format. */
UNIV_INLINE
void
dtype_read_for_order_and_null_size(
@@ -177,17 +192,16 @@ dtype_read_for_order_and_null_size(
type->prtype = type->prtype | DATA_BINARY_TYPE;
}
- if (buf[0] & 64) {
- type->prtype = type->prtype | DATA_NONLATIN1;
- }
-
type->len = mach_read_from_2(buf + 2);
+
+ type->prtype = dtype_form_prtype(type->prtype,
+ data_mysql_default_charset_coll);
}
/**************************************************************************
Reads to a type the stored information which determines its alphabetical
-ordering and the storage size of an SQL NULL value. This is the 4.1.x storage
-format. */
+ordering and the storage size of an SQL NULL value. This is the >= 4.1.x
+storage format. */
UNIV_INLINE
void
dtype_new_read_for_order_and_null_size(
@@ -195,6 +209,8 @@ dtype_new_read_for_order_and_null_size(
dtype_t* type, /* in: type struct */
byte* buf) /* in: buffer for stored type order info */
{
+ ulint charset_coll;
+
ut_ad(6 == DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE);
type->mtype = buf[0] & 63;
@@ -204,14 +220,28 @@ dtype_new_read_for_order_and_null_size(
type->prtype = type->prtype | DATA_BINARY_TYPE;
}
- if (buf[0] & 64) {
- type->prtype = type->prtype | DATA_NONLATIN1;
- }
-
type->len = mach_read_from_2(buf + 2);
- type->chrset = mach_read_from_2(buf + 4);
-}
+ mach_read_from_2(buf + 4);
+
+ charset_coll = mach_read_from_2(buf + 4);
+
+ if (dtype_is_string_type(type->mtype)) {
+ ut_a(charset_coll < 256);
+
+ if (charset_coll == 0) {
+ /* This insert buffer record was inserted with MySQL
+ version < 4.1.2, and the charset-collation code was not
+ explicitly stored to dtype->prtype at that time. It
+ must be the default charset-collation of this MySQL
+ installation. */
+
+ charset_coll = data_mysql_default_charset_coll;
+ }
+
+ type->prtype = dtype_form_prtype(type->prtype, charset_coll);
+ }
+}
/***************************************************************************
Returns the size of a fixed size data type, 0 if not a fixed size type. */
@@ -250,7 +280,7 @@ dtype_get_fixed_size(
case DATA_VARMYSQL:
case DATA_BLOB:
return(0);
- default: ut_a(0);
+ default: ut_error;
}
return(0);
diff --git a/innobase/include/dict0crea.h b/innobase/include/dict0crea.h
index ccdedff42c8..8b6944fc605 100644
--- a/innobase/include/dict0crea.h
+++ b/innobase/include/dict0crea.h
@@ -17,15 +17,6 @@ Created 1/8/1996 Heikki Tuuri
#include "mtr0mtr.h"
/*************************************************************************
-Creates the default clustered index for a table: the records are ordered
-by row id. */
-
-void
-dict_create_default_index(
-/*======================*/
- dict_table_t* table, /* in: table */
- trx_t* trx); /* in: transaction handle */
-/*************************************************************************
Creates a table create graph. */
tab_node_t*
@@ -81,12 +72,25 @@ dict_create_or_check_foreign_constraint_tables(void);
/*================================================*/
/* out: DB_SUCCESS or error code */
/************************************************************************
-Adds foreign key definitions to data dictionary tables in the database. */
+Adds foreign key definitions to data dictionary tables in the database. We
+look at table->foreign_list, and also generate names to constraints that were
+not named by the user. A generated constraint has a name of the format
+databasename/tablename_ibfk_<number>, where the numbers start from 1, and are
+given locally for this table, that is, the number is not global, as in the
+old format constraints < 4.0.18 it used to be. */
ulint
dict_create_add_foreigns_to_dictionary(
/*===================================*/
/* out: error code or DB_SUCCESS */
+ ulint start_id,/* in: if we are actually doing ALTER TABLE
+ ADD CONSTRAINT, we want to generate constraint
+ numbers which are bigger than in the table so
+ far; we number the constraints from
+ start_id + 1 up; start_id should be set to 0 if
+ we are creating a new table, or if the table
+ so far has no constraints for which the name
+ was generated here */
dict_table_t* table, /* in: table */
trx_t* trx); /* in: transaction */
diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h
index 234dece2cda..688685cff8b 100644
--- a/innobase/include/dict0dict.h
+++ b/innobase/include/dict0dict.h
@@ -26,6 +26,14 @@ Created 1/8/1996 Heikki Tuuri
#include "ut0byte.h"
#include "trx0types.h"
+/************************************************************************
+Get the database name length in a table name. */
+
+ulint
+dict_get_db_name_len(
+/*=================*/
+ /* out: database name length */
+ char* name); /* in: table name in the form dbname '/' tablename */
/*************************************************************************
Accepts a specified string. Comparisons are case-insensitive. */
@@ -217,6 +225,15 @@ dict_foreign_add_to_cache(
/* out: DB_SUCCESS or error code */
dict_foreign_t* foreign); /* in, own: foreign key constraint */
/*************************************************************************
+Checks if a table is referenced by foreign keys. */
+
+ibool
+dict_table_referenced_by_foreign_key(
+/*=================================*/
+ /* out: TRUE if table is referenced by a
+ foreign key */
+ dict_table_t* table); /* in: InnoDB table */
+/*************************************************************************
Scans a table create SQL string and adds to the data dictionary
the foreign key constraints declared in the string. This function
should be called after the indexes for a table have been created.
@@ -476,6 +493,17 @@ dict_table_get_sys_col_no(
/* out: column number */
dict_table_t* table, /* in: table */
ulint sys); /* in: DATA_ROW_ID, ... */
+/************************************************************************
+Checks if a column is in the ordering columns of the clustered index of a
+table. Column prefixes are treated like whole columns. */
+
+ibool
+dict_table_col_in_clustered_key(
+/*============================*/
+ /* out: TRUE if the column, or its prefix, is
+ in the clustered key */
+ dict_table_t* table, /* in: table */
+ ulint n); /* in: column number */
/***********************************************************************
Copies types of columns contained in table to tuple. */
@@ -660,13 +688,6 @@ dict_index_get_tree(
/* out: index tree */
dict_index_t* index); /* in: index */
/*************************************************************************
-Gets the column data type. */
-UNIV_INLINE
-dtype_t*
-dict_col_get_type(
-/*==============*/
- dict_col_t* col);
-/*************************************************************************
Gets the field order criterion. */
UNIV_INLINE
ulint
diff --git a/innobase/include/dict0dict.ic b/innobase/include/dict0dict.ic
index c5982c162a7..b70822e331f 100644
--- a/innobase/include/dict0dict.ic
+++ b/innobase/include/dict0dict.ic
@@ -543,8 +543,10 @@ dict_table_check_if_in_cache_low(
ulint table_fold;
ut_ad(table_name);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
+
/* Look for the table name in the hash table */
table_fold = ut_fold_string(table_name);
@@ -566,8 +568,10 @@ dict_table_get_low(
dict_table_t* table;
ut_ad(table_name);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
+
table = dict_table_check_if_in_cache_low(table_name);
if (table == NULL) {
@@ -621,7 +625,9 @@ dict_table_get_on_id_low(
dict_table_t* table;
ulint fold;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
UT_NOT_USED(trx);
/* Look for the table name in the hash table */
diff --git a/innobase/include/dict0mem.h b/innobase/include/dict0mem.h
index b18e20a644a..23753df4079 100644
--- a/innobase/include/dict0mem.h
+++ b/innobase/include/dict0mem.h
@@ -198,10 +198,11 @@ struct dict_tree_struct{
the list; if the tree is of the mixed
type, the first index in the list is the
index of the cluster which owns the tree */
+#ifdef UNIV_DEBUG
ulint magic_n;/* magic number */
-};
-
#define DICT_TREE_MAGIC_N 7545676
+#endif /* UNIV_DEBUG */
+};
/* Data structure for an index */
struct dict_index_struct{
@@ -247,7 +248,10 @@ struct dict_index_struct{
ulint stat_n_leaf_pages;
/* approximate number of leaf pages in the
index tree */
+#ifdef UNIV_DEBUG
ulint magic_n;/* magic number */
+#define DICT_INDEX_MAGIC_N 76789786
+#endif /* UNIV_DEBUG */
};
/* Data structure for a foreign key constraint; an example:
@@ -298,9 +302,6 @@ a foreign key constraint is enforced, therefore RESTRICT just means no flag */
#define DICT_FOREIGN_ON_DELETE_NO_ACTION 16
#define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32
-
-#define DICT_INDEX_MAGIC_N 76789786
-
/* Data structure for a database table */
struct dict_table_struct{
dulint id; /* id of the table or cluster */
@@ -419,10 +420,12 @@ struct dict_table_struct{
inited; MySQL gets the init value by executing
SELECT MAX(auto inc column) */
ib_longlong autoinc;/* autoinc counter value to give to the
- next inserted row */
+ next inserted row */
+#ifdef UNIV_DEBUG
ulint magic_n;/* magic number */
-};
#define DICT_TABLE_MAGIC_N 76333786
+#endif /* UNIV_DEBUG */
+};
/* Data structure for a stored procedure */
struct dict_proc_struct{
diff --git a/innobase/include/fut0fut.ic b/innobase/include/fut0fut.ic
index 0f1aa9dd9ae..6a107786376 100644
--- a/innobase/include/fut0fut.ic
+++ b/innobase/include/fut0fut.ic
@@ -30,7 +30,9 @@ fut_get_ptr(
ptr = buf_page_get(space, addr.page, rw_latch, mtr) + addr.boffset;
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(ptr, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
return(ptr);
}
diff --git a/innobase/include/ha0ha.ic b/innobase/include/ha0ha.ic
index 77064cdf9da..5369ca7f273 100644
--- a/innobase/include/ha0ha.ic
+++ b/innobase/include/ha0ha.ic
@@ -81,7 +81,9 @@ ha_search(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
+#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
@@ -111,7 +113,9 @@ ha_search_and_get_data(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
+#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
@@ -170,7 +174,9 @@ ha_search_with_data(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
+#endif /* UNIV_SYNC_DEBUG */
node = ha_chain_get_first(table, fold);
@@ -200,7 +206,9 @@ ha_search_and_delete_if_found(
{
ha_node_t* node;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold)));
+#endif /* UNIV_SYNC_DEBUG */
node = ha_search_with_data(table, fold, data);
diff --git a/innobase/include/hash0hash.h b/innobase/include/hash0hash.h
index 2e9ab498116..79efe016324 100644
--- a/innobase/include/hash0hash.h
+++ b/innobase/include/hash0hash.h
@@ -53,15 +53,24 @@ hash_calc_hash(
/* out: hashed value */
ulint fold, /* in: folded value */
hash_table_t* table); /* in: hash table */
+/************************************************************************
+Assert that the mutex for the table in a hash operation is owned. */
+#ifdef UNIV_SYNC_DEBUG
+# define HASH_ASSERT_OWNED(TABLE, FOLD) \
+ut_ad(!(TABLE)->mutexes || mutex_own(hash_get_mutex(TABLE, FOLD)));
+#else
+# define HASH_ASSERT_OWNED(TABLE, FOLD)
+#endif
+
/***********************************************************************
Inserts a struct to a hash table. */
#define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)\
-{\
+do {\
hash_cell_t* cell3333;\
TYPE* struct3333;\
\
- ut_ad(!(TABLE)->mutexes || mutex_own(hash_get_mutex(TABLE, FOLD)));\
+ HASH_ASSERT_OWNED(TABLE, FOLD)\
\
(DATA)->NAME = NULL;\
\
@@ -79,17 +88,17 @@ Inserts a struct to a hash table. */
\
struct3333->NAME = DATA;\
}\
-}
+} while (0)
/***********************************************************************
Deletes a struct from a hash table. */
#define HASH_DELETE(TYPE, NAME, TABLE, FOLD, DATA)\
-{\
+do {\
hash_cell_t* cell3333;\
TYPE* struct3333;\
\
- ut_ad(!(TABLE)->mutexes || mutex_own(hash_get_mutex(TABLE, FOLD)));\
+ HASH_ASSERT_OWNED(TABLE, FOLD)\
\
cell3333 = hash_get_nth_cell(TABLE, hash_calc_hash(FOLD, TABLE));\
\
@@ -100,13 +109,13 @@ Deletes a struct from a hash table. */
\
while (struct3333->NAME != DATA) {\
\
- ut_a(struct3333)\
+ ut_a(struct3333);\
struct3333 = struct3333->NAME;\
}\
\
struct3333->NAME = DATA->NAME;\
}\
-}
+} while (0)
/***********************************************************************
Gets the first struct in a hash chain, NULL if none. */
@@ -124,7 +133,7 @@ Looks for a struct in a hash table. */
#define HASH_SEARCH(NAME, TABLE, FOLD, DATA, TEST)\
{\
\
- ut_ad(!(TABLE)->mutexes || mutex_own(hash_get_mutex(TABLE, FOLD)));\
+ HASH_ASSERT_OWNED(TABLE, FOLD)\
\
(DATA) = HASH_GET_FIRST(TABLE, hash_calc_hash(FOLD, TABLE));\
\
@@ -160,7 +169,7 @@ the heap. The fold value must be stored in the struct NODE in a field named
'fold'. */
#define HASH_DELETE_AND_COMPACT(TYPE, NAME, TABLE, NODE)\
-{\
+do {\
TYPE* node111;\
TYPE* top_node111;\
hash_cell_t* cell111;\
@@ -211,33 +220,7 @@ the heap. The fold value must be stored in the struct NODE in a field named
/* Free the space occupied by the top node */\
\
mem_heap_free_top(hash_get_heap(TABLE, fold111), sizeof(TYPE));\
-}
-
-/***********************************************************************
-Calculates the number of stored structs in a hash table. */
-
-#define HASH_GET_N_NODES(TYPE, NAME, TABLE, N)\
-{\
- hash_cell_t* cell3333;\
- TYPE* struct3333;\
- ulint i3333;\
-\
- (N) = 0;\
-\
- for (i3333 = 0; i3333 < hash_get_n_cells(TABLE); i3333++) {\
-\
- cell3333 = hash_get_nth_cell(TABLE, i3333);\
-\
- struct3333 = cell3333->node;\
-\
- while (struct3333) {\
-\
- (N) = (N) + 1;\
-\
- struct = HASH_GET_NEXT(NAME, struct3333);\
- }\
- }\
-}
+} while (0)
/****************************************************************
Gets the mutex index for a fold value in a hash table. */
@@ -300,21 +283,6 @@ hash_mutex_exit(
/*============*/
hash_table_t* table, /* in: hash table */
ulint fold); /* in: fold */
-/****************************************************************
-Reserves all the mutexes of a hash table, in an ascending order. */
-
-void
-hash_mutex_enter_all(
-/*=================*/
- hash_table_t* table); /* in: hash table */
-/****************************************************************
-Releases all the mutexes of a hash table. */
-
-void
-hash_mutex_exit_all(
-/*================*/
- hash_table_t* table); /* in: hash table */
-
struct hash_cell_struct{
void* node; /* hash chain node, NULL if none */
@@ -335,10 +303,11 @@ struct hash_table_struct {
memory heaps; there are then n_mutexes many of
these heaps */
mem_heap_t* heap;
+#ifdef UNIV_DEBUG
ulint magic_n;
-};
-
#define HASH_TABLE_MAGIC_N 76561114
+#endif /* UNIV_DEBUG */
+};
#ifndef UNIV_NONINL
#include "hash0hash.ic"
diff --git a/innobase/include/hash0hash.ic b/innobase/include/hash0hash.ic
index 0d713140c13..1b9acfa2f34 100644
--- a/innobase/include/hash0hash.ic
+++ b/innobase/include/hash0hash.ic
@@ -18,6 +18,7 @@ hash_get_nth_cell(
hash_table_t* table, /* in: hash table */
ulint n) /* in: cell index */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(n < table->n_cells);
return(table->array + n);
@@ -32,6 +33,7 @@ hash_get_n_cells(
/* out: number of cells */
hash_table_t* table) /* in: table */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
return(table->n_cells);
}
@@ -45,6 +47,7 @@ hash_calc_hash(
ulint fold, /* in: folded value */
hash_table_t* table) /* in: hash table */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
return(ut_hash_ulint(fold, table->n_cells));
}
@@ -58,6 +61,7 @@ hash_get_mutex_no(
hash_table_t* table, /* in: hash table */
ulint fold) /* in: fold */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
return(ut_2pow_remainder(fold, table->n_mutexes));
}
@@ -71,6 +75,7 @@ hash_get_nth_heap(
hash_table_t* table, /* in: hash table */
ulint i) /* in: index of the heap */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(i < table->n_mutexes);
return(table->heaps[i]);
@@ -88,6 +93,8 @@ hash_get_heap(
{
ulint i;
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
+
if (table->heap) {
return(table->heap);
}
@@ -107,6 +114,7 @@ hash_get_nth_mutex(
hash_table_t* table, /* in: hash table */
ulint i) /* in: index of the mutex */
{
+ ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
ut_ad(i < table->n_mutexes);
return(table->mutexes + i);
diff --git a/innobase/include/ib_odbc.h b/innobase/include/ib_odbc.h
deleted file mode 100644
index 86884b41d39..00000000000
--- a/innobase/include/ib_odbc.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/******************************************************
-Innobase ODBC client library header; this is equivalent to
-the standard sql.h ODBC header file
-
-(c) 1998 Innobase Oy
-
-Created 2/22/1998 Heikki Tuuri
-*******************************************************/
-
-#ifndef ib_odbc_h
-#define ib_odbc_h
-
-typedef unsigned char UCHAR;
-typedef signed char SCHAR;
-typedef long int SDWORD;
-typedef short int SWORD;
-typedef unsigned long int UDWORD;
-typedef unsigned short int UWORD;
-
-typedef void* PTR;
-
-typedef void* HENV;
-typedef void* HDBC;
-typedef void* HSTMT;
-
-typedef signed short RETCODE;
-
-/* RETCODEs */
-#define SQL_NO_DATA_FOUND (-3)
-#define SQL_INVALID_HANDLE (-2)
-#define SQL_ERROR (-1)
-#define SQL_SUCCESS 0
-
-/* Standard SQL datatypes, using ANSI type numbering */
-#define SQL_CHAR 1
-#define SQL_INTEGER 4
-#define SQL_VARCHAR 12
-
-/* C datatype to SQL datatype mapping */
-#define SQL_C_CHAR SQL_CHAR
-#define SQL_C_LONG SQL_INTEGER
-
-/* Special length value */
-#define SQL_NULL_DATA (-1)
-
-#define SQL_PARAM_INPUT 1
-#define SQL_PARAM_OUTPUT 4
-
-/* Null handles */
-#define SQL_NULL_HENV NULL
-#define SQL_NULL_HDBC NULL
-#define SQL_NULL_HSTM NULL
-
-
-/**************************************************************************
-Allocates an SQL environment. */
-
-RETCODE
-SQLAllocEnv(
-/*========*/
- /* out: SQL_SUCCESS */
- HENV* phenv); /* out: pointer to an environment handle */
-/**************************************************************************
-Allocates an SQL connection. */
-
-RETCODE
-SQLAllocConnect(
-/*============*/
- /* out: SQL_SUCCESS */
- HENV henv, /* in: pointer to an environment handle */
- HDBC* phdbc); /* out: pointer to a connection handle */
-/**************************************************************************
-Allocates an SQL statement. */
-
-RETCODE
-SQLAllocStmt(
-/*=========*/
- HDBC hdbc, /* in: SQL connection */
- HSTMT* phstmt); /* out: pointer to a statement handle */
-/**************************************************************************
-Connects to a database server process (establishes a connection and a
-session). */
-
-RETCODE
-SQLConnect(
-/*=======*/
- /* out: SQL_SUCCESS */
- HDBC hdbc, /* in: SQL connection handle */
- UCHAR* szDSN, /* in: data source name (server name) */
- SWORD cbDSN, /* in: data source name length */
- UCHAR* szUID, /* in: user name */
- SWORD cbUID, /* in: user name length */
- UCHAR* szAuthStr, /* in: password */
- SWORD cbAuthStr); /* in: password length */
-/**************************************************************************
-Makes the server to parse and optimize an SQL string. */
-
-RETCODE
-SQLPrepare(
-/*=======*/
- /* out: SQL_SUCCESS */
- HSTMT hstmt, /* in: statement handle */
- UCHAR* szSqlStr, /* in: SQL string */
- SDWORD cbSqlStr); /* in: SQL string length */
-/**************************************************************************
-Binds a parameter in a prepared statement. */
-
-RETCODE
-SQLBindParameter(
-/*=============*/
- /* out: SQL_SUCCESS */
- HSTMT hstmt, /* in: statement handle */
- UWORD ipar, /* in: parameter index, starting from 1 */
- SWORD fParamType, /* in: SQL_PARAM_INPUT or SQL_PARAM_OUTPUT */
- SWORD fCType, /* in: SQL_C_CHAR, ... */
- SWORD fSqlType, /* in: SQL_CHAR, ... */
- UDWORD cbColDef, /* in: precision: ignored */
- SWORD ibScale, /* in: scale: ignored */
- PTR rgbValue, /* in: pointer to a buffer for the data */
- SDWORD cbValueMax, /* in: buffer size */
- SDWORD* pcbValue); /* in: pointer to a buffer for the data
- length or SQL_NULL_DATA */
-/**************************************************************************
-Executes a prepared statement where all parameters have been bound. */
-
-RETCODE
-SQLExecute(
-/*=======*/
- /* out: SQL_SUCCESS or SQL_ERROR */
- HSTMT hstmt); /* in: statement handle */
-/**************************************************************************
-Queries an error message. */
-
-RETCODE
-SQLError(
-/*=====*/
- /* out: SQL_SUCCESS or SQL_NO_DATA_FOUND */
- HENV henv, /* in: SQL_NULL_HENV */
- HDBC hdbc, /* in: SQL_NULL_HDBC */
- HSTMT hstmt, /* in: statement handle */
- UCHAR* szSqlState, /* in/out: SQLSTATE as a null-terminated string,
- (currently, always == "S1000") */
- SDWORD* pfNativeError, /* out: native error code */
- UCHAR* szErrorMsg, /* in/out: buffer for an error message as a
- null-terminated string */
- SWORD cbErrorMsgMax, /* in: buffer size for szErrorMsg */
- SWORD* pcbErrorMsg); /* out: error message length */
-
-#endif
diff --git a/innobase/include/ibuf0ibuf.h b/innobase/include/ibuf0ibuf.h
index bf03b06bd28..8ef67df26f8 100644
--- a/innobase/include/ibuf0ibuf.h
+++ b/innobase/include/ibuf0ibuf.h
@@ -177,15 +177,6 @@ ibuf_page_low(
mtr_t* mtr); /* in: mtr which will contain an x-latch to the
bitmap page if the page is not one of the fixed
address ibuf pages */
-/*************************************************************************
-Checks if an index page has so much free space that the free bit should
-be set TRUE in the ibuf bitmap. */
-
-ibool
-ibuf_index_page_has_free(
-/*=====================*/
- /* out: TRUE if there is enough free space */
- page_t* page); /* in: non-unique secondary index page */
/***************************************************************************
Frees excess pages from the ibuf free list. This function is called when an OS
thread calls fsp services to allocate a new file segment, or a new page to a
diff --git a/innobase/include/lock0lock.h b/innobase/include/lock0lock.h
index 49f4597b30c..103d28cd130 100644
--- a/innobase/include/lock0lock.h
+++ b/innobase/include/lock0lock.h
@@ -442,14 +442,6 @@ lock_rec_hash(
ulint space, /* in: space */
ulint page_no);/* in: page number */
/*************************************************************************
-Gets the mutex protecting record locks on a given page address. */
-
-mutex_t*
-lock_rec_get_mutex_for_addr(
-/*========================*/
- ulint space, /* in: space id */
- ulint page_no);/* in: page number */
-/*************************************************************************
Checks that a transaction id is sensible, i.e., not in the future. */
ibool
diff --git a/innobase/include/lock0lock.ic b/innobase/include/lock0lock.ic
index 64c43c88d2e..fabc9256401 100644
--- a/innobase/include/lock0lock.ic
+++ b/innobase/include/lock0lock.ic
@@ -64,7 +64,9 @@ lock_clust_rec_some_has_impl(
{
dulint trx_id;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(index->type & DICT_CLUSTERED);
ut_ad(page_rec_is_user_rec(rec));
diff --git a/innobase/include/log0log.h b/innobase/include/log0log.h
index dc44429d636..2bdc158502f 100644
--- a/innobase/include/log0log.h
+++ b/innobase/include/log0log.h
@@ -18,7 +18,9 @@ typedef struct log_struct log_t;
typedef struct log_group_struct log_group_t;
extern ibool log_do_write;
+#ifdef UNIV_LOG_DEBUG
extern ibool log_debug_writes;
+#endif /* UNIV_LOG_DEBUG */
/* Wait modes for log_write_up_to */
#define LOG_NO_WAIT 91
@@ -719,11 +721,13 @@ struct log_struct{
ulint max_buf_free; /* recommended maximum value of
buf_free, after which the buffer is
flushed */
+#ifdef UNIV_LOG_DEBUG
ulint old_buf_free; /* value of buf free when log was
last time opened; only in the debug
version */
dulint old_lsn; /* value of lsn when log was last time
opened; only in the debug version */
+#endif /* UNIV_LOG_DEBUG */
ibool check_flush_or_checkpoint;
/* this is set to TRUE when there may
be need to flush the log buffer, or
diff --git a/innobase/include/log0log.ic b/innobase/include/log0log.ic
index 7ae7e859032..e273b6a292b 100644
--- a/innobase/include/log0log.ic
+++ b/innobase/include/log0log.ic
@@ -10,6 +10,7 @@ Created 12/9/1995 Heikki Tuuri
#include "mach0data.h"
#include "mtr0mtr.h"
+#ifdef UNIV_LOG_DEBUG
/**********************************************************
Checks by parsing that the catenated log segment for a single mtr is
consistent. */
@@ -21,6 +22,7 @@ log_check_log_recs(
in the log_sys->buf log buffer */
ulint len, /* in: segment length in bytes */
dulint buf_start_lsn); /* in: buffer start lsn */
+#endif /* UNIV_LOG_DEBUG */
/****************************************************************
Gets a log block flush bit. */
@@ -255,7 +257,9 @@ log_block_init(
{
ulint no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
no = log_block_convert_lsn_to_no(lsn);
@@ -277,7 +281,9 @@ log_block_init_in_old_format(
{
ulint no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
no = log_block_convert_lsn_to_no(lsn);
@@ -407,7 +413,9 @@ log_get_online_backup_lsn_low(void)
/* out: online_backup_lsn, the caller must
own the log_sys mutex */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(log_sys->online_backup_state);
return(log_sys->online_backup_lsn);
@@ -422,7 +430,9 @@ log_get_online_backup_state_low(void)
/* out: online backup state, the caller must
own the log_sys mutex */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
return(log_sys->online_backup_state);
}
diff --git a/innobase/include/mach0data.h b/innobase/include/mach0data.h
index 006f55d5f1f..f28c9422670 100644
--- a/innobase/include/mach0data.h
+++ b/innobase/include/mach0data.h
@@ -88,25 +88,6 @@ mach_read_from_4(
/*=============*/
/* out: ulint integer */
byte* b); /* in: pointer to four bytes */
-/***********************************************************
-The following function is used to store data from a ulint to memory
-in standard order:
-we store the most significant byte to the lowest address. */
-UNIV_INLINE
-void
-mach_write(
-/*=======*/
- byte* b, /* in: pointer to sizeof(ulint) bytes where to store */
- ulint n); /* in: ulint integer to be stored */
-/************************************************************
-The following function is used to fetch data from memory to a ulint.
-The most significant byte is at the lowest address. */
-UNIV_INLINE
-ulint
-mach_read(
-/*======*/
- /* out: ulint integer */
- byte* b); /* in: pointer to sizeof(ulint) bytes */
/*************************************************************
Writes a ulint in a compressed form. */
UNIV_INLINE
diff --git a/innobase/include/mach0data.ic b/innobase/include/mach0data.ic
index 0934c27d9f4..3ccdcf1dc0a 100644
--- a/innobase/include/mach0data.ic
+++ b/innobase/include/mach0data.ic
@@ -167,44 +167,6 @@ mach_read_from_4(
#endif
}
-/***********************************************************
-The following function is used to store data from a ulint to memory
-in standard order: we store the most significant byte to the lowest
-address. */
-UNIV_INLINE
-void
-mach_write(
-/*=======*/
- byte* b, /* in: pointer to 4 bytes where to store */
- ulint n) /* in: ulint integer to be stored */
-{
- ut_ad(b);
-
- b[0] = (byte)(n >> 24);
- b[1] = (byte)(n >> 16);
- b[2] = (byte)(n >> 8);
- b[3] = (byte)n;
-}
-
-/************************************************************
-The following function is used to fetch data from memory to a ulint.
-The most significant byte is at the lowest address. */
-UNIV_INLINE
-ulint
-mach_read(
-/*======*/
- /* out: ulint integer */
- byte* b) /* in: pointer to 4 bytes */
-{
- ut_ad(b);
-
- return( ((ulint)(b[0]) << 24)
- + ((ulint)(b[1]) << 16)
- + ((ulint)(b[2]) << 8)
- + (ulint)(b[3])
- );
-}
-
/*************************************************************
Writes a ulint in a compressed form where the first byte codes the
length of the stored ulint. We look at the most significant bits of
diff --git a/innobase/include/mem0dbg.h b/innobase/include/mem0dbg.h
index 0b1aa53d694..6c92d669be3 100644
--- a/innobase/include/mem0dbg.h
+++ b/innobase/include/mem0dbg.h
@@ -60,6 +60,7 @@ mem_heap_validate_or_print(
ulint* n_blocks); /* out: number of blocks in the heap,
if a NULL pointer is passed as this
argument, it is ignored */
+#ifdef UNIV_MEM_DEBUG
/******************************************************************
Prints the contents of a memory heap. */
@@ -67,6 +68,7 @@ void
mem_heap_print(
/*===========*/
mem_heap_t* heap); /* in: memory heap */
+#endif /* UNIV_MEM_DEBUG */
/******************************************************************
Checks that an object is a memory heap (or a block of it) */
@@ -83,20 +85,7 @@ mem_heap_validate(
/*==============*/
/* out: TRUE if ok */
mem_heap_t* heap); /* in: memory heap */
-/*********************************************************************
-Prints information of dynamic memory usage and currently live
-memory heaps or buffers. Can only be used in the debug version. */
-
-void
-mem_print_info(void);
-/*=================*/
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated memory
-heaps or buffers since the last ..._print_info or..._print_new_info. */
-
-void
-mem_print_new_info(void);
-/*====================*/
+#ifdef UNIV_MEM_DEBUG
/*********************************************************************
TRUE if no memory is currently allocated. */
@@ -118,6 +107,7 @@ ibool
mem_validate(void);
/*===============*/
/* out: TRUE if ok */
+#endif /* UNIV_MEM_DEBUG */
/****************************************************************
Tries to find neigboring memory allocation blocks and dumps to stderr
the neighborhood of a given pointer. */
diff --git a/innobase/include/mem0dbg.ic b/innobase/include/mem0dbg.ic
index 765e23e747e..6efac719760 100644
--- a/innobase/include/mem0dbg.ic
+++ b/innobase/include/mem0dbg.ic
@@ -7,6 +7,7 @@ compilation module but is included in mem0mem.*.
Created 6/8/1994 Heikki Tuuri
*************************************************************************/
+#ifdef UNIV_MEM_DEBUG
extern mutex_t mem_hash_mutex;
extern ulint mem_current_allocated_memory;
@@ -89,3 +90,4 @@ mem_field_trailer_set_check(byte* field, ulint check);
ulint
mem_field_trailer_get_check(byte* field);
+#endif /* UNIV_MEM_DEBUG */
diff --git a/innobase/include/mem0mem.ic b/innobase/include/mem0mem.ic
index 1ff8c66e80a..fb4cef49ec9 100644
--- a/innobase/include/mem0mem.ic
+++ b/innobase/include/mem0mem.ic
@@ -162,7 +162,7 @@ mem_heap_alloc(
mem_block_set_free(block, free + MEM_SPACE_NEEDED(n));
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* In the debug version write debugging info to the field */
mem_field_init((byte*)buf, n);
@@ -171,7 +171,7 @@ mem_heap_alloc(
caller */
buf = (byte*)buf + MEM_FIELD_HEADER_SIZE;
- #endif
+#endif
#ifdef UNIV_SET_MEM_TO_ZERO
memset(buf, '\0', n);
#endif
@@ -212,15 +212,15 @@ mem_heap_free_heap_top(
{
mem_block_t* block;
mem_block_t* prev_block;
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ibool error;
ulint total_size;
ulint size;
- #endif
+#endif
ut_ad(mem_heap_check(heap));
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* Validate the heap and get its total allocated size */
mem_heap_validate_or_print(heap, NULL, FALSE, &error, &total_size,
@@ -232,7 +232,7 @@ mem_heap_free_heap_top(
NULL);
ut_a(!error);
- #endif
+#endif
block = UT_LIST_GET_LAST(heap->base);
@@ -259,7 +259,7 @@ mem_heap_free_heap_top(
/* Set the free field of block */
mem_block_set_free(block, old_top - (byte*)block);
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
/* In the debug version erase block from top up */
@@ -271,7 +271,7 @@ mem_heap_free_heap_top(
mem_current_allocated_memory -= (total_size - size);
mutex_exit(&mem_hash_mutex);
- #endif
+#endif
/* If free == start, we may free the block if it is not the first
one */
@@ -317,7 +317,7 @@ mem_heap_get_top(
buf = (byte*)block + mem_block_get_free(block) - MEM_SPACE_NEEDED(n);
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ut_ad(mem_block_get_start(block) <=(ulint)((byte*)buf - (byte*)block));
/* In the debug version, advance buf to point at the storage which
@@ -327,7 +327,7 @@ mem_heap_get_top(
/* Check that the field lengths agree */
ut_ad(n == (ulint)mem_field_header_get_len(buf));
- #endif
+#endif
return(buf);
}
@@ -351,13 +351,13 @@ mem_heap_free_top(
/* Subtract the free field of block */
mem_block_set_free(block, mem_block_get_free(block)
- MEM_SPACE_NEEDED(n));
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ut_ad(mem_block_get_start(block) <= mem_block_get_free(block));
/* In the debug version check the consistency, and erase field */
mem_field_erase((byte*)block + mem_block_get_free(block), n);
- #endif
+#endif
/* If free == start, we may free the block if it is not the first
one */
@@ -417,7 +417,7 @@ mem_heap_create_func(
/* Add the created block itself as the first block in the list */
UT_LIST_ADD_FIRST(list, block->base, block);
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
if (block == NULL) {
@@ -426,7 +426,7 @@ mem_heap_create_func(
mem_hash_insert(block, file_name, line);
- #endif
+#endif
return(block);
}
@@ -452,14 +452,14 @@ mem_heap_free_func(
block = UT_LIST_GET_LAST(heap->base);
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* In the debug version remove the heap from the hash table of heaps
and check its consistency */
mem_hash_remove(heap, file_name, line);
- #endif
+#endif
if (heap->free_block) {
mem_heap_free_block_free(heap);
@@ -493,18 +493,6 @@ mem_alloc_func(
ulint line /* in: line where created */
)
{
-#ifdef notdefined
- void* buf;
-
- buf = mem_area_alloc(n, mem_comm_pool);
-
-#ifdef UNIV_SET_MEM_TO_ZERO
- memset(buf, '\0', n);
-#endif
- return(buf);
-
-#else
-
mem_heap_t* heap;
void* buf;
@@ -525,8 +513,6 @@ mem_alloc_func(
ut_a((byte*)heap == (byte*)buf - MEM_BLOCK_HEADER_SIZE
- MEM_FIELD_HEADER_SIZE);
return(buf);
-
-#endif
}
/*******************************************************************
@@ -542,17 +528,11 @@ mem_free_func(
ulint line /* in: line where created */
)
{
-#ifdef notdefined
-
- mem_area_free(ptr, mem_comm_pool);
-
-#else
mem_heap_t* heap;
heap = (mem_heap_t*)((byte*)ptr - MEM_BLOCK_HEADER_SIZE
- MEM_FIELD_HEADER_SIZE);
mem_heap_free_func(heap, file_name, line);
-#endif
}
/*********************************************************************
diff --git a/innobase/include/mtr0log.h b/innobase/include/mtr0log.h
index da942dd45d7..f50c1dfcb6a 100644
--- a/innobase/include/mtr0log.h
+++ b/innobase/include/mtr0log.h
@@ -32,7 +32,6 @@ mlog_write_dulint(
/*==============*/
byte* ptr, /* in: pointer where to write */
dulint val, /* in: value to write */
- byte type, /* in: MLOG_8BYTES */
mtr_t* mtr); /* in: mini-transaction handle */
/************************************************************
Writes a string to a file page buffered in the buffer pool. Writes the
@@ -133,15 +132,6 @@ mlog_write_initial_log_record_fast(
byte type, /* in: log item type: MLOG_1BYTE, ... */
byte* log_ptr,/* in: pointer to mtr log which has been opened */
mtr_t* mtr); /* in: mtr */
-/****************************************************************
-Writes the contents of a mini-transaction log, if any, to the database log. */
-
-dulint
-mlog_write(
-/*=======*/
- dyn_array_t* mlog, /* in: mlog */
- ibool* modifications); /* out: TRUE if there were
- log items to write */
/************************************************************
Parses an initial log record written by mlog_write_initial_log_record. */
diff --git a/innobase/include/mtr0mtr.h b/innobase/include/mtr0mtr.h
index c47fb54a6f8..9cf592f71e1 100644
--- a/innobase/include/mtr0mtr.h
+++ b/innobase/include/mtr0mtr.h
@@ -132,16 +132,6 @@ void
mtr_commit(
/*=======*/
mtr_t* mtr); /* in: mini-transaction */
-/****************************************************************
-Writes to the database log the full contents of the pages that this mtr is
-the first to modify in the buffer pool. This function is called when the
-database is in the online backup state. */
-
-void
-mtr_log_write_backup_entries(
-/*=========================*/
- mtr_t* mtr, /* in: mini-transaction */
- dulint backup_lsn); /* in: online backup lsn */
/**************************************************************
Sets and returns a savepoint in mtr. */
UNIV_INLINE
@@ -205,7 +195,6 @@ mtr_read_dulint(
/*===========*/
/* out: value read */
byte* ptr, /* in: pointer from where to read */
- ulint type, /* in: MLOG_8BYTES */
mtr_t* mtr); /* in: mini-transaction handle */
/*************************************************************************
This macro locks an rw-lock in s-mode. */
@@ -306,7 +295,12 @@ struct mtr_memo_slot_struct{
/* Mini-transaction handle and buffer */
struct mtr_struct{
+#ifdef UNIV_DEBUG
ulint state; /* MTR_ACTIVE, MTR_COMMITTING, MTR_COMMITTED */
+#define MTR_ACTIVE 12231
+#define MTR_COMMITTING 56456
+#define MTR_COMMITTED 34676
+#endif /* UNIV_DEBUG */
dyn_array_t memo; /* memo stack for locks etc. */
dyn_array_t log; /* mini-transaction log */
ibool modifications;
@@ -321,15 +315,12 @@ struct mtr_struct{
this mtr */
dulint end_lsn;/* end lsn of the possible log entry for
this mtr */
+#ifdef UNIV_DEBUG
ulint magic_n;
-};
-
#define MTR_MAGIC_N 54551
+#endif /* UNIV_DEBUG */
+};
-#define MTR_ACTIVE 12231
-#define MTR_COMMITTING 56456
-#define MTR_COMMITTED 34676
-
#ifndef UNIV_NONINL
#include "mtr0mtr.ic"
#endif
diff --git a/innobase/include/odbc0odbc.h b/innobase/include/odbc0odbc.h
deleted file mode 100644
index 7f842b54b27..00000000000
--- a/innobase/include/odbc0odbc.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/******************************************************
-Innobase ODBC client library additional header
-
-(c) 1998 Innobase Oy
-
-Created 2/22/1998 Heikki Tuuri
-*******************************************************/
-
-#ifndef odbc0odbc_h
-#define odbc0odbc_h
-
-#include "ib_odbc.h"
-
-/* Datagram size in communications */
-#define ODBC_DATAGRAM_SIZE 8192
-
-/* Communication address maximum length in bytes */
-#define ODBC_ADDRESS_SIZE COM_MAX_ADDR_LEN
-
-#endif
diff --git a/innobase/include/os0file.h b/innobase/include/os0file.h
index 5f2d6e3ed21..813e6e72e65 100644
--- a/innobase/include/os0file.h
+++ b/innobase/include/os0file.h
@@ -20,6 +20,9 @@ extern ibool os_do_not_call_flush_at_each_write;
extern ibool os_has_said_disk_full;
extern ibool os_aio_print_debug;
+extern ulint os_file_n_pending_preads;
+extern ulint os_file_n_pending_pwrites;
+
#ifdef __WIN__
/* We define always WIN_ASYNC_IO, and check at run-time whether
@@ -60,6 +63,7 @@ log. */
#define OS_FILE_CREATE 52
#define OS_FILE_OVERWRITE 53
#define OS_FILE_OPEN_RAW 54
+#define OS_FILE_CREATE_PATH 55
#define OS_FILE_READ_ONLY 333
#define OS_FILE_READ_WRITE 444
@@ -228,7 +232,9 @@ os_file_create_simple(
string */
ulint create_mode,/* in: OS_FILE_OPEN if an existing file is opened
(if does not exist, error), or OS_FILE_CREATE if a new
- file is created (if exists, error) */
+ file is created (if exists, error), or
+ OS_FILE_CREATE_PATH if new file (if exists, error) and
+ subdirectories along its path are created (if needed)*/
ulint access_type,/* in: OS_FILE_READ_ONLY or OS_FILE_READ_WRITE */
ibool* success);/* out: TRUE if succeed, FALSE if error */
/********************************************************************
@@ -421,6 +427,59 @@ os_file_write(
ulint offset_high,/* in: most significant 32 bits of
offset */
ulint n); /* in: number of bytes to write */
+/***********************************************************************
+Check the existence and type of the given file. */
+
+ibool
+os_file_status(
+/*===========*/
+ /* out: TRUE if call succeeded */
+ char * path, /* in: pathname of the file */
+ ibool * exists, /* out: TRUE if file exists */
+ os_file_type_t* type); /* out: type of the file (if it exists) */
+/********************************************************************
+The function os_file_dirname returns a directory component of a
+null-terminated pathname string. In the usual case, dirname returns
+the string up to, but not including, the final '/', and basename
+is the component following the final '/'. Trailing '/' charac­
+ters are not counted as part of the pathname.
+
+If path does not contain a slash, dirname returns the string ".".
+
+Concatenating the string returned by dirname, a "/", and the basename
+yields a complete pathname.
+
+The return value is a copy of the directory component of the pathname.
+The copy is allocated from heap. It is the caller responsibility
+to free it after it is no longer needed.
+
+The following list of examples (taken from SUSv2) shows the strings
+returned by dirname and basename for different paths:
+
+ path dirname basename
+ "/usr/lib" "/usr" "lib"
+ "/usr/" "/" "usr"
+ "usr" "." "usr"
+ "/" "/" "/"
+ "." "." "."
+ ".." "." ".."
+*/
+
+char*
+os_file_dirname(
+/*============*/
+ /* out, own: directory component of the
+ pathname */
+ char* path); /* in: pathname */
+/********************************************************************
+Creates all missing subdirectories along the given path. */
+
+ibool
+os_file_create_subdirs_if_needed(
+/*=============================*/
+ /* out: TRUE if call succeeded
+ FALSE otherwise */
+ char* path); /* in: path name */
/****************************************************************************
Initializes the asynchronous io system. Creates separate aio array for
non-ibuf read and write, a third aio array for the ibuf i/o, with just one
diff --git a/innobase/include/os0proc.h b/innobase/include/os0proc.h
index 664952bd166..d0d3cf82e38 100644
--- a/innobase/include/os0proc.h
+++ b/innobase/include/os0proc.h
@@ -102,37 +102,6 @@ os_mem_alloc_nocache(
/*=================*/
/* out: allocated memory */
ulint n); /* in: number of bytes */
-#ifdef notdefined
-/********************************************************************
-Creates a new process. */
-
-ibool
-os_process_create(
-/*==============*/
- char* name, /* in: name of the executable to start
- or its full path name */
- char* cmd, /* in: command line for the starting
- process, or NULL if no command line
- specified */
- os_process_t* proc, /* out: handle to the process */
- os_process_id_t* id); /* out: process id */
-/**************************************************************************
-Exits a process. */
-
-void
-os_process_exit(
-/*============*/
- ulint code); /* in: exit code */
-/**************************************************************************
-Gets process exit code. */
-
-ibool
-os_process_get_exit_code(
-/*=====================*/
- /* out: TRUE if succeed, FALSE if fail */
- os_process_t proc, /* in: handle to the process */
- ulint* code); /* out: exit code */
-#endif
/********************************************************************
Sets the priority boost for threads released from waiting within the current
process. */
diff --git a/innobase/include/os0thread.h b/innobase/include/os0thread.h
index 554ca0563e4..6603229e524 100644
--- a/innobase/include/os0thread.h
+++ b/innobase/include/os0thread.h
@@ -99,13 +99,6 @@ os_thread_t
os_thread_get_curr(void);
/*====================*/
/*********************************************************************
-Waits for a thread to terminate. */
-
-void
-os_thread_wait(
-/*===========*/
- os_thread_t thread); /* in: thread to wait */
-/*********************************************************************
Advises the os to give up remainder of the thread's time slice. */
void
diff --git a/innobase/include/page0cur.h b/innobase/include/page0cur.h
index c3f0decdb4b..c85669ed4df 100644
--- a/innobase/include/page0cur.h
+++ b/innobase/include/page0cur.h
@@ -32,8 +32,11 @@ Created 10/4/1994 Heikki Tuuri
which extend it */
#define PAGE_CUR_DBG 6
-
+#ifdef PAGE_CUR_ADAPT
+# ifdef UNIV_SEARCH_PERF_STAT
extern ulint page_cur_short_succ;
+# endif /* UNIV_SEARCH_PERF_STAT */
+#endif /* PAGE_CUR_ADAPT */
/*************************************************************
Gets pointer to the page frame where the cursor is positioned. */
diff --git a/innobase/include/pars0pars.h b/innobase/include/pars0pars.h
index e08b071e246..8ff226ebbd0 100644
--- a/innobase/include/pars0pars.h
+++ b/innobase/include/pars0pars.h
@@ -21,7 +21,9 @@ extern int yydebug;
/* If the following is set TRUE, the lexer will print the SQL string
as it tokenizes it */
+#ifdef UNIV_SQL_DEBUG
extern ibool pars_print_lexed;
+#endif /* UNIV_SQL_DEBUG */
/* Global variable used while parsing a single procedure or query : the code is
NOT re-entrant */
@@ -390,41 +392,18 @@ pars_procedure_definition(
table */
sym_node_t* param_list, /* in: parameter declaration list */
que_node_t* stat_list); /* in: statement list */
-/*****************************************************************
-Reads stored procedure input parameter values from a buffer. */
-
-void
-pars_proc_read_input_params_from_buf(
-/*=================================*/
- que_t* graph, /* in: query graph which contains a stored procedure */
- byte* buf); /* in: buffer */
-/*****************************************************************
-Writes stored procedure output parameter values to a buffer. */
-ulint
-pars_proc_write_output_params_to_buf(
-/*=================================*/
- byte* buf, /* in: buffer which must be big enough */
- que_t* graph); /* in: query graph which contains a stored procedure */
/*****************************************************************
Parses a stored procedure call, when this is not within another stored
-procedure, that is, the client issues a procedure call directly. */
+procedure, that is, the client issues a procedure call directly.
+In MySQL/InnoDB, stored InnoDB procedures are invoked via the
+parsed procedure tree, not via InnoDB SQL, so this function is not used. */
que_fork_t*
pars_stored_procedure_call(
/*=======================*/
/* out: query graph */
sym_node_t* sym_node); /* in: stored procedure name */
-/*****************************************************************
-Writes info about query parameter markers (denoted with '?' in ODBC) into a
-buffer. */
-
-ulint
-pars_write_query_param_info(
-/*========================*/
- /* out: number of bytes used for info in buf */
- byte* buf, /* in: buffer which must be big enough */
- que_fork_t* graph); /* in: parsed query graph */
/**********************************************************************
Completes a query graph by adding query thread and fork nodes
above it and prepares the graph for running. The fork created is of
diff --git a/innobase/include/que0que.h b/innobase/include/que0que.h
index a3ed18e2b14..bcd7aed7e88 100644
--- a/innobase/include/que0que.h
+++ b/innobase/include/que0que.h
@@ -216,9 +216,7 @@ que_fork_start_command(
QUE_THR_RUNNING state, or NULL; the query
thread should be executed by que_run_threads
by the caller */
- que_fork_t* fork, /* in: a query fork */
- ulint command,/* in: command SESS_COMM_FETCH_NEXT, ... */
- ulint param); /* in: possible parameter to the command */
+ que_fork_t* fork); /* in: a query fork */
/***************************************************************************
Gets the trx of a query thread. */
UNIV_INLINE
@@ -309,22 +307,6 @@ que_thr_peek_stop(
mutex reserved is necessary before deciding
the actual stopping */
que_thr_t* thr); /* in: query thread */
-/***************************************************************************
-Returns TRUE if the query graph is for a SELECT statement. */
-UNIV_INLINE
-ibool
-que_graph_is_select(
-/*================*/
- /* out: TRUE if a select */
- que_t* graph); /* in: graph */
-/**************************************************************************
-Prints info of an SQL query graph node. */
-
-void
-que_node_print_info(
-/*================*/
- que_node_t* node); /* in: query graph node */
-
/* Query graph query thread node: the fields are protected by the kernel
mutex with the exceptions named below */
@@ -388,11 +370,6 @@ struct que_fork_struct{
sym_tab_t* sym_tab; /* symbol table of the query,
generated by the parser, or NULL
if the graph was created 'by hand' */
- ulint id; /* id of this query graph */
- ulint command; /* command currently executed in the
- graph */
- ulint param; /* possible command parameter */
-
/* The following cur_... fields are relevant only in a select graph */
ulint cur_end; /* QUE_CUR_NOT_DEFINED, QUE_CUR_START,
diff --git a/innobase/include/que0que.ic b/innobase/include/que0que.ic
index ae4ed10560f..a63922f8c80 100644
--- a/innobase/include/que0que.ic
+++ b/innobase/include/que0que.ic
@@ -238,21 +238,3 @@ que_thr_peek_stop(
return(FALSE);
}
-
-/***************************************************************************
-Returns TRUE if the query graph is for a SELECT statement. */
-UNIV_INLINE
-ibool
-que_graph_is_select(
-/*================*/
- /* out: TRUE if a select */
- que_t* graph) /* in: graph */
-{
- if (graph->fork_type == QUE_FORK_SELECT_SCROLL
- || graph->fork_type == QUE_FORK_SELECT_NON_SCROLL) {
-
- return(TRUE);
- }
-
- return(FALSE);
-}
diff --git a/innobase/include/rem0cmp.ic b/innobase/include/rem0cmp.ic
index ebf513f538c..75cb3ef04e8 100644
--- a/innobase/include/rem0cmp.ic
+++ b/innobase/include/rem0cmp.ic
@@ -9,24 +9,6 @@ Created 7/1/1994 Heikki Tuuri
/*****************************************************************
This function is used to compare two data fields for which we know the
data type. */
-
-int
-cmp_data_data_slow(
-/*===============*/
- /* out: 1, 0, -1, if data1 is greater, equal,
- less than data2, respectively */
- dtype_t* cur_type,/* in: data type of the fields */
- byte* data1, /* in: data field (== a pointer to a memory
- buffer) */
- ulint len1, /* in: data field length or UNIV_SQL_NULL */
- byte* data2, /* in: data field (== a pointer to a memory
- buffer) */
- ulint len2); /* in: data field length or UNIV_SQL_NULL */
-
-
-/*****************************************************************
-This function is used to compare two data fields for which we know the
-data type. */
UNIV_INLINE
int
cmp_data_data(
diff --git a/innobase/include/row0ins.h b/innobase/include/row0ins.h
index a5b4b74e7fc..f3f0b7e8eca 100644
--- a/innobase/include/row0ins.h
+++ b/innobase/include/row0ins.h
@@ -145,10 +145,11 @@ struct ins_node_struct{
entry_list and sys fields are stored here;
if this is NULL, entry list should be created
and buffers for sys fields in row allocated */
+#ifdef UNIV_DEBUG
ulint magic_n;
-};
-
#define INS_NODE_MAGIC_N 15849075
+#endif /* UNIV_DEBUG */
+};
/* Insert node types */
#define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
diff --git a/innobase/include/row0mysql.h b/innobase/include/row0mysql.h
index fade3709631..32a0c8b5d75 100644
--- a/innobase/include/row0mysql.h
+++ b/innobase/include/row0mysql.h
@@ -510,13 +510,15 @@ struct row_prebuilt_struct {
byte* ins_upd_rec_buff;/* buffer for storing data converted
to the Innobase format from the MySQL
format */
- ibool hint_no_need_to_fetch_extra_cols;
- /* normally this is TRUE, but
- MySQL will set this to FALSE
- if we might be required to fetch also
- other columns than mentioned in the
- query: the clustered index column(s),
- or an auto-increment column*/
+ ulint hint_need_to_fetch_extra_cols;
+ /* normally this is set to 0; if this
+ is set to ROW_RETRIEVE_PRIMARY_KEY,
+ then we should at least retrieve all
+ columns in the primary key; if this
+ is set to ROW_RETRIEVE_ALL_COLS, then
+ we must retrieve all columns in the
+ key (if read_just_key == 1), or all
+ columns in the table */
upd_node_t* upd_node; /* Innobase SQL update node used
to perform updates and deletes */
que_fork_t* ins_graph; /* Innobase SQL query graph used
@@ -572,6 +574,11 @@ struct row_prebuilt_struct {
#define ROW_MYSQL_DUMMY_TEMPLATE 3 /* dummy template used in
row_scan_and_check_index */
+/* Values for hint_need_to_fetch_extra_cols */
+#define ROW_RETRIEVE_PRIMARY_KEY 1
+#define ROW_RETRIEVE_ALL_COLS 2
+
+
#ifndef UNIV_NONINL
#include "row0mysql.ic"
#endif
diff --git a/innobase/include/row0row.h b/innobase/include/row0row.h
index d1befbbbad3..3956f3c1692 100644
--- a/innobase/include/row0row.h
+++ b/innobase/include/row0row.h
@@ -68,16 +68,6 @@ row_build_index_entry(
dict_index_t* index, /* in: index on the table */
mem_heap_t* heap); /* in: memory heap from which the memory for
the index entry is allocated */
-/*********************************************************************
-Builds an index entry from a row. */
-
-void
-row_build_index_entry_to_tuple(
-/*===========================*/
- dtuple_t* entry, /* in/out: index entry; the dtuple must have
- enough fields for the index! */
- dtuple_t* row, /* in: row */
- dict_index_t* index); /* in: index on the table */
/***********************************************************************
An inverse function to dict_row_build_index_entry. Builds a row from a
record in a clustered index. */
@@ -103,21 +93,6 @@ row_build(
mem_heap_t* heap); /* in: memory heap from which the memory
needed is allocated */
/***********************************************************************
-An inverse function to dict_row_build_index_entry. Builds a row from a
-record in a clustered index. */
-
-void
-row_build_to_tuple(
-/*===============*/
- dtuple_t* row, /* in/out: row built; see the NOTE below! */
- dict_index_t* index, /* in: clustered index */
- rec_t* rec); /* in: record in the clustered index;
- NOTE: the data fields in the row will point
- directly into this record, therefore,
- the buffer page of this record must be
- at least s-latched and the latch held
- as long as the row dtuple is used! */
-/***********************************************************************
Converts an index record to a typed data tuple. */
dtuple_t*
diff --git a/innobase/include/row0upd.h b/innobase/include/row0upd.h
index f5e0a88231f..687e90deee5 100644
--- a/innobase/include/row0upd.h
+++ b/innobase/include/row0upd.h
@@ -384,10 +384,11 @@ struct upd_node_struct{
sym_node_t* table_sym;/* table node in symbol table */
que_node_t* col_assign_list;
/* column assignment list */
+#ifdef UNIV_DEBUG
ulint magic_n;
-};
-
#define UPD_NODE_MAGIC_N 1579975
+#endif /* UNIV_DEBUG */
+};
/* Node execution states */
#define UPD_NODE_SET_IX_LOCK 1 /* execution came to the node from
diff --git a/innobase/include/row0upd.ic b/innobase/include/row0upd.ic
index 1878431d1a4..6b9deeac5e3 100644
--- a/innobase/include/row0upd.ic
+++ b/innobase/include/row0upd.ic
@@ -107,8 +107,10 @@ row_upd_rec_sys_fields(
dulint roll_ptr)/* in: roll ptr of the undo log record */
{
ut_ad(index->type & DICT_CLUSTERED);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!buf_block_align(rec)->is_hashed
|| rw_lock_own(&btr_search_latch, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
row_set_rec_trx_id(rec, index, trx->id);
row_set_rec_roll_ptr(rec, index, roll_ptr);
diff --git a/innobase/include/srv0srv.h b/innobase/include/srv0srv.h
index 6e47c468d26..8aac71de2a9 100644
--- a/innobase/include/srv0srv.h
+++ b/innobase/include/srv0srv.h
@@ -13,7 +13,6 @@ Created 10/10/1995 Heikki Tuuri
#include "univ.i"
#include "sync0sync.h"
#include "os0sync.h"
-#include "com0com.h"
#include "que0types.h"
#include "trx0types.h"
@@ -216,13 +215,7 @@ srv_boot(void);
/*==========*/
/* out: DB_SUCCESS or error code */
/*************************************************************************
-Initializes the server. */
-
-void
-srv_init(void);
-/*==========*/
-/*************************************************************************
-Frees the OS fast mutex created in srv_init(). */
+Frees the OS fast mutex created in srv_boot(). */
void
srv_free(void);
@@ -272,23 +265,6 @@ srv_master_thread(
/* out: a dummy parameter */
void* arg); /* in: a dummy parameter required by
os_thread_create */
-/*************************************************************************
-Reads a keyword and a value from a file. */
-
-ulint
-srv_read_init_val(
-/*==============*/
- /* out: DB_SUCCESS or error code */
- FILE* initfile, /* in: file pointer */
- char* keyword, /* in: keyword before value(s), or NULL if
- no keyword read */
- char* str_buf, /* in/out: buffer for a string value to read,
- buffer size must be 10000 bytes, if NULL
- then not read */
- ulint* num_val, /* out: numerical value to read, if NULL
- then not read */
- ibool print_not_err); /* in: if TRUE, then we will not print
- error messages to console */
/***********************************************************************
Tells the Innobase server that there has been activity in the database
and wakes up the master thread if it is suspended (not sleeping). Used
@@ -428,9 +404,6 @@ struct srv_sys_struct{
os_event_t operational; /* created threads must wait for the
server to become operational by
waiting for this event */
- com_endpoint_t* endpoint; /* the communication endpoint of the
- server */
-
srv_table_t* threads; /* server thread table */
UT_LIST_BASE_NODE_T(que_thr_t)
tasks; /* task queue */
diff --git a/innobase/include/srv0start.h b/innobase/include/srv0start.h
index 97a59fd14c7..0074de537c3 100644
--- a/innobase/include/srv0start.h
+++ b/innobase/include/srv0start.h
@@ -21,16 +21,6 @@ srv_normalize_path_for_win(
/*=======================*/
char* str); /* in/out: null-terminated character string */
/*************************************************************************
-Adds a slash or a backslash to the end of a string if it is missing
-and the string is not empty. */
-
-char*
-srv_add_path_separator_if_needed(
-/*=============================*/
- /* out, own: string which has the separator if the
- string is not empty */
- char* str); /* in: null-terminated character string */
-/*************************************************************************
Reads the data files and their sizes from a character string given in
the .cnf file. */
diff --git a/innobase/include/sync0rw.h b/innobase/include/sync0rw.h
index 5aa3dcdffc3..d71691b4353 100644
--- a/innobase/include/sync0rw.h
+++ b/innobase/include/sync0rw.h
@@ -25,13 +25,16 @@ smaller than 30 and the order of the numerical values like below! */
#define RW_NO_LATCH 3
typedef struct rw_lock_struct rw_lock_t;
+#ifdef UNIV_SYNC_DEBUG
typedef struct rw_lock_debug_struct rw_lock_debug_t;
+#endif /* UNIV_SYNC_DEBUG */
typedef UT_LIST_BASE_NODE_T(rw_lock_t) rw_lock_list_t;
extern rw_lock_list_t rw_lock_list;
extern mutex_t rw_lock_list_mutex;
+#ifdef UNIV_SYNC_DEBUG
/* The global mutex which protects debug info lists of all rw-locks.
To modify the debug info list of an rw-lock, this mutex has to be
@@ -42,6 +45,7 @@ extern os_event_t rw_lock_debug_event; /* If deadlock detection does
may wait for this event */
extern ibool rw_lock_debug_waiters; /* This is set to TRUE, if
there may be waiters for the event */
+#endif /* UNIV_SYNC_DEBUG */
extern ulint rw_s_system_call_count;
extern ulint rw_s_spin_wait_count;
@@ -327,6 +331,7 @@ ulint
rw_lock_get_reader_count(
/*=====================*/
rw_lock_t* lock);
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks if the thread has locked the rw-lock in the specified mode, with
the pass value == 0. */
@@ -337,6 +342,7 @@ rw_lock_own(
rw_lock_t* lock, /* in: rw-lock */
ulint lock_type); /* in: lock type: RW_LOCK_SHARED,
RW_LOCK_EX */
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Checks if somebody has locked the rw-lock in the specified mode. */
@@ -346,6 +352,7 @@ rw_lock_is_locked(
rw_lock_t* lock, /* in: rw-lock */
ulint lock_type); /* in: lock type: RW_LOCK_SHARED,
RW_LOCK_EX */
+#ifdef UNIV_SYNC_DEBUG
/*******************************************************************
Prints debug info of an rw-lock. */
@@ -392,6 +399,7 @@ void
rw_lock_debug_print(
/*================*/
rw_lock_debug_t* info); /* in: debug struct */
+#endif /* UNIV_SYNC_DEBUG */
/* NOTE! The structure appears here only for the compiler to know its size.
Do not use its fields directly! The structure used in the spin lock
@@ -434,10 +442,12 @@ struct rw_lock_struct {
UT_LIST_NODE_T(rw_lock_t) list;
/* All allocated rw locks are put into a
list */
+#ifdef UNIV_SYNC_DEBUG
UT_LIST_BASE_NODE_T(rw_lock_debug_t) debug_list;
/* In the debug version: pointer to the debug
info list of the lock */
- ulint level; /* Debug version: level in the global latching
+#endif /* UNIV_SYNC_DEBUG */
+ ulint level; /* Level in the global latching
order; default SYNC_LEVEL_NONE */
char* cfile_name; /* File name where lock created */
ulint cline; /* Line where created */
@@ -450,6 +460,7 @@ struct rw_lock_struct {
#define RW_LOCK_MAGIC_N 22643
+#ifdef UNIV_SYNC_DEBUG
/* The structure for storing debug info of an rw-lock */
struct rw_lock_debug_struct {
@@ -464,6 +475,7 @@ struct rw_lock_debug_struct {
/* Debug structs are linked in a two-way
list */
};
+#endif /* UNIV_SYNC_DEBUG */
#ifndef UNIV_NONINL
#include "sync0rw.ic"
diff --git a/innobase/include/sync0rw.ic b/innobase/include/sync0rw.ic
index 36ef0a985ed..8fc93f4a9da 100644
--- a/innobase/include/sync0rw.ic
+++ b/innobase/include/sync0rw.ic
@@ -20,6 +20,7 @@ rw_lock_s_lock_spin(
be passed to another thread to unlock */
char* file_name,/* in: file name where lock requested */
ulint line); /* in: line where requested */
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Inserts the debug information for an rw-lock. */
@@ -40,7 +41,7 @@ rw_lock_remove_debug_info(
rw_lock_t* lock, /* in: rw-lock */
ulint pass, /* in: pass value */
ulint lock_type); /* in: lock type */
-
+#endif /* UNIV_SYNC_DEBUG */
/************************************************************************
Accessor functions for rw lock. */
@@ -132,19 +133,19 @@ rw_lock_s_lock_low(
char* file_name, /* in: file name where lock requested */
ulint line) /* in: line where requested */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(rw_lock_get_mutex(lock)));
-
+#endif /* UNIV_SYNC_DEBUG */
/* Check if the writer field is free */
if (lock->writer == RW_LOCK_NOT_LOCKED) {
/* Set the shared lock by incrementing the reader count */
lock->reader_count++;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, pass, RW_LOCK_SHARED, file_name,
line);
- #endif
-
+#endif
lock->last_s_file_name = file_name;
lock->last_s_line = line;
@@ -175,9 +176,9 @@ rw_lock_s_lock_direct(
lock->last_s_file_name = file_name;
lock->last_s_line = line;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, 0, RW_LOCK_SHARED, file_name, line);
- #endif
+#endif
}
/**********************************************************************
@@ -204,9 +205,9 @@ rw_lock_x_lock_direct(
lock->last_x_file_name = file_name;
lock->last_x_line = line;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, 0, RW_LOCK_EX, file_name, line);
- #endif
+#endif
}
/**********************************************************************
@@ -236,7 +237,9 @@ rw_lock_s_lock_func(
the threads which have s-locked a latch. This would use some CPU
time. */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!rw_lock_own(lock, RW_LOCK_SHARED)); /* see NOTE above */
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(rw_lock_get_mutex(lock));
@@ -275,10 +278,10 @@ rw_lock_s_lock_func_nowait(
/* Set the shared lock by incrementing the reader count */
lock->reader_count++;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, 0, RW_LOCK_SHARED, file_name,
line);
- #endif
+#endif
lock->last_s_file_name = file_name;
lock->last_s_line = line;
@@ -320,9 +323,9 @@ rw_lock_x_lock_func_nowait(
lock->writer_count++;
lock->pass = 0;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, 0, RW_LOCK_EX, file_name, line);
- #endif
+#endif
lock->last_x_file_name = file_name;
lock->last_x_line = line;
@@ -361,9 +364,9 @@ rw_lock_s_unlock_func(
ut_a(lock->reader_count > 0);
lock->reader_count--;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_remove_debug_info(lock, pass, RW_LOCK_SHARED);
- #endif
+#endif
/* If there may be waiters and this was the last s-lock,
signal the object */
@@ -402,9 +405,9 @@ rw_lock_s_unlock_direct(
lock->reader_count--;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_remove_debug_info(lock, 0, RW_LOCK_SHARED);
- #endif
+#endif
ut_ad(!lock->waiters);
ut_ad(rw_lock_validate(lock));
@@ -442,9 +445,9 @@ rw_lock_x_unlock_func(
rw_lock_set_writer(lock, RW_LOCK_NOT_LOCKED);
}
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_remove_debug_info(lock, pass, RW_LOCK_EX);
- #endif
+#endif
/* If there may be waiters, signal the lock */
if (lock->waiters && (lock->writer_count == 0)) {
@@ -486,9 +489,9 @@ rw_lock_x_unlock_direct(
rw_lock_set_writer(lock, RW_LOCK_NOT_LOCKED);
}
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_remove_debug_info(lock, 0, RW_LOCK_EX);
- #endif
+#endif
ut_ad(!lock->waiters);
ut_ad(rw_lock_validate(lock));
diff --git a/innobase/include/sync0sync.h b/innobase/include/sync0sync.h
index 330b6b77b08..3a7203bbb56 100644
--- a/innobase/include/sync0sync.h
+++ b/innobase/include/sync0sync.h
@@ -185,6 +185,7 @@ sync_thread_levels_empty_gen(
allowed to be owned by the thread,
also purge_is_running mutex is
allowed */
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks that the current thread owns the mutex. Works only
in the debug version. */
@@ -217,6 +218,7 @@ Prints debug info of currently reserved mutexes. */
void
mutex_list_print_info(void);
/*========================*/
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
NOT to be used outside this module except in debugging! Gets the value
of the lock word. */
@@ -225,6 +227,7 @@ ulint
mutex_get_lock_word(
/*================*/
mutex_t* mutex); /* in: mutex */
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
NOT to be used outside this module except in debugging! Gets the waiters
field in a mutex. */
@@ -234,15 +237,7 @@ mutex_get_waiters(
/*==============*/
/* out: value to set */
mutex_t* mutex); /* in: mutex */
-/**********************************************************************
-Implements the memory barrier operation which makes a serialization point to
-the instruction flow. This is needed because the Pentium may speculatively
-execute reads before preceding writes are committed. We could also use here
-any LOCKed instruction (see Intel Software Dev. Manual, Vol. 3). */
-
-void
-mutex_fence(void);
-/*=============*/
+#endif /* UNIV_SYNC_DEBUG */
/*
LATCHING ORDER WITHIN THE DATABASE
@@ -451,13 +446,13 @@ struct mutex_struct {
Otherwise, this is 0. */
UT_LIST_NODE_T(mutex_t) list; /* All allocated mutexes are put into
a list. Pointers to the next and prev. */
+#ifdef UNIV_SYNC_DEBUG
+ const char* file_name; /* File where the mutex was locked */
+ ulint line; /* Line where the mutex was locked */
os_thread_id_t thread_id; /* Debug version: The thread id of the
thread which locked the mutex. */
- char* file_name; /* Debug version: File name where the mutex
- was locked */
- ulint line; /* Debug version: Line where the mutex was
- locked */
- ulint level; /* Debug version: level in the global latching
+#endif /* UNIV_SYNC_DEBUG */
+ ulint level; /* Level in the global latching
order; default SYNC_LEVEL_NONE */
char* cfile_name; /* File name where mutex created */
ulint cline; /* Line where created */
diff --git a/innobase/include/sync0sync.ic b/innobase/include/sync0sync.ic
index c11cc0d196e..758c8524f66 100644
--- a/innobase/include/sync0sync.ic
+++ b/innobase/include/sync0sync.ic
@@ -25,6 +25,7 @@ mutex_spin_wait(
mutex_t* mutex, /* in: pointer to mutex */
char* file_name,/* in: file name where mutex requested */
ulint line); /* in: line where requested */
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Sets the debug information for a reserved mutex. */
@@ -34,6 +35,7 @@ mutex_set_debug_info(
mutex_t* mutex, /* in: mutex */
char* file_name, /* in: file where requested */
ulint line); /* in: line where requested */
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Releases the threads waiting in the primary wait array for this mutex. */
@@ -200,9 +202,9 @@ mutex_exit(
/*=======*/
mutex_t* mutex) /* in: pointer to mutex */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(mutex));
-#ifdef UNIV_SYNC_DEBUG
mutex->thread_id = ULINT_UNDEFINED;
sync_thread_reset_level(mutex);
@@ -249,14 +251,9 @@ mutex_enter_func(
the atomic test_and_set; we could peek, and possibly save time. */
if (!mutex_test_and_set(mutex)) {
-
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
mutex_set_debug_info(mutex, file_name, line);
- #endif
-
- mutex->file_name = file_name;
- mutex->line = line;
-
+#endif
return; /* Succeeded! */
}
diff --git a/innobase/include/trx0rseg.ic b/innobase/include/trx0rseg.ic
index 6b242b66c09..35e927f5e79 100644
--- a/innobase/include/trx0rseg.ic
+++ b/innobase/include/trx0rseg.ic
@@ -24,7 +24,9 @@ trx_rsegf_get(
header = TRX_RSEG + buf_page_get(space, page_no, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(header, SYNC_RSEG_HEADER);
+#endif /* UNIV_SYNC_DEBUG */
return(header);
}
@@ -45,7 +47,9 @@ trx_rsegf_get_new(
header = TRX_RSEG + buf_page_get(space, page_no, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(header, SYNC_RSEG_HEADER_NEW);
+#endif /* UNIV_SYNC_DEBUG */
return(header);
}
@@ -64,7 +68,7 @@ trx_rsegf_get_nth_undo(
if (n >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: trying to get slot %lu of rseg\n", (unsigned long) n);
- ut_a(0);
+ ut_error;
}
return(mtr_read_ulint(rsegf + TRX_RSEG_UNDO_SLOTS +
@@ -85,7 +89,7 @@ trx_rsegf_set_nth_undo(
if (n >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: trying to set slot %lu of rseg\n", (unsigned long) n);
- ut_a(0);
+ ut_error;
}
mlog_write_ulint(rsegf + TRX_RSEG_UNDO_SLOTS + n * TRX_RSEG_SLOT_SIZE,
diff --git a/innobase/include/trx0sys.ic b/innobase/include/trx0sys.ic
index 343e6d7c2fa..8f455e554ea 100644
--- a/innobase/include/trx0sys.ic
+++ b/innobase/include/trx0sys.ic
@@ -60,7 +60,9 @@ trx_sys_get_nth_rseg(
trx_sys_t* sys, /* in: trx system */
ulint n) /* in: index of slot */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(n < TRX_SYS_N_RSEGS);
return(sys->rseg_array[n]);
@@ -98,7 +100,9 @@ trx_sysf_get(
header = TRX_SYS + buf_page_get(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(header, SYNC_TRX_SYS_HEADER);
+#endif /* UNIV_SYNC_DEBUG */
return(header);
}
@@ -115,7 +119,9 @@ trx_sysf_rseg_get_space(
ulint i, /* in: slot index == rseg id */
mtr_t* mtr) /* in: mtr */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
@@ -138,7 +144,9 @@ trx_sysf_rseg_get_page_no(
mtr_t* mtr) /* in: mtr */
{
ut_ad(sys_header);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(i < TRX_SYS_N_RSEGS);
return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
@@ -158,7 +166,9 @@ trx_sysf_rseg_set_space(
ulint space, /* in: space id */
mtr_t* mtr) /* in: mtr */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
@@ -182,7 +192,9 @@ trx_sysf_rseg_set_page_no(
slot is reset to unused */
mtr_t* mtr) /* in: mtr */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(sys_header);
ut_ad(i < TRX_SYS_N_RSEGS);
@@ -236,7 +248,9 @@ trx_get_on_id(
{
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
@@ -266,7 +280,9 @@ trx_list_get_min_trx_id(void)
{
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx = UT_LIST_GET_LAST(trx_sys->trx_list);
@@ -289,7 +305,9 @@ trx_is_active(
{
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (ut_dulint_cmp(trx_id, trx_list_get_min_trx_id()) < 0) {
@@ -325,7 +343,9 @@ trx_sys_get_new_trx_id(void)
{
dulint id;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* VERY important: after the database is started, max_trx_id value is
divisible by TRX_SYS_TRX_ID_WRITE_MARGIN, and the following if
@@ -355,7 +375,9 @@ trx_sys_get_new_trx_no(void)
/*========================*/
/* out: new, allocated trx number */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
return(trx_sys_get_new_trx_id());
}
diff --git a/innobase/include/trx0trx.h b/innobase/include/trx0trx.h
index 6b08b674db8..d9b91ee62dc 100644
--- a/innobase/include/trx0trx.h
+++ b/innobase/include/trx0trx.h
@@ -203,13 +203,9 @@ trx_sig_send(
ulint type, /* in: signal type */
ulint sender, /* in: TRX_SIG_SELF or
TRX_SIG_OTHER_SESS */
- ibool reply, /* in: TRUE if the sender of the signal
- wants reply after the operation induced
- by the signal is completed; if type
- is TRX_SIG_END_WAIT, this must be
- FALSE */
que_thr_t* receiver_thr, /* in: query thread which wants the
- reply, or NULL */
+ reply, or NULL; if type is
+ TRX_SIG_END_WAIT, this must be NULL */
trx_savept_t* savept, /* in: possible rollback savepoint, or
NULL */
que_thr_t** next_thr); /* in/out: next query thread to run;
@@ -225,7 +221,6 @@ been handled. */
void
trx_sig_reply(
/*==========*/
- trx_t* trx, /* in: trx handle */
trx_sig_t* sig, /* in: signal */
que_thr_t** next_thr); /* in/out: next query thread to run;
if the value which is passed in is
@@ -297,15 +292,9 @@ struct trx_sig_struct{
TRX_SIG_BEING_HANDLED */
ulint sender; /* TRX_SIG_SELF or
TRX_SIG_OTHER_SESS */
- ibool reply; /* TRUE if the sender of the signal
+ que_thr_t* receiver; /* non-NULL if the sender of the signal
wants reply after the operation induced
- by the signal is completed; if this
- field is TRUE and the receiver field
- below is NULL, then a SUCCESS message
- is sent to the client of the session
- to which this trx belongs */
- que_thr_t* receiver; /* query thread which wants the reply,
- or NULL */
+ by the signal is completed */
trx_savept_t savept; /* possible rollback savepoint */
UT_LIST_NODE_T(trx_sig_t)
signals; /* queue of pending signals to the
diff --git a/innobase/include/trx0undo.h b/innobase/include/trx0undo.h
index 7f0378c68d3..20002076cc3 100644
--- a/innobase/include/trx0undo.h
+++ b/innobase/include/trx0undo.h
@@ -251,20 +251,6 @@ trx_undo_update_cleanup(
page_t* undo_page, /* in: update undo log header page,
x-latched */
mtr_t* mtr); /* in: mtr */
-/**************************************************************************
-Discards an undo log and puts the segment to the list of cached update undo
-log segments. This optimized function is called if there is no need to
-keep the update undo log because there exist no read views and the transaction
-made no delete markings, which would make purge necessary. We restrict this
-to undo logs of size 1 to make things simpler. */
-
-dulint
-trx_undo_update_cleanup_by_discard(
-/*===============================*/
- /* out: log sequence number at which mtr is
- committed */
- trx_t* trx, /* in: trx owning the update undo log */
- mtr_t* mtr); /* in: mtr */
/**********************************************************************
Frees or caches an insert undo log after a transaction commit or rollback.
Knowledge of inserts is not needed after a commit or rollback, therefore
diff --git a/innobase/include/trx0undo.ic b/innobase/include/trx0undo.ic
index bedbc02b00b..a04b234b495 100644
--- a/innobase/include/trx0undo.ic
+++ b/innobase/include/trx0undo.ic
@@ -126,7 +126,9 @@ trx_undo_page_get(
page = buf_page_get(space, page_no, RW_X_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TRX_UNDO_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
return(page);
}
@@ -146,7 +148,9 @@ trx_undo_page_get_s_latched(
page = buf_page_get(space, page_no, RW_S_LATCH, mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TRX_UNDO_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
return(page);
}
diff --git a/innobase/include/univold.i b/innobase/include/univold.i
deleted file mode 100644
index 8bcd28e180f..00000000000
--- a/innobase/include/univold.i
+++ /dev/null
@@ -1,164 +0,0 @@
-/***************************************************************************
-Version control for database, common definitions, and include files
-
-(c) 1994 - 2000 Innobase Oy
-
-Created 1/20/1994 Heikki Tuuri
-****************************************************************************/
-
-#ifndef univ_i
-#define univ_i
-
-#define UNIV_INTEL
-#define UNIV_PENTIUM
-/* If UNIV_WINNT is not defined, we assume Windows 95 */
-
-#define UNIV_WINNT
-#define UNIV_WINNT4
-#define __NT__
-
-#define UNIV_VISUALC
-
-#define __WIN__
-#define _WIN32_WINNT 0x0400
-
-/* DEBUG VERSION CONTROL
- ===================== */
-/* Make a non-inline debug version */
-/*
-#define UNIV_DEBUG
-#define UNIV_MEM_DEBUG
-#define UNIV_SYNC_DEBUG
-#define UNIV_SEARCH_DEBUG
-
-#define UNIV_IBUF_DEBUG
-
-#define UNIV_SEARCH_PERF_STAT
-#define UNIV_SYNC_PERF_STAT
-*/
-#define UNIV_LIGHT_MEM_DEBUG
-
-#define YYDEBUG 1
-/*
-#define UNIV_SQL_DEBUG
-#define UNIV_LOG_DEBUG
-*/
- /* the above option prevents forcing of log to disk
- at a buffer page write: it should be tested with this
- option off; also some ibuf tests are suppressed */
-/*
-#define UNIV_BASIC_LOG_DEBUG
-*/
- /* the above option enables basic recovery debugging:
- new allocated file pages are reset */
-
-/* The debug version is slower, thus we may change the length of test loops
-depending on the UNIV_DBC parameter */
-#ifdef UNIV_DEBUG
-#define UNIV_DBC 1
-#else
-#define UNIV_DBC 100
-#endif
-
-#ifndef UNIV_DEBUG
-/* Definition for inline version */
-
-#ifdef UNIV_VISUALC
-#define UNIV_INLINE __inline
-#elif defined(UNIV_GNUC)
-#define UNIV_INLINE extern __inline__
-#endif
-
-#else
-/* If we want to compile a noninlined version we use the following macro
-definitions: */
-
-#define UNIV_NONINL
-#define UNIV_INLINE
-
-#endif /* UNIV_DEBUG */
-/* If the compiler does not know inline specifier, we use: */
-/*
-#define UNIV_INLINE static
-*/
-
-
-/*
- MACHINE VERSION CONTROL
- =======================
-*/
-
-#ifdef UNIV_PENTIUM
-
-/* In a 32-bit computer word size is 4 */
-#define UNIV_WORD_SIZE 4
-
-/* The following alignment is used in memory allocations in memory heap
-management to ensure correct alignment for doubles etc. */
-#define UNIV_MEM_ALIGNMENT 8
-
-/* The following alignment is used in aligning lints etc. */
-#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
-
-#endif
-
-/*
- DATABASE VERSION CONTROL
- ========================
-*/
-
-/* The universal page size of the database */
-#define UNIV_PAGE_SIZE (2 * 8192)/* NOTE! Currently, this has to be a
- power of 2 and divisible by
- UNIV_MEM_ALIGNMENT */
-
-/* Do non-buffered io in buffer pool read/write operations */
-#define UNIV_NON_BUFFERED_IO
-
-/* Maximum number of parallel threads in a parallelized operation */
-#define UNIV_MAX_PARALLELISM 32
-
-/*
- UNIVERSAL TYPE DEFINITIONS
- ==========================
-*/
-
-
-typedef unsigned char byte;
-
-/* An other basic type we use is unsigned long integer which is intended to be
-equal to the word size of the machine. */
-
-typedef unsigned long int ulint;
-
-typedef long int lint;
-
-/* The following type should be at least a 64-bit floating point number */
-typedef double utfloat;
-
-/* The 'undefined' value for a ulint */
-#define ULINT_UNDEFINED ((ulint)(-1))
-
-/* The undefined 32-bit unsigned integer */
-#define ULINT32_UNDEFINED 0xFFFFFFFF
-
-/* Maximum value for a ulint */
-#define ULINT_MAX ((ulint)(-2))
-
-
-/* Definition of the boolean type */
-typedef ulint bool;
-
-#define TRUE 1
-#define FALSE 0
-
-/* The following number as the length of a logical field means that the field
-has the SQL NULL as its value. */
-#define UNIV_SQL_NULL ULINT_UNDEFINED
-
-#include <stdio.h>
-#include "ut0dbg.h"
-#include "ut0ut.h"
-#include "db0err.h"
-
-#endif
diff --git a/innobase/include/univoldmysql.i b/innobase/include/univoldmysql.i
deleted file mode 100644
index 269b584d073..00000000000
--- a/innobase/include/univoldmysql.i
+++ /dev/null
@@ -1,181 +0,0 @@
-/***************************************************************************
-Version control for database, common definitions, and include files
-
-(c) 1994 - 1996 Innobase Oy
-
-Created 1/20/1994 Heikki Tuuri
-****************************************************************************/
-
-#ifndef univ_i
-#define univ_i
-
-#define UNIV_INTEL
-#define UNIV_PENTIUM
-/* If UNIV_WINNT is not defined, we assume Windows 95 */
-
-#define UNIV_WINNT
-#define UNIV_WINNT4
-
-#define UNIV_VISUALC
-
-/* DEBUG VERSION CONTROL
- ===================== */
-/* Make a profiler version where mutex_fence does not use CPUID and therefore
-is not totally safe. The sync-library must be recompiled before profiling. */
-/*
-#define UNIV_PROFILE
-*/
-/* When the following flag is defined, also mutex lock word reset to 0
-in mutex_exit is performed using a serializing instruction, which does not
-allow speculative reads be performed before memory writes */
-/*
-#define SYNC_SERIALIZE_MUTEX_RESET
-*/
-/* Make a non-inline debug version */
-
-#define UNIV_DEBUG
-#define UNIV_MEM_DEBUG
-#define UNIV_SYNC_DEBUG
-#define UNIV_SEARCH_DEBUG
-
-#define UNIV_IBUF_DEBUG
-
-#define UNIV_SEARCH_PERF_STAT
-#define UNIV_SYNC_PERF_STAT
-
-
-#define UNIV_LIGHT_MEM_DEBUG
-
-#define YYDEBUG 1
-/*
-#define UNIV_SQL_DEBUG
-#define UNIV_LOG_DEBUG
-*/
- /* the above option prevents forcing of log to disk
- at a buffer page write: it should be tested with this
- option off; also some ibuf tests are suppressed */
-/*
-#define UNIV_BASIC_LOG_DEBUG
-*/
- /* the above option enables basic recovery debugging:
- new allocated file pages are reset */
-
-/* The debug version is slower, thus we may change the length of test loops
-depending on the UNIV_DBC parameter */
-#ifdef UNIV_DEBUG
-#define UNIV_DBC 1
-#else
-#define UNIV_DBC 100
-#endif
-
-#ifndef UNIV_DEBUG
-/* Definition for inline version */
-
-#ifdef UNIV_VISUALC
-#define UNIV_INLINE __inline
-#elif defined(UNIV_GNUC)
-#define UNIV_INLINE extern __inline__
-#endif
-
-#else
-/* If we want to compile a noninlined version we use the following macro
-definitions: */
-
-#define UNIV_NONINL
-#define UNIV_INLINE
-
-#endif /* UNIV_DEBUG */
-/* If the compiler does not know inline specifier, we use: */
-/*
-#define UNIV_INLINE static
-*/
-
-
-/*
- MACHINE VERSION CONTROL
- =======================
-*/
-
-#ifdef UNIV_PENTIUM
-
-/* In a 32-bit computer word size is 4 */
-#define UNIV_WORD_SIZE 4
-
-/* The following alignment is used in memory allocations in memory heap
-management to ensure correct alignment for doubles etc. */
-#define UNIV_MEM_ALIGNMENT 8
-
-/* The following alignment is used in aligning lints etc. */
-#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE
-
-#endif
-
-/*
- DATABASE VERSION CONTROL
- ========================
-*/
-
-/* The universal page size of the database */
-#define UNIV_PAGE_SIZE 8192 /* NOTE! Currently, this has to be a
- power of 2 and divisible by
- UNIV_MEM_ALIGNMENT */
-/* 2-based logarithm of UNIV_PAGE_SIZE */
-#define UNIV_PAGE_SIZE_SHIFT 13
-
-/* Do asynchronous io in buffer pool read/write operations */
-#ifdef UNIV_WINNT
-#define UNIV_ASYNC_IO
-#endif
-
-/* Do non-buffered io in buffer pool read/write operations */
-#define UNIV_NON_BUFFERED_IO
-
-/* Maximum number of parallel threads in a parallelized operation */
-#define UNIV_MAX_PARALLELISM 32
-
-/*
- UNIVERSAL TYPE DEFINITIONS
- ==========================
-*/
-
-/*
-typedef unsigned char byte;
-*/
-
-/* An other basic type we use is unsigned long integer which is intended to be
-equal to the word size of the machine. */
-
-typedef unsigned long int ulint;
-
-typedef long int lint;
-
-/* The following type should be at least a 64-bit floating point number */
-typedef double utfloat;
-
-/* The 'undefined' value for a ulint */
-#define ULINT_UNDEFINED ((ulint)(-1))
-
-/* The undefined 32-bit unsigned integer */
-#define ULINT32_UNDEFINED 0xFFFFFFFF
-
-/* Maximum value for a ulint */
-#define ULINT_MAX ((ulint)(-2))
-
-/* Definition of the boolean type */
-#ifndef bool
-typedef ulint bool;
-#endif
-
-#define TRUE 1
-#define FALSE 0
-
-/* The following number as the length of a logical field means that the field
-has the SQL NULL as its value. */
-#define UNIV_SQL_NULL ULINT_UNDEFINED
-
-#include <stdio.h>
-#include "ut0dbg.h"
-#include "ut0ut.h"
-#include "db0err.h"
-
-#endif
diff --git a/innobase/include/usr0sess.h b/innobase/include/usr0sess.h
index 365f828ecfc..c7bcfb20fed 100644
--- a/innobase/include/usr0sess.h
+++ b/innobase/include/usr0sess.h
@@ -11,7 +11,6 @@ Created 6/25/1996 Heikki Tuuri
#include "univ.i"
#include "ut0byte.h"
-#include "hash0hash.h"
#include "trx0types.h"
#include "srv0srv.h"
#include "trx0types.h"
@@ -19,74 +18,14 @@ Created 6/25/1996 Heikki Tuuri
#include "que0types.h"
#include "data0data.h"
#include "rem0rec.h"
-#include "com0com.h"
-/* The session system global data structure */
-extern sess_sys_t* sess_sys;
-
-/*************************************************************************
-Sets the session id in a client message. */
-
-void
-sess_cli_msg_set_sess(
-/*==================*/
- byte* str, /* in/out: message string */
- dulint sess_id);/* in: session id */
-/***************************************************************************
-Sets the message type of a message from the client. */
-UNIV_INLINE
-void
-sess_cli_msg_set_type(
-/*==================*/
- byte* str, /* in: message string */
- ulint type); /* in: message type */
-/***************************************************************************
-Gets the message type of a message from the server. */
-UNIV_INLINE
-ulint
-sess_srv_msg_get_type(
-/*==================*/
- /* out: message type */
- byte* str); /* in: message string */
-/***************************************************************************
-Creates a session sytem at database start. */
-
-void
-sess_sys_init_at_db_start(void);
-/*===========================*/
/*************************************************************************
Opens a session. */
sess_t*
-sess_open(
-/*======*/
+sess_open(void);
+/*============*/
/* out, own: session object */
- com_endpoint_t* endpoint, /* in: communication endpoint used
- for communicating with the client */
- byte* addr_buf, /* in: client address */
- ulint addr_len); /* in: client address length */
-/*************************************************************************
-Closes a session, freeing the memory occupied by it. */
-
-void
-sess_close(
-/*=======*/
- sess_t* sess); /* in, own: session object */
-/*************************************************************************
-Raises an SQL error. */
-
-void
-sess_raise_error_low(
-/*=================*/
- trx_t* trx, /* in: transaction */
- ulint err_no, /* in: error number */
- ulint type, /* in: more info of the error, or 0 */
- dict_table_t* table, /* in: dictionary table or NULL */
- dict_index_t* index, /* in: table index or NULL */
- dtuple_t* tuple, /* in: tuple to insert or NULL */
- rec_t* rec, /* in: record or NULL */
- char* err_str);/* in: arbitrary null-terminated error string,
- or NULL */
/*************************************************************************
Closes a session, freeing the memory occupied by it, if it is in a state
where it should be closed. */
@@ -96,221 +35,25 @@ sess_try_close(
/*===========*/
/* out: TRUE if closed */
sess_t* sess); /* in, own: session object */
-/*************************************************************************
-Initializes the first fields of a message to client. */
-
-void
-sess_srv_msg_init(
-/*==============*/
- sess_t* sess, /* in: session object */
- byte* buf, /* in: message buffer, must be at least of size
- SESS_SRV_MSG_DATA */
- ulint type); /* in: message type */
-/*************************************************************************
-Sends a simple message to client. */
-
-void
-sess_srv_msg_send_simple(
-/*=====================*/
- sess_t* sess, /* in: session object */
- ulint type, /* in: message type */
- ulint rel_kernel); /* in: SESS_RELEASE_KERNEL or
- SESS_NOT_RELEASE_KERNEL */
-/***************************************************************************
-Processes a message from a client. NOTE: May release the kernel mutex
-temporarily. */
-
-void
-sess_receive_msg_rel_kernel(
-/*========================*/
- sess_t* sess, /* in: session */
- byte* str, /* in: message string */
- ulint len); /* in: message length */
-/***************************************************************************
-When a command has been completed, this function sends the message about it
-to the client. */
-
-void
-sess_command_completed_message(
-/*===========================*/
- sess_t* sess, /* in: session */
- byte* msg, /* in: message buffer */
- ulint len); /* in: message data length */
-/***********************************************************************
-Starts a new connection and a session, or starts a query based on a client
-message. This is called by a SRV_COM thread. */
-
-void
-sess_process_cli_msg(
-/*=================*/
- byte* str, /* in: message string */
- ulint len, /* in: string length */
- byte* addr, /* in: address string */
- ulint alen); /* in: address length */
-
/* The session handle. All fields are protected by the kernel mutex */
struct sess_struct{
- dulint id; /* session id */
- dulint usr_id; /* user id */
- hash_node_t hash; /* hash chain node */
- ulint refer_count; /* reference count to the session
- object: when this drops to zero
- and the session has no query graphs
- left, discarding the session object
- is allowed */
- dulint error_count; /* if this counter has increased while
- a thread is parsing an SQL command,
- its graph should be discarded */
- ibool disconnecting; /* TRUE if the session is to be
- disconnected when its reference
- count drops to 0 */
ulint state; /* state of the session */
- dulint msgs_sent; /* count of messages sent to the
- client */
- dulint msgs_recv; /* count of messages received from the
- client */
- ibool client_waits; /* when the session receives a message
- from the client, this set to TRUE, and
- when the session sends a message to
- the client this is set to FALSE */
trx_t* trx; /* transaction object permanently
assigned for the session: the
transaction instance designated by the
trx id changes, but the memory
structure is preserved */
- ulint next_graph_id; /* next query graph id to assign */
UT_LIST_BASE_NODE_T(que_t)
graphs; /* query graphs belonging to this
session */
- /*------------------------------*/
- ulint err_no; /* latest error number, 0 if none */
- char* err_str; /* latest error string */
- ulint err_len; /* error string length */
- /*------------------------------*/
- com_endpoint_t* endpoint; /* server communications endpoint used
- to communicate with the client */
- char* addr_buf; /* client address string */
- ulint addr_len; /* client address string length */
- /*------------------------------*/
- byte* big_msg; /* if the client sends a message which
- does not fit in a single packet,
- it is assembled in this buffer; if
- this field is not NULL, it is assumed
- that the message should be catenated
- here */
- ulint big_msg_size; /* size of the big message buffer */
- ulint big_msg_len; /* length of data in the big message
- buffer */
-};
-
-/* The session system; this is protected by the kernel mutex */
-struct sess_sys_struct{
- ulint state; /* state of the system:
- SESS_SYS_RUNNING or
- SESS_SYS_SHUTTING_DOWN */
- sess_t* shutdown_req; /* if shutdown was requested by some
- session, confirmation of shutdown
- completion should be sent to this
- session */
- dulint free_sess_id; /* first unused session id */
- hash_table_t* hash; /* hash table of the sessions */
};
-
-/*---------------------------------------------------*/
-/* The format of an incoming message from a client */
-#define SESS_CLI_MSG_CHECKSUM 0 /* the checksum should be the first
- field in the message */
-#define SESS_CLI_MSG_SESS_ID 4 /* this is set to 0 if the client
- wants to connect and establish
- a new session */
-#define SESS_CLI_MSG_SESS_ID_CHECK 12 /* checksum of the sess id field */
-#define SESS_CLI_MSG_TYPE 16
-#define SESS_CLI_MSG_NO 20
-#define SESS_CLI_MSG_CONTINUE 28 /* 0, or SESS_MSG_FIRST_PART
- SESS_MSG_MIDDLE_PART, or
- SESS_MSG_LAST_PART */
-#define SESS_CLI_MSG_CONT_SIZE 32 /* size of a multipart message in
- kilobytes (rounded upwards) */
-#define SESS_CLI_MSG_DATA 36
-/*---------------------------------------------------*/
-
-/* Client-to-session message types */
-#define SESS_CLI_CONNECT 1
-#define SESS_CLI_PREPARE 2
-#define SESS_CLI_EXECUTE 3
-#define SESS_CLI_BREAK_EXECUTION 4
-
-/* Client-to-session statement command types */
-#define SESS_COMM_FETCH_NEXT 1
-#define SESS_COMM_FETCH_PREV 2
-#define SESS_COMM_FETCH_FIRST 3
-#define SESS_COMM_FETCH_LAST 4
-#define SESS_COMM_FETCH_NTH 5
-#define SESS_COMM_FETCH_NTH_LAST 6
-#define SESS_COMM_EXECUTE 7
-#define SESS_COMM_NO_COMMAND 8
-
-/*---------------------------------------------------*/
-/* The format of an outgoing message from a session to the client */
-#define SESS_SRV_MSG_CHECKSUM 0 /* the checksum should be the first
- field in the message */
-#define SESS_SRV_MSG_SESS_ID 4
-#define SESS_SRV_MSG_TYPE 12
-#define SESS_SRV_MSG_NO 16
-#define SESS_SRV_MSG_CONTINUE 24 /* 0, or SESS_MSG_FIRST_PART
- SESS_MSG_MIDDLE_PART, or
- SESS_MSG_LAST_PART */
-#define SESS_SRV_MSG_CONT_SIZE 28 /* size of a multipart message
- in kilobytes (rounded upward) */
-#define SESS_SRV_MSG_DATA 32
-/*---------------------------------------------------*/
-
-/* Session-to-client message types */
-#define SESS_SRV_ACCEPT_CONNECT 1
-#define SESS_SRV_SUCCESS 2
-#define SESS_SRV_ERROR 3
-
-/* Multipart messages */
-#define SESS_MSG_SINGLE_PART 0
-#define SESS_MSG_FIRST_PART 1
-#define SESS_MSG_MIDDLE_PART 2
-#define SESS_MSG_LAST_PART 3
-
-/* Error numbers */
-#define SESS_ERR_NONE 0
-#define SESS_ERR_TRX_COMMITTED 1
-#define SESS_ERR_TRX_ROLLED_BACK 2
-#define SESS_ERR_SESSION_DISCONNECTED 3
-#define SESS_ERR_REPLY_FAILED 4
-#define SESS_ERR_CANNOT_BREAK_OP 5
-#define SESS_ERR_MSG_LOST 6
-#define SESS_ERR_MSG_CORRUPTED 7
-#define SESS_ERR_EXTRANEOUS_MSG 8
-#define SESS_ERR_OUT_OF_MEMORY 9
-#define SESS_ERR_SQL_ERROR 10
-#define SESS_ERR_STMT_NOT_FOUND 11
-#define SESS_ERR_STMT_NOT_READY 12
-#define SESS_ERR_EXTRANEOUS_SRV_MSG 13
-#define SESS_ERR_BREAK_BY_CLIENT 14
-
/* Session states */
#define SESS_ACTIVE 1
#define SESS_ERROR 2 /* session contains an error message
which has not yet been communicated
to the client */
-/* Session system states */
-#define SESS_SYS_RUNNING 1
-#define SESS_SYS_SHUTTING_DOWN 2
-
-/* Session hash table size */
-#define SESS_HASH_SIZE 1024
-
-/* Flags used in sess_srv_msg_send */
-#define SESS_RELEASE_KERNEL 1
-#define SESS_NOT_RELEASE_KERNEL 2
-
#ifndef UNIV_NONINL
#include "usr0sess.ic"
#endif
diff --git a/innobase/include/usr0sess.ic b/innobase/include/usr0sess.ic
index ee2592c7963..c851d5745b9 100644
--- a/innobase/include/usr0sess.ic
+++ b/innobase/include/usr0sess.ic
@@ -5,27 +5,3 @@ Sessions
Created 6/25/1996 Heikki Tuuri
*******************************************************/
-
-/***************************************************************************
-Sets the message type of a message from the client. */
-UNIV_INLINE
-void
-sess_cli_msg_set_type(
-/*==================*/
- byte* str, /* in: message string */
- ulint type) /* in: message type */
-{
- mach_write_to_4(str + SESS_CLI_MSG_TYPE, type);
-}
-
-/***************************************************************************
-Gets the message type of a message from the server. */
-UNIV_INLINE
-ulint
-sess_srv_msg_get_type(
-/*==================*/
- /* out: message type */
- byte* str) /* in: message string */
-{
- return(mach_read_from_4(str + SESS_SRV_MSG_TYPE));
-}
diff --git a/innobase/include/usr0types.h b/innobase/include/usr0types.h
index 67070ccce27..29359425169 100644
--- a/innobase/include/usr0types.h
+++ b/innobase/include/usr0types.h
@@ -10,7 +10,5 @@ Created 6/25/1996 Heikki Tuuri
#define usr0types_h
typedef struct sess_struct sess_t;
-typedef struct sess_sys_struct sess_sys_t;
-typedef struct sess_sig_struct sess_sig_t;
#endif
diff --git a/innobase/include/ut0dbg.h b/innobase/include/ut0dbg.h
index 9b07d5da488..085b4811a73 100644
--- a/innobase/include/ut0dbg.h
+++ b/innobase/include/ut0dbg.h
@@ -10,7 +10,6 @@ Created 1/30/1994 Heikki Tuuri
#define ut0dbg_h
#include "univ.i"
-#include <assert.h>
#include <stdlib.h>
#include "os0thread.h"
@@ -24,7 +23,7 @@ extern const char* ut_dbg_msg_assert_fail;
extern const char* ut_dbg_msg_trap;
extern const char* ut_dbg_msg_stop;
-#define ut_a(EXPR)\
+#define ut_a(EXPR) do {\
if (!((ulint)(EXPR) + ut_dbg_zero)) {\
ut_print_timestamp(stderr);\
fprintf(stderr, ut_dbg_msg_assert_fail,\
@@ -33,38 +32,32 @@ extern const char* ut_dbg_msg_stop;
fputs("InnoDB: Failing assertion: " #EXPR "\n", stderr);\
fputs(ut_dbg_msg_trap, stderr);\
ut_dbg_stop_threads = TRUE;\
- (*ut_dbg_null_ptr)++;\
+ if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL;\
}\
if (ut_dbg_stop_threads) {\
fprintf(stderr, ut_dbg_msg_stop,\
os_thread_pf(os_thread_get_curr_id()), IB__FILE__, (ulint)__LINE__);\
os_thread_sleep(1000000000);\
- }
+ }\
+} while (0)
-#define ut_error\
+#define ut_error do {\
ut_print_timestamp(stderr);\
fprintf(stderr, ut_dbg_msg_assert_fail,\
os_thread_pf(os_thread_get_curr_id()), IB__FILE__, (ulint)__LINE__);\
fprintf(stderr, ut_dbg_msg_trap);\
ut_dbg_stop_threads = TRUE;\
- (*ut_dbg_null_ptr)++;
+ if (*(ut_dbg_null_ptr)) ut_dbg_null_ptr = NULL;\
+} while (0)
#ifdef UNIV_DEBUG
#define ut_ad(EXPR) ut_a(EXPR)
-#define ut_d(EXPR) {EXPR;}
+#define ut_d(EXPR) do {EXPR;} while (0)
#else
#define ut_ad(EXPR)
#define ut_d(EXPR)
#endif
-
#define UT_NOT_USED(A) A = A
-
-
-
-
-
-
#endif
-
diff --git a/innobase/include/ut0mem.h b/innobase/include/ut0mem.h
index ba6905a8618..b7dfe77a08e 100644
--- a/innobase/include/ut0mem.h
+++ b/innobase/include/ut0mem.h
@@ -95,10 +95,26 @@ ut_str_catenate(
/* out, own: catenated null-terminated string */
char* str1, /* in: null-terminated string */
char* str2); /* in: null-terminated string */
+/**************************************************************************
+Return a copy of the given string. The returned string must be freed
+using mem_free. */
+
+char*
+ut_strdup(
+/*======*/
+ /* out, own: cnull-terminated string */
+ char* str); /* in: null-terminated string */
+/**************************************************************************
+Checks if a null-terminated string contains a certain character. */
+
+ibool
+ut_str_contains(
+/*============*/
+ char* str, /* in: null-terminated string */
+ char c); /* in: character */
#ifndef UNIV_NONINL
#include "ut0mem.ic"
#endif
#endif
-
diff --git a/innobase/include/ut0rnd.ic b/innobase/include/ut0rnd.ic
index e166a26fe86..5493c37404a 100644
--- a/innobase/include/ut0rnd.ic
+++ b/innobase/include/ut0rnd.ic
@@ -176,19 +176,19 @@ ut_fold_string(
/* out: folded value */
char* str) /* in: null-terminated string */
{
- #ifdef UNIV_DEBUG
+#ifdef UNIV_DEBUG
ulint i = 0;
- #endif
+#endif
ulint fold = 0;
ut_ad(str);
while (*str != '\0') {
- #ifdef UNIV_DEBUG
+#ifdef UNIV_DEBUG
i++;
ut_a(i < 100);
- #endif
+#endif
fold = ut_fold_ulint_pair(fold, (ulint)(*str));
str++;
diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c
index 3541604a09a..2430380d65c 100644
--- a/innobase/lock/lock0lock.c
+++ b/innobase/lock/lock0lock.c
@@ -343,179 +343,6 @@ lock_deadlock_recursive(
#define lock_mutex_enter_kernel() mutex_enter(&kernel_mutex)
#define lock_mutex_exit_kernel() mutex_exit(&kernel_mutex)
-#ifdef notdefined
-/*************************************************************************
-Reserves the kernel mutex. This function is used in this module to allow
-monitoring the contention degree on the kernel mutex caused by the lock
-operations. */
-UNIV_INLINE
-void
-lock_mutex_enter_kernel(void)
-/*=========================*/
-{
- mutex_enter(&kernel_mutex);
-}
-
-/*************************************************************************
-Releases the kernel mutex. This function is used in this module to allow
-monitoring the contention degree on the kernel mutex caused by the lock
-operations. */
-UNIV_INLINE
-void
-lock_mutex_exit_kernel(void)
-/*=========================*/
-{
- mutex_exit(&kernel_mutex);
-}
-#endif
-
-#ifdef notdefined
-
-/*************************************************************************
-Gets the mutex protecting record locks for a page in the buffer pool. */
-UNIV_INLINE
-mutex_t*
-lock_rec_get_mutex(
-/*===============*/
- byte* ptr) /* in: pointer to somewhere within a buffer frame */
-{
- return(buf_frame_get_lock_mutex(ptr));
-}
-
-/*************************************************************************
-Reserves the mutex protecting record locks for a page in the buffer pool. */
-UNIV_INLINE
-void
-lock_rec_mutex_enter(
-/*=================*/
- byte* ptr) /* in: pointer to somewhere within a buffer frame */
-{
- mutex_enter(lock_rec_get_mutex(ptr));
-}
-
-/*************************************************************************
-Releases the mutex protecting record locks for a page in the buffer pool. */
-UNIV_INLINE
-void
-lock_rec_mutex_exit(
-/*================*/
- byte* ptr) /* in: pointer to somewhere within a buffer frame */
-{
- mutex_exit(lock_rec_get_mutex(ptr));
-}
-
-/*************************************************************************
-Checks if the caller owns the mutex to record locks of a page. Works only in
-the debug version. */
-UNIV_INLINE
-ibool
-lock_rec_mutex_own(
-/*===============*/
- /* out: TRUE if the current OS thread has reserved the
- mutex */
- byte* ptr) /* in: pointer to somewhere within a buffer frame */
-{
- return(mutex_own(lock_rec_get_mutex(ptr)));
-}
-
-/*************************************************************************
-Gets the mutex protecting record locks on a given page address. */
-
-mutex_t*
-lock_rec_get_mutex_for_addr(
-/*========================*/
- ulint space, /* in: space id */
- ulint page_no)/* in: page number */
-{
- return(hash_get_mutex(lock_sys->rec_hash,
- lock_rec_fold(space, page_no)));
-}
-
-/*************************************************************************
-Checks if the caller owns the mutex to record locks of a page. Works only in
-the debug version. */
-UNIV_INLINE
-ibool
-lock_rec_mutex_own_addr(
-/*====================*/
- ulint space, /* in: space id */
- ulint page_no)/* in: page number */
-{
- return(mutex_own(lock_rec_get_mutex_for_addr(space, page_no)));
-}
-
-/*************************************************************************
-Reserves all the mutexes protecting record locks. */
-UNIV_INLINE
-void
-lock_rec_mutex_enter_all(void)
-/*==========================*/
-{
- hash_table_t* table;
- ulint n_mutexes;
- ulint i;
-
- table = lock_sys->rec_hash;
-
- n_mutexes = table->n_mutexes;
-
- for (i = 0; i < n_mutexes; i++) {
-
- mutex_enter(hash_get_nth_mutex(table, i));
- }
-}
-
-/*************************************************************************
-Releases all the mutexes protecting record locks. */
-UNIV_INLINE
-void
-lock_rec_mutex_exit_all(void)
-/*=========================*/
-{
- hash_table_t* table;
- ulint n_mutexes;
- ulint i;
-
- table = lock_sys->rec_hash;
-
- n_mutexes = table->n_mutexes;
-
- for (i = 0; i < n_mutexes; i++) {
-
- mutex_exit(hash_get_nth_mutex(table, i));
- }
-}
-
-/*************************************************************************
-Checks that the current OS thread owns all the mutexes protecting record
-locks. */
-UNIV_INLINE
-ibool
-lock_rec_mutex_own_all(void)
-/*========================*/
- /* out: TRUE if owns all */
-{
- hash_table_t* table;
- ulint n_mutexes;
- ibool owns_yes = TRUE;
- ulint i;
-
- table = lock_sys->rec_hash;
-
- n_mutexes = table->n_mutexes;
-
- for (i = 0; i < n_mutexes; i++) {
- if (!mutex_own(hash_get_nth_mutex(table, i))) {
-
- owns_yes = FALSE;
- }
- }
-
- return(owns_yes);
-}
-
-#endif
-
/*************************************************************************
Checks that a transaction id is sensible, i.e., not in the future. */
@@ -1126,7 +953,9 @@ lock_rec_get_next_on_page(
ulint space;
ulint page_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(lock) == LOCK_REC);
space = lock->un_member.rec_lock.space;
@@ -1163,7 +992,9 @@ lock_rec_get_first_on_page_addr(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = HASH_GET_FIRST(lock_sys->rec_hash,
lock_rec_hash(space, page_no));
@@ -1221,7 +1052,9 @@ lock_rec_get_first_on_page(
ulint space;
ulint page_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
hash = buf_frame_get_lock_hash_val(ptr);
@@ -1253,7 +1086,9 @@ lock_rec_get_next(
rec_t* rec, /* in: record on a page */
lock_t* lock) /* in: lock */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(lock) == LOCK_REC);
for (;;) {
@@ -1282,7 +1117,9 @@ lock_rec_get_first(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = lock_rec_get_first_on_page(rec);
@@ -1370,7 +1207,9 @@ lock_rec_get_prev(
ulint page_no;
lock_t* found_lock = NULL;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(in_lock) == LOCK_REC);
space = in_lock->un_member.rec_lock.space;
@@ -1410,7 +1249,9 @@ lock_table_has(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* Look for stronger locks the same trx already has on the table */
@@ -1454,7 +1295,9 @@ lock_rec_has_expl(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((precise_mode & LOCK_MODE_MASK) == LOCK_S
|| (precise_mode & LOCK_MODE_MASK) == LOCK_X);
ut_ad(!(precise_mode & LOCK_INSERT_INTENTION));
@@ -1501,7 +1344,9 @@ lock_rec_other_has_expl_req(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(mode == LOCK_X || mode == LOCK_S);
ut_ad(gap == 0 || gap == LOCK_GAP);
ut_ad(wait == 0 || wait == LOCK_WAIT);
@@ -1540,7 +1385,9 @@ lock_rec_other_has_conflicting(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = lock_rec_get_first(rec);
@@ -1572,7 +1419,9 @@ lock_rec_find_similar_on_page(
lock_t* lock;
ulint heap_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
heap_no = rec_get_heap_no(rec);
@@ -1606,7 +1455,9 @@ lock_sec_rec_some_has_impl_off_kernel(
{
page_t* page;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(!(index->type & DICT_CLUSTERED));
ut_ad(page_rec_is_user_rec(rec));
@@ -1664,7 +1515,9 @@ lock_rec_create(
ulint n_bits;
ulint n_bytes;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
page = buf_frame_align(rec);
space = buf_frame_get_space_id(page);
@@ -1748,7 +1601,9 @@ lock_rec_enqueue_waiting(
lock_t* lock;
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* Test if there already is some other reason to suspend thread:
we do not enqueue a lock request if the query thread should be
@@ -1756,7 +1611,7 @@ lock_rec_enqueue_waiting(
if (que_thr_stop(thr)) {
- ut_a(0);
+ ut_error;
return(DB_QUE_THR_SUSPENDED);
}
@@ -1834,7 +1689,9 @@ lock_rec_add_to_queue(
page_t* page;
ibool somebody_waits = FALSE;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((type_mode & (LOCK_WAIT | LOCK_GAP))
|| ((type_mode & LOCK_MODE_MASK) != LOCK_S)
|| !lock_rec_other_has_expl_req(LOCK_X, 0, LOCK_WAIT, rec, trx));
@@ -1914,7 +1771,9 @@ lock_rec_lock_fast(
lock_t* lock;
ulint heap_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((LOCK_MODE_MASK & mode) != LOCK_S
|| lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
ut_ad((LOCK_MODE_MASK & mode) != LOCK_X
@@ -1978,7 +1837,9 @@ lock_rec_lock_slow(
trx_t* trx;
ulint err;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((LOCK_MODE_MASK & mode) != LOCK_S
|| lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
ut_ad((LOCK_MODE_MASK & mode) != LOCK_X
@@ -2023,7 +1884,7 @@ possible, enqueues a waiting lock request. This is a low-level function
which does NOT look at implicit locks! Checks lock compatibility within
explicit locks. This function sets a normal next-key lock, or in the case
of a page supremum record, a gap type lock. */
-
+static
ulint
lock_rec_lock(
/*==========*/
@@ -2040,7 +1901,9 @@ lock_rec_lock(
{
ulint err;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((LOCK_MODE_MASK & mode) != LOCK_S
|| lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
ut_ad((LOCK_MODE_MASK & mode) != LOCK_X
@@ -2078,7 +1941,9 @@ lock_rec_has_to_wait_in_queue(
ulint page_no;
ulint heap_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_wait(wait_lock));
ut_ad(lock_get_type(wait_lock) == LOCK_REC);
@@ -2105,13 +1970,15 @@ lock_rec_has_to_wait_in_queue(
/*****************************************************************
Grants a lock to a waiting lock request and releases the waiting
transaction. */
-
+static
void
lock_grant(
/*=======*/
lock_t* lock) /* in: waiting lock request */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock_reset_lock_and_trx_wait(lock);
@@ -2153,7 +2020,9 @@ lock_rec_cancel(
/*============*/
lock_t* lock) /* in: waiting record lock request */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(lock) == LOCK_REC);
/* Reset the bit (there can be only one set bit) in the lock bitmap */
@@ -2172,7 +2041,7 @@ lock_rec_cancel(
Removes a record lock request, waiting or granted, from the queue and
grants locks to other transactions in the queue if they now are entitled
to a lock. NOTE: all record locks contained in in_lock are removed. */
-
+static
void
lock_rec_dequeue_from_page(
/*=======================*/
@@ -2186,7 +2055,9 @@ lock_rec_dequeue_from_page(
lock_t* lock;
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(in_lock) == LOCK_REC);
trx = in_lock->trx;
@@ -2229,7 +2100,9 @@ lock_rec_discard(
ulint page_no;
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(in_lock) == LOCK_REC);
trx = in_lock->trx;
@@ -2258,7 +2131,9 @@ lock_rec_free_all_from_discard_page(
lock_t* lock;
lock_t* next_lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
space = buf_frame_get_space_id(page);
page_no = buf_frame_get_page_no(page);
@@ -2291,7 +2166,9 @@ lock_rec_reset_and_release_wait(
lock_t* lock;
ulint heap_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
heap_no = rec_get_heap_no(rec);
@@ -2323,7 +2200,9 @@ lock_rec_inherit_to_gap(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = lock_rec_get_first(rec);
@@ -2343,7 +2222,7 @@ lock_rec_inherit_to_gap(
Makes a record to inherit the gap locks (except LOCK_INSERT_INTENTION type)
of another record as gap type locks, but does not reset the lock bits of the
other record. Also waiting lock requests are inherited as GRANTED gap locks. */
-
+static
void
lock_rec_inherit_to_gap_if_gap_lock(
/*================================*/
@@ -2353,7 +2232,9 @@ lock_rec_inherit_to_gap_if_gap_lock(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = lock_rec_get_first(rec);
@@ -2386,7 +2267,9 @@ lock_rec_move(
ulint heap_no;
ulint type_mode;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
heap_no = rec_get_heap_no(donator);
@@ -3022,7 +2905,9 @@ lock_deadlock_occurs(
char* err_buf;
ut_ad(trx && lock);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
retry:
/* We check that adding this trx to the waits-for graph
does not produce a cycle. First mark all active transactions
@@ -3064,11 +2949,6 @@ retry:
ut_a(strlen(lock_latest_err_buf) < 4100);
- /*
- sess_raise_error_low(trx, DB_DEADLOCK, lock->type_mode, table,
- index, NULL, NULL, NULL);
- */
-
return(TRUE);
}
@@ -3103,7 +2983,9 @@ lock_deadlock_recursive(
ulint ret;
ut_a(trx && start && wait_lock);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (trx->deadlock_mark == 1) {
/* We have already exhaustively searched the subtree starting
@@ -3294,7 +3176,9 @@ lock_table_create(
lock_t* lock;
ut_ad(table && trx);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (type_mode == LOCK_AUTO_INC) {
/* Only one trx can have the lock on the table
@@ -3344,7 +3228,9 @@ lock_table_remove_low(
dict_table_t* table;
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
table = lock->un_member.tab_lock.table;
trx = lock->trx;
@@ -3378,14 +3264,16 @@ lock_table_enqueue_waiting(
lock_t* lock;
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* Test if there already is some other reason to suspend thread:
we do not enqueue a lock request if the query thread should be
stopped anyway */
if (que_thr_stop(thr)) {
- ut_a(0);
+ ut_error;
return(DB_QUE_THR_SUSPENDED);
}
@@ -3448,7 +3336,9 @@ lock_table_other_has_incompatible(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = UT_LIST_GET_LAST(table->locks);
@@ -3588,7 +3478,7 @@ lock_table_has_to_wait_in_queue(
Removes a table lock request, waiting or granted, from the queue and grants
locks to other transactions in the queue, if they now are entitled to a
lock. */
-
+static
void
lock_table_dequeue(
/*===============*/
@@ -3598,7 +3488,9 @@ lock_table_dequeue(
{
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(in_lock) == LOCK_TABLE);
lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock);
@@ -3654,7 +3546,9 @@ lock_release_off_kernel(
ulint count;
lock_t* lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = UT_LIST_GET_LAST(trx->trx_locks);
@@ -3715,7 +3609,9 @@ lock_cancel_waiting_and_release(
/*============================*/
lock_t* lock) /* in: waiting lock request */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (lock_get_type(lock) == LOCK_REC) {
@@ -3748,7 +3644,9 @@ lock_reset_all_on_table_for_trx(
lock_t* lock;
lock_t* prev_lock;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
lock = UT_LIST_GET_LAST(trx->trx_locks);
@@ -3810,7 +3708,9 @@ lock_table_print(
500 bytes */
lock_t* lock) /* in: table type lock */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(lock_get_type(lock) == LOCK_TABLE);
buf += sprintf(buf, "TABLE LOCK table %s trx id %lu %lu",
@@ -3857,7 +3757,9 @@ lock_rec_print(
char* buf_start = buf;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(lock_get_type(lock) == LOCK_REC);
space = lock->un_member.rec_lock.space;
@@ -3921,7 +3823,9 @@ lock_rec_print(
}
if (page) {
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
}
for (i = 0; i < lock_rec_get_n_bits(lock); i++) {
@@ -3966,7 +3870,9 @@ lock_get_n_rec_locks(void)
ulint n_locks = 0;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < hash_get_n_cells(lock_sys->rec_hash); i++) {
@@ -4238,7 +4144,9 @@ lock_table_queue_validate(
lock_t* lock;
ibool is_waiting;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
is_waiting = FALSE;
@@ -4391,12 +4299,16 @@ lock_rec_validate_page(
ulint i;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
page = buf_page_get(space, page_no, RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
lock_mutex_enter_kernel();
loop:
@@ -4642,7 +4554,9 @@ lock_rec_convert_impl_to_expl(
{
trx_t* impl_trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(page_rec_is_user_rec(rec));
if (index->type & DICT_CLUSTERED) {
diff --git a/innobase/log/log0log.c b/innobase/log/log0log.c
index f041137840c..e99ea269920 100644
--- a/innobase/log/log0log.c
+++ b/innobase/log/log0log.c
@@ -32,7 +32,9 @@ ulint log_fsp_current_free_limit = 0;
log_t* log_sys = NULL;
ibool log_do_write = TRUE;
+#ifdef UNIV_LOG_DEBUG
ibool log_debug_writes = FALSE;
+#endif /* UNIV_LOG_DEBUG */
/* These control how often we print warnings if the last checkpoint is too
old */
@@ -86,9 +88,8 @@ the previous */
Completes a checkpoint write i/o to a log file. */
static
void
-log_io_complete_checkpoint(
-/*=======================*/
- log_group_t* group); /* in: log group */
+log_io_complete_checkpoint(void);
+/*============================*/
/**********************************************************
Completes an archiving i/o. */
static
@@ -133,7 +134,9 @@ log_buf_pool_get_oldest_modification(void)
{
dulint lsn;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
lsn = buf_pool_get_oldest_modification();
@@ -231,7 +234,9 @@ log_write_low(
ulint data_len;
byte* log_block;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
part_loop:
/* Calculate a part length */
@@ -298,7 +303,9 @@ log_close(void)
log_t* log = log_sys;
ulint checkpoint_age;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
lsn = log->lsn;
@@ -414,7 +421,9 @@ log_group_get_capacity(
/* out: capacity in bytes */
log_group_t* group) /* in: log group */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
return((group->file_size - LOG_FILE_HDR_SIZE) * group->n_files);
}
@@ -430,7 +439,9 @@ log_group_calc_size_offset(
ulint offset, /* in: real offset within the log group */
log_group_t* group) /* in: log group */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
return(offset - LOG_FILE_HDR_SIZE * (1 + offset / group->file_size));
}
@@ -446,7 +457,9 @@ log_group_calc_real_offset(
ulint offset, /* in: size offset within the log group */
log_group_t* group) /* in: log group */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
return(offset + LOG_FILE_HDR_SIZE
* (1 + offset / (group->file_size - LOG_FILE_HDR_SIZE)));
@@ -469,7 +482,9 @@ log_group_calc_lsn_offset(
ib_longlong group_size;
ib_longlong offset;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
/* If total log file size is > 2 GB we can easily get overflows
with 32-bit integers. Use 64-bit integers instead. */
@@ -583,7 +598,9 @@ log_calc_max_ages(void)
ulint archive_margin;
ulint smallest_archive_margin;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(log_sys->mutex));
@@ -655,7 +672,18 @@ failure:
if (!success) {
fprintf(stderr,
-"InnoDB: Error: log file group too small for innodb_thread_concurrency\n");
+"InnoDB: Error: ib_logfiles are too small for innodb_thread_concurrency %lu.\n"
+"InnoDB: The combined size of ib_logfiles should be bigger than\n"
+"InnoDB: 200 kB * innodb_thread_concurrency.\n"
+"InnoDB: To get mysqld to start up, set innodb_thread_concurrency in my.cnf\n"
+"InnoDB: to a lower value, for example, to 8. After an ERROR-FREE shutdown\n"
+"InnoDB: of mysqld you can adjust the size of ib_logfiles, as explained in\n"
+"InnoDB: section 5 of http://www.innodb.com/ibman.php",
+ (ulong)srv_thread_concurrency);
+ fprintf(stderr,
+"InnoDB: Cannot continue operation. Calling exit(1).\n");
+
+ exit(1);
}
return(success);
@@ -862,7 +890,9 @@ log_flush_do_unlocks(
ulint code) /* in: any ORed combination of LOG_UNLOCK_FLUSH_LOCK
and LOG_UNLOCK_NONE_FLUSHED_LOCK */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
/* NOTE that we must own the log mutex when doing the setting of the
events: this is because transactions will wait for these events to
@@ -894,14 +924,17 @@ log_group_check_flush_completion(
/* out: LOG_UNLOCK_NONE_FLUSHED_LOCK or 0 */
log_group_t* group) /* in: log group */
{
- ut_ad(mutex_own(&(log_sys->mutex)));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (!log_sys->one_flushed && group->n_pending_writes == 0) {
-
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Log flushed first to group %lu\n",
(ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
log_sys->written_to_some_lsn = log_sys->write_lsn;
log_sys->one_flushed = TRUE;
@@ -909,10 +942,12 @@ log_group_check_flush_completion(
return(LOG_UNLOCK_NONE_FLUSHED_LOCK);
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes && (group->n_pending_writes == 0)) {
printf("Log flushed to group %lu\n", (ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
return(0);
}
@@ -928,7 +963,9 @@ log_sys_check_flush_completion(void)
ulint move_start;
ulint move_end;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (log_sys->n_pending_writes == 0) {
@@ -986,12 +1023,20 @@ log_io_complete(
fil_flush(group->space_id);
}
- log_io_complete_checkpoint(group);
+#ifdef UNIV_LOG_DEBUG
+ if (log_debug_writes) {
+ fprintf(stderr,
+ "Checkpoint info written to group %lu\n",
+ group->id);
+ }
+#endif /* UNIV_LOG_DEBUG */
+
+ log_io_complete_checkpoint();
return;
}
- ut_a(0); /* We currently use synchronous writing of the
+ ut_error; /* We currently use synchronous writing of the
logs and cannot end up here! */
if (srv_unix_file_flush_method != SRV_UNIX_O_DSYNC
@@ -1035,7 +1080,9 @@ log_group_file_header_flush(
UT_NOT_USED(type);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(nth_file < group->n_files);
@@ -1049,11 +1096,13 @@ log_group_file_header_flush(
dest_offset = nth_file * group->file_size;
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf(
"Writing log file header to group %lu file %lu\n",
(ulong) group->id, (ulong) nth_file);
}
+#endif /* UNIV_LOG_DEBUG */
if (log_do_write) {
log_sys->n_log_ios++;
@@ -1103,7 +1152,9 @@ log_group_write_buf(
ulint next_offset;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(len % OS_FILE_LOG_BLOCK_SIZE == 0);
ut_a(ut_dulint_get_low(start_lsn) % OS_FILE_LOG_BLOCK_SIZE == 0);
@@ -1136,6 +1187,7 @@ loop:
write_len = len;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf(
@@ -1160,6 +1212,7 @@ loop:
+ i * OS_FILE_LOG_BLOCK_SIZE));
}
}
+#endif /* UNIV_LOG_DEBUG */
/* Calculate the checksums for each log block and write them to
the trailer fields of the log blocks */
@@ -1287,6 +1340,7 @@ loop:
return;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Writing log from %lu %lu up to lsn %lu %lu\n",
(ulong) ut_dulint_get_high(log_sys->written_to_all_lsn),
@@ -1294,6 +1348,7 @@ loop:
(ulong) ut_dulint_get_high(log_sys->lsn),
(ulong) ut_dulint_get_low(log_sys->lsn));
}
+#endif /* UNIV_LOG_DEBUG */
log_sys->n_pending_writes++;
@@ -1502,7 +1557,9 @@ void
log_complete_checkpoint(void)
/*=========================*/
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(log_sys->n_pending_checkpoint_writes == 0);
log_sys->next_checkpoint_no
@@ -1517,9 +1574,8 @@ log_complete_checkpoint(void)
Completes an asynchronous checkpoint info write i/o to a log file. */
static
void
-log_io_complete_checkpoint(
-/*=======================*/
- log_group_t* group) /* in: log group */
+log_io_complete_checkpoint(void)
+/*============================*/
{
mutex_enter(&(log_sys->mutex));
@@ -1527,11 +1583,6 @@ log_io_complete_checkpoint(
log_sys->n_pending_checkpoint_writes--;
- if (log_debug_writes) {
- printf("Checkpoint info written to group %lu\n",
- (ulong) group->id);
- }
-
if (log_sys->n_pending_checkpoint_writes == 0) {
log_complete_checkpoint();
}
@@ -1593,7 +1644,9 @@ log_group_checkpoint(
byte* buf;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(LOG_CHECKPOINT_SIZE <= OS_FILE_LOG_BLOCK_SIZE);
buf = group->checkpoint_buf;
@@ -1747,7 +1800,9 @@ log_group_read_checkpoint_info(
log_group_t* group, /* in: log group */
ulint field) /* in: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2 */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
log_sys->n_log_ios++;
@@ -1765,7 +1820,9 @@ log_groups_write_checkpoint_info(void)
{
log_group_t* group;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
group = UT_LIST_GET_FIRST(log_sys->log_groups);
@@ -1850,12 +1907,14 @@ log_checkpoint(
log_sys->next_checkpoint_lsn = oldest_lsn;
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Making checkpoint no %lu at lsn %lu %lu\n",
(ulong) ut_dulint_get_low(log_sys->next_checkpoint_no),
(ulong) ut_dulint_get_high(oldest_lsn),
(ulong) ut_dulint_get_low(oldest_lsn));
}
+#endif /* UNIV_LOG_DEBUG */
log_groups_write_checkpoint_info();
@@ -2030,7 +2089,9 @@ log_group_read_log_seg(
ulint source_offset;
ibool sync;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
sync = FALSE;
@@ -2102,9 +2163,11 @@ log_group_archive_file_header_write(
byte* buf;
ulint dest_offset;
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(nth_file < group->n_files);
@@ -2141,9 +2204,11 @@ log_group_archive_completed_header_write(
byte* buf;
ulint dest_offset;
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(nth_file < group->n_files);
buf = *(group->archive_file_header_bufs + nth_file);
@@ -2182,9 +2247,11 @@ log_group_archive(
ulint n_files;
ulint open_mode;
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
start_lsn = log_sys->archived_lsn;
@@ -2234,9 +2301,11 @@ loop:
exit(1);
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Created archive file %s\n", name);
}
+#endif /* UNIV_LOG_DEBUG */
ret = os_file_close(file_handle);
@@ -2263,6 +2332,7 @@ loop:
len = group->file_size - (next_offset % group->file_size);
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf(
"Archiving starting at lsn %lu %lu, len %lu to group %lu\n",
@@ -2270,6 +2340,7 @@ loop:
(ulong) ut_dulint_get_low(start_lsn),
(ulong) len, (ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
log_sys->n_pending_archive_ios++;
@@ -2309,9 +2380,11 @@ log_archive_groups(void)
{
log_group_t* group;
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
group = UT_LIST_GET_FIRST(log_sys->log_groups);
@@ -2334,9 +2407,11 @@ log_archive_write_complete_groups(void)
dulint end_lsn;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
group = UT_LIST_GET_FIRST(log_sys->log_groups);
@@ -2360,10 +2435,12 @@ log_archive_write_complete_groups(void)
trunc_files = n_files - 1;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes && trunc_files) {
printf("Complete file(s) archived to group %lu\n",
(ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
/* Calculate the archive file space start lsn */
start_lsn = ut_dulint_subtract(log_sys->next_archived_lsn,
@@ -2386,9 +2463,11 @@ log_archive_write_complete_groups(void)
fil_space_truncate_start(group->archive_space_id,
trunc_files * group->file_size);
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Archiving writes completed\n");
}
+#endif /* UNIV_LOG_DEBUG */
}
/**********************************************************
@@ -2398,16 +2477,20 @@ void
log_archive_check_completion_low(void)
/*==================================*/
{
+#ifdef UNIV_SYNC_DEBUG
ut_a(0);
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (log_sys->n_pending_archive_ios == 0
&& log_sys->archiving_phase == LOG_ARCHIVE_READ) {
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Archiving read completed\n");
}
+#endif /* UNIV_LOG_DEBUG */
/* Archive buffer has now been read in: start archive writes */
@@ -2501,8 +2584,7 @@ loop:
start_lsn = log_sys->archived_lsn;
if (calc_new_limit) {
- ut_a(log_sys->archive_buf_size % OS_FILE_LOG_BLOCK_SIZE
- == 0);
+ ut_a(log_sys->archive_buf_size % OS_FILE_LOG_BLOCK_SIZE == 0);
limit_lsn = ut_dulint_add(start_lsn,
log_sys->archive_buf_size);
@@ -2556,6 +2638,7 @@ loop:
log_sys->next_archived_lsn = limit_lsn;
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf("Archiving from lsn %lu %lu to lsn %lu %lu\n",
(ulong) ut_dulint_get_high(log_sys->archived_lsn),
@@ -2563,6 +2646,7 @@ loop:
(ulong) ut_dulint_get_high(limit_lsn),
(ulong) ut_dulint_get_low(limit_lsn));
}
+#endif /* UNIV_LOG_DEBUG */
/* Read the log segment to the archive buffer */
@@ -2638,7 +2722,9 @@ log_archive_close_groups(
log_group_t* group;
ulint trunc_len;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (log_sys->archiving_state == LOG_ARCH_OFF) {
@@ -2667,12 +2753,14 @@ log_archive_close_groups(
group->archived_file_no += 2;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
printf(
"Incrementing arch file no to %lu in log group %lu\n",
(ulong) group->archived_file_no + 2,
(ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
}
}
@@ -3142,6 +3230,7 @@ loop:
ut_a(0 == ut_dulint_cmp(lsn, log_sys->lsn));
}
+#ifdef UNIV_LOG_DEBUG
/**********************************************************
Checks by parsing that the catenated log segment for a single mtr is
consistent. */
@@ -3161,7 +3250,9 @@ log_check_log_recs(
byte* buf1;
byte* scan_buf;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (len == 0) {
@@ -3192,6 +3283,7 @@ log_check_log_recs(
return(TRUE);
}
+#endif /* UNIV_LOG_DEBUG */
/**********************************************************
Peeks the current lsn. */
diff --git a/innobase/log/log0recv.c b/innobase/log/log0recv.c
index 01679a374b0..432a6ed1e85 100644
--- a/innobase/log/log0recv.c
+++ b/innobase/log/log0recv.c
@@ -165,14 +165,16 @@ void
recv_sys_empty_hash(void)
/*=====================*/
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(recv_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (recv_sys->n_addrs != 0) {
fprintf(stderr,
"InnoDB: Error: %lu pages with log records were left unprocessed!\n"
"InnoDB: Maximum page number with log records on it %lu\n",
(ulong) recv_sys->n_addrs,
(ulong) recv_max_parsed_page_no);
- ut_a(0);
+ ut_error;
}
hash_table_free(recv_sys->addr_hash);
@@ -181,9 +183,10 @@ recv_sys_empty_hash(void)
recv_sys->addr_hash = hash_create(buf_pool_get_curr_size() / 256);
}
+#ifndef UNIV_LOG_DEBUG
/************************************************************
Frees the recovery system. */
-
+static
void
recv_sys_free(void)
/*===============*/
@@ -200,6 +203,7 @@ recv_sys_free(void)
mutex_exit(&(recv_sys->mutex));
}
+#endif /* !UNIV_LOG_DEBUG */
/************************************************************
Truncates possible corrupted or extra records from a log group. */
@@ -358,7 +362,7 @@ Copies a log segment from the most up-to-date log group to the other log
groups, so that they all contain the latest log data. Also writes the info
about the latest checkpoint to the groups, and inits the fields in the group
memory structs to up-to-date values. */
-
+static
void
recv_synchronize_groups(
/*====================*/
@@ -483,6 +487,7 @@ recv_find_max_checkpoint(
log_group_read_checkpoint_info(group, field);
if (!recv_check_cp_is_consistent(buf)) {
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Checkpoint in group %lu at %lu invalid, %lu\n",
@@ -492,6 +497,7 @@ recv_find_max_checkpoint(
+ LOG_CHECKPOINT_CHECKSUM_1));
}
+#endif /* UNIV_LOG_DEBUG */
goto not_consistent;
}
@@ -505,12 +511,14 @@ recv_find_max_checkpoint(
checkpoint_no =
mach_read_from_8(buf + LOG_CHECKPOINT_NO);
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Checkpoint number %lu found in group %lu\n",
(ulong) ut_dulint_get_low(checkpoint_no),
(ulong) group->id);
}
+#endif /* UNIV_LOG_DEBUG */
if (ut_dulint_cmp(checkpoint_no, max_no) >= 0) {
*max_group = group;
@@ -1076,7 +1084,9 @@ recv_recover_page(
&mtr);
ut_a(success);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
}
/* Read the newest modification lsn from the page */
@@ -1141,6 +1151,7 @@ recv_recover_page(
start_lsn = recv->start_lsn;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Applying log rec type %lu len %lu to space %lu page no %lu\n",
@@ -1148,7 +1159,8 @@ recv_recover_page(
(ulong) recv_addr->space,
(ulong) recv_addr->page_no);
}
-
+#endif /* UNIV_LOG_DEBUG */
+
recv_parse_or_apply_log_rec_body(recv->type, buf,
buf + recv->len, page, &mtr);
mach_write_to_8(page + UNIV_PAGE_SIZE
@@ -1278,14 +1290,13 @@ loop:
goto loop;
}
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(!allow_ibuf == mutex_own(&log_sys->mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (!allow_ibuf) {
- ut_ad(mutex_own(&(log_sys->mutex)));
-
recv_no_ibuf_operations = TRUE;
- } else {
- ut_ad(!mutex_own(&(log_sys->mutex)));
}
-
+
recv_sys->apply_log_recs = TRUE;
recv_sys->apply_batch_on = TRUE;
@@ -1315,8 +1326,10 @@ loop:
page = buf_page_get(space, page_no,
RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page,
SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
recv_recover_page(FALSE, FALSE, page,
space, page_no);
mtr_commit(&mtr);
@@ -1539,7 +1552,9 @@ recv_update_replicate(
replica = buf_page_get(space + RECV_REPLICA_SPACE_ADD, page_no,
RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(replica, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
ptr = recv_parse_or_apply_log_rec_body(type, body, end_ptr, replica,
&mtr);
@@ -1608,7 +1623,9 @@ recv_compare_replicate(
replica = buf_page_get(space + RECV_REPLICA_SPACE_ADD, page_no,
RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(replica, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
recv_check_identical(page + FIL_PAGE_DATA,
replica + FIL_PAGE_DATA,
@@ -1649,7 +1666,9 @@ recv_compare_spaces(
IB__FILE__, __LINE__,
&mtr);
if (frame) {
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(frame, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
ut_memcpy(page, frame, UNIV_PAGE_SIZE);
} else {
/* Read it from file */
@@ -1662,7 +1681,9 @@ recv_compare_spaces(
IB__FILE__, __LINE__,
&mtr);
if (frame) {
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(frame, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
ut_memcpy(replica, frame, UNIV_PAGE_SIZE);
} else {
/* Read it from file */
@@ -1803,10 +1824,11 @@ recv_calc_lsn_on_data_add(
return(ut_dulint_add(lsn, lsn_len));
}
+#ifdef UNIV_LOG_DEBUG
/***********************************************************
Checks that the parser recognizes incomplete initial segments of a log
record as incomplete. */
-
+static
void
recv_check_incomplete_log_recs(
/*===========================*/
@@ -1824,6 +1846,7 @@ recv_check_incomplete_log_recs(
&page_no, &body));
}
}
+#endif /* UNIV_LOG_DEBUG */
/***********************************************************
Prints diagnostic info of corrupt log. */
@@ -1912,7 +1935,9 @@ recv_parse_log_recs(
byte* body;
ulint n_recs;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(!ut_dulint_is_zero(recv_sys->parse_start_lsn));
loop:
ptr = recv_sys->buf + recv_sys->recovered_offset;
@@ -1965,12 +1990,14 @@ loop:
recv_sys->recovered_offset += len;
recv_sys->recovered_lsn = new_recovered_lsn;
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Parsed a single log rec type %lu len %lu space %lu page no %lu\n",
(ulong) type, (ulong) len, (ulong) space,
(ulong) page_no);
}
+#endif /* UNIV_LOG_DEBUG */
if (type == MLOG_DUMMY_RECORD) {
/* Do nothing */
@@ -2052,13 +2079,15 @@ loop:
*/
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Parsed a multi log rec type %lu len %lu space %lu page no %lu\n",
(ulong) type, (ulong) len, (ulong) space,
(ulong) page_no);
}
-
+#endif /* UNIV_LOG_DEBUG */
+
total_len += len;
n_recs++;
@@ -2463,6 +2492,7 @@ recv_group_scan_log_recs(
start_lsn = end_lsn;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Scanned group %lu up to log sequence number %lu %lu\n",
@@ -2470,6 +2500,7 @@ recv_group_scan_log_recs(
(ulong) ut_dulint_get_high(*group_scanned_lsn),
(ulong) ut_dulint_get_low(*group_scanned_lsn));
}
+#endif /* UNIV_LOG_DEBUG */
}
/************************************************************
@@ -2850,10 +2881,12 @@ recv_recovery_from_checkpoint_finish(void)
recv_apply_hashed_log_recs(TRUE);
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Log records applied to the database\n");
}
+#endif /* UNIV_LOG_DEBUG */
if (recv_needed_recovery) {
trx_sys_print_mysql_master_log_pos();
@@ -2895,8 +2928,9 @@ recv_reset_logs(
{
log_group_t* group;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(log_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
log_sys->lsn = ut_dulint_align_up(lsn, OS_FILE_LOG_BLOCK_SIZE);
group = UT_LIST_GET_FIRST(log_sys->log_groups);
@@ -3164,6 +3198,7 @@ ask_again:
break;
}
+#ifdef UNIV_LOG_DEBUG
if (log_debug_writes) {
fprintf(stderr,
"InnoDB: Archive read starting at lsn %lu %lu, len %lu from file %s\n",
@@ -3171,6 +3206,7 @@ ask_again:
(ulong) ut_dulint_get_low(start_lsn),
(ulong) len, name);
}
+#endif /* UNIV_LOG_DEBUG */
fil_io(OS_FILE_READ | OS_FILE_LOG, TRUE,
group->archive_space_id, read_offset / UNIV_PAGE_SIZE,
diff --git a/innobase/log/trash/log0trsh.c b/innobase/log/trash/log0trsh.c
deleted file mode 100644
index 7f48118a0d1..00000000000
--- a/innobase/log/trash/log0trsh.c
+++ /dev/null
@@ -1,648 +0,0 @@
-/******************************************************
-Recovery
-
-(c) 1997 Innobase Oy
-
-Created 9/20/1997 Heikki Tuuri
-*******************************************************/
-
-#include "log0recv.h"
-
-#ifdef UNIV_NONINL
-#include "log0recv.ic"
-#endif
-
-#include "mem0mem.h"
-#include "buf0buf.h"
-#include "buf0flu.h"
-#include "srv0srv.h"
-
-/* Size of block reads when the log groups are scanned forward to do
-roll-forward */
-#define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
-
-/* Size of block reads when the log groups are scanned backwards to synchronize
-them */
-#define RECV_BACK_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
-
-recv_sys_t* recv_sys = NULL;
-
-recv_recover_page(block->frame, block->space, block->offset);
-
-/************************************************************
-Creates the recovery system. */
-
-void
-recv_sys_create(void)
-/*=================*/
-{
- ut_a(recv_sys == NULL);
-
- recv_sys = mem_alloc(sizeof(recv_t));
-
- mutex_create(&(recv_sys->mutex));
-
- recv_sys->hash = NULL;
- recv_sys->heap = NULL;
-}
-
-/************************************************************
-Inits the recovery system for a recovery operation. */
-
-void
-recv_sys_init(void)
-/*===============*/
-{
- recv_sys->hash = hash_create(buf_pool_get_curr_size() / 64);
- recv_sys->heap = mem_heap_create_in_buffer(256);
-}
-
-/************************************************************
-Empties the recovery system. */
-
-void
-recv_sys_empty(void)
-/*================*/
-{
- mutex_enter(&(recv_sys->mutex));
-
- hash_free(recv_sys->hash);
- mem_heap_free(recv_sys->heap);
-
- recv_sys->hash = NULL;
- recv_sys->heap = NULL;
-
- mutex_exit(&(recv_sys->mutex));
-}
-
-/***********************************************************
-For recovery purposes copies the log buffer to a group to synchronize log
-data. */
-static
-void
-recv_log_buf_flush(
-/*===============*/
- log_group_t* group, /* in: log group */
- dulint start_lsn, /* in: start lsn of the log data in
- the log buffer; must be divisible by
- OS_FILE_LOG_BLOCK_SIZE */
- dulint end_lsn) /* in: end lsn of the log data in the
- log buffer; must be divisible by
- OS_FILE_LOG_BLOCK_SIZE */
-{
- ulint len;
-
- ut_ad(mutex_own(&(log_sys->mutex)));
-
- len = ut_dulint_minus(end_lsn, start_lsn);
-
- log_group_write_buf(LOG_RECOVER, group, log_sys->buf, len, start_lsn,
- 0);
-}
-
-/***********************************************************
-Compares two buffers containing log segments and determines the highest lsn
-where they match, if any. */
-static
-dulint
-recv_log_bufs_cmp(
-/*==============*/
- /* out: if no match found, ut_dulint_zero or
- if start_lsn == LOG_START_LSN, returns
- LOG_START_LSN; otherwise the highest matching
- lsn */
- byte* recv_buf, /* in: buffer containing valid log data */
- byte* buf, /* in: buffer of data from a possibly
- incompletely written log group */
- dulint start_lsn, /* in: buffer start lsn, must be divisible
- by OS_FILE_LOG_BLOCK_SIZE and must be >=
- LOG_START_LSN */
- dulint end_lsn, /* in: buffer end lsn, must be divisible
- by OS_FILE_LOG_BLOCK_SIZE */
- dulint recovered_lsn) /* in: recovery succeeded up to this lsn */
-{
- ulint len;
- ulint offset;
- byte* log_block1;
- byte* log_block2;
- ulint no;
- ulint data_len;
-
- ut_ad(ut_dulint_cmp(start_lsn, LOG_START_LSN) >= 0);
-
- if (ut_dulint_cmp(end_lsn, recovered_lsn) > 0) {
- end_lsn = ut_dulint_align_up(recovered_lsn,
- OS_FILE_LOG_BLOCK_SIZE);
- }
-
- len = ut_dulint_minus(end_lsn, start_lsn);
-
- if (len == 0) {
-
- goto no_match;
- }
-
- ut_ad(len % OS_FILE_LOG_BLOCK_SIZE == 0);
-
- log_block1 = recv_buf + len;
- log_block2 = buf + len;
-
- for (;;) {
- log_block1 -= OS_FILE_LOG_BLOCK_SIZE;
- log_block2 -= OS_FILE_LOG_BLOCK_SIZE;
-
- no = log_block_get_hdr_no(log_block1);
- ut_a(no == log_block_get_trl_no(log_block1));
-
- if ((no == log_block_get_hdr_no(log_block2))
- && (no == log_block_get_trl_no(log_block2))) {
-
- /* Match found if the block is not corrupted */
-
- data_len = log_block_get_data_len(log_block2);
-
- if (0 == ut_memcmp(log_block1 + LOG_BLOCK_DATA,
- log_block2 + LOG_BLOCK_DATA,
- data_len - LOG_BLOCK_DATA)) {
-
- /* Match found */
-
- return(ut_dulint_add(start_lsn,
- log_block2 - buf + data_len));
- }
- }
-
- if (log_block1 == recv_buf) {
-
- /* No match found */
-
- break;
- }
- }
-no_match:
- if (ut_dulint_cmp(start_lsn, LOG_START_LSN) == 0) {
-
- return(LOG_START_LSN);
- }
-
- return(ut_dulint_zero);
-}
-
-/************************************************************
-Copies a log segment from the most up-to-date log group to the other log
-group, so that it contains the latest log data. */
-static
-void
-recv_copy_group(
-/*============*/
- log_group_t* up_to_date_group, /* in: the most up-to-date
- log group */
- log_group_t* group, /* in: copy to this log group */
- dulint_lsn recovered_lsn) /* in: recovery succeeded up
- to this lsn */
-{
- dulint start_lsn;
- dulint end_lsn;
- dulint match;
- byte* buf;
- byte* buf1;
-
- ut_ad(mutex_own(&(log_sys->mutex)));
-
- if (0 == ut_dulint_cmp(LOG_START_LSN, recovered_lsn)) {
-
- return;
- }
-
- ut_ad(RECV_BACK_SCAN_SIZE <= log_sys->buf_size);
-
- buf1 = mem_alloc(2 * RECV_BACK_SCAN_SIZE);
- buf = ut_align(buf, RECV_BACK_SCAN_SIZE););
-
- end_lsn = ut_dulint_align_up(recovered_lsn, RECV_BACK_SCAN_SIZE);
-
- match = ut_dulint_zero;
-
- for (;;) {
- if (ut_dulint_cmp(ut_dulint_add(LOG_START_LSN,
- RECV_BACK_SCAN_SIZE), end_lsn) >= 0) {
- start_lsn = LOG_START_LSN;
- } else {
- start_lsn = ut_dulint_subtract(end_lsn,
- RECV_BACK_SCAN_SIZE);
- }
-
- log_group_read_log_seg(LOG_RECOVER, buf, group, start_lsn,
- end_lsn);
- log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
- up_to_date_group, start_lsn, end_lsn);
-
- match = recv_log_bufs_cmp(log_sys->buf, buf, start_lsn,
- end_lsn, recovered_lsn);
-
- if (ut_dulint_cmp(match, recovered_lsn) != 0) {
- recv_log_buf_flush(group, start_lsn, end_lsn);
- }
-
- if (!ut_dulint_zero(match)) {
-
- mem_free(buf1);
-
- return;
- }
-
- end_lsn = start_lsn;
- }
-}
-
-/************************************************************
-Copies a log segment from the most up-to-date log group to the other log
-groups, so that they all contain the latest log data. Also writes the info
-about the latest checkpoint to the groups, and inits the fields in the group
-memory structs to up-to-date values. */
-
-void
-recv_synchronize_groups(
-/*====================*/
- log_group_t* up_to_date_group, /* in: the most up-to-date
- log group */
- dulint_lsn recovered_lsn, /* in: recovery succeeded up
- to this lsn */
- log_group_t* max_checkpoint_group) /* in: the group with the most
- recent checkpoint info */
-{
- log_group_t* group;
-
- ut_ad(mutex_own(&(log_sys->mutex)));
-
- group = UT_LIST_GET_FIRST(log_sys->log_groups);
-
- while (group) {
- if (group != up_to_date_group) {
-
- /* Copy log data */
-
- recv_copy_group(group, up_to_date_group,
- recovered_lsn);
- }
-
- if (group != max_checkpoint_group) {
-
- /* Copy the checkpoint info to the group */
-
- log_group_checkpoint(group);
-
- mutex_exit(&(log_sys->mutex));
-
- /* Wait for the checkpoint write to complete */
- rw_lock_s_lock(&(log_sys->checkpoint_lock));
- rw_lock_s_unlock(&(log_sys->checkpoint_lock));
-
- mutex_enter(&(log_sys->mutex));
- }
-
- /* Update the fields in the group struct to correspond to
- recovered_lsn */
-
- log_group_set_fields(group, recovered_lsn);
-
- group = UT_LIST_GET_NEXT(log_groups, group);
- }
-}
-
-/************************************************************
-Looks for the maximum consistent checkpoint from the log groups. */
-static
-ulint
-recv_find_max_checkpoint(
-/*=====================*/
- /* out: error code or DB_SUCCESS */
- log_group_t** max_group, /* out: max group */
- ulint* max_field) /* out: LOG_CHECKPOINT_1 or
- LOG_CHECKPOINT_2 */
-{
- log_group_t* group;
- dulint max_no;
- dulint cp_no;
- ulint field;
- ulint fold;
- byte* buf;
-
- ut_ad(mutex_own(&(log_sys->mutex)));
-
- /* Look for the latest checkpoint from the log groups */
- group = UT_LIST_GET_FIRST(log_sys->log_groups);
-
- checkpoint_no = ut_dulint_zero;
- checkpoint_lsn = ut_dulint_zero;
- *max_group = NULL;
-
- buf = log_sys->checkpoint_buf;
-
- while (group) {
- group->state = LOG_GROUP_CORRUPTED;
-
- for (field = LOG_CHECKPOINT_1; field <= LOG_CHECKPOINT_2;
- field += LOG_CHECKPOINT_2 - LOG_CHECKPOINT_1) {
-
- log_group_read_checkpoint_info(group, field);
-
- /* Check the consistency of the checkpoint info */
- fold = ut_fold_binary(buf, LOG_CHECKPOINT_CHECKSUM_1);
-
- if (fold != mach_read_from_4(buf
- + LOG_CHECKPOINT_CHECKSUM_1)) {
- goto not_consistent;
- }
-
- fold = ut_fold_binary(buf + LOG_CHECKPOINT_LSN,
- LOG_CHECKPOINT_CHECKSUM_2
- - LOG_CHECKPOINT_LSN);
- if (fold != mach_read_from_4(buf
- + LOG_CHECKPOINT_CHECKSUM_2)) {
- goto not_consistent;
- }
-
- group->state = LOG_GROUP_OK;
-
- group->lsn = mach_read_from_8(buf
- + LOG_CHECKPOINT_LSN);
- group->lsn_offset = mach_read_from_4(buf
- + LOG_CHECKPOINT_OFFSET);
- group->lsn_file_count = mach_read_from_4(
- buf + LOG_CHECKPOINT_FILE_COUNT);
-
- cp_no = mach_read_from_8(buf + LOG_CHECKPOINT_NO);
-
- if (ut_dulint_cmp(cp_no, max_no) >= 0) {
- *max_group = group;
- *max_field = field;
- max_no = cp_no;
- }
-
- not_consistent:
- }
-
- group = UT_LIST_GET_NEXT(log_groups, group);
- }
-
- if (*max_group == NULL) {
-
- return(DB_ERROR);
- }
-
- return(DB_SUCCESS);
-}
-
-/***********************************************************
-Parses log records from a buffer and stores them to a hash table to wait
-merging to file pages. If the hash table becomes too big, merges automatically
-it to file pages. */
-static
-bool
-recv_parse_and_hash_log_recs(
-/*=========================*/
- /* out: TRUE if limit_lsn has been reached */
- byte* buf, /* in: buffer containing a log segment or
- garbage */
- ulint len, /* in: buffer length */
- dulint start_lsn, /* in: buffer start lsn */
- dulint limit_lsn, /* in: recover at least to this lsn */
- dulint* recovered_lsn) /* out: was able to parse up to this lsn */
-{
-
-}
-
-/************************************************************
-Recovers from a checkpoint. When this function returns, the database is able
-to start processing new user transactions, but the function
-recv_recovery_from_checkpoint_finish should be called later to complete
-the recovery and free the resources used in it. */
-
-ulint
-recv_recovery_from_checkpoint_start(
-/*================================*/
- /* out: error code or DB_SUCCESS */
- dulint limit_lsn) /* in: recover up to this lsn if possible */
-{
- log_group_t* max_cp_group;
- log_group_t* up_to_date_group;
- ulint max_cp_field;
- byte* buf;
- ulint err;
- dulint checkpoint_lsn;
- dulint checkpoint_no;
- dulint recovered_lsn;
- dulint old_lsn;
- dulint end_lsn;
- dulint start_lsn;
- bool finished;
- dulint flush_start_lsn;
-
- mutex_enter(&(log_sys->mutex));
-
- /* Look for the latest checkpoint from any of the log groups */
-
- err = recv_find_max_checkpoint(&max_cp_group, &max_cp_field);
-
- if (err != DB_SUCCESS) {
- mutex_exit(&(log_sys->mutex));
-
- return(err);
- }
-
- log_group_read_checkpoint_info(max_cp_group, max_cp_field);
-
- buf = log_sys->checkpoint_buf;
-
- checkpoint_lsn = mach_read_from_8(buf + LOG_CHECKPOINT_LSN);
- checkpoint_no = mach_read_from_8(buf + LOG_CHECKPOINT_NO);
-
- if (ut_dulint_cmp(limit_lsn, checkpoint_lsn) < 0) {
- mutex_exit(&(log_sys->mutex));
-
- return(DB_ERROR);
- }
-
- /* Start reading the log groups from the checkpoint lsn up. The
- variable flush_start_lsn tells a lsn up to which the log is known
- to be contiguously written in all log groups. */
-
- recovered_lsn = checkpoint_lsn;
- flush_start_lsn = ut_dulint_align_down(checkpoint_lsn,
- OS_FILE_LOG_BLOCK_SIZE);
- up_to_date_group = max_cp_group;
-
- ut_ad(RECV_SCAN_SIZE <= log_sys->buf_size);
-
- group = UT_LIST_GET_FIRST(log_sys->log_groups);
-
- while (group) {
- finished = FALSE;
-
- if (group->state == LOG_GROUP_CORRUPTED) {
- finished = TRUE;
- }
-
- start_lsn = flush_start_lsn;
-
- while (!finished) {
- end_lsn = ut_dulint_add(start_lsn, RECV_SCAN_SIZE);
-
- log_group_read_log_seg(LOG_RECOVER, log_sys->buf,
- group, start_lsn, end_lsn);
- old_lsn = recovered_lsn;
-
- finished = recv_parse_and_hash_log_recs(log_sys->buf,
- RECV_SCAN_SIZE, start_lsn,
- limit_lsn, &flush_start_lsn,
- &recovered_lsn);
-
- if (ut_dulint_cmp(recovered_lsn, old_lsn) > 0) {
-
- /* We found a more up-to-date group */
- up_to_date_group = group;
- }
-
- start_lsn = end_lsn;
- }
-
- group = UT_LIST_GET_NEXT(log_groups, group);
- }
-
- /* Delete possible corrupted or extra log records from all log
- groups */
-
- recv_truncate_groups(recovered_lsn);
-
- /* Synchronize the uncorrupted log groups to the most up-to-date log
- group; we may also have to copy checkpoint info to groups */
-
- log_sys->next_checkpoint_lsn = checkpoint_lsn;
- log_sys->next_checkpoint_no = checkpoint_no;
-
- recv_synchronize_groups(up_to_date_group, _lsn, max_cp_group);
-
- log_sys->next_checkpoint_no = ut_dulint_add(checkpoint_no, 1);
-
- /* The database is now ready to start almost normal processing of user
- transactions */
-
- return(DB_SUCCESS);
-}
-
-/************************************************************
-Completes recovery from a checkpoint. */
-
-void
-recv_recovery_from_checkpoint_finish(void)
-/*======================================*/
-{
- /* Rollback the uncommitted transactions which have no user session */
-
- trx_rollback_all_without_sess();
-
- /* Merge the hashed log records */
-
- recv_merge_hashed_log_recs();
-
- /* Free the resources of the recovery system */
-
- recv_sys_empty();
-}
-
-/****************************************************************
-Writes to the log a record about incrementing the row id counter. */
-UNIV_INLINE
-void
-log_write_row_id_incr_rec(void)
-/*===========================*/
-{
- log_t* log = log_sys;
- ulint data_len;
-
- mutex_enter(&(log->mutex));
-
- data_len = (log->buf_free % OS_FILE_LOG_BLOCK_SIZE) + 1;
-
- if (data_len >= OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_TRL_SIZE) {
-
- /* The string does not fit within the current log block
- or the the block would become full */
-
- mutex_exit(&(log->mutex));
-
- log_write_row_id_incr_rec_slow();
-
- return;
- }
-
- *(log->buf + log->buf_free) = MLOG_INCR_ROW_ID | MLOG_SINGLE_REC_FLAG;
-
- log_block_set_data_len(ut_align_down(log->buf + log->buf_free,
- OS_FILE_LOG_BLOCK_SIZE),
- data_len);
-#ifdef UNIV_LOG_DEBUG
- log->old_buf_free = log->buf_free;
- log->old_lsn = log->lsn;
- log_check_log_recs(log->buf + log->buf_free, 1, log->lsn);
-#endif
- log->buf_free++;
-
- ut_ad(log->buf_free <= log->buf_size);
-
- UT_DULINT_INC(log->lsn);
-
- mutex_exit(&(log->mutex));
-}
-
-/****************************************************************
-Writes to the log a record about incrementing the row id counter. */
-static
-void
-log_write_row_id_incr_rec_slow(void)
-/*================================*/
-{
- byte type;
-
- log_reserve_and_open(1);
-
- type = MLOG_INCR_ROW_ID | MLOG_SINGLE_REC_FLAG;
-
- log_write_low(&type, 1);
-
- log_close();
-
- log_release();
-}
-
-/**************************************************************************
-Parses and applies a log record MLOG_SET_ROW_ID. */
-
-byte*
-dict_hdr_parse_set_row_id(
-/*======================*/
- /* out: end of log record or NULL */
- byte* ptr, /* in: buffer */
- byte* end_ptr,/* in: buffer end */
- page_t* page) /* in: page or NULL */
-{
- dulint dval;
-
- ptr = mach_dulint_parse_compressed(ptr, end_ptr, &dval);
-
- if (ptr == NULL) {
-
- return(NULL);
- }
-
- if (!page) {
-
- return(ptr);
- }
-
- mach_write_to_8(page + DICT_HDR + DICT_HDR_ROW_ID, dval);
-
- return(ptr);
-}
-
diff --git a/innobase/mach/ts/makefile b/innobase/mach/ts/makefile
deleted file mode 100644
index e9531e6ebe0..00000000000
--- a/innobase/mach/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsmach: ..\mach.lib tsmach.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\mach.lib ..\..\ut.lib ..\..\os.lib tsmach.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/mach/ts/tsmach.c b/innobase/mach/ts/tsmach.c
deleted file mode 100644
index a4b67227d20..00000000000
--- a/innobase/mach/ts/tsmach.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/************************************************************************
-The test module for the machine-dependent utilities
-
-(c) 1995 Innobase Oy
-
-Created 11/28/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "../mach0data.h"
-
-byte arr[4000000];
-
-
-/*********************************************************************
-Test for ulint write and read. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint a, i, j;
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Speed test of ulint read and write \n");
-
- a = 0;
-
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
- for (i = 0; i < 10000; i++) {
-
- a += mach_read_from_4(arr + i * 4);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- j * i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
- for (i = 0; i < 10000; i++) {
-
- a += mach_read(arr + i * 4);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- j * i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
- for (i = 0; i < 10000; i++) {
-
- a += mach_read_from_4(arr + i * 4 + 1);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- j * i, tm - oldtm);
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
- for (i = 0; i < 10000; i++) {
-
- a += mach_read(arr + i * 4 + 1);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- j * i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000000; i++) {
-
- a += mach_read_from_4(arr + i * 4);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- i, tm - oldtm);
- oldtm = ut_clock();
-
- for (i = 0; i < 1000000; i++) {
-
- a += mach_read(arr + i * 4);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu ulints %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
- for (i = 0; i < 10000; i++) {
-
- a += mach_read_from_2(arr + i * 2);
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for read of %lu 16-bit ints %lu millisecs\n",
- j * i, tm - oldtm);
-}
-
-/*********************************************************************
-Test for ulint write and read. */
-
-void
-test2(void)
-/*=======*/
-{
- ulint a[2];
-
- printf("-------------------------------------------\n");
- printf("TEST 2. Correctness test of ulint read and write \n");
-
- mach_write_to_4((byte*)&a, 737237727);
-
- ut_a(737237727 == mach_read_from_4((byte*)&a));
-
- mach_write_to_2((byte*)&a, 7372);
-
- ut_a(7372 == mach_read_from_2((byte*)&a));
-
- mach_write_to_1((byte*)&a, 27);
-
- ut_a(27 == mach_read_from_1((byte*)&a));
-
- mach_write((byte*)&a, 737237727);
-
- ut_a(737237727 == mach_read((byte*)&a));
-}
-
-void
-main(void)
-{
- test1();
- test2();
-
- printf("TEST SUCCESSFULLY COMPLETED!\n");
-}
diff --git a/innobase/mem/mem0dbg.c b/innobase/mem/mem0dbg.c
index 004197a5b8e..d521143eb47 100644
--- a/innobase/mem/mem0dbg.c
+++ b/innobase/mem/mem0dbg.c
@@ -7,6 +7,7 @@ but is included in mem0mem.* !
Created 6/9/1994 Heikki Tuuri
*************************************************************************/
+#ifdef UNIV_MEM_DEBUG
mutex_t mem_hash_mutex; /* The mutex which protects in the
debug version the hash table containing
the list of live memory heaps, and
@@ -16,12 +17,11 @@ mutex_t mem_hash_mutex; /* The mutex which protects in the
extent of memory allocations. Only used in the debug version.
Protected by mem_hash_mutex above. */
-ulint mem_n_created_heaps = 0;
-ulint mem_n_allocations = 0;
-ulint mem_total_allocated_memory = 0;
-ulint mem_current_allocated_memory = 0;
-ulint mem_max_allocated_memory = 0;
-ulint mem_last_print_info = 0;
+static ulint mem_n_created_heaps = 0;
+static ulint mem_n_allocations = 0;
+static ulint mem_total_allocated_memory = 0;
+ulint mem_current_allocated_memory = 0;
+static ulint mem_max_allocated_memory = 0;
/* Size of the hash table for memory management tracking */
#define MEM_HASH_SIZE 997
@@ -43,12 +43,12 @@ struct mem_hash_node_struct {
typedef UT_LIST_BASE_NODE_T(mem_hash_node_t) mem_hash_cell_t;
/* The hash table of allocated heaps */
-mem_hash_cell_t mem_hash_table[MEM_HASH_SIZE];
+static mem_hash_cell_t mem_hash_table[MEM_HASH_SIZE];
/* The base node of the list of all allocated heaps */
-mem_hash_cell_t mem_all_list_base;
+static mem_hash_cell_t mem_all_list_base;
-ibool mem_hash_initialized = FALSE;
+static ibool mem_hash_initialized = FALSE;
UNIV_INLINE
@@ -65,45 +65,44 @@ mem_hash_get_nth_cell(ulint i)
return(&(mem_hash_table[i]));
}
+#endif /* UNIV_MEM_DEBUG */
/* Accessor functions for a memory field in the debug version */
void
mem_field_header_set_len(byte* field, ulint len)
{
- ut_ad(len >= 0);
-
- mach_write(field - 2 * sizeof(ulint), len);
+ mach_write_to_4(field - 2 * sizeof(ulint), len);
}
ulint
mem_field_header_get_len(byte* field)
{
- return(mach_read(field - 2 * sizeof(ulint)));
+ return(mach_read_from_4(field - 2 * sizeof(ulint)));
}
void
mem_field_header_set_check(byte* field, ulint check)
{
- mach_write(field - sizeof(ulint), check);
+ mach_write_to_4(field - sizeof(ulint), check);
}
ulint
mem_field_header_get_check(byte* field)
{
- return(mach_read(field - sizeof(ulint)));
+ return(mach_read_from_4(field - sizeof(ulint)));
}
void
mem_field_trailer_set_check(byte* field, ulint check)
{
- mach_write(field + mem_field_header_get_len(field), check);
+ mach_write_to_4(field + mem_field_header_get_len(field), check);
}
ulint
mem_field_trailer_get_check(byte* field)
{
- return(mach_read(field +
+ return(mach_read_from_4(field +
mem_field_header_get_len(field)));
}
@@ -164,6 +163,7 @@ mem_field_init(
mem_field_header_set_check(usr_buf, rnd);
mem_field_trailer_set_check(usr_buf, rnd);
+#ifdef UNIV_MEM_DEBUG
/* Update the memory allocation information */
mutex_enter(&mem_hash_mutex);
@@ -182,6 +182,7 @@ mem_field_init(
combination of 0xBA and 0xBE */
mem_init_buf(usr_buf, n);
+#endif /* UNIV_MEM_DEBUG */
}
/**********************************************************************
@@ -191,12 +192,14 @@ void
mem_field_erase(
/*============*/
byte* buf, /* in: memory field */
- ulint n) /* in: how many bytes the user requested */
+ ulint n __attribute__((unused)))
+ /* in: how many bytes the user requested */
{
byte* usr_buf;
usr_buf = buf + MEM_FIELD_HEADER_SIZE;
-
+
+#ifdef UNIV_MEM_DEBUG
mutex_enter(&mem_hash_mutex);
mem_current_allocated_memory -= n;
mutex_exit(&mem_hash_mutex);
@@ -208,8 +211,10 @@ mem_field_erase(
combination of 0xDE and 0xAD */
mem_erase_buf(buf, MEM_SPACE_NEEDED(n));
+#endif /* UNIV_MEM_DEBUG */
}
+#ifdef UNIV_MEM_DEBUG
/*******************************************************************
Initializes a buffer to a random combination of hex BA and BE.
Used to initialize allocated memory. */
@@ -372,6 +377,7 @@ mem_hash_remove(
mutex_exit(&mem_hash_mutex);
}
+#endif /* UNIV_MEM_DEBUG */
/*******************************************************************
Checks a memory heap for consistency and prints the contents if requested.
@@ -408,12 +414,12 @@ mem_heap_validate_or_print(
ulint total_len = 0;
ulint block_count = 0;
ulint phys_len = 0;
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
ulint len;
byte* field;
byte* user_field;
ulint check_field;
- #endif
+#endif
/* Pessimistically, we set the parameters to error values */
if (us_size != NULL) {
@@ -451,7 +457,7 @@ mem_heap_validate_or_print(
return;
}
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* We can trace the fields of the block only in the debug
version */
if (print) {
@@ -518,7 +524,7 @@ mem_heap_validate_or_print(
return;
}
- #endif
+#endif
block = UT_LIST_GET_NEXT(list, block);
block_count++;
@@ -603,130 +609,7 @@ mem_heap_validate(
return(TRUE);
}
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated
-memory heaps or buffers. Can only be used in the debug version. */
-static
-void
-mem_print_info_low(
-/*===============*/
- ibool print_all __attribute__((unused)))
- /* in: if TRUE, all heaps are printed,
- else only the heaps allocated after the
- previous call of this function */
-{
#ifdef UNIV_MEM_DEBUG
- mem_hash_node_t* node;
- ulint n_heaps = 0;
- ulint allocated_mem;
- ulint ph_size;
- ulint total_allocated_mem = 0;
- ibool error;
- ulint n_blocks;
-#endif
- FILE* outfile;
-
- /* outfile = fopen("ibdebug", "a"); */
-
- outfile = stdout;
-
- fprintf(outfile, "\n");
- fprintf(outfile,
- "________________________________________________________\n");
- fprintf(outfile, "MEMORY ALLOCATION INFORMATION\n\n");
-
-#ifndef UNIV_MEM_DEBUG
-
- mem_pool_print_info(outfile, mem_comm_pool);
-
- fprintf(outfile,
- "Sorry, non-debug version cannot give more memory info\n");
-
- /* fclose(outfile); */
-
- return;
-#else
- mutex_enter(&mem_hash_mutex);
-
- fprintf(outfile, "LIST OF CREATED HEAPS AND ALLOCATED BUFFERS: \n\n");
-
- if (!print_all) {
- fprintf(outfile, "AFTER THE LAST PRINT INFO\n");
- }
-
- node = UT_LIST_GET_FIRST(mem_all_list_base);
-
- while (node != NULL) {
- n_heaps++;
-
- if (!print_all && node->nth_heap < mem_last_print_info) {
-
- goto next_heap;
- }
-
- mem_heap_validate_or_print(node->heap, NULL,
- FALSE, &error, &allocated_mem,
- &ph_size, &n_blocks);
- total_allocated_mem += allocated_mem;
-
- fprintf(outfile,
- "%lu: file %s line %lu of size %lu phys.size %lu with %lu blocks, type %lu\n",
- node->nth_heap, node->file_name, node->line,
- allocated_mem, ph_size, n_blocks,
- (node->heap)->type);
- next_heap:
- node = UT_LIST_GET_NEXT(all_list, node);
- }
-
- fprintf(outfile, "\n");
-
- fprintf(outfile, "Current allocated memory : %lu\n",
- mem_current_allocated_memory);
- fprintf(outfile, "Current allocated heaps and buffers : %lu\n",
- n_heaps);
- fprintf(outfile, "Cumulative allocated memory : %lu\n",
- mem_total_allocated_memory);
- fprintf(outfile, "Maximum allocated memory : %lu\n",
- mem_max_allocated_memory);
- fprintf(outfile, "Cumulative created heaps and buffers : %lu\n",
- mem_n_created_heaps);
- fprintf(outfile, "Cumulative number of allocations : %lu\n",
- mem_n_allocations);
-
- mem_last_print_info = mem_n_created_heaps;
-
- mutex_exit(&mem_hash_mutex);
-
- mem_pool_print_info(outfile, mem_comm_pool);
-
-/* mem_validate(); */
-
-/* fclose(outfile); */
-#endif
-}
-
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated memory
-heaps or buffers. Can only be used in the debug version. */
-
-void
-mem_print_info(void)
-/*================*/
-{
- mem_print_info_low(TRUE);
-}
-
-/*********************************************************************
-Prints information of dynamic memory usage and currently allocated memory
-heaps or buffers since the last ..._print_info or..._print_new_info. */
-
-void
-mem_print_new_info(void)
-/*====================*/
-{
- mem_print_info_low(FALSE);
-}
-
/*********************************************************************
TRUE if no memory is currently allocated. */
@@ -735,8 +618,6 @@ mem_all_freed(void)
/*===============*/
/* out: TRUE if no heaps exist */
{
- #ifdef UNIV_MEM_DEBUG
-
mem_hash_node_t* node;
ulint heap_count = 0;
ulint i;
@@ -764,15 +645,6 @@ mem_all_freed(void)
} else {
return(FALSE);
}
-
- #else
-
- printf(
- "Sorry, non-debug version cannot check if all memory is freed.\n");
-
- return(FALSE);
-
- #endif
}
/*********************************************************************
@@ -783,8 +655,6 @@ mem_validate_no_assert(void)
/*========================*/
/* out: TRUE if error */
{
- #ifdef UNIV_MEM_DEBUG
-
mem_hash_node_t* node;
ulint n_heaps = 0;
ulint allocated_mem;
@@ -843,14 +713,6 @@ mem_validate_no_assert(void)
mutex_exit(&mem_hash_mutex);
return(error);
-
- #else
-
- printf("Sorry, non-debug version cannot validate dynamic memory\n");
-
- return(FALSE);
-
- #endif
}
/****************************************************************
@@ -865,6 +727,7 @@ mem_validate(void)
return(TRUE);
}
+#endif /* UNIV_MEM_DEBUG */
/****************************************************************
Tries to find neigboring memory allocation blocks and dumps to stderr
diff --git a/innobase/mem/mem0mem.c b/innobase/mem/mem0mem.c
index 94cf85dfd63..6de8d0c5f20 100644
--- a/innobase/mem/mem0mem.c
+++ b/innobase/mem/mem0mem.c
@@ -294,13 +294,13 @@ mem_heap_block_free(
init_block = block->init_block;
block->magic_n = MEM_FREED_BLOCK_MAGIC_N;
- #ifdef UNIV_MEM_DEBUG
+#ifdef UNIV_MEM_DEBUG
/* In the debug version we set the memory to a random combination
of hex 0xDE and 0xAD. */
mem_erase_buf((byte*)block, len);
- #endif
+#endif
if (init_block) {
/* Do not have to free: do nothing */
diff --git a/innobase/mem/mem0pool.c b/innobase/mem/mem0pool.c
index 2817e1f12d4..4f1ac2bcd7c 100644
--- a/innobase/mem/mem0pool.c
+++ b/innobase/mem/mem0pool.c
@@ -259,7 +259,9 @@ mem_pool_fill_free_list(
mem_area_t* area2;
ibool ret;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(pool->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (i >= 63) {
/* We come here when we have run out of space in the
@@ -296,7 +298,7 @@ mem_pool_fill_free_list(
if (UT_LIST_GET_LEN(pool->free_list[i + 1]) == 0) {
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
UT_LIST_REMOVE(free_list, pool->free_list[i + 1], area);
@@ -374,7 +376,7 @@ mem_area_alloc(
"InnoDB: Probably a race condition because now the area is marked free!\n");
}
- ut_a(0);
+ ut_error;
}
if (UT_LIST_GET_LEN(pool->free_list[n]) == 0) {
@@ -384,7 +386,7 @@ mem_area_alloc(
(ulong) n);
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
ut_ad(mem_area_get_size(area) == ut_2_exp(n));
@@ -480,7 +482,7 @@ mem_area_free(
"InnoDB: element is marked free!\n");
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
size = mem_area_get_size(area);
@@ -491,7 +493,7 @@ mem_area_free(
"InnoDB: previous allocated area!\n");
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
#ifdef UNIV_LIGHT_MEM_DEBUG
@@ -508,7 +510,7 @@ mem_area_free(
(ulong) size, (ulong) next_size);
mem_analyze_corruption((byte*)area);
- ut_a(0);
+ ut_error;
}
}
#endif
diff --git a/innobase/mem/ts/makefile b/innobase/mem/ts/makefile
deleted file mode 100644
index 0f6855322ce..00000000000
--- a/innobase/mem/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsmem: ..\mem.lib tsmem.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\mem.lib ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\os.lib tsmem.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/mem/ts/tsmem.c b/innobase/mem/ts/tsmem.c
deleted file mode 100644
index 4a108251673..00000000000
--- a/innobase/mem/ts/tsmem.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/************************************************************************
-The test module for the memory management of Innobase
-
-(c) 1994, 1995 Innobase Oy
-
-Created 6/10/1994 Heikki Tuuri
-*************************************************************************/
-
-#include "../mem0mem.h"
-#include "sync0sync.h"
-#include "ut0rnd.h"
-
-mem_heap_t* heap_arr[1200];
-
-byte* buf_arr[10000];
-ulint rnd_arr[10000];
-
-
-#ifdef UNIV_DEBUG
-/*********************************************************************
-Debug version test. */
-
-void
-test1(void)
-/*=======*/
-{
- mem_heap_t* heap_1, *heap_2;
- byte* buf_1, *buf_2, *buf_3;
- byte check;
- bool error;
- ulint i;
- ulint j;
- ulint sum;
- ulint user_size;
- ulint phys_size, phys_size_1, phys_size_2;
- ulint n_blocks;
- ulint p;
- byte block[1024];
- byte* top_1, *top_2;
-
- /* For this test to work the memory alignment must be
- even (presumably a reasonable assumption) */
- ut_a(0 == (UNIV_MEM_ALIGNMENT & 1));
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Basic test \n");
-
- heap_1 = mem_heap_create(0);
-
- buf_1 = mem_heap_alloc(heap_1, 11);
-
- heap_2 = mem_heap_create(0);
-
- buf_2 = mem_heap_alloc(heap_1, 15);
-
- /* Test that the field is properly initialized */
- for (i = 0; i < 11; i++) {
- ut_a((*(buf_1 + i) == 0xBA) || (*(buf_1 + i) == 0xBE));
- }
-
- check = *(buf_1 + 11);
-
- mem_validate();
-
- /* Make an advertent error in the heap */
- (*(buf_1 + 11))++;
-
- error = mem_validate_no_assert();
-
- ut_a(error);
-
- /* Fix the error in heap before freeing */
- *(buf_1 + 11) = check;
-
- mem_print_info();
-
- /* Free the top buffer buf_2 */
- mem_heap_free_top(heap_1, 15);
-
- /* Test that the field is properly erased */
- for (i = 0; i < 15; i++) {
- ut_a((*(buf_2 + i) == 0xDE) || (*(buf_2 + i) == 0xAD));
- }
-
- /* Test that a new buffer is allocated from the same position
- as buf_2 */
- buf_3 = mem_heap_alloc(heap_1, 15);
-
- ut_a(buf_3 == buf_2);
-
- mem_heap_free(heap_1);
-
- /* Test that the field is properly erased */
- for (i = 0; i < 11; i++) {
- ut_a((*(buf_1 + i) == 0xDE) || (*(buf_1 + i) == 0xAD));
- }
-
- mem_validate();
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 2. Test of massive allocation and freeing\n");
-
- sum = 0;
- for (i = 0; i < 10000; i++) {
-
- j = ut_rnd_gen_ulint() % 16 + 15;
-
- sum = sum + j;
-
- buf_1 = mem_heap_alloc(heap_2, j);
- rnd_arr[i] = j;
-
- buf_arr[i] = buf_1;
-
- ut_a(buf_1 == mem_heap_get_top(heap_2, j));
- }
-
- mem_heap_validate_or_print(heap_2, NULL, FALSE, &error, &user_size,
- &phys_size_1,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == sum);
-
- (*(buf_1 - 1))++;
-
- ut_a(mem_validate_no_assert());
-
- (*(buf_1 - 1))--;
-
- mem_print_info();
-
-
- for (p = 10000; p > 0 ; p--) {
-
- j = rnd_arr[p - 1];
-
- ut_a(buf_arr[p - 1] == mem_heap_get_top(heap_2, j));
- mem_heap_free_top(heap_2, j);
- }
-
- mem_print_info();
-
- mem_heap_free(heap_2);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 3. More tests on the validating \n");
-
- heap_1 = mem_heap_create(UNIV_MEM_ALIGNMENT * 20);
-
- buf_1 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 20);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error, &user_size,
- &phys_size_1,
- &n_blocks);
-
- ut_a((ulint)(buf_1 - (byte*)heap_1) == (MEM_BLOCK_HEADER_SIZE
- + MEM_FIELD_HEADER_SIZE));
-
- mem_validate();
-
- mem_print_info();
-
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 20);
- ut_a(phys_size_1 == (ulint)(ut_calc_align(MEM_FIELD_HEADER_SIZE
- + UNIV_MEM_ALIGNMENT * 20
- + MEM_FIELD_TRAILER_SIZE,
- UNIV_MEM_ALIGNMENT)
- + MEM_BLOCK_HEADER_SIZE));
-
- ut_a(n_blocks == 1);
-
- buf_2 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 3 - 1);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size_2,
- &n_blocks);
-
- printf("Physical size of the heap %ld\n", phys_size_2);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 23 - 1);
- ut_a(phys_size_2 == (ulint) (phys_size_1
- + ut_calc_align(MEM_FIELD_HEADER_SIZE
- + phys_size_1 * 2
- + MEM_FIELD_TRAILER_SIZE,
- UNIV_MEM_ALIGNMENT)
- + MEM_BLOCK_HEADER_SIZE));
-
- ut_a(n_blocks == 2);
-
- buf_3 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT * 3 + 5);
-
- ut_a((ulint)(buf_3 - buf_2) == ut_calc_align(
- (UNIV_MEM_ALIGNMENT * 3
- + MEM_FIELD_TRAILER_SIZE),
- UNIV_MEM_ALIGNMENT)
- + MEM_FIELD_HEADER_SIZE);
-
-
- ut_memcpy(buf_3, buf_2, UNIV_MEM_ALIGNMENT * 3);
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 26 + 4);
- ut_a(phys_size == phys_size_2);
- ut_a(n_blocks == 2);
-
-
- /* Make an advertent error to buf_3 */
-
- (*(buf_3 - 1))++;
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(error);
- ut_a(user_size == 0);
- ut_a(phys_size == 0);
- ut_a(n_blocks == 0);
-
- /* Fix the error and make another */
-
- (*(buf_3 - 1))--;
- (*(buf_3 + UNIV_MEM_ALIGNMENT * 3 + 5))++;
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(error);
-
- (*(buf_3 + UNIV_MEM_ALIGNMENT * 3 + 5))--;
-
- buf_1 = mem_heap_alloc(heap_1, UNIV_MEM_ALIGNMENT + 4);
-
- ut_a((ulint)(buf_1 - buf_3) == ut_calc_align(UNIV_MEM_ALIGNMENT * 3 + 5
- + MEM_FIELD_TRAILER_SIZE ,
- UNIV_MEM_ALIGNMENT)
- + MEM_FIELD_HEADER_SIZE);
-
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- &user_size, &phys_size,
- &n_blocks);
-
- ut_a(!error);
- ut_a(user_size == UNIV_MEM_ALIGNMENT * 27 + 8);
- ut_a(phys_size == phys_size_2);
- ut_a(n_blocks == 2);
-
-
- mem_print_info();
-
- mem_heap_free(heap_1);
-
- printf("-------------------------------------------\n");
- printf("TEST 4. Test of massive allocation \n");
- printf("of heaps to test the hash table\n");
-
- for (i = 0; i < 500; i++) {
- heap_arr[i] = mem_heap_create(i);
- buf_2 = mem_heap_alloc(heap_arr[i], 2 * i);
- }
-
- mem_validate();
-
- for (i = 0; i < 500; i++) {
- mem_heap_free(heap_arr[i]);
- }
-
- mem_validate();
-
- mem_print_info();
-
- /* Validating a freed heap should generate an error */
-
- mem_heap_validate_or_print(heap_1, NULL, FALSE, &error,
- NULL, NULL, NULL);
-
- ut_a(error);
-
- printf("-------------------------------------------\n");
- printf("TEST 5. Test of mem_alloc and mem_free \n");
-
- buf_1 = mem_alloc(11100);
- buf_2 = mem_alloc(23);
-
- ut_memcpy(buf_2, buf_1, 23);
-
- mem_validate();
-
- mem_print_info();
-
- mem_free(buf_1);
- mem_free(buf_2);
-
- mem_validate();
-
- printf("-------------------------------------------\n");
- printf("TEST 6. Test of mem_heap_print \n");
-
- heap_1 = mem_heap_create(0);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 10; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- printf("A heap with 1 Pascal and 10 Cobol's\n");
- mem_heap_print(heap_1);
-
- for (i = 0; i < 10; i++) {
- mem_heap_free_top(heap_1, 6);
- }
-
- printf("A heap with 1 Pascal and 0 Cobol's\n");
- mem_heap_print(heap_1);
-
- ut_a(mem_all_freed() == FALSE);
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 7. Test of mem_heap_fast_create \n");
-
- heap_1 = mem_heap_fast_create(1024, block);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 1000; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- for (i = 0; i < 1000; i++) {
- mem_heap_free_top(heap_1, 6);
- }
-
- ut_a(mem_all_freed() == FALSE);
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
- printf("-------------------------------------------\n");
- printf("TEST 8. Test of heap top freeing \n");
-
- heap_1 = mem_heap_fast_create(1024, block);
-
- top_1 = mem_heap_get_heap_top(heap_1);
-
- buf_1 = mem_heap_alloc(heap_1, 7);
-
- ut_memcpy(buf_1, "Pascal", 7);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- top_2 = mem_heap_get_heap_top(heap_1);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
- }
-
- mem_heap_free_heap_top(heap_1, top_2);
-
- mem_heap_free_heap_top(heap_1, top_1);
-
- ut_a(mem_all_freed() == FALSE);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
-
- }
-
- mem_heap_empty(heap_1);
-
- for (i = 0; i < 500; i++) {
- buf_1 = mem_heap_alloc(heap_1, 6);
- ut_memcpy(buf_1, "Cobol", 6);
-
- }
-
- mem_heap_free(heap_1);
-
- ut_a(mem_all_freed() == TRUE);
-
- mem_print_info();
-
-}
-#endif /* UNIV_DEBUG */
-
-/****************************************************************
-Allocation speed test. */
-
-void
-test2(void)
-/*=======*/
-{
- mem_heap_t* heap;
- ulint tm, oldtm;
- ulint i;
- byte* buf;
- byte block[512];
-
- printf("-------------------------------------------\n");
- printf("TEST B1. Test of speed \n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- heap = mem_heap_create(500);
- mem_heap_free(heap);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap create-free pairs %ld millisecs.\n",
- i, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- heap = mem_heap_fast_create(512, block);
- mem_heap_free(heap);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap fast-create-free pairs %ld millisecs.\n",
- i, tm - oldtm);
-
-
- heap = mem_heap_create(500);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
- buf = mem_heap_alloc(heap, 50);
- mem_heap_free_top(heap, 50);
- }
-
- tm = ut_clock();
-
- printf("Time for %ld heap alloc-free-top pairs %ld millisecs.\n",
- i, tm - oldtm);
-
- mem_heap_free(heap);
-}
-
-
-void
-main(void)
-{
- sync_init();
- mem_init(2500000);
-
- #ifdef UNIV_DEBUG
-
- test1();
-
- #endif
-
- test2();
-
- ut_ad(sync_all_freed());
-
- ut_ad(mem_all_freed());
-
- printf("TEST SUCCESSFULLY COMPLETED!\n");
-}
diff --git a/innobase/mtr/mtr0log.c b/innobase/mtr/mtr0log.c
index 4b5d7e61de6..5a4aaa2377d 100644
--- a/innobase/mtr/mtr0log.c
+++ b/innobase/mtr/mtr0log.c
@@ -59,7 +59,7 @@ mlog_write_initial_log_record(
fprintf(stderr,
"InnoDB: Error: trying to write to a stray memory location %lx\n",
(ulong) ptr);
- ut_a(0);
+ ut_error;
}
log_ptr = mlog_open(mtr, 20);
@@ -222,7 +222,7 @@ mlog_write_ulint(
fprintf(stderr,
"InnoDB: Error: trying to write to a stray memory location %lx\n",
(ulong) ptr);
- ut_a(0);
+ ut_error;
}
if (type == MLOG_1BYTE) {
@@ -261,7 +261,6 @@ mlog_write_dulint(
/*==============*/
byte* ptr, /* in: pointer where to write */
dulint val, /* in: value to write */
- byte type, /* in: MLOG_8BYTES */
mtr_t* mtr) /* in: mini-transaction handle */
{
byte* log_ptr;
@@ -270,11 +269,10 @@ mlog_write_dulint(
fprintf(stderr,
"InnoDB: Error: trying to write to a stray memory location %lx\n",
(ulong) ptr);
- ut_a(0);
+ ut_error;
}
ut_ad(ptr && mtr);
- ut_ad(type == MLOG_8BYTES);
mach_write_to_8(ptr, val);
@@ -286,7 +284,8 @@ mlog_write_dulint(
return;
}
- log_ptr = mlog_write_initial_log_record_fast(ptr, type, log_ptr, mtr);
+ log_ptr = mlog_write_initial_log_record_fast(ptr, MLOG_8BYTES,
+ log_ptr, mtr);
mach_write_to_2(log_ptr, ptr - buf_frame_align(ptr));
log_ptr += 2;
@@ -314,7 +313,7 @@ mlog_write_string(
fprintf(stderr,
"InnoDB: Error: trying to write to a stray memory location %lx\n",
(ulong) ptr);
- ut_a(0);
+ ut_error;
}
ut_ad(ptr && mtr);
ut_a(len < UNIV_PAGE_SIZE);
diff --git a/innobase/mtr/mtr0mtr.c b/innobase/mtr/mtr0mtr.c
index 63ce491523b..ac1a638063d 100644
--- a/innobase/mtr/mtr0mtr.c
+++ b/innobase/mtr/mtr0mtr.c
@@ -171,7 +171,7 @@ mtr_log_parse_full_page(
/****************************************************************
Writes to the database log the full contents of the pages that this mtr has
modified. */
-
+static
void
mtr_log_write_backup_full_pages(
/*============================*/
@@ -495,13 +495,11 @@ mtr_read_dulint(
/*===========*/
/* out: value read */
byte* ptr, /* in: pointer from where to read */
- ulint type __attribute__((unused)), /* in: MLOG_8BYTES */
mtr_t* mtr __attribute__((unused)))
/* in: mini-transaction handle */
{
ut_ad(mtr->state == MTR_ACTIVE);
ut_ad(ptr && mtr);
- ut_ad(type == MLOG_8BYTES);
ut_ad(mtr_memo_contains(mtr, buf_block_align(ptr),
MTR_MEMO_PAGE_S_FIX) ||
mtr_memo_contains(mtr, buf_block_align(ptr),
diff --git a/innobase/mtr/ts/makefile b/innobase/mtr/ts/makefile
deleted file mode 100644
index 3a155fb1401..00000000000
--- a/innobase/mtr/ts/makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsmtr: ..\mtr.lib tsmtr.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\mtr.lib ..\..\dyn.lib ..\..\log.lib ..\..\mach.lib ..\..\buf.lib ..\..\fil.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsmtr.c $(LFL)
-
diff --git a/innobase/mtr/ts/tsbuf.c b/innobase/mtr/ts/tsbuf.c
deleted file mode 100644
index a2a18d7afaf..00000000000
--- a/innobase/mtr/ts/tsbuf.c
+++ /dev/null
@@ -1,531 +0,0 @@
-/************************************************************************
-The test module for the file system and buffer manager
-
-(c) 1995 Innobase Oy
-
-Created 11/16/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "os0thread.h"
-#include "os0file.h"
-#include "ut0ut.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "fil0fil.h"
-#include "..\buf0buf.h"
-#include "..\buf0flu.h"
-#include "..\buf0lru.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[5];
-
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/************************************************************************
-Creates the test database files. */
-
-void
-create_db(void)
-/*===========*/
-{
- ulint i;
- buf_block_t* block;
- byte* frame;
- ulint j;
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1; i++) {
- for (j = 0; j < 4096; j++) {
- block = buf_page_create(i, j);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_x_lock(buf_page_get_lock(block));
-
- if (j > 0) {
- fil_page_set_prev(frame, j - 1);
- } else {
- fil_page_set_prev(frame, 0);
- }
-
- if (j < 4095) {
- fil_page_set_next(frame, j + 1);
- } else {
- fil_page_set_next(frame, 0);
- }
-
- *((ulint*)(frame + 16)) = j;
-
- buf_page_note_modification(block);
-
- rw_lock_x_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
-/* buf_LRU_print(); */
-
- /* Flush the pool of dirty pages by reading low-offset pages */
- for (i = 0; i < 1000; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == i);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
-/* buf_LRU_print(); */
-
- os_thread_sleep(1000000);
-
- ut_a(buf_all_freed());
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[10];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- name[0] = 't';
- name[1] = 's';
- name[2] = 'f';
- name[3] = 'i';
- name[4] = 'l';
- name[5] = 'e';
- name[8] = '\0';
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < 1; i++) {
-
- name[6] = (char)(k + (ulint)'a');
- name[7] = (char)(i + (ulint)'a');
-
- files[i] = os_file_create("j:\\tsfile4", OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- "j:\\tsfile4", OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_set_size(files[i], 4096 * 8192, 0);
- ut_a(ret);
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create("noname", k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create("j:\\tsfile4", 4096, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i, j, k;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- buf_flush_batch(BUF_FLUSH_LIST, 1000);
-
- os_thread_sleep(1000000);
-
- buf_all_freed();
-
- oldtm = ut_clock();
-
- for (k = 0; k < 1; k++) {
- for (i = 0; i < 1; i++) {
- for (j = 0; j < 409; j++) {
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test2(void)
-/*=======*/
-{
- ulint i, j, k, rnd;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 100; k++) {
- rnd += 23651;
- rnd = rnd % 4096;
-
- i = rnd / 4096;
- j = rnd % 2048;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf("Wall clock time for random read %lu milliseconds\n",
- tm - oldtm);
-}
-
-/************************************************************************
-Reads the test database files. */
-
-void
-test4(void)
-/*=======*/
-{
- ulint i, j, k, rnd;
- buf_block_t* block;
- byte* frame;
- ulint tm, oldtm;
-
- /* Flush the pool of high-offset pages */
- for (i = 0; i < 1000; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == i);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
- printf("Test starts\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 400; k++) {
-
- rnd += 4357;
-
- i = 0;
- j = 1001 + rnd % 3000;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random no read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-
- /* Flush the pool of high-offset pages */
- for (i = 0; i < 1000; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == i);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
- printf("Test starts\n");
-
- oldtm = ut_clock();
-
- rnd = 123;
-
- for (k = 0; k < 400; k++) {
-
- rnd += 4357;
-
- i = 0;
- j = 1001 + rnd % 400;
-
- block = buf_page_get(i, j, NULL);
-
- frame = buf_block_get_frame(block);
-
- rw_lock_s_lock(buf_page_get_lock(block));
-
- ut_a(*((ulint*)(frame + 16)) == j);
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-
- buf_page_release(block);
- }
-
- tm = ut_clock();
- printf(
- "Wall clock time for %lu random read-ahead %lu milliseconds\n",
- k, tm - oldtm);
-
-}
-
-/************************************************************************
-Tests speed of CPU algorithms. */
-
-void
-test3(void)
-/*=======*/
-{
- ulint i, j;
- buf_block_t* block;
- ulint tm, oldtm;
-
- for (i = 0; i < 400; i++) {
-
- block = buf_page_get(0, i, NULL);
-
- buf_page_release(block);
- }
-
- os_thread_sleep(2000000);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 500; j++) {
- for (i = 0; i < 200; i++) {
-
- block = buf_page_get(0, i, NULL);
-
-/*
- rw_lock_s_lock(buf_page_get_lock(block));
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-*/
-
- buf_page_release(block);
-
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu page get-release %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 500; j++) {
- for (i = 0; i < 200; i++) {
-
- buf_block_get(block);
-/*
- rw_lock_s_lock(buf_page_get_lock(block));
-
- rw_lock_s_unlock(buf_page_get_lock(block));
-*/
- buf_page_release(block);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu block get-release %lu milliseconds\n",
- i * j, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000; i++) {
- block = buf_block_alloc();
- buf_block_free(block);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu block alloc-free %lu milliseconds\n",
- i, tm - oldtm);
-
- ha_print_info(buf_pool->page_hash);
-}
-
-/************************************************************************
-Frees the spaces in the file system. */
-
-void
-free_system(void)
-/*=============*/
-{
- ulint i;
-
- for (i = 0; i < 1; i++) {
- fil_space_free(i);
- }
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint n;
-
- oldtm = ut_clock();
-
- os_aio_init(160, 5);
- sync_init();
- mem_init();
- fil_init(26); /* Allow 25 open files at a time */
- buf_pool_init(1000, 1000);
-
- buf_validate();
-
- ut_a(fil_validate());
-
- create_files();
-
- create_db();
-
- buf_validate();
-
- test1();
-
- test3();
-
- test4();
-
- test2();
-
- buf_validate();
-
- n = buf_flush_batch(BUF_FLUSH_LIST, 500);
-
- os_thread_sleep(1000000);
-
- buf_all_freed();
-
- free_system();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/mtr/ts/tsmtr.c b/innobase/mtr/ts/tsmtr.c
deleted file mode 100644
index 42997cd2699..00000000000
--- a/innobase/mtr/ts/tsmtr.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/************************************************************************
-The test module for the mini-transaction utilities
-
-(c) 1995 Innobase Oy
-
-Created 11/26/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "sync0rw.h"
-#include "mem0mem.h"
-#include "log0log.h"
-#include "..\mtr0mtr.h"
-#include "..\mtr0log.h"
-
-rw_lock_t rwl[MTR_BUF_MEMO_SIZE];
-
-/*********************************************************************
-Test for mtr buffer */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i;
- mtr_t mtr;
-
- printf("-------------------------------------------\n");
- printf("MTR-TEST 1. Test of mtr buffer\n");
-
- mtr_start(&mtr);
-
- for (i = 0; i < MTR_BUF_MEMO_SIZE; i++) {
- rw_lock_create(rwl + i);
- }
-
- for (i = 0; i < MTR_BUF_MEMO_SIZE; i++) {
- rw_lock_s_lock(rwl + i);
- mtr_memo_push(&mtr, rwl + i, MTR_MEMO_S_LOCK);
- }
-
- mtr_commit(&mtr);
-
- rw_lock_list_print_info();
- ut_ad(rw_lock_n_locked() == 0);
-
-}
-
-/************************************************************************
-Speed test function. */
-void
-speed_mtr(void)
-/*===========*/
-{
- mtr_t mtr;
-
- mtr_start(&mtr);
-
- mtr_s_lock(rwl, &mtr);
- mtr_s_lock(rwl + 1, &mtr);
- mtr_s_lock(rwl + 2, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Speed test function without mtr. */
-void
-speed_no_mtr(void)
-/*===========*/
-{
- rw_lock_s_lock(rwl);
- rw_lock_s_lock(rwl + 1);
- rw_lock_s_lock(rwl + 2);
- rw_lock_s_unlock(rwl + 2);
- rw_lock_s_unlock(rwl + 1);
- rw_lock_s_unlock(rwl);
-}
-
-/************************************************************************
-Speed test function. */
-
-void
-test2(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint i, j;
- mtr_t mtr;
- byte buf[50];
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- speed_mtr();
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu mtrs %lu milliseconds\n",
- i, tm - oldtm);
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- speed_no_mtr();
- }
-
- tm = ut_clock();
- printf("Wall clock time for %lu no-mtrs %lu milliseconds\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
- for (j = 0; j < 250; j++) {
- mlog_catenate_ulint(&mtr, 5, MLOG_1BYTE);
- mlog_catenate_ulint(&mtr, i, MLOG_4BYTES);
- mlog_catenate_ulint(&mtr, i + 1, MLOG_4BYTES);
- mlog_catenate_string(&mtr, buf, 50);
- }
- mtr_commit(&mtr);
- }
- tm = ut_clock();
- printf("Wall clock time for %lu log writes %lu milliseconds\n",
- i * j, tm - oldtm);
- mtr_start(&mtr);
- for (j = 0; j < 250; j++) {
- mlog_catenate_ulint(&mtr, 5, MLOG_1BYTE);
- mlog_catenate_ulint(&mtr, i, MLOG_4BYTES);
- mlog_catenate_ulint(&mtr, i + 1, MLOG_4BYTES);
- mlog_catenate_string(&mtr, buf, 50);
- }
-
- mtr_print(&mtr);
- mtr_commit(&mtr);
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- sync_init();
- mem_init();
- log_init();
-
- test1();
- test2();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/odbc/Makefile.am b/innobase/odbc/Makefile.am
deleted file mode 100644
index f4282ba3907..00000000000
--- a/innobase/odbc/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-# & Innobase Oy
-#
-# 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; either version 2 of the License, or
-# (at your option) any later version.
-#
-# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-include ../include/Makefile.i
-
-noinst_LIBRARIES = libodbc.a
-
-libodbc_a_SOURCES = odbc0odbc.c
-
-EXTRA_PROGRAMS =
diff --git a/innobase/odbc/makefilewin b/innobase/odbc/makefilewin
deleted file mode 100644
index 969043e096d..00000000000
--- a/innobase/odbc/makefilewin
+++ /dev/null
@@ -1,7 +0,0 @@
-include ..\include\makefile.i
-
-innobase.lib: odbc0odbc.obj
- lib -out:..\libs\innobase.lib odbc0odbc.obj ..\libs\btr.lib ..\libs\eval.lib ..\libs\ibuf.lib ..\libs\trx.lib ..\libs\pars.lib ..\libs\que.lib ..\libs\lock.lib ..\libs\row.lib ..\libs\read.lib ..\libs\srv.lib ..\libs\com.lib ..\libs\usr.lib ..\libs\thr.lib ..\libs\fut.lib ..\libs\fsp.lib ..\libs\page.lib ..\libs\dyn.lib ..\libs\mtr.lib ..\libs\log.lib ..\libs\rem.lib ..\libs\fil.lib ..\libs\buf.lib ..\libs\dict.lib ..\libs\data.lib ..\libs\mach.lib ..\libs\ha.lib ..\libs\ut.lib ..\libs\sync.lib ..\libs\mem.lib ..\libs\os.lib
-
-odbc0odbc.obj: odbc0odbc.c
- $(CCOM) $(CFL) -c odbc0odbc.c
diff --git a/innobase/odbc/odbc0dummy.c b/innobase/odbc/odbc0dummy.c
deleted file mode 100644
index e44677aa266..00000000000
--- a/innobase/odbc/odbc0dummy.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Used to screen off linker 'undefined symbol' errors
-when making an ODBC client library */
-
-
-unsigned long srv_test_cache_evict;
-
-void buf_frame_alloc(void)
-{}
-
-void buf_frame_free(void)
-{}
-
-void trx_create(void)
-{}
-
-void* kernel_mutex_temp;
-
-void trx_sig_send(void)
-{}
-
-void rec_sprintf(void)
-{}
-
-void dtuple_sprintf(void)
-{}
-
-void pars_write_query_param_info (void)
-{}
-
-void que_graph_try_free (void)
-{}
-
-void pars_sql (void)
-{}
-
-void que_run_threads (void)
-{}
-
-void que_fork_start_command(void)
-{}
-
-void dict_procedure_add_to_cache(void)
-{}
-
-void dict_mem_procedure_create(void)
-{}
-
-void pars_proc_read_input_params_from_buf(void)
-{}
-
-void dict_procedure_reserve_parsed_copy(void)
-{}
-
-void* srv_sys;
-
-void* srv_print_latch_waits;
-
-void* srv_spin_wait_delay;
-
-void* srv_n_spin_wait_rounds;
-
-void* buf_debug_prints;
diff --git a/innobase/odbc/odbc0odbc.c b/innobase/odbc/odbc0odbc.c
deleted file mode 100644
index 0deb17c6714..00000000000
--- a/innobase/odbc/odbc0odbc.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/******************************************************
-Innobase ODBC client library
-
-(c) 1998 Innobase Oy
-
-Created 2/22/1998 Heikki Tuuri
-*******************************************************/
-
-#include "odbc0odbc.h"
-
-#include "mem0mem.h"
-#include "com0com.h"
-#include "usr0sess.h"
-
-#define ODBC_STAT_INITIAL 1
-#define ODBC_STAT_PREPARED 2
-#define ODBC_STAT_EXECUTED 3
-
-
-typedef struct odbc_conn_struct odbc_conn_t;
-typedef struct odbc_env_struct odbc_env_t;
-
-/* ODBC parameter description struct */
-
-typedef struct odbc_param_struct odbc_param_t;
-struct odbc_param_struct{
- ulint data_type; /* SQL_CHAR, ... */
- ibool is_input; /* TRUE if an input parameter of a stored
- procedure, FALSE if an output parameter */
- byte* buf; /* buffer where the value is stored before
- SQLExecute, or where it comes after SQLExecute
- in the case of an output parameter */
- lint* data_len; /* pointer to where the data len or the value
- SQL_NULL_DATA is stored */
- ulint buf_len; /* buffer size */
-};
-
-/* ODBC statement data structure */
-
-typedef struct odbc_stat_struct odbc_stat_t;
-struct odbc_stat_struct{
- ulint state; /* ODBC_STAT_INITIAL,
- ODBC_STAT_PREPARED,
- ODBC_STAT_EXECUTED */
- ulint id; /* statement id */
- ulint n_params; /* number of parameters */
- odbc_param_t* params; /* pointer to an array describing
- the parameters, if any */
- ulint n_params_bound; /* number of parameters that have
- been bound: the statement cannot be
- executed before n_params_bound
- == n_params */
- byte* error_msg; /* possible error message, or NULL;
- allocated separately from dynamic
- memory */
- ulint error_msg_len; /* error mesage length if it is
- non-NULL */
- odbc_conn_t* conn; /* connection */
- UT_LIST_NODE_T(odbc_stat_t)
- stat_list; /* list of the statements of the
- connection */
-};
-
-/* ODBC connection data structure */
-
-struct odbc_conn_struct{
- ibool connected; /* TRUE if connected */
- char* server_name; /* server name where connected
- (= server address) */
- ulint server_name_len;/* length of the server name */
- com_endpoint_t* com_endpoint; /* connection endpoint for this client
- connection */
- dulint out_msg_count; /* count of outgoing messages */
- byte* out_datagram_buf;/* buffer for outgoing datagrams to
- the server */
- byte* in_datagram_buf;/* buffer for incoming datagrams from
- the server */
- byte* addr_buf; /* buffer for the address from which
- an incoming datagram came; in practice,
- this will be the server address */
- dulint sess_id; /* user session id, once the
- connection to the server is
- established */
- odbc_env_t* env; /* environment */
- UT_LIST_BASE_NODE_T(odbc_stat_t)
- stat_list; /* list of the statements of the
- connection */
- UT_LIST_NODE_T(odbc_conn_t)
- conn_list; /* list of the connections of the
- environment */
-};
-
-/* ODBC environment data structure */
-
-struct odbc_env_struct{
- UT_LIST_BASE_NODE_T(odbc_conn_t) conn_list;
- /* list of the connections of the
- environment */
-};
-
-/**************************************************************************
-Gets the nth parameter description struct for a statement. */
-UNIV_INLINE
-odbc_param_t*
-stat_get_nth_param(
-/*===============*/
- /* out: nth parameter */
- odbc_stat_t* stat, /* in: pointer to statement handle */
- ulint i) /* in: parameter index */
-{
- ut_ad(stat->n_params > i);
-
- return(stat->params + i);
-}
-
-/**************************************************************************
-Allocates an SQL environment. */
-
-RETCODE
-SQLAllocEnv(
-/*========*/
- /* out: SQL_SUCCESS */
- HENV* phenv) /* out: pointer to an environment handle */
-{
- odbc_env_t* env;
-
- if (!sync_initialized) {
- sync_init();
- mem_init(2000000);
- }
-
- env = mem_alloc(sizeof(odbc_env_t));
-
- UT_LIST_INIT(env->conn_list);
-
- *phenv = env;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Allocates an SQL connection. */
-
-RETCODE
-SQLAllocConnect(
-/*============*/
- /* out: SQL_SUCCESS */
- HENV henv, /* in: pointer to an environment handle */
- HDBC* phdbc) /* out: pointer to a connection handle */
-{
- odbc_conn_t* conn;
- odbc_env_t* env;
-
- ut_a(henv);
-
- env = henv;
- conn = mem_alloc(sizeof(odbc_conn_t));
-
- conn->connected = FALSE;
- conn->env = env;
-
- UT_LIST_INIT(conn->stat_list);
-
- UT_LIST_ADD_LAST(conn_list, env->conn_list, conn);
-
- *phdbc = conn;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Allocates an SQL statement. */
-
-RETCODE
-SQLAllocStmt(
-/*=========*/
- HDBC hdbc, /* in: SQL connection */
- HSTMT* phstmt) /* out: pointer to a statement handle */
-{
- odbc_conn_t* conn;
- odbc_stat_t* stat;
-
- ut_a(hdbc);
-
- conn = hdbc;
-
- stat = mem_alloc(sizeof(odbc_stat_t));
-
- stat->state = ODBC_STAT_INITIAL;
- stat->error_msg = NULL;
- stat->conn = conn;
-
- UT_LIST_ADD_LAST(stat_list, conn->stat_list, stat);
-
- *phstmt = stat;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Sends the message in datagram_buf to the server. */
-static
-void
-odbc_send_cli_msg(
-/*==============*/
- odbc_conn_t* conn, /* in: connection, does not have to be
- connected yet */
- ulint len) /* in: message length (excluding the standard
- header of size SESS_CLI_MSG_DATA) */
-{
- ulint ret;
- ulint fold;
- byte* msg;
-
- ut_a(len + SESS_CLI_MSG_DATA <= ODBC_DATAGRAM_SIZE);
-
- msg = conn->out_datagram_buf;
-
- mach_write_to_8(msg + SESS_CLI_MSG_NO, conn->out_msg_count);
-
- UT_DULINT_INC(conn->out_msg_count);
-
- fold = ut_fold_binary(msg + 4, len + SESS_CLI_MSG_DATA - 4);
-
- ut_ad(SESS_CLI_MSG_CHECKSUM == 0);
-
- mach_write_to_4(msg + SESS_CLI_MSG_CHECKSUM, fold);
-
- ret = com_sendto(conn->com_endpoint, msg, SESS_CLI_MSG_DATA + len,
- conn->server_name, conn->server_name_len);
- ut_a(ret == 0);
-}
-
-/**************************************************************************
-Receives a message in datagram_buf from the server. */
-static
-void
-odbc_recv_srv_msg(
-/*==============*/
- odbc_conn_t* conn, /* in: connection, does not have to be
- connected yet */
- ulint* len) /* out: received message length (excluding the
- standard header of size SESS_SRV_MSG_DATA) */
-{
- ulint total_len;
- ulint addr_len;
- ulint ret;
-
- ret = com_recvfrom(conn->com_endpoint, conn->in_datagram_buf,
- ODBC_DATAGRAM_SIZE, &total_len, (char*)conn->addr_buf,
- ODBC_ADDRESS_SIZE, &addr_len);
- ut_a(ret == 0);
- ut_a(total_len >= SESS_SRV_MSG_DATA);
-
- *len = total_len - SESS_SRV_MSG_DATA;
-}
-
-/**************************************************************************
-Connects to a database server process (establishes a connection and a
-session). */
-
-RETCODE
-SQLConnect(
-/*=======*/
- /* out: SQL_SUCCESS */
- HDBC hdbc, /* in: SQL connection handle */
- UCHAR* szDSN, /* in: data source name (server name) */
- SWORD cbDSN, /* in: data source name length */
- UCHAR* szUID, /* in: user name */
- SWORD cbUID, /* in: user name length */
- UCHAR* szAuthStr, /* in: password */
- SWORD cbAuthStr) /* in: password length */
-{
- com_endpoint_t* ep;
- odbc_conn_t* conn;
- ulint err;
- ulint size;
- byte* msg;
- ulint len;
- UCHAR catenated_name[100];
-
- ut_a(hdbc && szDSN);
-
- UT_NOT_USED(szUID);
- UT_NOT_USED(cbUID);
- UT_NOT_USED(szAuthStr);
- UT_NOT_USED(cbAuthStr);
-
- conn = hdbc;
-
- ut_a(!conn->connected);
-
- conn->server_name = mem_alloc(cbDSN);
- ut_memcpy(conn->server_name, szDSN, cbDSN);
-
- conn->server_name_len = cbDSN;
-
- ep = com_endpoint_create(COM_SHM);
-
- ut_a(ep);
-
- conn->com_endpoint = ep;
-
- conn->out_msg_count = ut_dulint_zero;
-
- size = ODBC_DATAGRAM_SIZE;
-
- err = com_endpoint_set_option(ep, COM_OPT_MAX_DGRAM_SIZE,
- (byte*)&size, 4);
- ut_a(err == 0);
-
- /* Make the data source name catenated to user name as the
- address of the communications endpoint */
-
- ut_a((ulint)cbDSN + (ulint)cbUID < 100);
-
- ut_memcpy(catenated_name, szDSN, (ulint)cbDSN);
- ut_memcpy(catenated_name + (ulint)cbDSN, szUID, (ulint)cbUID);
-
- err = com_bind(ep, (char*)catenated_name, (ulint)cbDSN
- + (ulint)cbUID);
- ut_a(err == 0);
-
- conn->in_datagram_buf = mem_alloc(ODBC_DATAGRAM_SIZE);
-
- msg = mem_alloc(ODBC_DATAGRAM_SIZE);
-
- conn->out_datagram_buf = msg;
- conn->addr_buf = mem_alloc(ODBC_ADDRESS_SIZE);
-
- /* Set the session id to dulint 0 as we are not yet connected */
-
- sess_cli_msg_set_sess(msg, ut_dulint_zero);
- sess_cli_msg_set_type(msg, SESS_CLI_CONNECT);
-
- /*------------------------------------------*/
-
- odbc_send_cli_msg(conn, 0);
-
- odbc_recv_srv_msg(conn, &len);
-
- /*------------------------------------------*/
-
- ut_a(len == 0);
- ut_a(sess_srv_msg_get_type(conn->in_datagram_buf)
- == SESS_SRV_ACCEPT_CONNECT);
-
- conn->sess_id = mach_read_from_8(conn->in_datagram_buf
- + SESS_SRV_MSG_SESS_ID);
-
- /* Write the session id to out_datagram_buf: it will not be rewritten
- until the connection is closed, as the session id will stay the same */
-
- sess_cli_msg_set_sess(msg, conn->sess_id);
-
- /* We currently only send single part messages: the following will
- stay 0 during the connection */
-
- mach_write_to_4(msg + SESS_CLI_MSG_CONTINUE, 0);
- mach_write_to_4(msg + SESS_CLI_MSG_CONT_SIZE, 0);
-
- conn->connected = TRUE;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Stores an error message to a statement handle, so that it can be later
-queried with SQLError. */
-static
-void
-odbc_stat_store_error_msg(
-/*======================*/
- odbc_stat_t* stat, /* in: statement handle */
- byte* msg, /* in: error message sent by the server */
- ulint len) /* in: length of msg */
-{
- if (stat->error_msg) {
- mem_free(stat->error_msg);
- }
-
- stat->error_msg_len = len;
-
- len += SESS_SRV_MSG_DATA;
-
- stat->error_msg = mem_alloc(len);
- ut_memcpy(stat->error_msg, msg, len);
-}
-
-/**************************************************************************
-Queries an error message. */
-
-RETCODE
-SQLError(
-/*=====*/
- /* out: SQL_SUCCESS or SQL_NO_DATA_FOUND */
- HENV henv, /* in: SQL_NULL_HENV */
- HDBC hdbc, /* in: SQL_NULL_HDBC */
- HSTMT hstmt, /* in: statement handle */
- UCHAR* szSqlState, /* in/out: SQLSTATE as a null-terminated string,
- (currently, always == "S1000") */
- SDWORD* pfNativeError, /* out: native error code */
- UCHAR* szErrorMsg, /* in/out: buffer for an error message as a
- null-terminated string */
- SWORD cbErrorMsgMax, /* in: buffer size for szErrorMsg */
- SWORD* pcbErrorMsg) /* out: error message length */
-{
- odbc_stat_t* stat;
- ulint len;
-
- ut_a(henv == SQL_NULL_HENV);
- ut_a(hdbc == SQL_NULL_HDBC);
- ut_a(hstmt);
- ut_a(cbErrorMsgMax > 1);
-
- stat = hstmt;
-
- if (stat->error_msg == NULL) {
-
- return(SQL_NO_DATA_FOUND);
- }
-
- *pfNativeError = 0;
- ut_memcpy(szSqlState, (char *) "S1000", 6);
-
- len = (ulint)cbErrorMsgMax - 1;
-
- if (stat->error_msg_len < len) {
- len = stat->error_msg_len;
- }
-
- ut_memcpy(szErrorMsg, stat->error_msg + SESS_SRV_MSG_DATA, len);
-
- *(szErrorMsg + len) = '\0';
-
- *pcbErrorMsg = (SWORD)len;
-
- if (stat->error_msg) {
- mem_free(stat->error_msg);
- stat->error_msg = NULL;
- }
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Makes the server to parse and optimize an SQL string. */
-
-RETCODE
-SQLPrepare(
-/*=======*/
- /* out: SQL_SUCCESS or SQL_ERROR */
- HSTMT hstmt, /* in: statement handle */
- UCHAR* szSqlStr, /* in: SQL string */
- SDWORD cbSqlStr) /* in: SQL string length */
-{
- odbc_stat_t* stat;
- odbc_conn_t* conn;
- odbc_param_t* param;
- ulint len;
- byte* msg;
- ulint i;
-
- stat = hstmt;
- conn = stat->conn;
-
- if (stat->error_msg) {
- mem_free(stat->error_msg);
- stat->error_msg = NULL;
- }
-
- ut_memcpy(conn->out_datagram_buf + SESS_CLI_MSG_DATA, szSqlStr,
- 1 + (ulint)cbSqlStr);
-
- sess_cli_msg_set_type(conn->out_datagram_buf, SESS_CLI_PREPARE);
-
- /* The client message will be decoded in sess_receive_prepare */
-
- /*------------------------------------------*/
-
- odbc_send_cli_msg(conn, 1 + (ulint)cbSqlStr);
-
- odbc_recv_srv_msg(conn, &len);
-
- /*------------------------------------------*/
-
- /* The server message was coded in sess_receive_prepare */
-
- ut_a(len >= 8);
-
- msg = conn->in_datagram_buf;
-
- if (sess_srv_msg_get_type(msg) != SESS_SRV_SUCCESS) {
-
- ut_a(sess_srv_msg_get_type(msg) == SESS_SRV_ERROR);
-
- odbc_stat_store_error_msg(stat, msg, len);
-
- return(SQL_ERROR);
- }
-
- stat->id = mach_read_from_4(msg + SESS_SRV_MSG_DATA);
-
- stat->n_params = mach_read_from_4(msg + SESS_SRV_MSG_DATA + 4);
-
- stat->n_params_bound = 0;
-
- ut_a(len == 8 + stat->n_params);
-
- if (stat->n_params > 0) {
-
- stat->params = mem_alloc(stat->n_params
- * sizeof(odbc_param_t));
- for (i = 0; i < stat->n_params; i++) {
- param = stat_get_nth_param(stat, i);
-
- param->is_input = mach_read_from_1(
- msg + SESS_SRV_MSG_DATA + 8 + i);
- /* Set buf to NULL so that we know when the parameter
- has been bound */
-
- param->buf = NULL;
- }
- }
-
- stat->state = ODBC_STAT_PREPARED;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Binds a parameter in a prepared statement. */
-
-RETCODE
-SQLBindParameter(
-/*=============*/
- /* out: SQL_SUCCESS */
- HSTMT hstmt, /* in: statement handle */
- UWORD ipar, /* in: parameter index, starting from 1 */
- SWORD fParamType, /* in: SQL_PARAM_INPUT or SQL_PARAM_OUTPUT */
- SWORD fCType, /* in: SQL_C_CHAR, ... */
- SWORD fSqlType, /* in: SQL_CHAR, ... */
- UDWORD cbColDef, /* in: precision: ignored */
- SWORD ibScale, /* in: scale: ignored */
- PTR rgbValue, /* in: pointer to a buffer for the data */
- SDWORD cbValueMax, /* in: buffer size */
- SDWORD* pcbValue) /* in: pointer to a buffer for the data
- length or SQL_NULL_DATA */
-{
- odbc_stat_t* stat;
- odbc_param_t* param;
-
- stat = hstmt;
-
- ut_a(stat->state != ODBC_STAT_INITIAL);
- ut_a(rgbValue);
- ut_a(ipar <= stat->n_params);
- ut_a(ipar > 0);
- ut_a(cbValueMax >= 0);
- ut_a(pcbValue);
-
- UT_NOT_USED(ibScale);
- UT_NOT_USED(fCType);
- UT_NOT_USED(cbColDef);
-
- if (stat->error_msg) {
- mem_free(stat->error_msg);
- stat->error_msg = NULL;
- }
-
- param = stat_get_nth_param(stat, ipar - 1);
-
- if (param->buf == NULL) {
- stat->n_params_bound++;
- }
-
- param->data_type = fSqlType;
-
- ut_a((fParamType != SQL_PARAM_INPUT) || param->is_input);
- ut_a((fParamType == SQL_PARAM_INPUT) || !param->is_input);
-
- param->buf = rgbValue;
- param->buf_len = cbValueMax;
- param->data_len = pcbValue;
-
- return(SQL_SUCCESS);
-}
-
-/**************************************************************************
-Executes a prepared statement where all parameters have been bound. */
-
-RETCODE
-SQLExecute(
-/*=======*/
- /* out: SQL_SUCCESS or SQL_ERROR */
- HSTMT hstmt) /* in: statement handle */
-{
- odbc_stat_t* stat;
- odbc_conn_t* conn;
- odbc_param_t* param;
- lint len;
- ulint msg_len;
- byte* msg;
- byte* ptr;
- lint int_val;
- ulint i;
-
- stat = hstmt;
-
- ut_a(stat->state != ODBC_STAT_INITIAL);
- ut_a(stat->n_params == stat->n_params_bound);
-
- if (stat->error_msg) {
- mem_free(stat->error_msg);
- stat->error_msg = NULL;
- }
-
- conn = stat->conn;
- msg = conn->out_datagram_buf;
-
- sess_cli_msg_set_type(msg, SESS_CLI_EXECUTE);
-
- ptr = msg + SESS_CLI_MSG_DATA;
-
- mach_write_to_4(ptr, stat->id);
-
- ptr += 4;
-
- for (i = 0; i < stat->n_params; i++) {
-
- param = stat_get_nth_param(stat, i);
-
- if (param->is_input) {
- /* Copy its length and data to the message buffer */
-
- len = *(param->data_len);
-
- mach_write_to_4(ptr, (ulint)len);
-
- ptr += 4;
-
- if (len != SQL_NULL_DATA) {
- if (param->data_type == SQL_INTEGER) {
- ut_ad(len == 4);
- int_val = *((lint*)(param->buf));
-
- mach_write_to_4(ptr, (ulint)int_val);
- } else {
- ut_memcpy(ptr, param->buf, len);
- }
-
- ptr += len;
- }
- }
- }
-
- /* The client message will be decoded in sess_receive_command */
-
- /*------------------------------------------*/
-
- odbc_send_cli_msg(conn, ptr - (msg + SESS_CLI_MSG_DATA));
-
- odbc_recv_srv_msg(conn, &msg_len);
-
- /*------------------------------------------*/
-
- /* The server message was coded in sess_command_completed_message */
-
- msg = conn->in_datagram_buf;
-
- if (sess_srv_msg_get_type(msg) != SESS_SRV_SUCCESS) {
-
- ut_a(sess_srv_msg_get_type(msg) == SESS_SRV_ERROR);
-
- odbc_stat_store_error_msg(stat, msg, msg_len);
-
- return(SQL_ERROR);
- }
-
- ptr = msg + SESS_SRV_MSG_DATA;
-
- for (i = 0; i < stat->n_params; i++) {
-
- param = stat_get_nth_param(stat, i);
-
- if (!param->is_input) {
- /* Copy its length and data from the message buffer */
-
- len = (lint)mach_read_from_4(ptr);
-
- ptr += 4;
-
- *(param->data_len) = len;
-
- if (len != SQL_NULL_DATA) {
- if (param->data_type == SQL_INTEGER) {
- ut_ad(len == 4);
-
- int_val = (lint)mach_read_from_4(ptr);
-
- *((lint*)(param->buf)) = int_val;
- } else {
- ut_memcpy(param->buf, ptr, (ulint)len);
- }
-
- ptr += len;
- }
- }
- }
-
- ut_ad(msg + SESS_SRV_MSG_DATA + msg_len == ptr);
-
- return(SQL_SUCCESS);
-}
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c
index a87ab974b83..7973cfc6fe8 100644
--- a/innobase/os/os0file.c
+++ b/innobase/os/os0file.c
@@ -716,7 +716,9 @@ os_file_create_simple(
string */
ulint create_mode,/* in: OS_FILE_OPEN if an existing file is opened
(if does not exist, error), or OS_FILE_CREATE if a new
- file is created (if exists, error) */
+ file is created (if exists, error), or
+ OS_FILE_CREATE_PATH if new file (if exists, error) and
+ subdirectories along its path are created (if needed)*/
ulint access_type,/* in: OS_FILE_READ_ONLY or OS_FILE_READ_WRITE */
ibool* success)/* out: TRUE if succeed, FALSE if error */
{
@@ -734,6 +736,14 @@ try_again:
create_flag = OPEN_EXISTING;
} else if (create_mode == OS_FILE_CREATE) {
create_flag = CREATE_NEW;
+ } else if (create_mode == OS_FILE_CREATE_PATH) {
+ /* create subdirs along the path if needed */
+ *success = os_file_create_subdirs_if_needed(name);
+ if (!*success) {
+ ut_error;
+ }
+ create_flag = CREATE_NEW;
+ create_mode = OS_FILE_CREATE;
} else {
create_flag = 0;
ut_error;
@@ -787,6 +797,14 @@ try_again:
}
} else if (create_mode == OS_FILE_CREATE) {
create_flag = O_RDWR | O_CREAT | O_EXCL;
+ } else if (create_mode == OS_FILE_CREATE_PATH) {
+ /* create subdirs along the path if needed */
+ *success = os_file_create_subdirs_if_needed(name);
+ if (!*success) {
+ return (-1);
+ }
+ create_flag = O_RDWR | O_CREAT | O_EXCL;
+ create_mode = OS_FILE_CREATE;
} else {
create_flag = 0;
ut_error;
@@ -1068,7 +1086,7 @@ try_again:
} else if (type == OS_DATA_FILE) {
type_str = "DATA";
} else {
- ut_a(0);
+ ut_error;
}
if (purpose == OS_FILE_AIO) {
@@ -1076,7 +1094,7 @@ try_again:
} else if (purpose == OS_FILE_NORMAL) {
purpose_str = "NORMAL";
} else {
- ut_a(0);
+ ut_error;
}
/* printf("Opening file %s, mode %s, type %s, purpose %s\n",
@@ -1558,7 +1576,7 @@ os_file_flush(
/* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */
- ut_a(0);
+ ut_error;
return(FALSE);
#else
@@ -1593,7 +1611,7 @@ os_file_flush(
/* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */
- ut_a(0);
+ ut_error;
return(FALSE);
#endif
@@ -2114,6 +2132,185 @@ retry:
#endif
}
+/***********************************************************************
+Check the existence and type of the given file. */
+
+ibool
+os_file_status(
+/*===========*/
+ /* out: TRUE if call succeeded */
+ char* path, /* in: pathname of the file */
+ ibool* exists, /* out: TRUE if file exists */
+ os_file_type_t* type) /* out: type of the file (if it exists) */
+{
+#ifdef __WIN__
+ int ret;
+ struct _stat statinfo;
+
+ ret = _stat(path, &statinfo);
+ if (ret && (errno == ENOENT || errno == ENOTDIR)) {
+ /* file does not exist */
+ *exists = FALSE;
+ return(TRUE);
+ } else if (ret) {
+ /* file exists, but stat call failed */
+
+ os_file_handle_error_no_exit(0, path, "stat");
+
+ return(FALSE);
+ }
+
+ if (_S_IFDIR & statinfo.st_mode) {
+ *type = OS_FILE_TYPE_DIR;
+ } else if (_S_IFREG & statinfo.st_mode) {
+ *type = OS_FILE_TYPE_FILE;
+ } else {
+ *type = OS_FILE_TYPE_UNKNOWN;
+ }
+
+ *exists = TRUE;
+
+ return(TRUE);
+#else
+ int ret;
+ struct stat statinfo;
+
+ ret = stat(path, &statinfo);
+ if (ret && (errno == ENOENT || errno == ENOTDIR)) {
+ /* file does not exist */
+ *exists = FALSE;
+ return(TRUE);
+ } else if (ret) {
+ /* file exists, but stat call failed */
+
+ os_file_handle_error_no_exit(0, path, "stat");
+
+ return(FALSE);
+ }
+
+ if (S_ISDIR(statinfo.st_mode)) {
+ *type = OS_FILE_TYPE_DIR;
+ } else if (S_ISLNK(statinfo.st_mode)) {
+ *type = OS_FILE_TYPE_LINK;
+ } else if (S_ISREG(statinfo.st_mode)) {
+ *type = OS_FILE_TYPE_FILE;
+ } else {
+ *type = OS_FILE_TYPE_UNKNOWN;
+ }
+
+ *exists = TRUE;
+
+ return(TRUE);
+#endif
+}
+
+/* path name separator character */
+#ifdef __WIN__
+# define OS_FILE_PATH_SEPARATOR '\\'
+#else
+# define OS_FILE_PATH_SEPARATOR '/'
+#endif
+
+/********************************************************************
+The function os_file_dirname returns a directory component of a
+null-terminated pathname string. In the usual case, dirname returns
+the string up to, but not including, the final '/', and basename
+is the component following the final '/'. Trailing '/' charac­
+ters are not counted as part of the pathname.
+
+If path does not contain a slash, dirname returns the string ".".
+
+Concatenating the string returned by dirname, a "/", and the basename
+yields a complete pathname.
+
+The return value is a copy of the directory component of the pathname.
+The copy is allocated from heap. It is the caller responsibility
+to free it after it is no longer needed.
+
+The following list of examples (taken from SUSv2) shows the strings
+returned by dirname and basename for different paths:
+
+ path dirname basename
+ "/usr/lib" "/usr" "lib"
+ "/usr/" "/" "usr"
+ "usr" "." "usr"
+ "/" "/" "/"
+ "." "." "."
+ ".." "." ".."
+*/
+
+char*
+os_file_dirname(
+/*============*/
+ /* out, own: directory component of the
+ pathname */
+ char* path) /* in: pathname */
+{
+ char* dir;
+ int i, length, last_slash;
+
+ /* find the offset of the last slash */
+ length = ut_strlen(path);
+ for (i = length - 1; i >= 0 && path[i] != OS_FILE_PATH_SEPARATOR; i++);
+ last_slash = i;
+
+ if (last_slash < 0) {
+ /* no slash in the path, return "." */
+ return(ut_strdup((char*)"."));
+ }
+
+ /* ok, there is a slash */
+
+ if (last_slash == 0) {
+ /* last slash is the first char of the path */
+ return(ut_strdup((char*)"/"));
+ }
+
+ /* non-trivial directory component */
+ dir = ut_strdup(path);
+ dir[last_slash] = 0;
+
+ return(dir);
+}
+
+/********************************************************************
+Creates all missing subdirectories along the given path. */
+
+ibool
+os_file_create_subdirs_if_needed(
+/*=============================*/
+ /* out: TRUE if call succeeded
+ FALSE otherwise */
+ char* path) /* in: path name */
+{
+ char* subdir;
+ static char rootdir[2] = { OS_FILE_PATH_SEPARATOR, 0 };
+ ibool success, subdir_exists;
+ os_file_type_t type;
+
+ subdir = os_file_dirname(path);
+ if (0 == strcmp(subdir, rootdir) || 0 == strcmp(subdir, ".")) {
+ /* subdir is root or cwd, nothing to do */
+ ut_free(subdir);
+ return(TRUE);
+ }
+
+ /* test if subdir exists */
+ success = os_file_status(subdir, &subdir_exists, &type);
+ if (success && !subdir_exists) {
+ /* subdir does not exist, create it */
+ success = os_file_create_subdirs_if_needed(subdir);
+ if (!success) {
+ ut_free(subdir);
+ return(FALSE);
+ }
+ success = os_file_create_directory(subdir, FALSE);
+ }
+
+ ut_free(subdir);
+ return(success);
+}
+
/********************************************************************
Returns a pointer to the nth slot in the aio array. */
static
@@ -2430,7 +2627,7 @@ os_aio_get_array_no(
return(3);
} else {
- ut_a(0);
+ ut_error;
return(0);
}
@@ -2457,7 +2654,7 @@ os_aio_get_array_from_no(
return(os_aio_write_array);
} else {
- ut_a(0);
+ ut_error;
return(NULL);
}
@@ -3047,7 +3244,7 @@ os_aio_posix_handle(
if (sig != SIGRTMIN + 1 + array_no) {
- ut_a(0);
+ ut_error;
return(FALSE);
}
@@ -3312,7 +3509,7 @@ consecutive_loop:
slot->name, (ulong) slot->offset_high,
(ulong) slot->offset,
(ulong) total_len);
- ut_a(0);
+ ut_error;
}
/* Do a 'last millisecond' check that the page end
diff --git a/innobase/os/os0fileold.c b/innobase/os/os0fileold.c
deleted file mode 100644
index a9554727f0e..00000000000
--- a/innobase/os/os0fileold.c
+++ /dev/null
@@ -1,1956 +0,0 @@
-/******************************************************
-The interface to the operating system file i/o primitives
-
-(c) 1995 Innobase Oy
-
-Created 10/21/1995 Heikki Tuuri
-*******************************************************/
-
-#include "os0file.h"
-#include "os0sync.h"
-#include "ut0mem.h"
-
-#ifndef __WIN__
-#include <errno.h>
-#endif
-
-/* We use these mutexes to protect lseek + file i/o operation, if the
-OS does not provide an atomic pread or pwrite, or similar */
-#define OS_FILE_N_SEEK_MUTEXES 16
-os_mutex_t os_file_seek_mutexes[OS_FILE_N_SEEK_MUTEXES];
-
-/* In simulated aio, merge at most this many consecutive i/os */
-#define OS_AIO_MERGE_N_CONSECUTIVE 32
-
-/* If this flag is TRUE, then we will use the native aio of the
-OS (provided we compiled Innobase with it in), otherwise we will
-use simulated aio we build below with threads */
-
-bool os_aio_use_native_aio = FALSE;
-
-/* The aio array slot structure */
-typedef struct os_aio_slot_struct os_aio_slot_t;
-
-struct os_aio_slot_struct{
- bool is_read; /* TRUE if a read operation */
- ulint pos; /* index of the slot in the aio
- array */
- bool reserved; /* TRUE if this slot is reserved */
- ulint len; /* length of the block to read or
- write */
- byte* buf; /* buffer used in i/o */
- ulint type; /* OS_FILE_READ or OS_FILE_WRITE */
- ulint offset; /* 32 low bits of file offset in
- bytes */
- ulint offset_high; /* 32 high bits of file offset */
- os_file_t file; /* file where to read or write */
- char* name; /* file name or path */
- bool io_already_done;/* used only in simulated aio:
- TRUE if the physical i/o already
- made and only the slot message
- needs to be passed to the caller
- of os_aio_simulated_handle */
- void* message1; /* message which is given by the */
- void* message2; /* the requester of an aio operation
- and which can be used to identify
- which pending aio operation was
- completed */
-#ifdef WIN_ASYNC_IO
- OVERLAPPED control; /* Windows control block for the
- aio request */
-#elif defined(POSIX_ASYNC_IO)
- struct aiocb control; /* Posix control block for aio
- request */
-#endif
-};
-
-/* The aio array structure */
-typedef struct os_aio_array_struct os_aio_array_t;
-
-struct os_aio_array_struct{
- os_mutex_t mutex; /* the mutex protecting the aio array */
- os_event_t not_full; /* The event which is set to signaled
- state when there is space in the aio
- outside the ibuf segment */
- ulint n_slots; /* Total number of slots in the aio array.
- This must be divisible by n_threads. */
- ulint n_segments;/* Number of segments in the aio array of
- pending aio requests. A thread can wait
- separately for any one of the segments. */
- ulint n_reserved;/* Number of reserved slots in the
- aio array outside the ibuf segment */
- os_aio_slot_t* slots; /* Pointer to the slots in the array */
- os_event_t* events; /* Pointer to an array of event handles
- where we copied the handles from slots,
- in the same order. This can be used in
- WaitForMultipleObjects; used only in
- Windows */
-};
-
-/* Array of events used in simulated aio */
-os_event_t* os_aio_segment_wait_events = NULL;
-
-/* The aio arrays for non-ibuf i/o and ibuf i/o, as well as sync aio. These
-are NULL when the module has not yet been initialized. */
-os_aio_array_t* os_aio_read_array = NULL;
-os_aio_array_t* os_aio_write_array = NULL;
-os_aio_array_t* os_aio_ibuf_array = NULL;
-os_aio_array_t* os_aio_log_array = NULL;
-os_aio_array_t* os_aio_sync_array = NULL;
-
-ulint os_aio_n_segments = ULINT_UNDEFINED;
-
-/***************************************************************************
-Retrieves the last error number if an error occurs in a file io function.
-The number should be retrieved before any other OS calls (because they may
-overwrite the error number). If the number is not known to this program,
-the OS error number + 100 is returned. */
-
-ulint
-os_file_get_last_error(void)
-/*========================*/
- /* out: error number, or OS error number + 100 */
-{
- ulint err;
-
-#ifdef __WIN__
-
- err = (ulint) GetLastError();
-
- if (err == ERROR_FILE_NOT_FOUND) {
- return(OS_FILE_NOT_FOUND);
- } else if (err == ERROR_DISK_FULL) {
- return(OS_FILE_DISK_FULL);
- } else if (err == ERROR_FILE_EXISTS) {
- return(OS_FILE_ALREADY_EXISTS);
- } else {
- return(100 + err);
- }
-#else
- err = (ulint) errno;
-
- printf("%lu\n", err);
- perror("os0file:");
-
- if (err == ENOSPC ) {
- return(OS_FILE_DISK_FULL);
-#ifdef POSIX_ASYNC_IO
- } else if (err == EAGAIN) {
- return(OS_FILE_AIO_RESOURCES_RESERVED);
-#endif
- } else if (err == ENOENT) {
- return(OS_FILE_NOT_FOUND);
- } else if (err == EEXIST) {
- return(OS_FILE_ALREADY_EXISTS);
- } else {
- return(100 + err);
- }
-#endif
-}
-
-/********************************************************************
-Does error handling when a file operation fails. If we have run out
-of disk space, then the user can clean the disk. If we do not find
-a specified file, then the user can copy it to disk. */
-static
-bool
-os_file_handle_error(
-/*=================*/
- /* out: TRUE if we should retry the operation */
- os_file_t file, /* in: file pointer */
- char* name) /* in: name of a file or NULL */
-{
- int input_char;
- ulint err;
-
- err = os_file_get_last_error();
-
- if (err == OS_FILE_DISK_FULL) {
-ask_again:
- printf("\n");
- if (name) {
- printf(
- "Innobase encountered a problem with file %s.\n",
- name);
- }
- printf("Disk is full. Try to clean the disk to free space\n");
- printf("before answering the following: How to continue?\n");
- printf("(Y == freed some space: try again)\n");
- printf("(N == crash the database: will restart it)?\n");
-ask_with_no_question:
- input_char = getchar();
-
- if (input_char == (int) 'N') {
- ut_error;
-
- return(FALSE);
- } else if (input_char == (int) 'Y') {
-
- return(TRUE);
- } else if (input_char == (int) '\n') {
-
- goto ask_with_no_question;
- } else {
- goto ask_again;
- }
- } else if (err == OS_FILE_AIO_RESOURCES_RESERVED) {
-
- return(TRUE);
- } else {
- ut_error;
- }
-
- return(FALSE);
-}
-
-/********************************************************************
-Opens an existing file or creates a new. */
-
-os_file_t
-os_file_create(
-/*===========*/
- /* out, own: handle to the file, not defined if error,
- error number can be retrieved with os_get_last_error */
- char* name, /* in: name of the file or path as a null-terminated
- string */
- ulint create_mode, /* in: OS_FILE_OPEN if an existing file is opened
- (if does not exist, error), or OS_FILE_CREATE if a new
- file is created (if exists, error), OS_FILE_OVERWRITE
- if a new is created or an old overwritten */
- ulint purpose,/* in: OS_FILE_AIO, if asynchronous, non-buffered i/o
- is desired, OS_FILE_NORMAL, if any normal file */
- bool* success)/* out: TRUE if succeed, FALSE if error */
-{
-#ifdef __WIN__
- os_file_t file;
- DWORD create_flag;
- DWORD attributes;
- bool retry;
-
-try_again:
- ut_a(name);
-
- if (create_mode == OS_FILE_OPEN) {
- create_flag = OPEN_EXISTING;
- } else if (create_mode == OS_FILE_CREATE) {
- create_flag = CREATE_NEW;
- } else if (create_mode == OS_FILE_OVERWRITE) {
- create_flag = CREATE_ALWAYS;
- } else {
- create_flag = 0;
- ut_error;
- }
-
- if (purpose == OS_FILE_AIO) {
- /* use asynchronous (overlapped) io and no buffering
- of writes in the OS */
- attributes = 0;
-#ifdef WIN_ASYNC_IO
- if (os_aio_use_native_aio) {
- attributes = attributes | FILE_FLAG_OVERLAPPED;
- }
-#endif
-#ifdef UNIV_NON_BUFFERED_IO
- attributes = attributes | FILE_FLAG_NO_BUFFERING;
-#endif
- } else if (purpose == OS_FILE_NORMAL) {
- attributes = 0
-#ifdef UNIV_NON_BUFFERED_IO
- | FILE_FLAG_NO_BUFFERING
-#endif
- ;
- } else {
- attributes = 0;
- ut_error;
- }
-
- file = CreateFile(name,
- GENERIC_READ | GENERIC_WRITE, /* read and write
- access */
- FILE_SHARE_READ,/* file can be read by other
- processes */
- NULL, /* default security attributes */
- create_flag,
- attributes,
- NULL); /* no template file */
-
- if (file == INVALID_HANDLE_VALUE) {
- *success = FALSE;
-
- if (create_mode != OS_FILE_OPEN
- && os_file_get_last_error() == OS_FILE_DISK_FULL) {
-
- retry = os_file_handle_error(file, name);
-
- if (retry) {
- goto try_again;
- }
- }
- } else {
- *success = TRUE;
- }
-
- return(file);
-#else
- os_file_t file;
- int create_flag;
- bool retry;
-
-try_again:
- ut_a(name);
-
- if (create_mode == OS_FILE_OPEN) {
- create_flag = O_RDWR;
- } else if (create_mode == OS_FILE_CREATE) {
- create_flag = O_RDWR | O_CREAT | O_EXCL;
- } else if (create_mode == OS_FILE_OVERWRITE) {
- create_flag = O_RDWR | O_CREAT | O_TRUNC;
- } else {
- create_flag = 0;
- ut_error;
- }
-
- UT_NOT_USED(purpose);
-
- if (create_mode == OS_FILE_CREATE) {
-
- file = open(name, create_flag, S_IRWXU | S_IRWXG | S_IRWXO);
- } else {
- file = open(name, create_flag);
- }
-
- if (file == -1) {
- *success = FALSE;
-
- printf("Error in opening file %s, errno %lu\n", name,
- (ulint)errno);
- perror("os0file.c:");
-
- if (create_mode != OS_FILE_OPEN
- && errno == ENOSPC) {
-
- retry = os_file_handle_error(file, name);
-
- if (retry) {
- goto try_again;
- }
- }
- } else {
- *success = TRUE;
- }
-
- return(file);
-#endif
-}
-
-/***************************************************************************
-Closes a file handle. In case of error, error number can be retrieved with
-os_file_get_last_error. */
-
-bool
-os_file_close(
-/*==========*/
- /* out: TRUE if success */
- os_file_t file) /* in, own: handle to a file */
-{
-#ifdef __WIN__
- BOOL ret;
-
- ut_a(file);
-
- ret = CloseHandle(file);
-
- if (ret) {
- return(TRUE);
- }
-
- return(FALSE);
-#else
- int ret;
-
- ret = close(file);
-
- if (ret == -1) {
- return(FALSE);
- }
-
- return(TRUE);
-#endif
-}
-
-/***************************************************************************
-Gets a file size. */
-
-bool
-os_file_get_size(
-/*=============*/
- /* out: TRUE if success */
- os_file_t file, /* in: handle to a file */
- ulint* size, /* out: least significant 32 bits of file
- size */
- ulint* size_high)/* out: most significant 32 bits of size */
-{
-#ifdef __WIN__
- DWORD high;
- DWORD low;
-
- low = GetFileSize(file, &high);
-
- if ((low == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) {
- return(FALSE);
- }
-
- *size = low;
- *size_high = high;
-
- return(TRUE);
-#else
- *size = (ulint) lseek(file, 0, SEEK_END);
- *size_high = 0;
-
- return(TRUE);
-#endif
-}
-
-/***************************************************************************
-Sets a file size. This function can be used to extend or truncate a file. */
-
-bool
-os_file_set_size(
-/*=============*/
- /* out: TRUE if success */
- char* name, /* in: name of the file or path as a
- null-terminated string */
- os_file_t file, /* in: handle to a file */
- ulint size, /* in: least significant 32 bits of file
- size */
- ulint size_high)/* in: most significant 32 bits of size */
-{
-#ifdef __WIN__
- DWORD high;
- DWORD low;
- DWORD ret;
- BOOL ret2;
- DWORD err;
- bool retry;
-
-try_again:
- low = size;
- high = size_high;
-
- ret = SetFilePointer(file, low, &high, FILE_BEGIN);
-
- if (ret == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
- err = GetLastError();
-
- goto error_handling;
- }
-
- ret2 = SetEndOfFile(file);
-
- if (ret2) {
- ret2 = os_file_flush(file);
- }
-
- if (ret2) {
- return(TRUE);
- }
-#else
- ulint offset;
- ulint n_bytes;
- ulint low;
- ssize_t ret;
- bool retry;
- ulint i;
- byte buf[UNIV_PAGE_SIZE * 8];
-
- /* Write buffer full of zeros */
- for (i = 0; i < UNIV_PAGE_SIZE * 8; i++) {
- buf[i] = '\0';
- }
-
-try_again:
- low = size;
-#if (UNIV_WORD_SIZE == 8)
- low = low + (size_high << 32);
-#endif
- while (offset < low) {
- if (low - offset < UNIV_PAGE_SIZE * 8) {
- n_bytes = low - offset;
- } else {
- n_bytes = UNIV_PAGE_SIZE * 8;
- }
-
- ret = pwrite(file, buf, n_bytes, offset);
-
- if (ret != n_bytes) {
- goto error_handling;
- }
- offset += n_bytes;
- }
-
- ret = os_file_flush(file);
-
- if (ret) {
- return(TRUE);
- }
-#endif
-
-error_handling:
- retry = os_file_handle_error(file, name);
-
- if (retry) {
- goto try_again;
- }
-
- ut_error;
-}
-
-/***************************************************************************
-Flushes the write buffers of a given file to the disk. */
-
-bool
-os_file_flush(
-/*==========*/
- /* out: TRUE if success */
- os_file_t file) /* in, own: handle to a file */
-{
-#ifdef __WIN__
- BOOL ret;
-
- ut_a(file);
-
- ret = FlushFileBuffers(file);
-
- if (ret) {
- return(TRUE);
- }
-
- return(FALSE);
-#else
- int ret;
-
- ret = fsync(file);
-
- if (ret == 0) {
- return(TRUE);
- }
-
- return(FALSE);
-#endif
-}
-
-
-#ifndef __WIN__
-/***********************************************************************
-Does a synchronous read operation in Posix. */
-static
-ssize_t
-os_file_pread(
-/*==========*/
- /* out: number of bytes read, -1 if error */
- os_file_t file, /* in: handle to a file */
- void* buf, /* in: buffer where to read */
- ulint n, /* in: number of bytes to read */
- ulint offset) /* in: offset from where to read */
-{
-#ifdef HAVE_PREAD
- return(pread(file, buf, n, (off_t) offset));
-#else
- ssize_t ret;
- ulint i;
-
- /* Protect the seek / read operation with a mutex */
- i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
-
- os_mutex_enter(os_file_seek_mutexes[i]);
-
- ret = lseek(file, (off_t) offset, 0);
-
- if (ret < 0) {
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- return(ret);
- }
-
- ret = read(file, buf, n);
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- return(ret);
-#endif
-}
-
-/***********************************************************************
-Does a synchronous write operation in Posix. */
-static
-ssize_t
-os_file_pwrite(
-/*===========*/
- /* out: number of bytes written, -1 if error */
- os_file_t file, /* in: handle to a file */
- void* buf, /* in: buffer from where to write */
- ulint n, /* in: number of bytes to write */
- ulint offset) /* in: offset where to write */
-{
-#ifdef HAVE_PWRITE
- return(pwrite(file, buf, n, (off_t) offset));
-#else
- ssize_t ret;
- ulint i;
-
- /* Protect the seek / write operation with a mutex */
- i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
-
- os_mutex_enter(os_file_seek_mutexes[i]);
-
- ret = lseek(file, (off_t) offset, 0);
-
- if (ret < 0) {
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- return(ret);
- }
-
- ret = write(file, buf, n);
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- return(ret);
-#endif
-}
-#endif
-
-/***********************************************************************
-Requests a synchronous positioned read operation. */
-
-bool
-os_file_read(
-/*=========*/
- /* out: TRUE if request was
- successful, FALSE if fail */
- os_file_t file, /* in: handle to a file */
- void* buf, /* in: buffer where to read */
- ulint offset, /* in: least significant 32 bits of file
- offset where to read */
- ulint offset_high, /* in: most significant 32 bits of
- offset */
- ulint n) /* in: number of bytes to read */
-{
-#ifdef __WIN__
- BOOL ret;
- DWORD len;
- DWORD ret2;
- DWORD err;
- DWORD low;
- DWORD high;
- bool retry;
- ulint i;
-
-try_again:
- ut_ad(file);
- ut_ad(buf);
- ut_ad(n > 0);
-
- low = offset;
- high = offset_high;
-
- /* Protect the seek / read operation with a mutex */
- i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
-
- os_mutex_enter(os_file_seek_mutexes[i]);
-
- ret2 = SetFilePointer(file, low, &high, FILE_BEGIN);
-
- if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
- err = GetLastError();
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- goto error_handling;
- }
-
- ret = ReadFile(file, buf, n, &len, NULL);
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- if (ret && len == n) {
- return(TRUE);
- }
-
- err = GetLastError();
-#else
- bool retry;
- ssize_t ret;
- ulint i;
-
-#if (UNIV_WORD_SIZE == 8)
- offset = offset + (offset_high << 32);
-#endif
-try_again:
- /* Protect the seek / read operation with a mutex */
- i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
-
- os_mutex_enter(os_file_seek_mutexes[i]);
-
- ret = os_file_pread(file, buf, n, (off_t) offset);
-
- if (ret == n) {
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- return(TRUE);
- }
-#endif
-error_handling:
- retry = os_file_handle_error(file, NULL);
-
- if (retry) {
- goto try_again;
- }
-
- ut_error;
-
- return(FALSE);
-}
-
-/***********************************************************************
-Requests a synchronous write operation. */
-
-bool
-os_file_write(
-/*==========*/
- /* out: TRUE if request was
- successful, FALSE if fail */
- char* name, /* in: name of the file or path as a
- null-terminated string */
- os_file_t file, /* in: handle to a file */
- void* buf, /* in: buffer from which to write */
- ulint offset, /* in: least significant 32 bits of file
- offset where to write */
- ulint offset_high, /* in: most significant 32 bits of
- offset */
- ulint n) /* in: number of bytes to write */
-{
-#ifdef __WIN__
- BOOL ret;
- DWORD len;
- DWORD ret2;
- DWORD err;
- DWORD low;
- DWORD high;
- bool retry;
- ulint i;
-
-try_again:
- ut_ad(file);
- ut_ad(buf);
- ut_ad(n > 0);
-
- low = offset;
- high = offset_high;
-
- /* Protect the seek / write operation with a mutex */
- i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;
-
- os_mutex_enter(os_file_seek_mutexes[i]);
-
- ret2 = SetFilePointer(file, low, &high, FILE_BEGIN);
-
- if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
- err = GetLastError();
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- goto error_handling;
- }
-
- ret = WriteFile(file, buf, n, &len, NULL);
-
- os_mutex_exit(os_file_seek_mutexes[i]);
-
- if (ret && len == n) {
- return(TRUE);
- }
-#else
- bool retry;
- ssize_t ret;
-
-#if (UNIV_WORD_SIZE == 8)
- offset = offset + (offset_high << 32);
-#endif
-try_again:
- ret = pwrite(file, buf, n, (off_t) offset);
-
- if (ret == n) {
- return(TRUE);
- }
-#endif
-
-error_handling:
- retry = os_file_handle_error(file, name);
-
- if (retry) {
- goto try_again;
- }
-
- ut_error;
-
- return(FALSE);
-}
-
-/********************************************************************
-Returns a pointer to the nth slot in the aio array. */
-static
-os_aio_slot_t*
-os_aio_array_get_nth_slot(
-/*======================*/
- /* out: pointer to slot */
- os_aio_array_t* array, /* in: aio array */
- ulint index) /* in: index of the slot */
-{
- ut_a(index < array->n_slots);
-
- return((array->slots) + index);
-}
-
-/****************************************************************************
-Creates an aio wait array. */
-static
-os_aio_array_t*
-os_aio_array_create(
-/*================*/
- /* out, own: aio array */
- ulint n, /* in: maximum number of pending aio operations
- allowed; n must be divisible by n_segments */
- ulint n_segments) /* in: number of segments in the aio array */
-{
- os_aio_array_t* array;
- ulint i;
- os_aio_slot_t* slot;
-#ifdef WIN_ASYNC_IO
- OVERLAPPED* over;
-#endif
- ut_a(n > 0);
- ut_a(n_segments > 0);
- ut_a(n % n_segments == 0);
-
- array = ut_malloc(sizeof(os_aio_array_t));
-
- array->mutex = os_mutex_create(NULL);
- array->not_full = os_event_create(NULL);
- array->n_slots = n;
- array->n_segments = n_segments;
- array->n_reserved = 0;
- array->slots = ut_malloc(n * sizeof(os_aio_slot_t));
- array->events = ut_malloc(n * sizeof(os_event_t));
-
- for (i = 0; i < n; i++) {
- slot = os_aio_array_get_nth_slot(array, i);
-
- slot->pos = i;
- slot->reserved = FALSE;
-#ifdef WIN_ASYNC_IO
- over = &(slot->control);
-
- over->hEvent = os_event_create(NULL);
-
- *((array->events) + i) = over->hEvent;
-#elif defined(POSIX_ASYNC_IO)
- slot->ready = os_event_create(NULL);
-#endif
- }
-
- return(array);
-}
-
-/****************************************************************************
-Initializes the asynchronous io system. Creates separate aio array for
-non-ibuf read and write, a third aio array for the ibuf i/o, with just one
-segment, two aio arrays for log reads and writes with one segment, and a
-synchronous aio array of the specified size. The combined number of segments
-in the three first aio arrays is the parameter n_segments given to the
-function. The caller must create an i/o handler thread for each segment in
-the four first arrays, but not for the sync aio array. */
-
-void
-os_aio_init(
-/*========*/
- ulint n, /* in: maximum number of pending aio operations
- allowed; n must be divisible by n_segments */
- ulint n_segments, /* in: combined number of segments in the four
- first aio arrays; must be >= 4 */
- ulint n_slots_sync) /* in: number of slots in the sync aio array */
-{
- ulint n_read_segs;
- ulint n_write_segs;
- ulint n_per_seg;
- ulint i;
-
- ut_ad(n % n_segments == 0);
- ut_ad(n_segments >= 4);
-
- n_per_seg = n / n_segments;
- n_write_segs = (n_segments - 2) / 2;
- n_read_segs = n_segments - 2 - n_write_segs;
-
- os_aio_read_array = os_aio_array_create(n_read_segs * n_per_seg,
- n_read_segs);
- os_aio_write_array = os_aio_array_create(n_write_segs * n_per_seg,
- n_write_segs);
- os_aio_ibuf_array = os_aio_array_create(n_per_seg, 1);
-
- os_aio_log_array = os_aio_array_create(n_per_seg, 1);
-
- os_aio_sync_array = os_aio_array_create(n_slots_sync, 1);
-
- os_aio_n_segments = n_segments;
-
-#if !(defined(WIN_ASYNC_IO) || defined(POSIX_ASYNC_IO))
- os_aio_use_native_aio = FALSE;
-#endif
- os_aio_validate();
-
- for (i = 0; i < OS_FILE_N_SEEK_MUTEXES; i++) {
- os_file_seek_mutexes[i] = os_mutex_create(NULL);
- }
-
- os_aio_segment_wait_events = ut_malloc(n_segments * sizeof(void*));
-
- for (i = 0; i < n_segments; i++) {
- os_aio_segment_wait_events[i] = os_event_create(NULL);
- }
-}
-
-/**************************************************************************
-Calculates segment number for a slot. */
-static
-ulint
-os_aio_get_segment_no_from_slot(
-/*============================*/
- /* out: segment number (which is the number
- used by, for example, i/o-handler threads) */
- os_aio_array_t* array, /* in: aio wait array */
- os_aio_slot_t* slot) /* in: slot in this array */
-{
- ulint segment;
- ulint seg_len;
-
- if (array == os_aio_ibuf_array) {
- segment = 0;
-
- } else if (array == os_aio_log_array) {
- segment = 1;
-
- } else if (array == os_aio_read_array) {
- seg_len = os_aio_read_array->n_slots /
- os_aio_read_array->n_segments;
-
- segment = 2 + slot->pos / seg_len;
- } else {
- ut_a(array == os_aio_write_array);
- seg_len = os_aio_write_array->n_slots /
- os_aio_write_array->n_segments;
-
- segment = os_aio_read_array->n_segments + 2
- + slot->pos / seg_len;
- }
-
- return(segment);
-}
-
-/**************************************************************************
-Calculates local segment number and aio array from global segment number. */
-static
-ulint
-os_aio_get_array_and_local_segment(
-/*===============================*/
- /* out: local segment number within
- the aio array */
- os_aio_array_t** array, /* out: aio wait array */
- ulint global_segment)/* in: global segment number */
-{
- ulint segment;
-
- ut_a(global_segment < os_aio_n_segments);
-
- if (global_segment == 0) {
- *array = os_aio_ibuf_array;
- segment = 0;
-
- } else if (global_segment == 1) {
- *array = os_aio_log_array;
- segment = 0;
-
- } else if (global_segment < os_aio_read_array->n_segments + 2) {
- *array = os_aio_read_array;
-
- segment = global_segment - 2;
- } else {
- *array = os_aio_write_array;
-
- segment = global_segment - (os_aio_read_array->n_segments + 2);
- }
-
- return(segment);
-}
-
-/***********************************************************************
-Gets an integer value designating a specified aio array. This is used
-to give numbers to signals in Posix aio. */
-static
-ulint
-os_aio_get_array_no(
-/*================*/
- os_aio_array_t* array) /* in: aio array */
-{
- if (array == os_aio_ibuf_array) {
-
- return(0);
-
- } else if (array == os_aio_log_array) {
-
- return(1);
-
- } else if (array == os_aio_read_array) {
-
- return(2);
- } else if (array == os_aio_write_array) {
-
- return(3);
- } else {
- ut_a(0);
-
- return(0);
- }
-}
-
-/***********************************************************************
-Gets the aio array for its number. */
-static
-os_aio_array_t*
-os_aio_get_array_from_no(
-/*=====================*/
- /* out: aio array */
- ulint n) /* in: array number */
-{
- if (n == 0) {
- return(os_aio_ibuf_array);
- } else if (n == 1) {
-
- return(os_aio_log_array);
- } else if (n == 2) {
-
- return(os_aio_read_array);
- } else if (n == 3) {
-
- return(os_aio_write_array);
- } else {
- ut_a(0);
-
- return(NULL);
- }
-}
-
-/***********************************************************************
-Requests for a slot in the aio array. If no slot is available, waits until
-not_full-event becomes signaled. */
-static
-os_aio_slot_t*
-os_aio_array_reserve_slot(
-/*======================*/
- /* out: pointer to slot */
- ulint type, /* in: OS_FILE_READ or OS_FILE_WRITE */
- os_aio_array_t* array, /* in: aio array */
- void* message1,/* in: message to be passed along with
- the aio operation */
- void* message2,/* in: message to be passed along with
- the aio operation */
- os_file_t file, /* in: file handle */
- char* name, /* in: name of the file or path as a
- null-terminated string */
- void* buf, /* in: buffer where to read or from which
- to write */
- ulint offset, /* in: least significant 32 bits of file
- offset */
- ulint offset_high, /* in: most significant 32 bits of
- offset */
- ulint len) /* in: length of the block to read or write */
-{
- os_aio_slot_t* slot;
-#ifdef WIN_ASYNC_IO
- OVERLAPPED* control;
-#elif POSIX_ASYNC_IO
- struct aiocb* control;
- ulint type;
-#endif
- ulint i;
-loop:
- os_mutex_enter(array->mutex);
-
- if (array->n_reserved == array->n_slots) {
- os_mutex_exit(array->mutex);
- os_event_wait(array->not_full);
-
- goto loop;
- }
-
- for (i = 0;; i++) {
- slot = os_aio_array_get_nth_slot(array, i);
-
- if (slot->reserved == FALSE) {
- break;
- }
- }
-
- array->n_reserved++;
-
- if (array->n_reserved == array->n_slots) {
- os_event_reset(array->not_full);
- }
-
- slot->reserved = TRUE;
- slot->message1 = message1;
- slot->message2 = message2;
- slot->file = file;
- slot->name = name;
- slot->len = len;
- slot->type = type;
- slot->buf = buf;
- slot->offset = offset;
- slot->offset_high = offset_high;
- slot->io_already_done = FALSE;
-
-#ifdef WIN_ASYNC_IO
- control = &(slot->control);
- control->Offset = (DWORD)offset;
- control->OffsetHigh = (DWORD)offset_high;
- os_event_reset(control->hEvent);
-
-#elif POSIX_ASYNC_IO
-
-#if (UNIV_WORD_SIZE == 8)
- offset = offset + (offset_high << 32);
-#else
- ut_a(offset_high == 0);
-#endif
- control = &(slot->control);
- control->aio_fildes = file;
- control->aio_buf = buf;
- control->aio_nbytes = len;
- control->aio_offset = offset;
- control->aio_reqprio = 0;
- control->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
- control->aio_sigevent.signo =
- SIGRTMAX + 1 + os_aio_get_array_no(array);
- /* TODO: How to choose the signal numbers? */
- control->aio_sigevent.sigev_value.sival_ptr = slot;
-#endif
- os_mutex_exit(array->mutex);
-
- return(slot);
-}
-
-/***********************************************************************
-Frees a slot in the aio array. */
-static
-void
-os_aio_array_free_slot(
-/*===================*/
- os_aio_array_t* array, /* in: aio array */
- os_aio_slot_t* slot) /* in: pointer to slot */
-{
- ut_ad(array);
- ut_ad(slot);
-
- os_mutex_enter(array->mutex);
-
- ut_ad(slot->reserved);
-
- slot->reserved = FALSE;
-
- array->n_reserved--;
-
- if (array->n_reserved == array->n_slots - 1) {
- os_event_set(array->not_full);
- }
-
-#ifdef WIN_ASYNC_IO
- os_event_reset(slot->control.hEvent);
-#endif
- os_mutex_exit(array->mutex);
-}
-
-/**************************************************************************
-Wakes up a simulated aio i/o-handler thread if it has something to do. */
-static
-void
-os_aio_simulated_wake_handler_thread(
-/*=================================*/
- ulint global_segment) /* in: the number of the segment in the aio
- arrays */
-{
- os_aio_array_t* array;
- ulint segment;
- os_aio_slot_t* slot;
- ulint n;
- ulint i;
-
- ut_ad(!os_aio_use_native_aio);
-
- segment = os_aio_get_array_and_local_segment(&array, global_segment);
-
- n = array->n_slots / array->n_segments;
-
- /* Look through n slots after the segment * n'th slot */
-
- os_mutex_enter(array->mutex);
-
- for (i = 0; i < n; i++) {
- slot = os_aio_array_get_nth_slot(array, i + segment * n);
-
- if (slot->reserved) {
- /* Found an i/o request */
-
- break;
- }
- }
-
- os_mutex_exit(array->mutex);
-
- if (i < n) {
- os_event_set(os_aio_segment_wait_events[global_segment]);
- }
-}
-
-/**************************************************************************
-Wakes up simulated aio i/o-handler threads if they have something to do. */
-
-void
-os_aio_simulated_wake_handler_threads(void)
-/*=======================================*/
-{
- ulint i;
-
- if (os_aio_use_native_aio) {
- /* We do not use simulated aio: do nothing */
-
- return;
- }
-
- for (i = 0; i < os_aio_n_segments; i++) {
- os_aio_simulated_wake_handler_thread(i);
- }
-}
-
-/***********************************************************************
-Requests an asynchronous i/o operation. */
-
-bool
-os_aio(
-/*===*/
- /* out: TRUE if request was queued
- successfully, FALSE if fail */
- ulint type, /* in: OS_FILE_READ or OS_FILE_WRITE */
- ulint mode, /* in: OS_AIO_NORMAL, ..., possibly ORed
- to OS_AIO_SIMULATED_WAKE_LATER: the
- last flag advises this function not to wake
- i/o-handler threads, but the caller will
- do the waking explicitly later, in this
- way the caller can post several requests in
- a batch; NOTE that the batch must not be
- so big that it exhausts the slots in aio
- arrays! NOTE that a simulated batch
- may introduce hidden chances of deadlocks,
- because i/os are not actually handled until
- all have been posted: use with great
- caution! */
- char* name, /* in: name of the file or path as a
- null-terminated string */
- os_file_t file, /* in: handle to a file */
- void* buf, /* in: buffer where to read or from which
- to write */
- ulint offset, /* in: least significant 32 bits of file
- offset where to read or write */
- ulint offset_high, /* in: most significant 32 bits of
- offset */
- ulint n, /* in: number of bytes to read or write */
- void* message1,/* in: messages for the aio handler (these
- can be used to identify a completed aio
- operation); if mode is OS_AIO_SYNC, these
- are ignored */
- void* message2)
-{
- os_aio_array_t* array;
- os_aio_slot_t* slot;
-#ifdef WIN_ASYNC_IO
- BOOL ret = TRUE;
- DWORD len = n;
- void* dummy_mess1;
- void* dummy_mess2;
-#endif
- ulint err = 0;
- bool retry;
- ulint wake_later;
-
- ut_ad(file);
- ut_ad(buf);
- ut_ad(n > 0);
- ut_ad(n % OS_FILE_LOG_BLOCK_SIZE == 0);
- ut_ad((ulint)buf % OS_FILE_LOG_BLOCK_SIZE == 0)
- ut_ad(offset % OS_FILE_LOG_BLOCK_SIZE == 0);
- ut_ad(os_aio_validate());
-
- wake_later = mode & OS_AIO_SIMULATED_WAKE_LATER;
- mode = mode & (~OS_AIO_SIMULATED_WAKE_LATER);
-
- if (mode == OS_AIO_SYNC
-#ifdef WIN_ASYNC_IO
- && !os_aio_use_native_aio
-#endif
- ) {
- /* This is actually an ordinary synchronous read or write:
- no need to use an i/o-handler thread. NOTE that if we use
- Windows async i/o, Windows does not allow us to use
- ordinary synchronous os_file_read etc. on the same file,
- therefore we have built a special mechanism for synchronous
- wait in the Windows case. */
-
- if (type == OS_FILE_READ) {
- return(os_file_read(file, buf, offset, offset_high, n));
- }
-
- ut_a(type == OS_FILE_WRITE);
-
- return(os_file_write(name, file, buf, offset, offset_high, n));
- }
-
-try_again:
- if (mode == OS_AIO_NORMAL) {
- if (type == OS_FILE_READ) {
- array = os_aio_read_array;
- } else {
- array = os_aio_write_array;
- }
- } else if (mode == OS_AIO_IBUF) {
- ut_ad(type == OS_FILE_READ);
-
- array = os_aio_ibuf_array;
- } else if (mode == OS_AIO_LOG) {
-
- array = os_aio_log_array;
- } else if (mode == OS_AIO_SYNC) {
- array = os_aio_sync_array;
- } else {
- ut_error;
- }
-
- slot = os_aio_array_reserve_slot(type, array, message1, message2, file,
- name, buf, offset, offset_high, n);
- if (type == OS_FILE_READ) {
- if (os_aio_use_native_aio) {
-#ifdef WIN_ASYNC_IO
- ret = ReadFile(file, buf, (DWORD)n, &len,
- &(slot->control));
-#elif defined(POSIX_ASYNC_IO)
- err = (ulint) aio_read(&(slot->control));
-#endif
- } else {
- if (!wake_later) {
- os_aio_simulated_wake_handler_thread(
- os_aio_get_segment_no_from_slot(array, slot));
- }
- }
- } else if (type == OS_FILE_WRITE) {
- if (os_aio_use_native_aio) {
-#ifdef WIN_ASYNC_IO
- ret = WriteFile(file, buf, (DWORD)n, &len,
- &(slot->control));
-#elif defined(POSIX_ASYNC_IO)
- err = (ulint) aio_write(&(slot->control));
-#endif
- } else {
- if (!wake_later) {
- os_aio_simulated_wake_handler_thread(
- os_aio_get_segment_no_from_slot(array, slot));
- }
- }
- } else {
- ut_error;
- }
-
-#ifdef WIN_ASYNC_IO
- if ((ret && len == n)
- || (!ret && GetLastError() == ERROR_IO_PENDING)) {
-
- /* aio was queued successfully! */
-
- if (mode == OS_AIO_SYNC) {
- /* We want a synchronous i/o operation on a file
- where we also use async i/o: in Windows we must
- use the same wait mechanism as for async i/o */
-
- return(os_aio_windows_handle(ULINT_UNDEFINED,
- slot->pos,
- &dummy_mess1, &dummy_mess2));
- }
-
- return(TRUE);
- }
-#else
- if (err == 0) {
- /* aio was queued successfully! */
-
- return(TRUE);
- }
-#endif
- os_aio_array_free_slot(array, slot);
-
- retry = os_file_handle_error(file, name);
-
- if (retry) {
-
- goto try_again;
- }
-
- ut_error;
-
- return(FALSE);
-}
-
-#ifdef WIN_ASYNC_IO
-/**************************************************************************
-This function is only used in Windows asynchronous i/o.
-Waits for an aio operation to complete. This function is used to wait the
-for completed requests. The aio array of pending requests is divided
-into segments. The thread specifies which segment or slot it wants to wait
-for. NOTE: this function will also take care of freeing the aio slot,
-therefore no other thread is allowed to do the freeing! */
-
-bool
-os_aio_windows_handle(
-/*==================*/
- /* out: TRUE if the aio operation succeeded */
- ulint segment, /* in: the number of the segment in the aio
- arrays to wait for; segment 0 is the ibuf
- i/o thread, segment 1 the log i/o thread,
- then follow the non-ibuf read threads, and as
- the last are the non-ibuf write threads; if
- this is ULINT_UNDEFINED, then it means that
- sync aio is used, and this parameter is
- ignored */
- ulint pos, /* this parameter is used only in sync aio:
- wait for the aio slot at this position */
- void** message1, /* out: the messages passed with the aio
- request; note that also in the case where
- the aio operation failed, these output
- parameters are valid and can be used to
- restart the operation, for example */
- void** message2)
-{
- os_aio_array_t* array;
- os_aio_slot_t* slot;
- ulint n;
- ulint i;
- bool ret_val;
- ulint err;
- BOOL ret;
- DWORD len;
-
- if (segment == ULINT_UNDEFINED) {
- array = os_aio_sync_array;
- segment = 0;
- } else {
- segment = os_aio_get_array_and_local_segment(&array, segment);
- }
-
- /* NOTE! We only access constant fields in os_aio_array. Therefore
- we do not have to acquire the protecting mutex yet */
-
- ut_ad(os_aio_validate());
- ut_ad(segment < array->n_segments);
-
- n = array->n_slots / array->n_segments;
-
- if (array == os_aio_sync_array) {
- ut_ad(pos < array->n_slots);
- os_event_wait(array->events[pos]);
- i = pos;
- } else {
- i = os_event_wait_multiple(n, (array->events) + segment * n);
- }
-
- os_mutex_enter(array->mutex);
-
- slot = os_aio_array_get_nth_slot(array, i + segment * n);
-
- ut_a(slot->reserved);
-
- ret = GetOverlappedResult(slot->file, &(slot->control), &len, TRUE);
-
- *message1 = slot->message1;
- *message2 = slot->message2;
-
- if (ret && len == slot->len) {
- ret_val = TRUE;
- } else {
- err = GetLastError();
- ut_error;
-
- ret_val = FALSE;
- }
-
- os_mutex_exit(array->mutex);
-
- os_aio_array_free_slot(array, slot);
-
- return(ret_val);
-}
-#endif
-
-#ifdef POSIX_ASYNC_IO
-/**************************************************************************
-This function is only used in Posix asynchronous i/o. Waits for an aio
-operation to complete. */
-
-bool
-os_aio_posix_handle(
-/*================*/
- /* out: TRUE if the aio operation succeeded */
- ulint array_no, /* in: array number 0 - 3 */
- void** message1, /* out: the messages passed with the aio
- request; note that also in the case where
- the aio operation failed, these output
- parameters are valid and can be used to
- restart the operation, for example */
- void** message2)
-{
- os_aio_array_t* array;
- os_aio_slot_t* slot;
- siginfo_t info;
- sigset_t sigset;
- int ret;
-
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGRTMAX + 1 + array_no);
-
- ret = sigwaitinfo(&sigset, &info);
-
- if (ret != SIGRTMAX + 1 + array_no) {
-
- ut_a(0);
-
- return(FALSE);
- }
-
- array = os_aio_get_array_from_no(array_no);
-
- os_mutex_enter(array->mutex);
-
- slot = siginfo.si_value.sival_ptr;
-
- ut_a(slot->reserved);
-
- *message1 = slot->message1;
- *message2 = slot->message2;
-
- os_mutex_exit(array->mutex);
-
- os_aio_array_free_slot(array, slot);
-
- return(TRUE);
-}
-#endif
-
-/**************************************************************************
-Does simulated aio. This function should be called by an i/o-handler
-thread. */
-
-bool
-os_aio_simulated_handle(
-/*====================*/
- /* out: TRUE if the aio operation succeeded */
- ulint global_segment, /* in: the number of the segment in the aio
- arrays to wait for; segment 0 is the ibuf
- i/o thread, segment 1 the log i/o thread,
- then follow the non-ibuf read threads, and as
- the last are the non-ibuf write threads */
- void** message1, /* out: the messages passed with the aio
- request; note that also in the case where
- the aio operation failed, these output
- parameters are valid and can be used to
- restart the operation, for example */
- void** message2)
-{
- os_aio_array_t* array;
- ulint segment;
- os_aio_slot_t* slot;
- os_aio_slot_t* slot2;
- os_aio_slot_t* consecutive_ios[OS_AIO_MERGE_N_CONSECUTIVE];
- ulint n_consecutive;
- ulint total_len;
- ulint offs;
- byte* combined_buf;
- bool ret;
- ulint n;
- ulint i;
-
- segment = os_aio_get_array_and_local_segment(&array, global_segment);
-
-restart:
- /* NOTE! We only access constant fields in os_aio_array. Therefore
- we do not have to acquire the protecting mutex yet */
-
- ut_ad(os_aio_validate());
- ut_ad(segment < array->n_segments);
-
- n = array->n_slots / array->n_segments;
-
- /* Look through n slots after the segment * n'th slot */
-
- os_mutex_enter(array->mutex);
-
- /* Check if there is a slot for which the i/o has already been
- done */
-
- for (i = 0; i < n; i++) {
- slot = os_aio_array_get_nth_slot(array, i + segment * n);
-
- if (slot->reserved && slot->io_already_done) {
-
- goto slot_io_done;
- }
- }
-
- n_consecutive = 0;
-
- for (i = 0; i < n; i++) {
- slot = os_aio_array_get_nth_slot(array, i + segment * n);
-
- if (slot->reserved) {
- /* Found an i/o request */
- consecutive_ios[n_consecutive] = slot;
- n_consecutive++;
-
- break;
- }
- }
-
- /* Check if there are several consecutive blocks to read or write */
-
-consecutive_loop:
- for (i = 0; i < n; i++) {
- slot2 = os_aio_array_get_nth_slot(array, i + segment * n);
-
- if (slot2->reserved && slot2 != slot
- && slot2->offset == slot->offset + slot->len
- && slot->offset + slot->len > slot->offset /* check that
- sum does not wrap over */
- && slot2->offset_high == slot->offset_high
- && slot2->type == slot->type
- && slot2->file == slot->file) {
-
- /* Found a consecutive i/o request */
-
- consecutive_ios[n_consecutive] = slot2;
- n_consecutive++;
-
- slot = slot2;
-
- if (n_consecutive < OS_AIO_MERGE_N_CONSECUTIVE) {
-
- goto consecutive_loop;
- } else {
- break;
- }
- }
- }
-
- if (n_consecutive == 0) {
-
- /* No i/o requested at the moment */
-
- goto wait_for_io;
- }
-
- /* We have now collected n_consecutive i/o requests in the array;
- allocate a single buffer which can hold all data, and perform the
- i/o */
-
- total_len = 0;
- slot = consecutive_ios[0];
-
- for (i = 0; i < n_consecutive; i++) {
- total_len += consecutive_ios[i]->len;
- }
-
- if (n_consecutive == 1) {
- /* We can use the buffer of the i/o request */
- combined_buf = slot->buf;
- } else {
- combined_buf = ut_malloc(total_len);
-
- ut_a(combined_buf);
- }
-
- /* We release the array mutex for the time of the i/o: NOTE that
- this assumes that there is just one i/o-handler thread serving
- a single segment of slots! */
-
- os_mutex_exit(array->mutex);
-
- if (slot->type == OS_FILE_WRITE && n_consecutive > 1) {
- /* Copy the buffers to the combined buffer */
- offs = 0;
-
- for (i = 0; i < n_consecutive; i++) {
-
- ut_memcpy(combined_buf + offs, consecutive_ios[i]->buf,
- consecutive_ios[i]->len);
- offs += consecutive_ios[i]->len;
- }
- }
-
- /* Do the i/o with ordinary, synchronous i/o functions: */
- if (slot->type == OS_FILE_WRITE) {
- ret = os_file_write(slot->name, slot->file, combined_buf,
- slot->offset, slot->offset_high, total_len);
- } else {
- ret = os_file_read(slot->file, combined_buf,
- slot->offset, slot->offset_high, total_len);
- }
-
- ut_a(ret);
-
- if (slot->type == OS_FILE_READ && n_consecutive > 1) {
- /* Copy the combined buffer to individual buffers */
- offs = 0;
-
- for (i = 0; i < n_consecutive; i++) {
-
- ut_memcpy(consecutive_ios[i]->buf, combined_buf + offs,
- consecutive_ios[i]->len);
- offs += consecutive_ios[i]->len;
- }
- }
-
- if (n_consecutive > 1) {
- ut_free(combined_buf);
- }
-
- os_mutex_enter(array->mutex);
-
- /* Mark the i/os done in slots */
-
- for (i = 0; i < n_consecutive; i++) {
- consecutive_ios[i]->io_already_done = TRUE;
- }
-
- /* We return the messages for the first slot now, and if there were
- several slots, the messages will be returned with subsequent calls
- of this function */
-
-slot_io_done:
-
- ut_a(slot->reserved);
-
- *message1 = slot->message1;
- *message2 = slot->message2;
-
- os_mutex_exit(array->mutex);
-
- os_aio_array_free_slot(array, slot);
-
- return(ret);
-
-wait_for_io:
- /* We wait here until there again can be i/os in the segment
- of this thread */
-
- os_event_reset(os_aio_segment_wait_events[global_segment]);
-
- os_mutex_exit(array->mutex);
-
- os_event_wait(os_aio_segment_wait_events[global_segment]);
-
- goto restart;
-}
-
-/**************************************************************************
-Validates the consistency of an aio array. */
-static
-bool
-os_aio_array_validate(
-/*==================*/
- /* out: TRUE if ok */
- os_aio_array_t* array) /* in: aio wait array */
-{
- os_aio_slot_t* slot;
- ulint n_reserved = 0;
- ulint i;
-
- ut_a(array);
-
- os_mutex_enter(array->mutex);
-
- ut_a(array->n_slots > 0);
- ut_a(array->n_segments > 0);
-
- for (i = 0; i < array->n_slots; i++) {
- slot = os_aio_array_get_nth_slot(array, i);
-
- if (slot->reserved) {
- n_reserved++;
- ut_a(slot->len > 0);
- }
- }
-
- ut_a(array->n_reserved == n_reserved);
-
- os_mutex_exit(array->mutex);
-
- return(TRUE);
-}
-
-/**************************************************************************
-Validates the consistency the aio system. */
-
-bool
-os_aio_validate(void)
-/*=================*/
- /* out: TRUE if ok */
-{
- os_aio_array_validate(os_aio_read_array);
- os_aio_array_validate(os_aio_write_array);
- os_aio_array_validate(os_aio_ibuf_array);
- os_aio_array_validate(os_aio_log_array);
- os_aio_array_validate(os_aio_sync_array);
-
- return(TRUE);
-}
-
-/**************************************************************************
-Prints info of the aio arrays. */
-
-void
-os_aio_print(void)
-/*==============*/
-{
- os_aio_array_t* array;
- os_aio_slot_t* slot;
- ulint n_reserved;
- ulint i;
-
- array = os_aio_read_array;
-loop:
- ut_a(array);
-
- printf("INFO OF AN AIO ARRAY\n");
-
- os_mutex_enter(array->mutex);
-
- ut_a(array->n_slots > 0);
- ut_a(array->n_segments > 0);
-
- n_reserved = 0;
-
- for (i = 0; i < array->n_slots; i++) {
- slot = os_aio_array_get_nth_slot(array, i);
-
- if (slot->reserved) {
- n_reserved++;
- printf("Reserved slot, messages %lx %lx\n",
- slot->message1, slot->message2);
- ut_a(slot->len > 0);
- }
- }
-
- ut_a(array->n_reserved == n_reserved);
-
- printf("Total of %lu reserved aio slots\n", n_reserved);
-
- os_mutex_exit(array->mutex);
-
- if (array == os_aio_read_array) {
- array = os_aio_write_array;
-
- goto loop;
- }
-
- if (array == os_aio_write_array) {
- array = os_aio_ibuf_array;
-
- goto loop;
- }
-
- if (array == os_aio_ibuf_array) {
- array = os_aio_log_array;
-
- goto loop;
- }
-
- if (array == os_aio_log_array) {
- array = os_aio_sync_array;
-
- goto loop;
- }
-}
-
-/**************************************************************************
-Checks that all slots in the system have been freed, that is, there are
-no pending io operations. */
-
-bool
-os_aio_all_slots_free(void)
-/*=======================*/
- /* out: TRUE if all free */
-{
- os_aio_array_t* array;
- ulint n_res = 0;
-
- array = os_aio_read_array;
-
- os_mutex_enter(array->mutex);
-
- n_res += array->n_reserved;
-
- os_mutex_exit(array->mutex);
-
- array = os_aio_write_array;
-
- os_mutex_enter(array->mutex);
-
- n_res += array->n_reserved;
-
- os_mutex_exit(array->mutex);
-
- array = os_aio_ibuf_array;
-
- os_mutex_enter(array->mutex);
-
- n_res += array->n_reserved;
-
- os_mutex_exit(array->mutex);
-
- array = os_aio_log_array;
-
- os_mutex_enter(array->mutex);
-
- n_res += array->n_reserved;
-
- os_mutex_exit(array->mutex);
-
- array = os_aio_sync_array;
-
- os_mutex_enter(array->mutex);
-
- n_res += array->n_reserved;
-
- os_mutex_exit(array->mutex);
-
- if (n_res == 0) {
-
- return(TRUE);
- }
-
- return(FALSE);
-}
diff --git a/innobase/os/os0proc.c b/innobase/os/os0proc.c
index a427c595bc0..85791c55348 100644
--- a/innobase/os/os0proc.c
+++ b/innobase/os/os0proc.c
@@ -515,83 +515,6 @@ os_mem_alloc_nocache(
#endif
}
-#ifdef notdefined
-/********************************************************************
-Creates a new process. */
-
-ibool
-os_process_create(
-/*==============*/
- char* name, /* in: name of the executable to start
- or its full path name */
- char* cmd, /* in: command line for the starting
- process, or NULL if no command line
- specified */
- os_process_t* proc, /* out: handle to the process */
- os_process_id_t* id) /* out: process id */
-
-{
- BOOL ret;
- PROCESS_INFORMATION pinfo;
- STARTUPINFO sinfo;
-
- /* The following assignments are default for the startupinfo
- structure */
- sinfo.cb = sizeof(STARTUPINFO);
- sinfo.lpReserved = NULL;
- sinfo.lpDesktop = NULL;
- sinfo.cbReserved2 = 0;
- sinfo.lpReserved = NULL;
-
- ret = CreateProcess(name,
- cmd,
- NULL, /* No security attributes */
- NULL, /* No thread security attrs */
- FALSE, /* Do not inherit handles */
- 0, /* No creation flags */
- NULL, /* No environment */
- NULL, /* Same current directory */
- &sinfo,
- &pinfo);
-
- *proc = pinfo.hProcess;
- *id = pinfo.dwProcessId;
-
- return(ret);
-}
-
-/**************************************************************************
-Exits a process. */
-
-void
-os_process_exit(
-/*============*/
- ulint code) /* in: exit code */
-{
- ExitProcess((UINT)code);
-}
-
-/**************************************************************************
-Gets a process exit code. */
-
-ibool
-os_process_get_exit_code(
-/*=====================*/
- /* out: TRUE if succeed, FALSE if fail */
- os_process_t proc, /* in: handle to the process */
- ulint* code) /* out: exit code */
-{
- DWORD ex_code;
- BOOL ret;
-
- ret = GetExitCodeProcess(proc, &ex_code);
-
- *code = (ulint)ex_code;
-
- return(ret);
-}
-#endif /* notdedfined */
-
/********************************************************************
Sets the priority boost for threads released from waiting within the current
process. */
diff --git a/innobase/os/os0trash.c b/innobase/os/os0trash.c
deleted file mode 100644
index e896ac9f083..00000000000
--- a/innobase/os/os0trash.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Stores the old console mode when echo is turned off */
-ulint os_old_console_mode;
-
-/********************************************************************
-Turns off echo from console input. */
-
-void
-os_console_echo_off(void)
-/*=====================*/
-{
- GetConsoleMode(stdio, &os_old_console_mode);
- SetConsoleMode(stdio, ENABLE_PROCESSED_INPUT);
-}
-
-/********************************************************************
-Turns on echo in console input. */
-
-void
-os_console_echo_on(void)
-/*====================*/
-{
- SetConsoleMode(stdio, &os_old_console_mode);
-}
-
-/********************************************************************
-Reads a character from the console. */
-
-char
-os_read_console(void)
-/*=================*/
-{
- char input_char;
- ulint n_chars;
-
- n_chars = 0;
-
- while (n_chars == 0) {
- ReadConsole(stdio, &input_char, 1, &n_chars, NULL);
- }
-
- return(input_char);
-}
-
diff --git a/innobase/os/ts/makefile b/innobase/os/ts/makefile
deleted file mode 100644
index 0e145a14e7f..00000000000
--- a/innobase/os/ts/makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-doall: tsos tsosaux
-
-
-tsos: ..\os.lib tsos.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\os.lib tsos.c $(LFL)
-
-tsosaux: tsosaux.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\..\ut.lib ..\os.lib tsosaux.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/os/ts/tsos.c b/innobase/os/ts/tsos.c
deleted file mode 100644
index ecc10b86d2f..00000000000
--- a/innobase/os/ts/tsos.c
+++ /dev/null
@@ -1,793 +0,0 @@
-/************************************************************************
-The test module for the operating system interface
-
-(c) 1995 Innobase Oy
-
-Created 9/27/1995 Heikki Tuuri
-*************************************************************************/
-
-
-#include "../os0thread.h"
-#include "../os0shm.h"
-#include "../os0proc.h"
-#include "../os0sync.h"
-#include "../os0file.h"
-#include "ut0ut.h"
-#include "ut0mem.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-
-#define _WIN32_WINNT 0x0400
-#include "n:\program files\devstudio\vc\include\windows.h"
-#include "n:\program files\devstudio\vc\include\winbase.h"
-
-ulint last_thr = 1;
-
-byte global_buf[4000000];
-
-ulint* cache_buf;
-
-os_file_t file;
-os_file_t file2;
-
-os_event_t gl_ready;
-
-mutex_t ios_mutex;
-ulint ios;
-ulint rnd = 9837497;
-
-/********************************************************************
-Start function for threads in test1. */
-
-ulint
-thread(void* arg)
-/*==============*/
-{
- ulint i;
- void* arg2;
- ulint count = 0;
- ulint n;
- ulint rnd_loc;
- byte local_buf[2000];
-
- arg2 = arg;
-
- n = *((ulint*)arg);
-
-/* printf("Thread %lu started!\n", n); */
-
- for (i = 0; i < 8000; i++) {
-
- rnd_loc = rnd;
- rnd += 763482469;
-
- ut_memcpy(global_buf + (rnd_loc % 1500000) + 8200, local_buf,
- 2000);
- if (last_thr != n) {
- count++;
- last_thr = n;
- }
-
- if (i % 32 == 0) {
- os_thread_yield();
- }
- }
-
- printf("Thread %lu exits: %lu thread switches noticed\n", n, count);
-
- return(0);
-}
-
-/*********************************************************************
-Test of the speed of wait for multiple events. */
-
-void
-testa1(void)
-/*========*/
-{
- ulint i;
- os_event_t arr[64];
- ulint tm, oldtm;
-
- printf("-------------------------------------------------\n");
- printf("TEST A1. Speed of waits\n");
-
- for (i = 0; i < 64; i++) {
- arr[i] = os_event_create(NULL);
- ut_a(arr[i]);
- }
-
- os_event_set(arr[1]);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000; i++) {
- os_event_wait_multiple(4, arr);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu multiple waits %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000; i++) {
- os_event_wait(arr[1]);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for %lu single waits %lu millisecs\n",
- i, tm - oldtm);
-
-
- for (i = 0; i < 64; i++) {
- os_event_free(arr[i]);
- }
-}
-
-/*********************************************************************
-Test for threads. */
-
-void
-test1(void)
-/*=======*/
-{
- os_thread_t thr[64];
- os_thread_id_t id[64];
- ulint n[64];
- ulint tm, oldtm;
- ulint i, j;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 1. Test of thread switching through yield\n");
-
- printf("Main thread %lu starts!\n", os_thread_get_curr_id());
-
- for (j = 0; j < 2; j++) {
-
- oldtm = ut_clock();
-
- for (i = 0; i < 64; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(thread, n + i, id + i);
-/* printf("Thread %lu created, id %lu \n", i, id[i]); */
- }
-
- for (i = 0; i < 64; i++) {
- os_thread_wait(thr[i]);
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 64; i++) {
-
- thr[5] = os_thread_create(thread, n + 5, id + 5);
-
-/* printf("Thread created, id %lu \n", id[5]); */
-
- os_thread_wait(thr[5]);
- }
-
- tm = ut_clock();
- printf("Wall clock time for single thread test %lu milliseconds\n",
- tm - oldtm);
- }
-}
-
-/*********************************************************************
-Test for shared memory and process switching through yield. */
-
-void
-test2(void)
-/*=======*/
-{
- os_shm_t shm;
- ulint tm, oldtm;
- ulint* pr_no;
- ulint count;
- ulint i;
- bool ret;
- os_process_t proc;
- os_process_id_t proc_id;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 2. Test of process switching through yield\n");
-
- shm = os_shm_create(1000, "TSOS_SHM");
-
- pr_no = os_shm_map(shm);
-
- *pr_no = 1;
- count = 0;
-
- ret = os_process_create("tsosaux.exe", NULL, &proc, &proc_id);
-
- printf("Last error: %lu\n", os_thread_get_last_error());
-
- ut_a(ret);
-
- printf("Process 1 starts test!\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 500000; i++) {
- if (*pr_no != 1) {
- count++;
- *pr_no = 1;
- }
-
- os_thread_yield();
- }
-
- tm = ut_clock();
-
- printf("Process 1 finishes test: %lu process switches noticed\n",
- count);
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_shm_unmap(shm);
-
- os_shm_free(shm);
-}
-
-#ifdef notdefined
-
-/*********************************************************************
-Test for asynchronous file io. */
-
-void
-test3(void)
-/*=======*/
-{
- ulint i;
- ulint j;
- void* mess;
- bool ret;
- void* buf;
- ulint rnd;
- ulint addr[64];
- ulint serv[64];
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 3. Test of asynchronous file io\n");
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- rnd = ut_time();
-
- rnd = rnd * 3416133;
-
- printf("rnd seed %lu\n", rnd % 4900);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 32; i++) {
-
- ret = os_aio_read(file, buf, 8192 * (rnd % 4900), 0,
- 8192, (void*)i);
- ut_a(ret);
- rnd += 1;
- ret = os_aio_wait(0, &mess);
- ut_a(ret);
- }
-
- tm = ut_clock();
- printf("Wall clock time for synchr. io %lu milliseconds\n",
- tm - oldtm);
-
- rnd = rnd * 3416133;
-
- printf("rnd seed %lu\n", rnd % 5000);
-
- oldtm = ut_clock();
-
- for (j = 0; j < 5; j++) {
-
- rnd = rnd + 3416133;
-
- for (i = 0; i < 16; i++) {
- ret = os_aio_read(file, buf, 8192 * (rnd % 5000), 0, 8192,
- (void*)i);
- addr[i] = rnd % 5000;
- ut_a(ret);
- rnd += 1;
- }
-
-
- for (i = 0; i < 16; i++) {
- ret = os_aio_read(file, buf, 8192 * (rnd % 5000), 0, 8192,
- (void*)i);
- addr[i] = rnd % 5000;
- ut_a(ret);
- rnd += 1;
- }
-
- rnd = rnd + 3416133;
-
- for (i = 0; i < 32; i++) {
- ret = os_aio_wait(0, &mess);
- ut_a(ret);
- ut_a((ulint)mess < 64);
- serv[(ulint)mess] = i;
- }
- }
- tm = ut_clock();
- printf("Wall clock time for aio %lu milliseconds\n", tm - oldtm);
-
- rnd = rnd * 3416133;
-
- printf("rnd seed %lu\n", rnd % 4900);
-
- oldtm = ut_clock();
-
-for (j = 0; j < 5; j++) {
-
- rnd = rnd + 3416133;
-
- for (i = 0; i < 1; i++) {
- ret = os_aio_read(file, buf, 8192 * (rnd % 4900), 0,
- 64 * 8192, (void*)i);
- ut_a(ret);
- rnd += 4;
- ret = os_aio_wait(0, &mess);
- ut_a(ret);
- ut_a((ulint)mess < 64);
- }
-}
- tm = ut_clock();
- printf("Wall clock time for synchr. io %lu milliseconds\n",
- tm - oldtm);
-
-
-/*
- for (i = 0; i < 63; i++) {
- printf("read %lu addr %lu served as %lu\n",
- i, addr[i], serv[i]);
- }
-*/
-
- ut_a(ret);
-}
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = os_aio_wait(segment, &mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- ut_a(ret);
-/* printf("Message for thread %lu %lu\n", segment,
- (ulint)mess); */
- if ((ulint)mess == 3333) {
- os_event_set(gl_ready);
- }
- }
-
- return(0);
-}
-
-/************************************************************************
-Test of io-handler threads */
-
-void
-test4(void)
-/*=======*/
-{
- ulint i;
- ulint j;
- bool ret;
- void* buf;
- ulint rnd;
- ulint tm, oldtm;
- os_thread_t thr[5];
- os_thread_id_t id[5];
- ulint n[5];
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 4. Test of asynchronous file io\n");
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- gl_ready = os_event_create(NULL);
- ios = 0;
-
- sync_init();
- mem_init();
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-
- rnd = 0;
-
- oldtm = ut_clock();
-
-for (j = 0; j < 128; j++) {
-
-
- for (i = 0; i < 32; i++) {
- ret = os_aio_read(file, (byte*)buf + 8192 * (rnd % 100),
- 8192 * (rnd % 4096), 0,
- 8192, (void*)i);
- ut_a(ret);
- rnd += 1;
- }
-
-/*
- rnd += 67475941;
-
- for (i = 0; i < 1; i++) {
- ret = os_aio_read(file2, buf, 8192 * (rnd % 5000), 0,
- 8192, (void*)i);
- ut_a(ret);
- rnd += 1;
- }
-*/
-}
- ret = os_aio_read(file, buf, 8192 * (rnd % 4096), 0, 8192,
- (void*)3333);
- ut_a(ret);
-
- ut_a(!os_aio_all_slots_free());
-/*
- printf("Starting flush!\n");
- ret = os_file_flush(file);
- ut_a(ret);
- printf("Ending flush!\n");
-*/
- tm = ut_clock();
-
- printf("All ios queued! N ios: %lu\n", ios);
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_event_wait(gl_ready);
-
- tm = ut_clock();
- printf("N ios: %lu\n", ios);
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- os_thread_sleep(2000000);
-
- printf("N ios: %lu\n", ios);
-
- ut_a(os_aio_all_slots_free());
-}
-
-/*************************************************************************
-Initializes the asyncronous io system for tests. */
-
-void
-init_aio(void)
-/*==========*/
-{
- bool ret;
- ulint i;
- void* buf;
- void* mess;
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- os_aio_init(160, 5);
- file = os_file_create("j:\\tsfile2", OS_FILE_CREATE, OS_FILE_TABLESPACE,
- &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() == OS_FILE_ALREADY_EXISTS);
-
- file = os_file_create("j:\\tsfile2", OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- } else {
-
- for (i = 0; i < 4100; i++) {
- ret = os_aio_write(file, buf, 8192 * i, 0, 8192, NULL);
- ut_a(ret);
-
- ret = os_aio_wait(0, &mess);
-
- ut_a(ret);
- ut_a(mess == NULL);
- }
- }
-
- file2 = os_file_create("F:\\tmp\\tsfile", OS_FILE_CREATE,
- OS_FILE_TABLESPACE,
- &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() == OS_FILE_ALREADY_EXISTS);
-
- file2 = os_file_create("F:\\tmp\\tsfile", OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- } else {
-
- for (i = 0; i < 5000; i++) {
- ret = os_aio_write(file2, buf, 8192 * i, 0, 8192, NULL);
- ut_a(ret);
-
- ret = os_aio_wait(0, &mess);
-
- ut_a(ret);
- ut_a(mess == NULL);
- }
- }
-}
-
-/************************************************************************
-Test of synchronous io */
-
-void
-test5(void)
-/*=======*/
-{
- ulint i, j, k;
- bool ret;
- void* buf;
- ulint rnd = 0;
- ulint tm = 0;
- ulint oldtm = 0;
- os_file_t files[1000];
- char name[5];
- ulint err;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 5. Test of creating and opening of many files\n");
-
- /* Align the buffer for file io */
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- name[2] = '.';
- name[3] = 'd';
- name[4] = '\0';
-
- oldtm = ut_clock();
-
- for (j = 0; j < 20; j++) {
- for (i = 0; i < 20; i++) {
- name[0] = (char)(i + (ulint)'A');
- name[1] = (char)(j + (ulint)'A');
- files[j * 20 + i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_NORMAL, &ret);
- if (!ret) {
- err = os_file_get_last_error();
- }
- ut_a(ret);
- }
- }
-
- for (k = 0; k < i * j; k++) {
- ret = os_file_close(files[k]);
- ut_a(ret);
- }
-
- for (j = 0; j < 20; j++) {
- for (i = 0; i < 20; i++) {
- name[0] = (char)(i + (ulint)'A');
- name[1] = (char)(j + (ulint)'A');
- ret = os_file_delete(name);
- ut_a(ret);
- }
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-}
-
-/************************************************************************
-Test of synchronous io */
-
-void
-test6(void)
-/*=======*/
-{
- ulint i, j;
- bool ret;
- void* buf;
- ulint rnd = 0;
- ulint tm = 0;
- ulint oldtm = 0;
- os_file_t s_file;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 6. Test of synchronous io\n");
-
- buf = (void*)(((ulint)global_buf + 6300) & (~0xFFF));
-
- ret = os_file_close(file);
- ut_a(ret);
-
- ret = os_file_close(file2);
- ut_a(ret);
-
- s_file = os_file_create("tsfile", OS_FILE_OPEN,
- OS_FILE_NORMAL, &ret);
- if (!ret) {
- printf("Error no %lu\n", os_file_get_last_error());
- }
-
- ut_a(ret);
-
- rnd = ut_time() * 6346353;
-
- oldtm = ut_clock();
-
- for (j = 0; j < 100; j++) {
-
- rnd += 8072791;
-
- for (i = 0; i < 32; i++) {
- ret = os_file_read(s_file, buf, 8192 * (rnd % 5000), 0,
- 8192);
- ut_a(ret);
- rnd += 1;
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-}
-
-/************************************************************************
-Test of file size operations. */
-
-void
-test7(void)
-/*=======*/
-{
- bool ret;
- os_file_t f;
- ulint len;
- ulint high;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 7. Test of setting and getting file size\n");
-
-
- f = os_file_create("sizefile", OS_FILE_CREATE, OS_FILE_TABLESPACE,
- &ret);
- ut_a(ret);
-
- ret = os_file_get_size(f, &len, &high);
- ut_a(ret);
-
- ut_a(len == 0);
- ut_a(high == 0);
-
- ret = os_file_set_size(f, 5000000, 0);
- ut_a(ret);
-
- ret = os_file_get_size(f, &len, &high);
- ut_a(ret);
-
- ut_a(len == 5000000);
- ut_a(high == 0);
-
- ret = os_file_set_size(f, 4000000, 0);
- ut_a(ret);
-
- ret = os_file_get_size(f, &len, &high);
- ut_a(ret);
-
- ut_a(len == 4000000);
- ut_a(high == 0);
-
- ret = os_file_close(f);
- ut_a(ret);
-
- ret = os_file_delete("sizefile");
- ut_a(ret);
-}
-#endif
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- ulint i;
- CRITICAL_SECTION cs;
- ulint sum;
- ulint rnd;
-
- cache_buf = VirtualAlloc(NULL, 4 * 1024, MEM_COMMIT,
- PAGE_READWRITE /* | PAGE_NOCACHE */);
- oldtm = ut_clock();
-
- sum = 0;
- rnd = 0;
-
- for (i = 0; i < 1000000; i++) {
-
- sum += cache_buf[rnd * (16)];
-
- rnd += 1;
-
- if (rnd > 7) {
- rnd = 0;
- }
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for cache test %lu milliseconds\n", tm - oldtm);
-
- InterlockedExchange(&i, 5);
-
- InitializeCriticalSection(&cs);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000000; i++) {
-
- TryEnterCriticalSection(&cs);
-
- LeaveCriticalSection(&cs);
- }
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
- testa1();
-
- test1();
-
-/* test2(); */
-
-/* init_aio(); */
-/*
- test3();
-*/
-/* test4();
-
- test5();
-
- test6();
-
- test7(); */
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
-
diff --git a/innobase/os/ts/tsosaux.c b/innobase/os/ts/tsosaux.c
deleted file mode 100644
index 8f7780844e9..00000000000
--- a/innobase/os/ts/tsosaux.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/************************************************************************
-The test module for the operating system interface
-Auxiliary executable run alongside tsos.exe to test
-process switching speed
-
-(c) 1995 Innobase Oy
-
-Created 9/27/1995 Heikki Tuuri
-*************************************************************************/
-
-
-#include "../os0thread.h"
-#include "../os0shm.h"
-#include "../os0proc.h"
-#include "ut0ut.h"
-
-/*********************************************************************
-Test for shared memory and process switching through yield. */
-
-void
-test2(void)
-/*=======*/
-{
- os_shm_t shm;
- ulint tm, oldtm;
- ulint* pr_no;
- ulint count;
- ulint i;
-
- printf("-------------------------------------------\n");
- printf("OS-TEST 2. Test of process switching through yield\n");
-
-
- shm = os_shm_create(1000, "TSOS_SHM");
-
- pr_no = os_shm_map(shm);
-
- count = 0;
-
- printf("Process 2 starts test!\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000; i++) {
- if (*pr_no != 2) {
- count++;
- *pr_no = 2;
- }
- os_thread_yield();
- }
-
- tm = ut_clock();
-
- printf("Process 2 finishes test: %lu process switches noticed\n",
- count);
-
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
-
-
- os_shm_unmap(shm);
-
- os_shm_free(shm);
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- oldtm = ut_clock();
-
- test2();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-
- os_process_exit(0);
-}
diff --git a/innobase/page/page0cur.c b/innobase/page/page0cur.c
index 89dad4f268f..5d26d12bf20 100644
--- a/innobase/page/page0cur.c
+++ b/innobase/page/page0cur.c
@@ -16,11 +16,12 @@ Created 10/4/1994 Heikki Tuuri
#include "log0recv.h"
#include "rem0cmp.h"
-ulint page_cur_short_succ = 0;
-
-ulint page_rnd = 976722341;
+static ulint page_rnd = 976722341;
#ifdef PAGE_CUR_ADAPT
+# ifdef UNIV_SEARCH_PERF_STAT
+ulint page_cur_short_succ = 0;
+# endif /* UNIV_SEARCH_PERF_STAT */
/********************************************************************
Tries a search shortcut based on the last insert. */
@@ -716,7 +717,7 @@ page_cur_parse_insert_rec(
buf_page_print(page);
- ut_a(0);
+ ut_error;
}
ut_memcpy(buf, rec_get_start(cursor_rec), mismatch_index);
diff --git a/innobase/page/page0page.c b/innobase/page/page0page.c
index 9c9e1f4156c..c64a7590b94 100644
--- a/innobase/page/page0page.c
+++ b/innobase/page/page0page.c
@@ -19,9 +19,6 @@ Created 2/2/1994 Heikki Tuuri
#include "btr0sea.h"
#include "buf0buf.h"
-/* A cached template page used in page_create */
-page_t* page_template = NULL;
-
/* THE INDEX PAGE
==============
@@ -113,7 +110,7 @@ page_dir_find_owner_slot(
buf_page_print(page);
- ut_a(0);
+ ut_error;
}
i--;
@@ -321,20 +318,6 @@ page_create(
fil_page_set_type(page, FIL_PAGE_INDEX);
- /* If we have a page template, copy the page structure from there */
-
- if (page_template) {
- ut_memcpy(page + PAGE_HEADER,
- page_template + PAGE_HEADER, PAGE_HEADER_PRIV_END);
- ut_memcpy(page + PAGE_DATA,
- page_template + PAGE_DATA,
- PAGE_SUPREMUM_END - PAGE_DATA);
- ut_memcpy(page + UNIV_PAGE_SIZE - PAGE_EMPTY_DIR_START,
- page_template + UNIV_PAGE_SIZE - PAGE_EMPTY_DIR_START,
- PAGE_EMPTY_DIR_START - PAGE_DIR);
- return(frame);
- }
-
heap = mem_heap_create(200);
/* 3. CREATE THE INFIMUM AND SUPREMUM RECORDS */
@@ -409,17 +392,6 @@ page_create(
rec_set_next_offs(infimum_rec, (ulint)(supremum_rec - page));
rec_set_next_offs(supremum_rec, 0);
-#ifdef notdefined
- /* Disable the use of page_template: there is a race condition here:
- while one thread is creating page_template, another one can start
- using it before the memcpy completes! */
-
- if (page_template == NULL) {
- page_template = mem_alloc(UNIV_PAGE_SIZE);
-
- ut_memcpy(page_template, page, UNIV_PAGE_SIZE);
- }
-#endif
return(page);
}
@@ -469,7 +441,7 @@ page_copy_rec_list_end_no_locks(
(ulong)(rec - page),
(ulong)(page_cur_get_rec(&cur1) - page),
(ulong)(page_cur_get_rec(&cur2) - new_page));
- ut_a(0);
+ ut_error;
}
page_cur_move_to_next(&cur1);
diff --git a/innobase/page/ts/makefile b/innobase/page/ts/makefile
deleted file mode 100644
index cf96509ee73..00000000000
--- a/innobase/page/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tspage: ..\page.lib tspage.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\page.lib ..\..\btr.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tspage.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/page/ts/tspage.c b/innobase/page/ts/tspage.c
deleted file mode 100644
index 3b8869e5e14..00000000000
--- a/innobase/page/ts/tspage.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/************************************************************************
-The test for the index page
-
-(c) 1994-1996 Innobase Oy
-
-Created 1/31/1994 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "fil0fil.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "..\page0page.h"
-#include "..\page0cur.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 1
-#define N_FILES 2
-#define FILE_SIZE 1000 /* must be > 512 */
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "j:\\tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[9] = (char)((ulint)'0' + k);
- name[10] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test1(void)
-/*=======*/
-{
- page_t* page;
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint i;
- ulint rnd = 0;
- rec_t* rec;
- page_cur_t cursor;
- dict_index_t* index;
- dict_table_t* table;
- buf_block_t* block;
- buf_frame_t* frame;
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. Basic test\n");
-
- heap = mem_heap_create(0);
-
- table = dict_table_create("TS_TABLE1", 3);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL3", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE1", "IND1", 0, 3, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
- dict_index_add_field(index, "COL3", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE1", "IND1");
- ut_a(index);
-
- tuple = dtuple_create(heap, 3);
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 534671) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
-/* page_print_list(page, 151); */
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 7771) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_get_n_recs(page) == 0);
-
- ut_a(page_validate(page, index));
- page = page_create(frame, &mtr);
-
- rnd = 311;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 217;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
- page = page_create(frame, &mtr);
-
- rnd = 291;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 277;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- mem_heap_free(heap);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test2(void)
-/*=======*/
-{
- page_t* page;
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint i, j;
- ulint rnd = 0;
- rec_t* rec;
- page_cur_t cursor;
- dict_index_t* index;
- dict_table_t* table;
- buf_block_t* block;
- buf_frame_t* frame;
- ulint tm, oldtm;
- byte buf[8];
- mtr_t mtr;
- mtr_t mtr2;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. Speed test\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf, bigbuf + 800, 800);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- rnd = 0;
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf + rnd, bigbuf + rnd + 800, 800);
- rnd += 1600;
- if (rnd > 995000) {
- rnd = 0;
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- heap = mem_heap_create(0);
-
- table = dict_table_create("TS_TABLE2", 2);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE2", "IND2", 0, 2, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE2", "IND2");
- ut_a(index);
-
- tuple = dtuple_create(heap, 3);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, 5, &mtr);
- buf_page_s_lock(block, &mtr);
-
- page = buf_block_get_frame(block);
- ut_a(page_validate(page, index));
- mtr_commit(&mtr);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for %lu empty loops with page create %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
-
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- mtr_commit(&mtr);
-
- rnd = 100;
- for (j = 0; j < 200; j++) {
- mtr_start(&mtr2);
-
- block = buf_page_get(0, 5, &mtr2);
- buf_page_x_lock(block, &mtr2);
-
- page = buf_block_get_frame(block);
-
- rnd = (rnd + 1) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr2);
- ut_a(rec);
-
- mtr_commit(&mtr2);
- }
- }
-
- tm = ut_clock();
- printf(
- "Wall time for sequential insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, 5, &mtr);
- buf_page_s_lock(block, &mtr);
-
- page = buf_block_get_frame(block);
- ut_a(page_validate(page, index));
- mtr_commit(&mtr);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 500;
- for (j = 0; j < 200; j++) {
- rnd = (rnd - 1) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for descend. seq. insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
-
- rnd = 677;
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
- }
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insert and delete of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- ut_a(page_validate(page, index));
- mtr_print(&mtr);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 200; j++) {
-/* rnd = (rnd + 54841) % 1000;*/
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for search of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 5 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 200; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple3(tuple, rnd, buf);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu empty loops %lu milliseconds\n",
- i * j, tm - oldtm);
- mtr_commit(&mtr);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
- os_aio_init(160, 5);
- fil_init(25);
- buf_pool_init(100, 100);
- dict_init();
- log_init();
-
- create_files();
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1();
- test2();
-
- mem_print_info();
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/pars/lexyy.c b/innobase/pars/lexyy.c
index 7c6711d2f97..f014200b2a6 100644
--- a/innobase/pars/lexyy.c
+++ b/innobase/pars/lexyy.c
@@ -627,7 +627,7 @@ Linux.
#define malloc(A) mem_alloc(A)
#define free(A) mem_free(A)
#define realloc(P, A) mem_realloc(P, A, __FILE__, __LINE__)
-#define exit(A) ut_a(0)
+#define exit(A) ut_error
#define YY_INPUT(buf, result, max_size) pars_get_lex_chars(buf, &result, max_size)
#define comment 1
diff --git a/innobase/pars/pars0pars.c b/innobase/pars/pars0pars.c
index 3e43b6ae262..5bbfca831f2 100644
--- a/innobase/pars/pars0pars.c
+++ b/innobase/pars/pars0pars.c
@@ -29,13 +29,14 @@ on 1/27/1998 */
#include "trx0trx.h"
#include "trx0roll.h"
#include "lock0lock.h"
-#include "odbc0odbc.h"
#include "eval0eval.h"
+#ifdef UNIV_SQL_DEBUG
/* If the following is set TRUE, the lexer will print the SQL string
as it tokenizes it */
ibool pars_print_lexed = FALSE;
+#endif /* UNIV_SQL_DEBUG */
/* Global variable used while parsing a single procedure or query : the code is
NOT re-entrant */
@@ -389,7 +390,7 @@ pars_resolve_exp_variables_and_types(
}
if (!node) {
- printf("PARSER ERROR: Unresolved identifier %s\n",
+ fprintf(stderr, "PARSER ERROR: Unresolved identifier %s\n",
sym_node->name);
}
@@ -522,25 +523,6 @@ pars_resolve_exp_list_columns(
}
/*************************************************************************
-Retrieves the stored procedure definition for a procedure name. */
-static
-void
-pars_retrieve_procedure_def(
-/*========================*/
- sym_node_t* sym_node) /* in: procedure name node */
-{
- ut_a(sym_node);
- ut_a(que_node_get_type(sym_node) == QUE_NODE_SYMBOL);
-
- sym_node->resolved = TRUE;
- sym_node->token_type = SYM_PROCEDURE_NAME;
-
- sym_node->procedure_def = dict_procedure_get((char*)sym_node->name,
- NULL);
- ut_a(sym_node->procedure_def);
-}
-
-/*************************************************************************
Retrieves the table definition for a table name id. */
static
void
@@ -1662,219 +1644,22 @@ pars_procedure_definition(
/*****************************************************************
Parses a stored procedure call, when this is not within another stored
-procedure, that is, the client issues a procedure call directly. */
+procedure, that is, the client issues a procedure call directly.
+In MySQL/InnoDB, stored InnoDB procedures are invoked via the
+parsed procedure tree, not via InnoDB SQL, so this function is not used. */
que_fork_t*
pars_stored_procedure_call(
/*=======================*/
/* out: query graph */
- sym_node_t* sym_node) /* in: stored procedure name */
+ sym_node_t* sym_node __attribute__((unused)))
+ /* in: stored procedure name */
{
- call_node_t* node;
- que_fork_t* fork;
- que_thr_t* thr;
- mem_heap_t* heap;
-
- heap = pars_sym_tab_global->heap;
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_PROCEDURE_CALL, heap);
- fork->trx = NULL;
-
- thr = que_thr_create(fork, heap);
-
- node = mem_heap_alloc(heap, sizeof(call_node_t));
-
- thr->child = node;
-
- node->common.type = QUE_NODE_CALL;
- node->common.parent = thr;
-
- sym_node->token_type = SYM_PROCEDURE_NAME;
-
- pars_retrieve_procedure_def(sym_node);
-
- node->procedure_def = sym_node->procedure_def;
- node->proc_name = sym_node;
-
- node->sym_tab = pars_sym_tab_global;
-
- pars_sym_tab_global->query_graph = fork;
-
- return(fork);
-}
-
-/*****************************************************************
-Writes info about query parameter markers (denoted with '?' in ODBC) into a
-buffer. */
-
-ulint
-pars_write_query_param_info(
-/*========================*/
- /* out: number of bytes used for info in buf */
- byte* buf, /* in: buffer which must be big enough */
- que_fork_t* graph) /* in: parsed query graph */
-{
- que_thr_t* thr;
- call_node_t* call_node;
- dict_proc_t* procedure_def;
- que_t* stored_graph;
- proc_node_t* proc_node;
- sym_node_t* param;
- ulint n_params;
- ibool is_input;
-
- /* We currently support parameter markers only in stored procedure
- calls, and there ALL procedure parameters must be marked with '?':
- no literal values are allowed */
-
- thr = UT_LIST_GET_FIRST(graph->thrs);
-
- n_params = 0;
-
- if (que_node_get_type(thr->child) == QUE_NODE_CALL) {
- call_node = thr->child;
-
- procedure_def = call_node->procedure_def;
-
- stored_graph = dict_procedure_reserve_parsed_copy(
- procedure_def);
- proc_node = que_fork_get_child(stored_graph);
-
- param = proc_node->param_list;
-
- while (param) {
- if (param->param_type == PARS_INPUT) {
- is_input = TRUE;
- } else {
- is_input = FALSE;
- }
-
- mach_write_to_1(buf + 4 + n_params, is_input);
-
- n_params++;
-
- param = que_node_get_next(param);
- }
-
- dict_procedure_release_parsed_copy(stored_graph);
- }
-
- mach_write_to_4(buf, n_params);
-
- return(4 + n_params);
+ ut_error;
+ return(NULL);
}
/*****************************************************************
-Reads stored procedure input parameter values from a buffer. */
-
-void
-pars_proc_read_input_params_from_buf(
-/*=================================*/
- que_t* graph, /* in: query graph which contains a stored procedure */
- byte* buf) /* in: buffer */
-{
- que_thr_t* thr;
- proc_node_t* proc_node;
- sym_node_t* param;
- byte* ptr;
- ulint len;
- lint odbc_len;
-
- ut_ad(graph->fork_type == QUE_FORK_PROCEDURE);
-
- thr = UT_LIST_GET_FIRST(graph->thrs);
-
- proc_node = thr->child;
-
- ptr = buf;
-
- param = proc_node->param_list;
-
- while (param) {
- if (param->param_type == PARS_INPUT) {
- odbc_len = (lint)mach_read_from_4(ptr);
-
- ptr += 4;
-
- if (odbc_len == SQL_NULL_DATA) {
- len = UNIV_SQL_NULL;
- } else {
- len = (ulint)odbc_len;
- }
-
- eval_node_copy_and_alloc_val(param, ptr, len);
-
- if (len != UNIV_SQL_NULL) {
- ptr += len;
- }
- }
-
- param = que_node_get_next(param);
- }
-
- ut_ad(ptr - buf < ODBC_DATAGRAM_SIZE);
-}
-
-/*****************************************************************
-Writes stored procedure output parameter values to a buffer. */
-
-ulint
-pars_proc_write_output_params_to_buf(
-/*=================================*/
- /* out: bytes used in buf */
- byte* buf, /* in: buffer which must be big enough */
- que_t* graph) /* in: query graph which contains a stored procedure */
-{
- que_thr_t* thr;
- proc_node_t* proc_node;
- sym_node_t* param;
- dfield_t* dfield;
- byte* ptr;
- ulint len;
- lint odbc_len;
-
- ut_ad(graph->fork_type == QUE_FORK_PROCEDURE);
-
- thr = UT_LIST_GET_FIRST(graph->thrs);
-
- proc_node = thr->child;
-
- ptr = buf;
-
- param = proc_node->param_list;
-
- while (param) {
- if (param->param_type == PARS_OUTPUT) {
- dfield = que_node_get_val(param);
-
- len = dfield_get_len(dfield);
-
- if (len == UNIV_SQL_NULL) {
- odbc_len = SQL_NULL_DATA;
- } else {
- odbc_len = (lint)len;
- }
-
- mach_write_to_4(ptr, (ulint)odbc_len);
-
- ptr += 4;
-
- if (len != UNIV_SQL_NULL) {
- ut_memcpy(ptr, dfield_get_data(dfield), len);
-
- ptr += len;
- }
- }
-
- param = que_node_get_next(param);
- }
-
- ut_ad(ptr - buf < ODBC_DATAGRAM_SIZE);
-
- return((ulint)(ptr - buf));
-}
-
-/*****************************************************************
Retrieves characters to the lexical analyzer. */
void
@@ -1886,13 +1671,12 @@ pars_get_lex_chars(
in the buffer */
{
int len;
- char print_buf[16];
len = pars_sym_tab_global->string_len
- pars_sym_tab_global->next_char_pos;
if (len == 0) {
#ifdef YYDEBUG
- /* printf("SQL string ends\n"); */
+ /* fputs("SQL string ends\n", stderr); */
#endif
*result = 0;
@@ -1903,18 +1687,18 @@ pars_get_lex_chars(
len = max_size;
}
+#ifdef UNIV_SQL_DEBUG
if (pars_print_lexed) {
if (len >= 5) {
len = 5;
}
-
- ut_memcpy(print_buf, pars_sym_tab_global->sql_string +
- pars_sym_tab_global->next_char_pos, len);
- print_buf[len] = '\0';
-
- printf("%s", print_buf);
+
+ fwrite(pars_sym_tab_global->sql_string +
+ pars_sym_tab_global->next_char_pos,
+ 1, len, stderr);
}
+#endif /* UNIV_SQL_DEBUG */
ut_memcpy(buf, pars_sym_tab_global->sql_string +
pars_sym_tab_global->next_char_pos, len);
@@ -1944,7 +1728,7 @@ yyerror(
{
ut_ad(s);
- printf("PARSER ERROR: Syntax error in SQL string\n");
+ fputs("PARSER ERROR: Syntax error in SQL string\n", stderr);
ut_error;
}
@@ -1968,10 +1752,10 @@ pars_sql(
heap = mem_heap_create(256);
+#ifdef UNIV_SYNC_DEBUG
/* Currently, the parser is not reentrant: */
-
ut_ad(mutex_own(&(dict_sys->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
pars_sym_tab_global = sym_tab_create(heap);
len = ut_strlen(str);
@@ -1996,7 +1780,7 @@ pars_sql(
graph->sym_tab = pars_sym_tab_global;
- /* printf("SQL graph size %lu\n", mem_heap_get_size(heap)); */
+ /* fprintf(stderr, "SQL graph size %lu\n", mem_heap_get_size(heap)); */
return(graph);
}
diff --git a/innobase/que/que0que.c b/innobase/que/que0que.c
index 7e4babd43ef..b2608b6d175 100644
--- a/innobase/que/que0que.c
+++ b/innobase/que/que0que.c
@@ -7,7 +7,7 @@ Created 5/27/1996 Heikki Tuuri
*******************************************************/
#include "que0que.h"
-
+
#ifdef UNIV_NONINL
#include "que0que.ic"
#endif
@@ -25,7 +25,6 @@ Created 5/27/1996 Heikki Tuuri
#include "log0log.h"
#include "eval0proc.h"
#include "eval0eval.h"
-#include "odbc0odbc.h"
#define QUE_PARALLELIZE_LIMIT (64 * 256 * 256 * 256)
#define QUE_ROUND_ROBIN_LIMIT (64 * 256 * 256 * 256)
@@ -73,37 +72,6 @@ void
que_thr_move_to_run_state(
/*======================*/
que_thr_t* thr); /* in: an query thread */
-/**************************************************************************
-Tries to parallelize query if it is not parallel enough yet. */
-static
-que_thr_t*
-que_try_parallelize(
-/*================*/
- /* out: next thread to execute */
- que_thr_t* thr); /* in: query thread */
-
-#ifdef notdefined
-/********************************************************************
-Adds info about the number of inserted rows etc. to the message to the
-client. */
-static
-void
-que_thr_add_update_info(
-/*====================*/
- que_thr_t* thr) /* in: query thread */
-{
- que_fork_t* graph;
-
- graph = thr->graph;
-
- mach_write_to_8(thr->msg_buf + SESS_SRV_MSG_N_INSERTS,
- graph->n_inserts);
- mach_write_to_8(thr->msg_buf + SESS_SRV_MSG_N_UPDATES,
- graph->n_updates);
- mach_write_to_8(thr->msg_buf + SESS_SRV_MSG_N_DELETES,
- graph->n_deletes);
-}
-#endif
/***************************************************************************
Adds a query graph to the session's list of graphs. */
@@ -114,7 +82,9 @@ que_graph_publish(
que_t* graph, /* in: graph */
sess_t* sess) /* in: session */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
UT_LIST_ADD_LAST(graphs, sess->graphs, graph);
}
@@ -221,7 +191,9 @@ que_thr_end_wait(
{
ibool was_active;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(thr);
ut_ad((thr->state == QUE_THR_LOCK_WAIT)
|| (thr->state == QUE_THR_PROCEDURE_WAIT)
@@ -260,7 +232,9 @@ que_thr_end_wait_no_next_thr(
ut_a(thr->state == QUE_THR_LOCK_WAIT); /* In MySQL this is the
only possible state here */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(thr);
ut_ad((thr->state == QUE_THR_LOCK_WAIT)
|| (thr->state == QUE_THR_PROCEDURE_WAIT)
@@ -310,15 +284,9 @@ que_fork_start_command(
QUE_THR_RUNNING state, or NULL; the query
thread should be executed by que_run_threads
by the caller */
- que_fork_t* fork, /* in: a query fork */
- ulint command,/* in: command SESS_COMM_FETCH_NEXT, ... */
- ulint param) /* in: possible parameter to the command */
+ que_fork_t* fork) /* in: a query fork */
{
que_thr_t* thr;
-
- /* Set the command parameters in the fork root */
- fork->command = command;
- fork->param = param;
fork->state = QUE_FORK_ACTIVE;
@@ -401,7 +369,9 @@ que_fork_error_handle(
{
que_thr_t* thr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->sess->state == SESS_ERROR);
ut_ad(UT_LIST_GET_LEN(trx->reply_signals) == 0);
ut_ad(UT_LIST_GET_LEN(trx->wait_thrs) == 0);
@@ -515,7 +485,7 @@ que_graph_free_recursive(
"que_thr struct appears corrupt; magic n %lu\n",
(unsigned long) thr->magic_n);
mem_analyze_corruption((byte*)thr);
- ut_a(0);
+ ut_error;
}
thr->magic_n = QUE_THR_MAGIC_FREED;
@@ -627,7 +597,7 @@ que_graph_free_recursive(
"que_node struct appears corrupt; type %lu\n",
(unsigned long) que_node_get_type(node));
mem_analyze_corruption((byte*)node);
- ut_a(0);
+ ut_error;
}
}
@@ -671,7 +641,9 @@ que_graph_try_free(
{
sess_t* sess;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
sess = (graph->trx)->sess;
@@ -696,65 +668,20 @@ does nothing! */
void
que_thr_handle_error(
/*=================*/
- que_thr_t* thr, /* in: query thread */
- ulint err_no, /* in: error number */
- byte* err_str,/* in, own: error string or NULL; NOTE: the
+ que_thr_t* thr __attribute__((unused)),
+ /* in: query thread */
+ ulint err_no __attribute__((unused)),
+ /* in: error number */
+ byte* err_str __attribute__((unused)),
+ /* in, own: error string or NULL; NOTE: the
function will take care of freeing of the
string! */
- ulint err_len)/* in: error string length */
+ ulint err_len __attribute__((unused)))
+ /* in: error string length */
{
- UT_NOT_USED(thr);
- UT_NOT_USED(err_no);
- UT_NOT_USED(err_str);
- UT_NOT_USED(err_len);
-
/* Does nothing */
}
-/**************************************************************************
-Tries to parallelize query if it is not parallel enough yet. */
-static
-que_thr_t*
-que_try_parallelize(
-/*================*/
- /* out: next thread to execute */
- que_thr_t* thr) /* in: query thread */
-{
- ut_ad(thr);
-
- /* Does nothing yet */
-
- return(thr);
-}
-
-/********************************************************************
-Builds a command completed-message to the client. */
-static
-ulint
-que_build_srv_msg(
-/*==============*/
- /* out: message data length */
- byte* buf, /* in: message buffer */
- que_fork_t* fork, /* in: query graph where execution completed */
- sess_t* sess) /* in: session */
-{
- ulint len;
-
- /* Currently, we only support stored procedures: */
- ut_ad(fork->fork_type == QUE_FORK_PROCEDURE);
-
- if (sess->state == SESS_ERROR) {
-
- return(0);
- }
-
- sess_srv_msg_init(sess, buf, SESS_SRV_SUCCESS);
-
- len = pars_proc_write_output_params_to_buf(buf + SESS_SRV_MSG_DATA,
- fork);
- return(len);
-}
-
/********************************************************************
Performs an execution step on a thr node. */
static
@@ -851,10 +778,6 @@ que_thr_dec_refer_count(
que_fork_t* fork;
trx_t* trx;
sess_t* sess;
- ibool send_srv_msg = FALSE;
- ibool release_stored_proc = FALSE;
- ulint msg_len = 0;
- byte msg_buf[ODBC_DATAGRAM_SIZE];
ulint fork_type;
ibool stopped;
@@ -875,8 +798,8 @@ que_thr_dec_refer_count(
already canceled before we came here: continue
running the thread */
- /* printf(
- "!!!!!!!!!! Wait already ended: continue thr\n"); */
+ /* fputs("!!!!!!!! Wait already ended: continue thr\n",
+ stderr); */
if (next_thr && *next_thr == NULL) {
*next_thr = thr;
@@ -929,40 +852,13 @@ que_thr_dec_refer_count(
} else if (fork_type == QUE_FORK_MYSQL_INTERFACE) {
/* Do nothing */
- } else if (fork->common.parent == NULL
- && fork->caller == NULL
- && UT_LIST_GET_LEN(trx->signals) == 0) {
-
- ut_a(0); /* not used in MySQL */
-
- /* Reply to the client */
-
- /* que_thr_add_update_info(thr); */
-
- fork->state = QUE_FORK_COMMAND_WAIT;
-
- msg_len = que_build_srv_msg(msg_buf, fork, sess);
-
- send_srv_msg = TRUE;
-
- if (fork->fork_type == QUE_FORK_PROCEDURE) {
-
- release_stored_proc = TRUE;
- }
-
- ut_ad(trx->graph == fork);
-
- trx->graph = NULL;
} else {
- /* Subprocedure calls not implemented yet */
- ut_a(0);
+ ut_error; /* not used in MySQL */
}
}
if (UT_LIST_GET_LEN(trx->signals) > 0 && trx->n_active_thrs == 0) {
- ut_ad(!send_srv_msg);
-
/* If the trx is signaled and its query thread count drops to
zero, then we start processing a signal; from it we may get
a new query thread to run */
@@ -976,26 +872,6 @@ que_thr_dec_refer_count(
}
mutex_exit(&kernel_mutex);
-
- if (send_srv_msg) {
- /* Note that, as we do not own the kernel mutex at this point,
- and neither do we own it all the time when doing the actual
- communication operation within the next function, it is
- possible that the messages will not get delivered in the right
- sequential order. This is possible if the client communicates
- an extra message to the server while the message below is still
- undelivered. But then the client should notice that there
- is an error in the order numbers of the messages. */
-
- sess_command_completed_message(sess, msg_buf, msg_len);
- }
-
- if (release_stored_proc) {
-
- /* Return the stored procedure graph to the dictionary cache */
-
- dict_procedure_release_parsed_copy(fork);
- }
}
/**************************************************************************
@@ -1013,7 +889,9 @@ que_thr_stop(
que_t* graph;
ibool ret = TRUE;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
graph = thr->graph;
trx = graph->trx;
@@ -1110,7 +988,7 @@ que_thr_move_to_run_state_for_mysql(
mem_analyze_corruption((byte*)thr);
- ut_a(0);
+ ut_error;
}
if (!thr->is_active) {
@@ -1147,7 +1025,7 @@ que_thr_stop_for_mysql_no_error(
mem_analyze_corruption((byte*)thr);
- ut_a(0);
+ ut_error;
}
thr->state = QUE_THR_COMPLETED;
@@ -1158,69 +1036,67 @@ que_thr_stop_for_mysql_no_error(
trx->n_active_thrs--;
}
+#ifdef UNIV_DEBUG
/**************************************************************************
Prints info of an SQL query graph node. */
-
+static
void
que_node_print_info(
/*================*/
que_node_t* node) /* in: query graph node */
{
- ulint type;
- char* str;
- ulint addr;
+ ulint type;
+ const char* str;
type = que_node_get_type(node);
- addr = (ulint)node;
-
if (type == QUE_NODE_SELECT) {
- str = (char *) "SELECT";
+ str = "SELECT";
} else if (type == QUE_NODE_INSERT) {
- str = (char *) "INSERT";
+ str = "INSERT";
} else if (type == QUE_NODE_UPDATE) {
- str = (char *) "UPDATE";
+ str = "UPDATE";
} else if (type == QUE_NODE_WHILE) {
- str = (char *) "WHILE";
+ str = "WHILE";
} else if (type == QUE_NODE_ASSIGNMENT) {
- str = (char *) "ASSIGNMENT";
+ str = "ASSIGNMENT";
} else if (type == QUE_NODE_IF) {
- str = (char *) "IF";
+ str = "IF";
} else if (type == QUE_NODE_FETCH) {
- str = (char *) "FETCH";
+ str = "FETCH";
} else if (type == QUE_NODE_OPEN) {
- str = (char *) "OPEN";
+ str = "OPEN";
} else if (type == QUE_NODE_PROC) {
- str = (char *) "STORED PROCEDURE";
+ str = "STORED PROCEDURE";
} else if (type == QUE_NODE_FUNC) {
- str = (char *) "FUNCTION";
+ str = "FUNCTION";
} else if (type == QUE_NODE_LOCK) {
- str = (char *) "LOCK";
+ str = "LOCK";
} else if (type == QUE_NODE_THR) {
- str = (char *) "QUERY THREAD";
+ str = "QUERY THREAD";
} else if (type == QUE_NODE_COMMIT) {
- str = (char *) "COMMIT";
+ str = "COMMIT";
} else if (type == QUE_NODE_UNDO) {
- str = (char *) "UNDO ROW";
+ str = "UNDO ROW";
} else if (type == QUE_NODE_PURGE) {
- str = (char *) "PURGE ROW";
+ str = "PURGE ROW";
} else if (type == QUE_NODE_ROLLBACK) {
- str = (char *) "ROLLBACK";
+ str = "ROLLBACK";
} else if (type == QUE_NODE_CREATE_TABLE) {
- str = (char *) "CREATE TABLE";
+ str = "CREATE TABLE";
} else if (type == QUE_NODE_CREATE_INDEX) {
- str = (char *) "CREATE INDEX";
+ str = "CREATE INDEX";
} else if (type == QUE_NODE_FOR) {
- str = (char *) "FOR LOOP";
+ str = "FOR LOOP";
} else if (type == QUE_NODE_RETURN) {
- str = (char *) "RETURN";
+ str = "RETURN";
} else {
- str = (char *) "UNKNOWN NODE TYPE";
+ str = "UNKNOWN NODE TYPE";
}
- printf("Node type %lu: %s, address %lx\n", (unsigned long) type, str,
- (unsigned long) addr);
+ fprintf(stderr, "Node type %lu: %s, address %p\n", (ulong) type, str, node);
}
+#endif /* UNIV_DEBUG */
/**************************************************************************
Performs an execution step on a query thread. */
@@ -1249,7 +1125,7 @@ que_thr_step(
#ifdef UNIV_DEBUG
if (que_trace_on) {
- printf("To execute: ");
+ fputs("To execute: ", stderr);
que_node_print_info(node);
}
#endif
@@ -1331,85 +1207,6 @@ que_thr_step(
return(thr);
}
-/***********************************************************************
-Checks if there is a need for a query thread switch or stopping the current
-thread. */
-
-que_thr_t*
-que_thr_check_if_switch(
-/*====================*/
- que_thr_t* thr, /* in: current query thread */
- ulint* cumul_resource) /* in: amount of resources used
- by the current call of que_run_threads
- (resources used by the OS thread!) */
-{
- que_thr_t* next_thr;
- ibool stopped;
-
- if (que_thr_peek_stop(thr)) {
-
- mutex_enter(&kernel_mutex);
-
- stopped = que_thr_stop(thr);
-
- mutex_exit(&kernel_mutex);
-
- if (stopped) {
- /* If a signal is processed, we may get a new query
- thread next_thr to run */
-
- next_thr = NULL;
-
- que_thr_dec_refer_count(thr, &next_thr);
-
- if (next_thr == NULL) {
-
- return(NULL);
- }
-
- thr = next_thr;
- }
- }
-
- if (thr->resource > QUE_PARALLELIZE_LIMIT) {
-
- /* Try parallelization of the query thread */
- thr = que_try_parallelize(thr);
-
- thr->resource = 0;
- }
-
- (*cumul_resource)++;
-
- if (*cumul_resource > QUE_ROUND_ROBIN_LIMIT) {
-
- /* It is time to round-robin query threads in the
- server task queue */
-
- if (srv_get_thread_type() == SRV_COM) {
- /* This OS thread is a SRV_COM thread: we put
- the query thread to the task queue and return
- to allow the OS thread to receive more
- messages from clients */
-
- ut_ad(thr->is_active);
-
- srv_que_task_enqueue(thr);
-
- return(NULL);
- } else {
- /* Change the query thread if there is another
- in the server task queue */
-
- thr = srv_que_round_robin(thr);
- }
-
- *cumul_resource = 0;
- }
-
- return(thr);
-}
-
/**************************************************************************
Runs query threads. Note that the individual query thread which is run
within this function may change if, e.g., the OS thread executing this
@@ -1425,7 +1222,9 @@ que_run_threads(
ulint loop_count;
ut_ad(thr->state == QUE_THR_RUNNING);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* cumul_resource counts how much resources the OS thread (NOT the
query thread) has spent in this function */
@@ -1433,27 +1232,6 @@ que_run_threads(
loop_count = QUE_MAX_LOOPS_WITHOUT_CHECK;
cumul_resource = 0;
loop:
- if (loop_count >= QUE_MAX_LOOPS_WITHOUT_CHECK) {
-
-/* In MySQL this thread switch is never needed!
-
- loop_count = 0;
-
- next_thr = que_thr_check_if_switch(thr, &cumul_resource);
-
- if (next_thr != thr) {
- if (next_thr == NULL) {
-
- return;
- }
-
- loop_count = QUE_MAX_LOOPS_WITHOUT_CHECK;
- }
-
- thr = next_thr;
-*/
- }
-
/* Check that there is enough space in the log to accommodate
possible log entries by this query step; if the operation can touch
more than about 4 pages, checks must be made also within the query
diff --git a/innobase/read/read0read.c b/innobase/read/read0read.c
index 4a8aaee39ca..889612deef4 100644
--- a/innobase/read/read0read.c
+++ b/innobase/read/read0read.c
@@ -54,9 +54,10 @@ read_view_oldest_copy_or_open_new(
ulint insert_done = 0;
ulint n;
ulint i;
-
- ut_ad(mutex_own(&kernel_mutex));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
old_view = UT_LIST_GET_LAST(trx_sys->view_list);
if (old_view == NULL) {
@@ -132,9 +133,9 @@ read_view_open_now(
read_view_t* view;
trx_t* trx;
ulint n;
-
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-
+#endif /* UNIV_SYNC_DEBUG */
view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap);
view->creator = cr_trx;
@@ -195,8 +196,9 @@ read_view_close(
/*============*/
read_view_t* view) /* in: read view */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-
+#endif /* UNIV_SYNC_DEBUG */
UT_LIST_REMOVE(view_list, trx_sys->view_list, view);
}
diff --git a/innobase/rem/rem0cmp.c b/innobase/rem/rem0cmp.c
index abfba3a31c9..254ebeec8c9 100644
--- a/innobase/rem/rem0cmp.c
+++ b/innobase/rem/rem0cmp.c
@@ -58,13 +58,14 @@ cmp_debug_dtuple_rec_with_match(
This function is used to compare two data fields for which the data type
is such that we must use MySQL code to compare them. The prototype here
must be a copy of the the one in ha_innobase.cc! */
-
+extern
int
innobase_mysql_cmp(
-/*===============*/
+/*===============*/
/* out: 1, 0, -1, if a is greater,
equal, less than b, respectively */
- int mysql_type, /* in: MySQL type */
+ int mysql_type, /* in: MySQL type */
+ uint charset_number, /* in: number of the charset */
unsigned char* a, /* in: data field */
unsigned int a_length, /* in: data field length,
not UNIV_SQL_NULL */
@@ -97,16 +98,28 @@ cmp_types_are_equal(
dtype_t* type1, /* in: type 1 */
dtype_t* type2) /* in: type 2 */
{
- if ((type1->mtype == DATA_VARCHAR && type2->mtype == DATA_CHAR)
- || (type1->mtype == DATA_CHAR && type2->mtype == DATA_VARCHAR)
- || (type1->mtype == DATA_FIXBINARY && type2->mtype == DATA_BINARY)
- || (type1->mtype == DATA_BINARY && type2->mtype == DATA_FIXBINARY)
- || (type1->mtype == DATA_MYSQL && type2->mtype == DATA_VARMYSQL)
- || (type1->mtype == DATA_VARMYSQL && type2->mtype == DATA_MYSQL)) {
-
- return(TRUE);
+ if (dtype_is_non_binary_string_type(type1->mtype, type1->prtype)
+ && dtype_is_non_binary_string_type(type2->mtype, type2->prtype)) {
+
+ /* Both are non-binary string types: they can be compared if
+ and only if the charset-collation is the same */
+
+ if (dtype_get_charset_coll(type1->prtype)
+ == dtype_get_charset_coll(type2->prtype)) {
+ return(TRUE);
+ }
+
+ return(FALSE);
}
+ if (dtype_is_binary_string_type(type1->mtype, type1->prtype)
+ && dtype_is_binary_string_type(type2->mtype, type2->prtype)) {
+
+ /* Both are binary string types: they can be compared */
+
+ return(TRUE);
+ }
+
if (type1->mtype != type2->mtype) {
return(FALSE);
@@ -128,11 +141,6 @@ cmp_types_are_equal(
return(FALSE);
}
- if (type1->mtype == DATA_BLOB && (type1->prtype & DATA_BINARY_TYPE)
- != (type2->prtype & DATA_BINARY_TYPE)) {
- return(FALSE);
- }
-
return(TRUE);
}
@@ -269,12 +277,13 @@ cmp_whole_field(
return(innobase_mysql_cmp(
(int)(type->prtype & DATA_MYSQL_TYPE_MASK),
+ (uint)dtype_get_charset_coll(type->prtype),
a, a_length, b, b_length));
default:
fprintf(stderr,
"InnoDB: unknown type number %lu\n",
(ulong) data_type);
- ut_a(0);
+ ut_error;
}
return(0);
@@ -322,7 +331,9 @@ cmp_data_data_slow(
if (cur_type->mtype >= DATA_FLOAT
|| (cur_type->mtype == DATA_BLOB
- && (cur_type->prtype & DATA_NONLATIN1))) {
+ && 0 == (cur_type->prtype & DATA_BINARY_TYPE)
+ && dtype_get_charset_coll(cur_type->prtype) !=
+ data_mysql_latin1_swedish_charset_coll)) {
return(cmp_whole_field(cur_type, data1, len1, data2, len2));
}
@@ -523,8 +534,10 @@ cmp_dtuple_rec_with_match(
}
if (cur_type->mtype >= DATA_FLOAT
- || (cur_type->mtype == DATA_BLOB
- && (cur_type->prtype & DATA_NONLATIN1))) {
+ || (cur_type->mtype == DATA_BLOB
+ && 0 == (cur_type->prtype & DATA_BINARY_TYPE)
+ && dtype_get_charset_coll(cur_type->prtype) !=
+ data_mysql_latin1_swedish_charset_coll)) {
ret = cmp_whole_field(cur_type,
dfield_get_data(dtuple_field), dtuple_f_len,
@@ -845,8 +858,10 @@ cmp_rec_rec_with_match(
}
if (cur_type->mtype >= DATA_FLOAT
- || (cur_type->mtype == DATA_BLOB
- && (cur_type->prtype & DATA_NONLATIN1))) {
+ || (cur_type->mtype == DATA_BLOB
+ && 0 == (cur_type->prtype & DATA_BINARY_TYPE)
+ && dtype_get_charset_coll(cur_type->prtype) !=
+ data_mysql_latin1_swedish_charset_coll)) {
ret = cmp_whole_field(cur_type,
rec1_b_ptr, rec1_f_len,
diff --git a/innobase/rem/rem0rec.c b/innobase/rem/rem0rec.c
index 5a3996c9dce..3d0b997db85 100644
--- a/innobase/rem/rem0rec.c
+++ b/innobase/rem/rem0rec.c
@@ -108,12 +108,12 @@ rec_get_nth_field(
if (n > 1024) {
fprintf(stderr, "Error: trying to access field %lu in rec\n",
(ulong) n);
- ut_a(0);
+ ut_error;
}
if (rec == NULL) {
fprintf(stderr, "Error: rec is NULL pointer\n");
- ut_a(0);
+ ut_error;
}
if (rec_get_1byte_offs_flag(rec)) {
diff --git a/innobase/rem/ts/makefile b/innobase/rem/ts/makefile
deleted file mode 100644
index c429afa273e..00000000000
--- a/innobase/rem/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsrem: ..\rem.lib tsrem.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\rem.lib ..\..\page.lib ..\..\mtr.lib ..\..\btr.lib ..\..\log.lib ..\..\dyn.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsrem.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/rem/ts/tsrem.c b/innobase/rem/ts/tsrem.c
deleted file mode 100644
index 4f2bdde0068..00000000000
--- a/innobase/rem/ts/tsrem.c
+++ /dev/null
@@ -1,464 +0,0 @@
-/************************************************************************
-The test for the record manager
-
-(c) 1994-1996 Innobase Oy
-
-Created 1/25/1994 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "fil0fil.h"
-#include "../rem0rec.h"
-#include "../rem0cmp.h"
-
-byte buf1[100000];
-
-/*********************************************************************
-Test for data tuples. */
-
-void
-test1(void)
-/*=======*/
-{
- dtype_t* type;
- dtuple_t* tuple, *tuple2;
- dfield_t* field;
- mem_heap_t* heap;
- ulint i, j;
- ulint n;
- char* p_Pascal;
- char* p_Cobol;
-
- heap = mem_heap_create(0);
-
- printf("-------------------------------------------\n");
- printf("DATA TUPLE-TEST 1. Basic tests.\n");
-
- tuple = dtuple_create(heap, 2);
-
- field = dtuple_get_nth_field(tuple, 0);
- dfield_set_data(field, "Pascal", 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
- dfield_set_data(field, "Cobol", 6);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 6, 0);
-
- dtuple_validate(tuple);
- dtuple_print(tuple);
-
- tuple2 = dtuple_create(heap, 10);
-
- for (i = 0; i < 10; i++) {
- field = dtuple_get_nth_field(tuple2, i);
- dfield_set_data(field, NULL, UNIV_SQL_NULL);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH,
- 6, 0);
- }
-
- dtuple_print(tuple2);
-
- printf("-------------------------------------------\n");
- printf("DATA TUPLE-TEST 2. Accessor function tests.\n");
-
- tuple = dtuple_create(heap, 2);
-
- p_Pascal = "Pascal";
- p_Cobol = "Cobol";
-
- field = dtuple_get_nth_field(tuple, 0);
- dfield_set_data(field, p_Pascal, 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
- dfield_set_data(field, p_Cobol, 6);
- dtype_set(dfield_get_type(field), DATA_VARCHAR, DATA_ENGLISH, 16, 3);
-
- ut_a(dtuple_get_n_fields(tuple) == 2);
-
- field = dtuple_get_nth_field(tuple, 0);
- ut_a(p_Pascal == dfield_get_data(field));
- ut_a(7 == dfield_get_len(field));
- type = dfield_get_type(field);
- ut_a(type->mtype == DATA_CHAR);
- ut_a(type->prtype == DATA_ENGLISH);
- ut_a(type->len == 7);
- ut_a(type->prec == 0);
-
- field = dtuple_get_nth_field(tuple, 1);
- ut_a(p_Cobol == dfield_get_data(field));
- ut_a(6 == dfield_get_len(field));
- type = dfield_get_type(field);
- ut_a(type->mtype == DATA_VARCHAR);
- ut_a(type->prtype == DATA_ENGLISH);
- ut_a(type->len == 16);
- ut_a(type->prec == 3);
-
- printf("-------------------------------------------\n");
- printf("DATA TYPE-TEST 3. Other function tests\n");
-
- ut_a(dtuple_get_data_size(tuple) == 13);
-
- ut_a(dtuple_fold(tuple, 2) == dtuple_fold(tuple, 2));
- ut_a(dtuple_fold(tuple, 1) != dtuple_fold(tuple, 2));
-
- printf("-------------------------------------------\n");
- printf("DATA TUPLE-TEST 4. Random tuple generation test\n");
-
- for (i = 0; i < 500; i++) {
- tuple = dtuple_gen_rnd_tuple(heap);
- printf("%lu ", i);
-
- dtuple_validate(tuple);
- n = dtuple_get_n_fields(tuple);
-
- if (n < 25) {
- tuple2 = dtuple_create(heap, n);
- for (j = 0; j < n; j++) {
- dfield_copy(
- dtuple_get_nth_field(tuple2, j),
- dtuple_get_nth_field(tuple, j));
- }
- dtuple_validate(tuple2);
-
- ut_a(dtuple_fold(tuple, n) ==
- dtuple_fold(tuple2, n));
- }
- }
-
- mem_print_info();
- mem_heap_free(heap);
-}
-
-/**********************************************************************
-Test for physical records. */
-
-void
-test2(void)
-/*=======*/
-{
- dtuple_t* tuple, *tuple2;
- dfield_t* field;
- mem_heap_t* heap;
- ulint i, n;
- char* p_Pascal;
- char* p_Cobol;
- rec_t* rec, *rec2;
- byte* data;
- ulint len;
- byte* buf;
-
- heap = mem_heap_create(0);
-
- printf("-------------------------------------------\n");
- printf("REC-TEST 1. Basic tests.\n");
-
- tuple = dtuple_create(heap, 2);
-
- p_Pascal = "Pascal";
- p_Cobol = "Cobol";
-
- field = dtuple_get_nth_field(tuple, 0);
- dfield_set_data(field, "Pascal", 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
- dfield_set_data(field, "Cobol", 6);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 6, 0);
-
- tuple2 = dtuple_create(heap, 37);
-
- for (i = 0; i < 37; i++) {
- field = dtuple_get_nth_field(tuple2, i);
- dfield_set_data(field, NULL, UNIV_SQL_NULL);
- dtype_set(dfield_get_type(field), DATA_CHAR,
- DATA_ENGLISH, 6, 0);
- }
-
- rec = rec_convert_dtuple_to_rec(buf1, tuple);
-
- rec_validate(rec);
- rec_print(rec);
-
- rec2 = rec_convert_dtuple_to_rec(buf1 + 1000, tuple2);
-
- rec_validate(rec2);
-
- data = rec_get_nth_field(rec, 0, &len);
-
- ut_a(0 == memcmp(p_Pascal, data, 7));
- ut_a(len == 7);
-
- data = rec_get_nth_field(rec, 1, &len);
-
- ut_a(0 == memcmp(p_Cobol, data, 6));
- ut_a(len == 6);
-
- ut_a(2 == rec_get_n_fields(rec));
-
- for (i = 0; i < 37; i++) {
- data = rec_get_nth_field(rec2, i, &len);
- ut_a(len == UNIV_SQL_NULL);
- }
-
- printf("-------------------------------------------\n");
- printf("REC-TEST 2. Test of accessor functions\n");
-
- rec_set_next_offs(rec, 8190);
- rec_set_n_owned(rec, 15);
- rec_set_heap_no(rec, 0);
-
- ut_a(rec_get_next_offs(rec) == 8190);
- ut_a(rec_get_n_owned(rec) == 15);
- ut_a(rec_get_heap_no(rec) == 0);
-
- rec_set_next_offs(rec, 1);
- rec_set_n_owned(rec, 1);
- rec_set_heap_no(rec, 8190);
-
- ut_a(rec_get_next_offs(rec) == 1);
- ut_a(rec_get_n_owned(rec) == 1);
- ut_a(rec_get_heap_no(rec) == 8190);
-
- buf = mem_heap_alloc(heap, 6);
-
- rec_copy_nth_field(buf, rec, 1, &len);
-
- ut_a(ut_memcmp(p_Cobol, buf, len) == 0);
- ut_a(len == 6);
-
- rec_set_nth_field(rec, 1, "Algol", 6);
-
- rec_validate(rec);
-
- rec_copy_nth_field(buf, rec, 1, &len);
-
- ut_a(ut_memcmp("Algol", buf, len) == 0);
- ut_a(len == 6);
-
- ut_a(rec_get_data_size(rec) == 13);
- ut_a((ulint)(rec_get_end(rec) - rec) == 13);
- ut_a(14 == (ulint)(rec - rec_get_start(rec)));
-
- ut_a(rec_get_size(rec) == 27);
-
- mem_heap_free(heap);
-
- printf("-------------------------------------------\n");
- printf("REC-TEST 3. Massive test of conversions \n");
-
- heap = mem_heap_create(0);
-
- for (i = 0; i < 100; i++) {
-
- tuple = dtuple_gen_rnd_tuple(heap);
-
- if (i % 10 == 0) {
- printf("%lu ", i);
- }
-
- if (i % 10 == 0) {
- printf(
- "data tuple generated: %lu fields, data size %lu\n",
- dtuple_get_n_fields(tuple),
- dtuple_get_data_size(tuple));
- }
-
- dtuple_validate(tuple);
-
- rec = rec_convert_dtuple_to_rec(buf1, tuple);
-
- rec_validate(rec);
-
- n = dtuple_get_n_fields(tuple);
-
- ut_a(cmp_dtuple_rec_prefix_equal(tuple, rec, n));
- ut_a(dtuple_fold(tuple, n) == rec_fold(rec, n));
- ut_a(rec_get_converted_size(tuple) == rec_get_size(rec));
- ut_a(rec_get_data_size(rec) == dtuple_get_data_size(tuple));
- }
-
- mem_print_info();
- mem_heap_free(heap);
-}
-
-/**********************************************************************
-Test for comparisons. */
-
-void
-test3(void)
-/*=======*/
-{
- dtuple_t* tuple, *tuple2, *tuple3;
- dfield_t* field;
- mem_heap_t* heap;
- ulint i, j;
- ulint field_match, byte_match;
- rec_t* rec;
- rec_t* rec2;
- ulint tm, oldtm;
- dict_index_t* index;
- dict_table_t* table;
-
- heap = mem_heap_create(0);
-
- printf("-------------------------------------------\n");
- printf("CMP-TEST 1. Basic tests.\n");
-
- tuple = dtuple_create(heap, 2);
-
- field = dtuple_get_nth_field(tuple, 0);
- dfield_set_data(field, "Pascal", 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple, 1);
- dfield_set_data(field, "Cobol", 6);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 6, 0);
-
- tuple2 = dtuple_create(heap, 2);
-
- field = dtuple_get_nth_field(tuple2, 0);
- dfield_set_data(field, "Pascal", 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple2, 1);
- dfield_set_data(field, "Cobom", 6);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 6, 0);
-
- tuple3 = dtuple_create(heap, 2);
-
- field = dtuple_get_nth_field(tuple3, 0);
- dfield_set_data(field, "PaSCal", 7);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 7, 0);
-
- field = dtuple_get_nth_field(tuple3, 1);
- dfield_set_data(field, "CobOL", 6);
- dtype_set(dfield_get_type(field), DATA_CHAR, DATA_ENGLISH, 6, 0);
-
- rec = rec_convert_dtuple_to_rec(buf1, tuple);
-
- rec_validate(rec);
-
- ut_a(!cmp_dtuple_rec_prefix_equal(tuple2, rec, 2));
- ut_a(cmp_dtuple_rec_prefix_equal(tuple, rec, 2));
- ut_a(cmp_dtuple_rec_prefix_equal(tuple3, rec, 2));
-
- oldtm = ut_clock();
- j = 0;
- for (i = 0; i < 1000; i++) {
- field_match = 1;
- byte_match = 4;
- if (1 == cmp_dtuple_rec_with_match(tuple2, rec,
- &field_match, &byte_match)) {
- j++;
- }
- }
- tm = ut_clock();
- printf("Time for fast comp. %lu records = %lu\n", j, tm - oldtm);
-
- ut_a(field_match == 1);
- ut_a(byte_match == 4);
-
- oldtm = ut_clock();
- j = 0;
- for (i = 0; i < 1000; i++) {
- field_match = 0;
- byte_match = 0;
- if (1 == cmp_dtuple_rec_with_match(tuple2, rec,
- &field_match, &byte_match)) {
- j++;
- }
- }
- tm = ut_clock();
- printf("Time for test comp. %lu records = %lu\n", j, tm - oldtm);
-
- ut_a(field_match == 1);
- ut_a(byte_match == 4);
-
- printf("-------------------------------------------\n");
- printf(
- "CMP-TEST 2. A systematic test of comparisons and conversions\n");
-
- tuple = dtuple_create(heap, 3);
- tuple2 = dtuple_create(heap, 3);
-
- table = dict_table_create("TS_TABLE1", 3);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL3", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE1", "IND1", 0, 3, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
- dict_index_add_field(index, "COL3", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE1", "IND1");
- ut_a(index);
-
- /* Compare all test data tuples to each other */
- for (i = 0; i < 512; i++) {
- dtuple_gen_test_tuple(tuple, i);
- rec = rec_convert_dtuple_to_rec(buf1, tuple);
- ut_a(rec_validate(rec));
-
- ut_a(0 == cmp_dtuple_rec(tuple, rec));
-
- for (j = 0; j < 512; j++) {
- dtuple_gen_test_tuple(tuple2, j);
- ut_a(dtuple_validate(tuple2));
-
- rec2 = rec_convert_dtuple_to_rec(buf1 + 500, tuple2);
-
- if (j < i) {
- ut_a(-1 == cmp_dtuple_rec(tuple2, rec));
- ut_a(-1 == cmp_rec_rec(rec2, rec, index));
- } else if (j == i) {
- ut_a(0 == cmp_dtuple_rec(tuple2, rec));
- ut_a(0 == cmp_rec_rec(rec2, rec, index));
- } else if (j > i) {
- ut_a(1 == cmp_dtuple_rec(tuple2, rec));
- ut_a(1 == cmp_rec_rec(rec2, rec, index));
- }
- }
- }
- mem_heap_free(heap);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
- fil_init(25);
- buf_pool_init(100, 100);
- dict_init();
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1();
- test2();
- test3();
-
- tm = ut_clock();
- printf("CPU time for test %lu microseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/row/row0ins.c b/innobase/row/row0ins.c
index c89f41f69ad..fc1f7a19d53 100644
--- a/innobase/row/row0ins.c
+++ b/innobase/row/row0ins.c
@@ -38,7 +38,7 @@ This prototype is copied from /mysql/sql/ha_innodb.cc.
Invalidates the MySQL query cache for the table.
NOTE that the exact prototype of this function has to be in
/innobase/row/row0ins.c! */
-
+extern
void
innobase_invalidate_query_cache(
/*============================*/
@@ -80,9 +80,9 @@ ins_node_create(
node->trx_id = ut_dulint_zero;
node->entry_sys_heap = mem_heap_create(128);
-
- node->magic_n = INS_NODE_MAGIC_N;
-
+#ifdef UNIV_DEBUG
+ node->magic_n = INS_NODE_MAGIC_N;
+#endif /* UNIV_DEBUG */
return(node);
}
@@ -194,6 +194,7 @@ ins_node_set_new_row(
ins_node_t* node, /* in: insert node */
dtuple_t* row) /* in: new row (or first row) for the node */
{
+ ut_ad(node->magic_n == INS_NODE_MAGIC_N);
node->state = INS_NODE_SET_IX_LOCK;
node->index = NULL;
node->entry = NULL;
@@ -682,14 +683,6 @@ row_ins_foreign_check_on_constraint(
(DICT_FOREIGN_ON_DELETE_CASCADE
| DICT_FOREIGN_ON_DELETE_SET_NULL))) {
- /* No action is defined: return a foreign key error if
- NO ACTION is not specified */
-
- if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
-
- return(DB_SUCCESS);
- }
-
row_ins_foreign_report_err((char*)"Trying to delete",
thr, foreign,
btr_pcur_get_rec(pcur), entry);
@@ -703,14 +696,6 @@ row_ins_foreign_check_on_constraint(
/* This is an UPDATE */
- /* No action is defined: return a foreign key error if
- NO ACTION is not specified */
-
- if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
-
- return(DB_SUCCESS);
- }
-
row_ins_foreign_report_err((char*)"Trying to update",
thr, foreign,
btr_pcur_get_rec(pcur), entry);
@@ -871,7 +856,7 @@ row_ins_foreign_check_on_constraint(
"InnoDB: Make a detailed bug report and send it\n");
fprintf(stderr, "InnoDB: to mysql@lists.mysql.com\n");
- ut_a(0);
+ ut_error;
*/
err = DB_SUCCESS;
@@ -1047,8 +1032,10 @@ row_ins_check_foreign_constraint(
mtr_t mtr;
run_again:
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_SHARED));
-
+#endif /* UNIV_SYNC_DEBUG */
+
err = DB_SUCCESS;
if (thr_get_trx(thr)->check_foreigns == FALSE) {
@@ -1365,58 +1352,6 @@ row_ins_check_foreign_constraints(
return(DB_SUCCESS);
}
-/*************************************************************************
-Reports a UNIQUE key error to dict_unique_err_buf so that SHOW INNODB
-STATUS can print it. */
-static
-void
-row_ins_unique_report_err(
-/*======================*/
- que_thr_t* thr, /* in: query thread */
- rec_t* rec, /* in: a record in the index */
- dtuple_t* entry, /* in: index entry to insert in the index */
- dict_index_t* index) /* in: index */
-{
- UT_NOT_USED(thr);
- UT_NOT_USED(rec);
- UT_NOT_USED(entry);
- UT_NOT_USED(index);
-
-#ifdef notdefined
- /* Disable reporting to test if the slowdown of REPLACE in 4.0.13 was
- caused by this! */
-
- char* buf = dict_unique_err_buf;
-
- /* The foreign err mutex protects also dict_unique_err_buf */
-
- mutex_enter(&dict_foreign_err_mutex);
-
- ut_sprintf_timestamp(buf);
- sprintf(buf + strlen(buf), " Transaction:\n");
- trx_print(buf + strlen(buf), thr_get_trx(thr));
-
- sprintf(buf + strlen(buf),
-"Unique key constraint fails for table %.500s.\n", index->table_name);
- sprintf(buf + strlen(buf),
-"Trying to add in index %.500s (%lu fields unique) tuple:\n", index->name,
- dict_index_get_n_unique(index));
-
- dtuple_sprintf(buf + strlen(buf), 1000, entry);
-
- sprintf(buf + strlen(buf),
-"\nBut there is already a record:\n");
-
- rec_sprintf(buf + strlen(buf), 1000, rec);
-
- sprintf(buf + strlen(buf), "\n");
-
- ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN);
-
- mutex_exit(&dict_foreign_err_mutex);
-#endif
-}
-
/*******************************************************************
Checks if a unique key violation to rec would occur at the index entry
insert. */
@@ -1547,8 +1482,6 @@ row_ins_scan_sec_index_for_duplicate(
if (cmp == 0) {
if (row_ins_dupl_error_with_rec(rec, entry, index)) {
- row_ins_unique_report_err(thr, rec, entry,
- index);
err = DB_DUPLICATE_KEY;
thr_get_trx(thr)->error_info = index;
@@ -1643,8 +1576,6 @@ row_ins_duplicate_error_in_clust(
if (row_ins_dupl_error_with_rec(rec, entry,
cursor->index)) {
trx->error_info = cursor->index;
- row_ins_unique_report_err(thr, rec, entry,
- cursor->index);
return(DB_DUPLICATE_KEY);
}
}
@@ -1667,9 +1598,6 @@ row_ins_duplicate_error_in_clust(
if (row_ins_dupl_error_with_rec(rec, entry,
cursor->index)) {
trx->error_info = cursor->index;
-
- row_ins_unique_report_err(thr, rec, entry,
- cursor->index);
return(DB_DUPLICATE_KEY);
}
}
@@ -2115,6 +2043,7 @@ row_ins(
ulint err;
ut_ad(node && thr);
+ ut_ad(node->magic_n == INS_NODE_MAGIC_N);
if (node->state == INS_NODE_ALLOC_ROW_ID) {
@@ -2179,7 +2108,7 @@ row_ins_step(
trx_start_if_not_started(trx);
node = thr->run_node;
-
+ ut_ad(node->magic_n == INS_NODE_MAGIC_N);
ut_ad(que_node_get_type(node) == QUE_NODE_INSERT);
parent = que_node_get_parent(node);
diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c
index cf7a3efcdfc..49e5aeac2e4 100644
--- a/innobase/row/row0mysql.c
+++ b/innobase/row/row0mysql.c
@@ -287,7 +287,7 @@ handle_new_error:
} else {
fprintf(stderr, "InnoDB: unknown error code %lu\n",
(ulong) err);
- ut_a(0);
+ ut_error;
}
if (trx->error_state != DB_SUCCESS) {
@@ -402,7 +402,7 @@ row_prebuilt_free(
mem_analyze_corruption((byte*)prebuilt);
- ut_a(0);
+ ut_error;
}
prebuilt->magic_n = ROW_PREBUILT_FREED;
@@ -450,7 +450,7 @@ row_prebuilt_free(
mem_analyze_corruption(
prebuilt->fetch_cache[i]);
- ut_a(0);
+ ut_error;
}
mem_free((prebuilt->fetch_cache[i]) - 4);
@@ -482,7 +482,7 @@ row_update_prebuilt_trx(
mem_analyze_corruption((byte*)trx);
- ut_a(0);
+ ut_error;
}
if (prebuilt->magic_n != ROW_PREBUILT_ALLOCATED) {
@@ -493,7 +493,7 @@ row_update_prebuilt_trx(
mem_analyze_corruption((byte*)prebuilt);
- ut_a(0);
+ ut_error;
}
prebuilt->trx = trx;
@@ -720,7 +720,7 @@ row_insert_for_mysql(
mem_analyze_corruption((byte*)prebuilt);
- ut_a(0);
+ ut_error;
}
if (srv_created_new_raw || srv_force_recovery) {
@@ -936,7 +936,7 @@ row_update_for_mysql(
mem_analyze_corruption((byte*)prebuilt);
- ut_a(0);
+ ut_error;
}
if (srv_created_new_raw || srv_force_recovery) {
@@ -1289,9 +1289,11 @@ row_create_table_for_mysql(
ulint err;
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
- ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
+ ut_ad(trx->dict_operation_lock_mode == RW_X_LATCH);
if (srv_created_new_raw) {
fprintf(stderr,
@@ -1408,10 +1410,12 @@ row_create_table_for_mysql(
"UNIV_MEM_DEBUG defined in univ.i and the server must be\n"
"quiet because allocation from a mem heap is not protected\n"
"by any semaphore.\n");
-
+#ifdef UNIV_MEM_DEBUG
ut_a(mem_validate());
-
printf("Memory validated\n");
+#else /* UNIV_MEM_DEBUG */
+ puts("Memory NOT validated (recompile with UNIV_MEM_DEBUG)");
+#endif /* UNIV_MEM_DEBUG */
}
heap = mem_heap_create(512);
@@ -1422,8 +1426,7 @@ row_create_table_for_mysql(
thr = pars_complete_graph_for_exec(node, trx, heap);
- ut_a(thr == que_fork_start_command(que_node_get_parent(thr),
- SESS_COMM_EXECUTE, 0));
+ ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
que_run_threads(thr);
err = trx->error_state;
@@ -1494,8 +1497,10 @@ row_create_index_for_mysql(
ulint err;
ulint i, j;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
ut_ad(mutex_own(&(dict_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
trx->op_info = (char *) "creating index";
@@ -1550,8 +1555,7 @@ row_create_index_for_mysql(
thr = pars_complete_graph_for_exec(node, trx, heap);
- ut_a(thr == que_fork_start_command(que_node_get_parent(thr),
- SESS_COMM_EXECUTE, 0));
+ ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
que_run_threads(thr);
err = trx->error_state;
@@ -1602,8 +1606,10 @@ row_table_add_foreign_constraints(
ulint keywordlen;
ulint err;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(sql_string);
trx->op_info = (char *) "adding foreign keys";
@@ -1774,7 +1780,9 @@ row_get_background_drop_list_len_low(void)
/*======================================*/
/* out: how many tables in list */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (!row_mysql_drop_list_inited) {
@@ -1926,7 +1934,7 @@ row_discard_tablespace_for_mysql(
graph->fork_type = QUE_FORK_MYSQL_INTERFACE;
- ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0));
+ ut_a(thr = que_fork_start_command(graph));
que_run_threads(thr);
@@ -2085,6 +2093,7 @@ row_drop_table_for_mysql(
char* name, /* in: table name */
trx_t* trx) /* in: transaction handle */
{
+ dict_foreign_t* foreign;
dict_table_t* table;
ulint space_id;
que_thr_t* thr;
@@ -2252,8 +2261,10 @@ row_drop_table_for_mysql(
locked_dictionary = TRUE;
}
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(dict_sys->mutex)));
ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
+#endif /* UNIV_SYNC_DEBUG */
graph = pars_sql(buf);
@@ -2282,6 +2293,38 @@ row_drop_table_for_mysql(
goto funct_exit;
}
+ /* Check if the table is referenced by foreign key constraints from
+ some other table (not the table itself) */
+
+ foreign = UT_LIST_GET_FIRST(table->referenced_list);
+
+ while (foreign && foreign->foreign_table == table) {
+ foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
+ }
+
+ if (foreign && trx->check_foreigns) {
+ char* buf = dict_foreign_err_buf;
+
+ /* We only allow dropping a referenced table if
+ FOREIGN_KEY_CHECKS is set to 0 */
+
+ err = DB_CANNOT_DROP_CONSTRAINT;
+
+ mutex_enter(&dict_foreign_err_mutex);
+ ut_sprintf_timestamp(buf);
+
+ sprintf(buf + strlen(buf),
+ " Cannot drop table %.500s\n", name);
+ sprintf(buf + strlen(buf),
+"because it is referenced by %.500s\n", foreign->foreign_table_name);
+
+ ut_a(strlen(buf) < DICT_FOREIGN_ERR_BUF_LEN);
+
+ mutex_exit(&dict_foreign_err_mutex);
+
+ goto funct_exit;
+ }
+
if (table->n_mysql_handles_opened > 0) {
ut_print_timestamp(stderr);
@@ -2321,7 +2364,7 @@ row_drop_table_for_mysql(
trx->dict_operation = TRUE;
trx->table_id = table->id;
- ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0));
+ ut_a(thr = que_fork_start_command(graph));
que_run_threads(thr);
@@ -2334,7 +2377,7 @@ row_drop_table_for_mysql(
row_mysql_handle_errors(&err, trx, thr, NULL);
- ut_a(0);
+ ut_error;
} else {
space_id = table->space;
dict_table_remove_from_cache(table);
@@ -2469,7 +2512,7 @@ row_is_mysql_tmp_table_name(
{
ulint i;
- for (i = 0; i <= ut_strlen(name) - 5; i++) {
+ for (i = 0; i + 5 <= ut_strlen(name); i++) {
if (ut_memcmp(name + i, (char*)"/#sql", 5) == 0) {
return(TRUE);
@@ -2505,6 +2548,7 @@ row_rename_table_for_mysql(
ulint keywordlen;
ulint len;
ulint i;
+ char* db_name;
ibool success;
char buf[2 * OS_FILE_MAX_PATH];
@@ -2593,6 +2637,15 @@ row_rename_table_for_mysql(
"PROCEDURE RENAME_TABLE_PROC () IS\n"
"new_table_name CHAR;\n"
"old_table_name CHAR;\n"
+ "gen_constr_prefix CHAR;\n"
+ "new_db_name CHAR;\n"
+ "foreign_id CHAR;\n"
+ "new_foreign_id CHAR;\n"
+ "old_db_name_len INT;\n"
+ "old_t_name_len INT;\n"
+ "new_db_name_len INT;\n"
+ "id_len INT;\n"
+ "found INT;\n"
"BEGIN\n"
"new_table_name :='";
@@ -2619,32 +2672,94 @@ row_rename_table_for_mysql(
}
str3 = mem_heap_alloc(heap,
- 1000 + 500 * n_constraints_to_drop);
+ 1000 + 1000 * n_constraints_to_drop);
*str3 = '\0';
sprintf(str3,
"';\n"
"UPDATE SYS_TABLES SET NAME = new_table_name\n"
"WHERE NAME = old_table_name;\n");
+ db_name = mem_heap_alloc(heap, 1 + dict_get_db_name_len(
+ old_name));
+ ut_memcpy(db_name, old_name, dict_get_db_name_len(old_name));
+ db_name[dict_get_db_name_len(old_name)] = '\0';
+
+ /* Internally, old format < 4.0.18 constraints have as the
+ constraint id <number>_<number>, while new format constraints
+ have <databasename>/<constraintname>. */
+
for (i = 0; i < n_constraints_to_drop; i++) {
+
sprintf(str3 + strlen(str3),
- "DELETE FROM SYS_FOREIGN_COLS WHERE ID = '%s';\n"
- "DELETE FROM SYS_FOREIGN WHERE ID = '%s';\n",
+ "DELETE FROM SYS_FOREIGN_COLS WHERE ID = '%s/%s';\n"
+ "DELETE FROM SYS_FOREIGN WHERE ID = '%s/%s';\n",
+ db_name, constraints_to_drop[i],
+ db_name, constraints_to_drop[i]);
+
+ if (!ut_str_contains(constraints_to_drop[i], '/')) {
+ /* If this happens to be an old format
+ constraint, let us delete it. Since all new
+ format constraints contain '/', it does no
+ harm to run these DELETEs anyway. */
+
+ sprintf(str3 + strlen(str3),
+ "DELETE FROM SYS_FOREIGN_COLS WHERE ID = '%s';\n"
+ "DELETE FROM SYS_FOREIGN WHERE ID = '%s';\n",
constraints_to_drop[i],
constraints_to_drop[i]);
+ }
}
sprintf(str3 + strlen(str3),
"END;\n");
- ut_a(strlen(str3) < 1000 + 500 * n_constraints_to_drop);
+ ut_a(strlen(str3) < 1000 + 1000 * n_constraints_to_drop);
} else {
str3 = (char*)
"';\n"
"UPDATE SYS_TABLES SET NAME = new_table_name\n"
"WHERE NAME = old_table_name;\n"
- "UPDATE SYS_FOREIGN SET FOR_NAME = new_table_name\n"
- "WHERE FOR_NAME = old_table_name;\n"
+ "found := 1;\n"
+ "old_db_name_len := INSTR(old_table_name, '/') - 1;\n"
+ "new_db_name_len := INSTR(new_table_name, '/') - 1;\n"
+ "new_db_name := SUBSTR(new_table_name, 0, new_db_name_len);\n"
+ "old_t_name_len := LENGTH(old_table_name);\n"
+ "gen_constr_prefix := CONCAT(old_table_name, '_ibfk_');\n"
+ "WHILE found = 1 LOOP\n"
+ " SELECT ID INTO foreign_id\n"
+ " FROM SYS_FOREIGN\n"
+ " WHERE FOR_NAME = old_table_name;\n"
+ " IF (SQL % NOTFOUND) THEN\n"
+ " found := 0;\n"
+ " ELSE\n"
+ " UPDATE SYS_FOREIGN\n"
+ " SET FOR_NAME = new_table_name\n"
+ " WHERE ID = foreign_id;\n"
+ " id_len := LENGTH(foreign_id);\n"
+ " IF (INSTR(foreign_id, '/') > 0) THEN\n"
+ " IF (INSTR(foreign_id,\n"
+ " gen_constr_prefix) > 0)\n"
+ " THEN\n"
+ " new_foreign_id :=\n"
+ " CONCAT(new_table_name,\n"
+ " SUBSTR(foreign_id, old_t_name_len,\n"
+ " id_len - old_t_name_len));\n"
+ " ELSE\n"
+ " new_foreign_id :=\n"
+ " CONCAT(new_db_name,\n"
+ " SUBSTR(foreign_id,\n"
+ " old_db_name_len,\n"
+ " id_len - old_db_name_len));\n"
+ " END IF;\n"
+ " UPDATE SYS_FOREIGN\n"
+ " SET ID = new_foreign_id\n"
+ " WHERE ID = foreign_id;\n"
+ " UPDATE SYS_FOREIGN_COLS\n"
+ " SET ID = new_foreign_id\n"
+ " WHERE ID = foreign_id;\n"
+ " END IF;\n"
+ " END IF;\n"
+ "END LOOP;\n"
"UPDATE SYS_FOREIGN SET REF_NAME = new_table_name\n"
"WHERE REF_NAME = old_table_name;\n"
"END;\n";
@@ -2679,7 +2794,7 @@ row_rename_table_for_mysql(
graph->fork_type = QUE_FORK_MYSQL_INTERFACE;
- ut_a(thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0));
+ ut_a(thr = que_fork_start_command(graph));
que_run_threads(thr);
diff --git a/innobase/row/row0purge.c b/innobase/row/row0purge.c
index d5895f20461..a409b64f8e4 100644
--- a/innobase/row/row0purge.c
+++ b/innobase/row/row0purge.c
@@ -140,7 +140,7 @@ row_purge_remove_clust_if_poss_low(
} else if (err == DB_OUT_OF_FILE_SPACE) {
success = FALSE;
} else {
- ut_a(0);
+ ut_error;
}
}
@@ -266,7 +266,7 @@ row_purge_remove_sec_if_poss_low(
} else if (err == DB_OUT_OF_FILE_SPACE) {
success = FALSE;
} else {
- ut_a(0);
+ ut_error;
}
}
}
@@ -447,8 +447,10 @@ skip_secondaries:
data_field = buf_page_get(0, page_no, RW_X_LATCH, &mtr)
+ offset + internal_offset;
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(buf_frame_align(data_field),
SYNC_TRX_UNDO_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
data_field_len = ufield->new_val.len;
diff --git a/innobase/row/row0row.c b/innobase/row/row0row.c
index 6c0c6c04cd5..6820cb5bccd 100644
--- a/innobase/row/row0row.c
+++ b/innobase/row/row0row.c
@@ -236,61 +236,6 @@ row_build(
return(row);
}
-#ifdef notdefined
-/***********************************************************************
-An inverse function to dict_row_build_index_entry. Builds a row from a
-record in a clustered index. */
-
-void
-row_build_to_tuple(
-/*===============*/
- dtuple_t* row, /* in/out: row built; see the NOTE below! */
- dict_index_t* index, /* in: clustered index */
- rec_t* rec) /* in: record in the clustered index;
- NOTE: the data fields in the row will point
- directly into this record, therefore,
- the buffer page of this record must be
- at least s-latched and the latch held
- as long as the row dtuple is used!
- NOTE 2: does not work with externally
- stored fields! */
-{
- dict_table_t* table;
- ulint n_fields;
- ulint i;
- dfield_t* dfield;
- byte* field;
- ulint len;
- ulint row_len;
- dict_col_t* col;
-
- ut_ad(index && rec);
- ut_ad(index->type & DICT_CLUSTERED);
-
- table = index->table;
- row_len = dict_table_get_n_cols(table);
-
- dtuple_set_info_bits(row, rec_get_info_bits(rec));
-
- n_fields = dict_index_get_n_fields(index);
-
- ut_ad(n_fields == rec_get_n_fields(rec));
-
- dict_table_copy_types(row, table);
-
- for (i = 0; i < n_fields; i++) {
-
- col = dict_field_get_col(dict_index_get_nth_field(index, i));
- dfield = dtuple_get_nth_field(row, dict_col_get_no(col));
- field = rec_get_nth_field(rec, i, &len);
-
- dfield_set_data(dfield, field, len);
- }
-
- ut_ad(dtuple_check_typed(row));
-}
-#endif
-
/***********************************************************************
Converts an index record to a typed data tuple. NOTE that externally
stored (often big) fields are NOT copied to heap. */
@@ -461,7 +406,7 @@ row_build_row_ref_in_tuple(
if (!table) {
fprintf(stderr, "InnoDB: table %s for index %s not found\n",
index->table_name, index->name);
- ut_a(0);
+ ut_error;
}
clust_index = dict_table_get_first_index(table);
@@ -470,7 +415,7 @@ row_build_row_ref_in_tuple(
fprintf(stderr,
"InnoDB: clust index for table %s for index %s not found\n",
index->table_name, index->name);
- ut_a(0);
+ ut_error;
}
ref_len = dict_index_get_n_unique(clust_index);
diff --git a/innobase/row/row0sel.c b/innobase/row/row0sel.c
index 57de309c090..4f70cea2058 100644
--- a/innobase/row/row0sel.c
+++ b/innobase/row/row0sel.c
@@ -930,7 +930,9 @@ row_sel_try_search_shortcut(
ut_ad(node->read_view);
ut_ad(plan->unique_search);
ut_ad(!plan->must_get_clust);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
row_sel_open_pcur(node, plan, TRUE, mtr);
@@ -2080,7 +2082,7 @@ row_sel_store_row_id_to_prebuilt(
(ulong) len, index->table_name, index->name,
(ulong) dict_index_get_sys_col_pos(index, DATA_ROW_ID),
err_buf);
- ut_a(0);
+ ut_error;
}
ut_memcpy(prebuilt->row_id, data, len);
@@ -2770,7 +2772,7 @@ row_search_for_mysql(
mem_analyze_corruption((byte*)prebuilt);
- ut_a(0);
+ ut_error;
}
if (trx->n_mysql_tables_in_use == 0) {
@@ -2831,7 +2833,7 @@ row_search_for_mysql(
if (direction != prebuilt->fetch_direction) {
if (prebuilt->n_fetch_cached > 0) {
- ut_a(0);
+ ut_error;
/* TODO: scrollable cursor: restore cursor to
the place of the latest returned row,
or better: prevent caching for a scroll
@@ -2886,7 +2888,16 @@ row_search_for_mysql(
if (match_mode == ROW_SEL_EXACT
&& index->type & DICT_UNIQUE
&& dtuple_get_n_fields(search_tuple)
- == dict_index_get_n_unique(index)) {
+ == dict_index_get_n_unique(index)
+ && (index->type & DICT_CLUSTERED
+ || !dtuple_contains_null(search_tuple))) {
+
+ /* Note above that a UNIQUE secondary index can contain many
+ rows with the same key value if one of the columns is the SQL
+ null. A clustered index under MySQL can never contain null
+ columns because we demand that all the columns in primary key
+ are non-null. */
+
unique_search = TRUE;
/* Even if the condition is unique, MySQL seems to try to
diff --git a/innobase/row/row0undo.c b/innobase/row/row0undo.c
index f223bb5eed5..613d0a3b890 100644
--- a/innobase/row/row0undo.c
+++ b/innobase/row/row0undo.c
@@ -334,7 +334,7 @@ row_undo_step(
exit(1);
}
- ut_a(0);
+ ut_error;
return(NULL);
}
diff --git a/innobase/row/row0upd.c b/innobase/row/row0upd.c
index b9e9b8c15c9..f8739b65c2f 100644
--- a/innobase/row/row0upd.c
+++ b/innobase/row/row0upd.c
@@ -77,8 +77,8 @@ index record. This is only used in foreign key checks and we can assume
that index does not contain column prefixes. */
static
ibool
-row_upd_changes_first_fields(
-/*=========================*/
+row_upd_changes_first_fields_binary(
+/*================================*/
/* out: TRUE if changes */
dtuple_t* entry, /* in: old value of index entry */
dict_index_t* index, /* in: index of entry */
@@ -196,7 +196,7 @@ row_upd_check_references_constraints(
if (foreign->referenced_index == index
&& (node->is_delete
- || row_upd_changes_first_fields(entry, index,
+ || row_upd_changes_first_fields_binary(entry, index,
node->update, foreign->n_fields))) {
if (foreign->foreign_table == NULL) {
@@ -287,7 +287,9 @@ upd_node_create(
node->select = NULL;
node->heap = mem_heap_create(128);
- node->magic_n = UPD_NODE_MAGIC_N;
+#ifdef UNIV_DEBUG
+ node->magic_n = UPD_NODE_MAGIC_N;
+#endif /* UNIV_DEBUG */
node->cmpl_info = 0;
@@ -1048,8 +1050,8 @@ index record. This is only used in foreign key checks and we can assume
that index does not contain column prefixes. */
static
ibool
-row_upd_changes_first_fields(
-/*=========================*/
+row_upd_changes_first_fields_binary(
+/*================================*/
/* out: TRUE if changes */
dtuple_t* entry, /* in: index entry */
dict_index_t* index, /* in: index of entry */
@@ -1074,15 +1076,16 @@ row_upd_changes_first_fields(
col = dict_field_get_col(ind_field);
col_pos = dict_col_get_clust_pos(col);
+ ut_a(ind_field->prefix_len == 0);
+
for (j = 0; j < n_upd_fields; j++) {
upd_field = upd_get_nth_field(update, j);
if (col_pos == upd_field->field_no
- && (ind_field->prefix_len > 0
- || 0 != cmp_dfield_dfield(
+ && !dfield_datas_are_binary_equal(
dtuple_get_nth_field(entry, i),
- &(upd_field->new_val)))) {
+ &(upd_field->new_val))) {
return(TRUE);
}
}
@@ -1804,6 +1807,7 @@ row_upd_step(
trx_start_if_not_started(trx);
node = thr->run_node;
+ ut_ad(node->magic_n == UPD_NODE_MAGIC_N);
sel_node = node->select;
@@ -1923,6 +1927,7 @@ row_upd_in_place_in_select(
node = que_node_get_parent(sel_node);
+ ut_ad(node->magic_n == UPD_NODE_MAGIC_N);
ut_ad(que_node_get_type(node) == QUE_NODE_UPDATE);
pcur = node->pcur;
diff --git a/innobase/row/row0vers.c b/innobase/row/row0vers.c
index fca56389e45..bc17ede89e3 100644
--- a/innobase/row/row0vers.c
+++ b/innobase/row/row0vers.c
@@ -60,8 +60,10 @@ row_vers_impl_x_locked_off_kernel(
ulint err;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
ut_ad(!rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
mutex_exit(&kernel_mutex);
@@ -254,7 +256,9 @@ row_vers_must_preserve_del_marked(
mtr_t* mtr) /* in: mtr holding the latch on the clustered index
record; it will also hold the latch on purge_view */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
mtr_s_lock(&(purge_sys->latch), mtr);
@@ -302,7 +306,9 @@ row_vers_old_has_index_entry(
ut_ad(mtr_memo_contains(mtr, buf_block_align(rec), MTR_MEMO_PAGE_X_FIX)
|| mtr_memo_contains(mtr, buf_block_align(rec),
MTR_MEMO_PAGE_S_FIX));
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
mtr_s_lock(&(purge_sys->latch), mtr);
clust_index = dict_table_get_first_index(index->table);
@@ -411,7 +417,9 @@ row_vers_build_for_consistent_read(
ut_ad(mtr_memo_contains(mtr, buf_block_align(rec), MTR_MEMO_PAGE_X_FIX)
|| mtr_memo_contains(mtr, buf_block_align(rec),
MTR_MEMO_PAGE_S_FIX));
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(!read_view_sees_trx_id(view, row_get_rec_trx_id(rec, index)));
rw_lock_s_lock(&(purge_sys->latch));
diff --git a/innobase/row/ts/makefile b/innobase/row/ts/makefile
deleted file mode 100644
index 589db50d4ed..00000000000
--- a/innobase/row/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tstcur: ..\tcur.lib tstcur.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\tcur.lib ..\..\trx.lib ..\..\btr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tstcur.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/row/ts/tstcur.c b/innobase/row/ts/tstcur.c
deleted file mode 100644
index f5a5eb1f9f3..00000000000
--- a/innobase/row/ts/tstcur.c
+++ /dev/null
@@ -1,1087 +0,0 @@
-/************************************************************************
-Test for the index system
-
-(c) 1994-1996 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "rem0rec.h"
-#include "..\tcur0ins.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 1
-#define N_FILES 1
-#define FILE_SIZE 4000 /* must be > 512 */
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space 0. */
-
-void
-init_space(void)
-/*============*/
-{
- mtr_t mtr;
-
- printf("Init space header\n");
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test1(void)
-/*=======*/
-{
- dtuple_t* tuple;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- ulint rnd = 0;
- dict_index_t* index;
- dict_table_t* table;
- byte buf[16];
- ulint i, j;
- ulint tm, oldtm;
- trx_t* trx;
-/* dict_tree_t* tree;*/
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- byte* field;
- ulint len;
- dtuple_t* search_tuple;
- dict_tree_t* index_tree;
- rec_t* rec;
-
- UT_NOT_USED(len);
- UT_NOT_USED(field);
- UT_NOT_USED(pcur2);
-/*
- printf("\n\n\nPress 2 x enter to start test\n");
-
- while (EOF == getchar()) {
-
- }
-
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(1024);
- heap2 = mem_heap_create(1024);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
-
- ut_a(TRUE == dict_create_table(table, trx));
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 75046,
- DICT_CLUSTERED, 2);
-
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-*/
- dict_table_print(table);
-
- /*---------------------------------------------------------*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 2. INSERT 1 ROW TO THE TABLE\n");
-
- trx = trx_start(ULINT_UNDEFINED);
-
- tuple = dtuple_create(heap, 3);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- dtuple_gen_test_tuple3(tuple, 0, buf);
- tcur_insert(tuple, table, heap2, trx);
-
- trx_commit(trx);
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 3. INSERT MANY ROWS TO THE TABLE IN A SINGLE TRX\n");
-
- rnd = 0;
- oldtm = ut_clock();
-
- trx = trx_start(ULINT_UNDEFINED);
- for (i = 0; i < 300 * UNIV_DBC * UNIV_DBC; i++) {
-
- if (i % 5000 == 0) {
- /* dict_table_print(table);
- buf_print();
- buf_LRU_print();
- printf("%lu rows inserted\n", i); */
- }
-
- table = dict_table_get("TS_TABLE1", trx);
-
- if (i == 2180) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 1) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- tcur_insert(tuple, table, heap2, trx);
-
- mem_heap_empty(heap2);
-
- if (i % 4 == 3) {
- }
- }
- trx_commit(trx);
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows inserted\n", i);
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 4. PRINT PART OF CONTENTS OF EACH INDEX TREE\n");
-
-/*
- mem_print_info();
-*/
-
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-
- tree = dict_index_get_tree(dict_table_get_next_index(
- dict_table_get_first_index(table)));
-
- btr_print_tree(tree, 5);
-*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
-/* mem_print_info(); */
-
- os_thread_sleep(5000000);
-
- for (j = 0; j < 5; j++) {
- printf("-------------------------------------------------\n");
- printf("TEST 5. CALCULATE THE JOIN OF THE TABLE WITH ITSELF\n");
-
- i = 0;
-
- oldtm = ut_clock();
-
- mtr_start(&mtr);
-
- index_tree = dict_index_get_tree(UT_LIST_GET_FIRST(table->indexes));
-
- search_tuple = dtuple_create(heap, 2);
-
- dtuple_gen_search_tuple3(search_tuple, i, buf);
-
- btr_pcur_open(index_tree, search_tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- while (!btr_pcur_is_after_last_in_tree(&pcur, &mtr)) {
-
- if (i % 20000 == 0) {
- printf("%lu rows joined\n", i);
- }
-
- index_tree = dict_index_get_tree(
- UT_LIST_GET_FIRST(table->indexes));
-
- rec = btr_pcur_get_rec(&pcur);
-
- rec_copy_prefix_to_dtuple(search_tuple, rec, 2, heap2);
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index_tree, search_tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &pcur2, &mtr2);
-
- btr_pcur_move_to_next(&pcur2, &mtr2);
-
- rec = btr_pcur_get_rec(&pcur2);
-
- field = rec_get_nth_field(rec, 1, &len);
-
- ut_a(len == 8);
-
- ut_a(ut_memcmp(field, dfield_get_data(
- dtuple_get_nth_field(search_tuple, 1)),
- len) == 0);
-
- btr_pcur_close(&pcur2, &mtr);
-
- mem_heap_empty(heap2);
-
- mtr_commit(&mtr2);
-
- btr_pcur_store_position(&pcur, &mtr);
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_move_to_next(&pcur, &mtr);
- i++;
- }
-
- btr_pcur_close(&pcur, &mtr);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows joined\n", i);
- }
-
- oldtm = ut_clock();
-
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 6. INSERT MANY ROWS TO THE TABLE IN SEPARATE TRXS\n");
-
- rnd = 200000;
-
- for (i = 0; i < 350; i++) {
-
- if (i % 4 == 0) {
- }
- trx = trx_start(ULINT_UNDEFINED);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- if (i == 2180) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 1) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- tcur_insert(tuple, table, heap2, trx);
-
- trx_commit(trx);
-
- mem_heap_empty(heap2);
- if (i % 4 == 3) {
- }
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows inserted in %lu transactions\n", i, i);
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 7. PRINT MEMORY ALLOCATION INFO\n");
-
- mem_print_info();
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 8. PRINT SEMAPHORE INFO\n");
-
- sync_print();
-
-
-
-#ifdef notdefined
- rnd = 90000;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- if (i == 50000) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 595659561) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- btr_pcur_open(tree, tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &cursor, &mtr);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- rnd = (rnd + 35608971) % 200000 + 1;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
-/* btr_print_tree(tree, 3); */
-
-#endif
- mem_heap_free(heap);
-}
-
-
-#ifdef notdefined
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 534671) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
-/* page_print_list(page, 151); */
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 7771) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_get_n_recs(page) == 0);
-
- ut_a(page_validate(page, index));
- page = page_create(frame, &mtr);
-
- rnd = 311;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 217;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
- page = page_create(frame, &mtr);
-
- rnd = 291;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 277;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- mem_heap_free(heap);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test2(void)
-/*=======*/
-{
- page_t* page;
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint i, j;
- ulint rnd = 0;
- rec_t* rec;
- page_cur_t cursor;
- dict_index_t* index;
- dict_table_t* table;
- buf_block_t* block;
- buf_frame_t* frame;
- ulint tm, oldtm;
- byte buf[8];
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. Speed test\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf, bigbuf + 800, 800);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- rnd = 0;
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf + rnd, bigbuf + rnd + 800, 800);
- rnd += 1600;
- if (rnd > 995000) {
- rnd = 0;
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- heap = mem_heap_create(0);
-
- table = dict_table_create("TS_TABLE2", 2);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE2", "IND2", 0, 2, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE2", "IND2");
- ut_a(index);
-
- tuple = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, 5, &mtr);
- buf_page_s_lock(block, &mtr);
-
- page = buf_block_get_frame(block);
- ut_a(page_validate(page, index));
- mtr_commit(&mtr);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for %lu empty loops with page create %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 100;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for sequential insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 500;
- for (j = 0; j < 250; j++) {
- rnd = (rnd - 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for descend. seq. insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
-
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
- }
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insert and delete of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- ut_a(page_validate(page, index));
- mtr_print(&mtr);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for search of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu empty loops %lu milliseconds\n",
- i * j, tm - oldtm);
- mtr_commit(&mtr);
-}
-
-#endif
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- mtr_t mtr;
-
- sync_init();
- mem_init();
- os_aio_init(160, 5);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
-
- create_files();
- init_space();
-
- mtr_start(&mtr);
-
- trx_sys_create(&mtr);
- dict_create(&mtr);
-
- mtr_commit(&mtr);
-
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1();
-
-/* mem_print_info(); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/srv/srv0que.c b/innobase/srv/srv0que.c
index 4d36adfefa4..ac8bd7d0e65 100644
--- a/innobase/srv/srv0que.c
+++ b/innobase/srv/srv0que.c
@@ -83,7 +83,9 @@ srv_que_task_enqueue_low(
{
ut_ad(thr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr);
diff --git a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c
index d2368c5341f..838e63b3e25 100644
--- a/innobase/srv/srv0srv.c
+++ b/innobase/srv/srv0srv.c
@@ -34,12 +34,9 @@ Created 10/8/1995 Heikki Tuuri
#include "sync0sync.h"
#include "sync0ipm.h"
#include "thr0loc.h"
-#include "com0com.h"
-#include "com0shm.h"
#include "que0que.h"
#include "srv0que.h"
#include "log0recv.h"
-#include "odbc0odbc.h"
#include "pars0pars.h"
#include "usr0sess.h"
#include "lock0lock.h"
@@ -253,9 +250,6 @@ ibool srv_use_adaptive_hash_indexes = TRUE;
ulint srv_n_spin_wait_rounds = 20;
ulint srv_spin_wait_delay = 5;
ibool srv_priority_boost = TRUE;
-char srv_endpoint_name[COM_MAX_ADDR_LEN];
-ulint srv_n_com_threads = ULINT_MAX;
-ulint srv_n_worker_threads = ULINT_MAX;
ibool srv_print_thread_releases = FALSE;
ibool srv_print_lock_waits = FALSE;
@@ -263,14 +257,14 @@ ibool srv_print_buf_io = FALSE;
ibool srv_print_log_io = FALSE;
ibool srv_print_latch_waits = FALSE;
-ulint srv_n_rows_inserted = 0;
-ulint srv_n_rows_updated = 0;
-ulint srv_n_rows_deleted = 0;
-ulint srv_n_rows_read = 0;
-ulint srv_n_rows_inserted_old = 0;
-ulint srv_n_rows_updated_old = 0;
-ulint srv_n_rows_deleted_old = 0;
-ulint srv_n_rows_read_old = 0;
+ulint srv_n_rows_inserted = 0;
+ulint srv_n_rows_updated = 0;
+ulint srv_n_rows_deleted = 0;
+ulint srv_n_rows_read = 0;
+static ulint srv_n_rows_inserted_old = 0;
+static ulint srv_n_rows_updated_old = 0;
+static ulint srv_n_rows_deleted_old = 0;
+static ulint srv_n_rows_read_old = 0;
/*
Set the following to 0 if you want InnoDB to write messages on
@@ -630,7 +624,9 @@ srv_suspend_thread(void)
ulint slot_no;
ulint type;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
slot_no = thr_local_get_slot_no(os_thread_get_curr_id());
@@ -681,7 +677,9 @@ srv_release_threads(
ut_ad(type >= SRV_WORKER);
ut_ad(type <= SRV_MASTER);
ut_ad(n > 0);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < OS_THREAD_MAX_N; i++) {
@@ -741,924 +739,9 @@ srv_get_thread_type(void)
return(type);
}
-/***********************************************************************
-Increments by 1 the count of active threads of the type given
-and releases master thread if necessary. */
-static
-void
-srv_inc_thread_count(
-/*=================*/
- ulint type) /* in: type of the thread */
-{
- mutex_enter(&kernel_mutex);
-
- srv_activity_count++;
-
- srv_n_threads_active[type]++;
-
- if (srv_n_threads_active[SRV_MASTER] == 0) {
-
- srv_release_threads(SRV_MASTER, 1);
- }
-
- mutex_exit(&kernel_mutex);
-}
-
-/***********************************************************************
-Decrements by 1 the count of active threads of the type given. */
-static
-void
-srv_dec_thread_count(
-/*=================*/
- ulint type) /* in: type of the thread */
-
-{
- mutex_enter(&kernel_mutex);
-
- /* FIXME: the following assertion sometimes fails: */
-
- if (srv_n_threads_active[type] == 0) {
- printf("Error: thread type %lu\n", (ulong) type);
-
- ut_ad(0);
- }
-
- srv_n_threads_active[type]--;
-
- mutex_exit(&kernel_mutex);
-}
-
-/***********************************************************************
-Calculates the number of allowed utility threads for a thread to decide if
-it has to suspend itself in the thread table. */
-static
-ulint
-srv_max_n_utilities(
-/*================*/
- /* out: maximum number of allowed utilities
- of the type given */
- ulint type) /* in: utility type */
-{
- ulint ret;
-
- if (srv_n_threads_active[SRV_COM] == 0) {
- if (srv_meter[type] > srv_meter_low_water[type]) {
- return(srv_n_threads[type] / 2);
- } else {
- return(0);
- }
- } else {
-
- if (srv_meter[type] < srv_meter_foreground[type]) {
- return(0);
- }
- ret = 1 + ((srv_n_threads[type]
- * (ulint)(srv_meter[type] - srv_meter_foreground[type]))
- / (ulint)(1000 - srv_meter_foreground[type]));
- if (ret > srv_n_threads[type]) {
- return(srv_n_threads[type]);
- } else {
- return(ret);
- }
- }
-}
-
-/***********************************************************************
-Increments the utility meter by the value given and releases utility
-threads if necessary. */
-
-void
-srv_increment_meter(
-/*================*/
- ulint type, /* in: utility type */
- ulint n) /* in: value to add to meter */
-{
- ulint m;
-
- mutex_enter(&kernel_mutex);
-
- srv_meter[type] += n;
-
- m = srv_max_n_utilities(type);
-
- if (m > srv_n_threads_active[type]) {
-
- srv_release_threads(type, m - srv_n_threads_active[type]);
- }
-
- mutex_exit(&kernel_mutex);
-}
-
-/***********************************************************************
-Releases max number of utility threads if no queries are active and
-the high-water mark for the utility is exceeded. */
-
-void
-srv_release_max_if_no_queries(void)
-/*===============================*/
-{
- ulint m;
- ulint type;
-
- mutex_enter(&kernel_mutex);
-
- if (srv_n_threads_active[SRV_COM] > 0) {
- mutex_exit(&kernel_mutex);
-
- return;
- }
-
- type = SRV_RECOVERY;
-
- m = srv_n_threads[type] / 2;
-
- if ((srv_meter[type] > srv_meter_high_water[type])
- && (srv_n_threads_active[type] < m)) {
-
- srv_release_threads(type, m - srv_n_threads_active[type]);
-
- printf("Releasing max background\n");
- }
-
- mutex_exit(&kernel_mutex);
-}
-
-#ifdef notdefined
-/***********************************************************************
-Releases one utility thread if no queries are active and
-the high-water mark 2 for the utility is exceeded. */
-static
-void
-srv_release_one_if_no_queries(void)
-/*===============================*/
-{
- ulint m;
- ulint type;
-
- mutex_enter(&kernel_mutex);
-
- if (srv_n_threads_active[SRV_COM] > 0) {
- mutex_exit(&kernel_mutex);
-
- return;
- }
-
- type = SRV_RECOVERY;
-
- m = 1;
-
- if ((srv_meter[type] > srv_meter_high_water2[type])
- && (srv_n_threads_active[type] < m)) {
-
- srv_release_threads(type, m - srv_n_threads_active[type]);
-
- printf("Releasing one background\n");
- }
-
- mutex_exit(&kernel_mutex);
-}
-
-/***********************************************************************
-Decrements the utility meter by the value given and suspends the calling
-thread, which must be an utility thread of the type given, if necessary. */
-static
-void
-srv_decrement_meter(
-/*================*/
- ulint type, /* in: utility type */
- ulint n) /* in: value to subtract from meter */
-{
- ulint opt;
- os_event_t event;
-
- mutex_enter(&kernel_mutex);
-
- if (srv_meter[type] < n) {
- srv_meter[type] = 0;
- } else {
- srv_meter[type] -= n;
- }
-
- opt = srv_max_n_utilities(type);
-
- if (opt < srv_n_threads_active[type]) {
-
- event = srv_suspend_thread();
- mutex_exit(&kernel_mutex);
-
- os_event_wait(event);
- } else {
- mutex_exit(&kernel_mutex);
- }
-}
-#endif
-
-/*************************************************************************
-Implements the server console. */
-
-ulint
-srv_console(
-/*========*/
- /* out: return code, not used */
- void* arg) /* in: argument, not used */
-{
- char command[256];
-
- UT_NOT_USED(arg);
-
- mutex_enter(&kernel_mutex);
- srv_table_reserve_slot(SRV_CONSOLE);
- mutex_exit(&kernel_mutex);
-
- os_event_wait(srv_sys->operational);
-
- for (;;) {
- scanf("%s", command);
-
- srv_inc_thread_count(SRV_CONSOLE);
-
- if (command[0] == 'c') {
- printf("Making checkpoint\n");
-
- log_make_checkpoint_at(ut_dulint_max, TRUE);
-
- printf("Checkpoint completed\n");
-
- } else if (command[0] == 'd') {
- srv_sim_disk_wait_pct = atoi(command + 1);
-
- printf(
- "Starting disk access simulation with pct %lu\n",
- (ulong) srv_sim_disk_wait_pct);
- } else {
- printf("\nNot supported!\n");
- }
-
- srv_dec_thread_count(SRV_CONSOLE);
- }
-
- return(0); /* Not reached */
-}
-
-/*************************************************************************
-Creates the first communication endpoint for the server. This
-first call also initializes the com0com.* module. */
-
-void
-srv_communication_init(
-/*===================*/
- char* endpoint) /* in: server address */
-{
- ulint ret;
- ulint len;
-
- srv_sys->endpoint = com_endpoint_create(COM_SHM);
-
- ut_a(srv_sys->endpoint);
-
- len = ODBC_DATAGRAM_SIZE;
-
- ret = com_endpoint_set_option(srv_sys->endpoint,
- COM_OPT_MAX_DGRAM_SIZE,
- (byte*)&len, sizeof(ulint));
- ut_a(ret == 0);
-
- ret = com_bind(srv_sys->endpoint, endpoint, ut_strlen(endpoint));
-
- ut_a(ret == 0);
-}
-
-#ifdef notdefined
-
-/*************************************************************************
-Implements the recovery utility. */
-static
-ulint
-srv_recovery_thread(
-/*================*/
- /* out: return code, not used */
- void* arg) /* in: not used */
-{
- ulint slot_no;
- os_event_t event;
-
- UT_NOT_USED(arg);
-
- slot_no = srv_table_reserve_slot(SRV_RECOVERY);
-
- os_event_wait(srv_sys->operational);
-
- for (;;) {
- /* Finish a possible recovery */
-
- srv_inc_thread_count(SRV_RECOVERY);
-
-/* recv_recovery_from_checkpoint_finish(); */
-
- srv_dec_thread_count(SRV_RECOVERY);
-
- mutex_enter(&kernel_mutex);
- event = srv_suspend_thread();
- mutex_exit(&kernel_mutex);
-
- /* Wait for somebody to release this thread; (currently, this
- should never be released) */
-
- os_event_wait(event);
- }
-
- return(0);
-}
-
-/*************************************************************************
-Implements the purge utility. */
-
-ulint
-srv_purge_thread(
-/*=============*/
- /* out: return code, not used */
- void* arg) /* in: not used */
-{
- UT_NOT_USED(arg);
-
- os_event_wait(srv_sys->operational);
-
- for (;;) {
- trx_purge();
- }
-
- return(0);
-}
-#endif /* notdefined */
-
-/*************************************************************************
-Creates the utility threads. */
-
-void
-srv_create_utility_threads(void)
-/*============================*/
-{
-/* os_thread_t thread;
- os_thread_id_t thr_id; */
- ulint i;
-
- mutex_enter(&kernel_mutex);
-
- srv_n_threads[SRV_RECOVERY] = 1;
- srv_n_threads_active[SRV_RECOVERY] = 1;
-
- mutex_exit(&kernel_mutex);
-
- for (i = 0; i < 1; i++) {
- /* thread = os_thread_create(srv_recovery_thread, NULL, &thr_id); */
-
- /* ut_a(thread); */
- }
-
-/* thread = os_thread_create(srv_purge_thread, NULL, &thr_id);
-
- ut_a(thread); */
-}
-
-#ifdef notdefined
-/*************************************************************************
-Implements the communication threads. */
-static
-ulint
-srv_com_thread(
-/*===========*/
- /* out: return code; not used */
- void* arg) /* in: not used */
-{
- byte* msg_buf;
- byte* addr_buf;
- ulint msg_len;
- ulint addr_len;
- ulint ret;
-
- UT_NOT_USED(arg);
-
- srv_table_reserve_slot(SRV_COM);
-
- os_event_wait(srv_sys->operational);
-
- msg_buf = mem_alloc(com_endpoint_get_max_size(srv_sys->endpoint));
- addr_buf = mem_alloc(COM_MAX_ADDR_LEN);
-
- for (;;) {
- ret = com_recvfrom(srv_sys->endpoint, msg_buf,
- com_endpoint_get_max_size(srv_sys->endpoint),
- &msg_len, (char*)addr_buf, COM_MAX_ADDR_LEN,
- &addr_len);
- ut_a(ret == 0);
-
- srv_inc_thread_count(SRV_COM);
-
- sess_process_cli_msg(msg_buf, msg_len, addr_buf, addr_len);
-
-/* srv_increment_meter(SRV_RECOVERY, 1); */
-
- srv_dec_thread_count(SRV_COM);
-
- /* Release one utility thread for each utility if
- high water mark 2 is exceeded and there are no
- active queries. This is done to utilize possible
- quiet time in the server. */
-
- srv_release_one_if_no_queries();
- }
-
- return(0);
-}
-#endif
-
-/*************************************************************************
-Creates the communication threads. */
-
-void
-srv_create_com_threads(void)
-/*========================*/
-{
- /* os_thread_t thread;
- os_thread_id_t thr_id; */
- ulint i;
-
- srv_n_threads[SRV_COM] = srv_n_com_threads;
-
- for (i = 0; i < srv_n_com_threads; i++) {
- /* thread = os_thread_create(srv_com_thread, NULL, &thr_id); */
- /* ut_a(thread); */
- }
-}
-
-#ifdef notdefined
-/*************************************************************************
-Implements the worker threads. */
-static
-ulint
-srv_worker_thread(
-/*==============*/
- /* out: return code, not used */
- void* arg) /* in: not used */
-{
- os_event_t event;
-
- UT_NOT_USED(arg);
-
- srv_table_reserve_slot(SRV_WORKER);
-
- os_event_wait(srv_sys->operational);
-
- for (;;) {
- mutex_enter(&kernel_mutex);
- event = srv_suspend_thread();
- mutex_exit(&kernel_mutex);
-
- /* Wait for somebody to release this thread */
- os_event_wait(event);
-
- srv_inc_thread_count(SRV_WORKER);
-
- /* Check in the server task queue if there is work for this
- thread, and do the work */
-
- srv_que_task_queue_check();
-
- srv_dec_thread_count(SRV_WORKER);
-
- /* Release one utility thread for each utility if
- high water mark 2 is exceeded and there are no
- active queries. This is done to utilize possible
- quiet time in the server. */
-
- srv_release_one_if_no_queries();
- }
-
- return(0);
-}
-#endif
-
-/*************************************************************************
-Creates the worker threads. */
-
-void
-srv_create_worker_threads(void)
-/*===========================*/
-{
-/* os_thread_t thread;
- os_thread_id_t thr_id; */
- ulint i;
-
- srv_n_threads[SRV_WORKER] = srv_n_worker_threads;
- srv_n_threads_active[SRV_WORKER] = srv_n_worker_threads;
-
- for (i = 0; i < srv_n_worker_threads; i++) {
- /* thread = os_thread_create(srv_worker_thread, NULL, &thr_id); */
- /* ut_a(thread); */
- }
-}
-
-#ifdef notdefined
-/*************************************************************************
-Reads a keyword and a value from a file. */
-
-ulint
-srv_read_init_val(
-/*==============*/
- /* out: DB_SUCCESS or error code */
- FILE* initfile, /* in: file pointer */
- char* keyword, /* in: keyword before value(s), or NULL if
- no keyword read */
- char* str_buf, /* in/out: buffer for a string value to read,
- buffer size must be 10000 bytes, if NULL
- then not read */
- ulint* num_val, /* out: numerical value to read, if NULL
- then not read */
- ibool print_not_err) /* in: if TRUE, then we will not print
- error messages to console */
-{
- ulint ret;
- char scan_buf[10000];
-
- if (keyword == NULL) {
-
- goto skip_keyword;
- }
-
- ret = fscanf(initfile, "%9999s", scan_buf);
-
- if (ret == 0 || ret == EOF || 0 != ut_strcmp(scan_buf, keyword)) {
- if (print_not_err) {
-
- return(DB_ERROR);
- }
-
- printf("Error in InnoDB booting: keyword %s not found\n",
- keyword);
- printf("from the initfile!\n");
-
- return(DB_ERROR);
- }
-skip_keyword:
- if (num_val == NULL && str_buf == NULL) {
-
- return(DB_SUCCESS);
- }
-
- ret = fscanf(initfile, "%9999s", scan_buf);
-
- if (ret == EOF || ret == 0) {
- if (print_not_err) {
-
- return(DB_ERROR);
- }
-
- printf(
- "Error in InnoDB booting: could not read first value after %s\n",
- keyword);
- printf("from the initfile!\n");
-
- return(DB_ERROR);
- }
-
- if (str_buf) {
- ut_memcpy(str_buf, scan_buf, 10000);
-
- printf("init keyword %s value %s read\n", keyword, str_buf);
-
- if (!num_val) {
- return(DB_SUCCESS);
- }
-
- ret = fscanf(initfile, "%9999s", scan_buf);
-
- if (ret == EOF || ret == 0) {
-
- if (print_not_err) {
-
- return(DB_ERROR);
- }
-
- printf(
- "Error in InnoDB booting: could not read second value after %s\n",
- keyword);
- printf("from the initfile!\n");
-
- return(DB_ERROR);
- }
- }
-
- if (ut_strlen(scan_buf) > 9) {
-
- if (print_not_err) {
-
- return(DB_ERROR);
- }
-
- printf(
- "Error in InnoDB booting: numerical value too big after %s\n",
- keyword);
- printf("in the initfile!\n");
-
- return(DB_ERROR);
- }
-
- *num_val = (ulint)atoi(scan_buf);
-
- if (*num_val >= 1000000000) {
-
- if (print_not_err) {
-
- return(DB_ERROR);
- }
-
- printf(
- "Error in InnoDB booting: numerical value too big after %s\n",
- keyword);
- printf("in the initfile!\n");
-
- return(DB_ERROR);
- }
-
- printf("init keyword %s value %lu read\n", keyword, *num_val);
-
- return(DB_SUCCESS);
-}
-
-/*************************************************************************
-Reads keywords and values from an initfile. */
-
-ulint
-srv_read_initfile(
-/*==============*/
- /* out: DB_SUCCESS or error code */
- FILE* initfile) /* in: file pointer */
-{
- char str_buf[10000];
- ulint n;
- ulint i;
- ulint ulint_val;
- ulint val1;
- ulint val2;
- ulint err;
-
- err = srv_read_init_val(initfile, "INNOBASE_DATA_HOME_DIR",
- str_buf, NULL, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_data_home = ut_malloc(ut_strlen(str_buf) + 1);
- ut_memcpy(srv_data_home, str_buf, ut_strlen(str_buf) + 1);
-
- err = srv_read_init_val(initfile,"TABLESPACE_NUMBER_OF_DATA_FILES",
- NULL, &n, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_n_data_files = n;
-
- srv_data_file_names = ut_malloc(n * sizeof(char*));
- srv_data_file_sizes = ut_malloc(n * sizeof(ulint));
-
- for (i = 0; i < n; i++) {
- err = srv_read_init_val(initfile,
- "DATA_FILE_PATH_AND_SIZE_MB",
- str_buf, &ulint_val, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_data_file_names[i] = ut_malloc(ut_strlen(str_buf) + 1);
- ut_memcpy(srv_data_file_names[i], str_buf,
- ut_strlen(str_buf) + 1);
- srv_data_file_sizes[i] = ulint_val
- * ((1024 * 1024) / UNIV_PAGE_SIZE);
- }
-
- err = srv_read_init_val(initfile,
- "NUMBER_OF_MIRRORED_LOG_GROUPS", NULL,
- &srv_n_log_groups, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- err = srv_read_init_val(initfile,
- "NUMBER_OF_LOG_FILES_IN_GROUP", NULL,
- &srv_n_log_files, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- err = srv_read_init_val(initfile, "LOG_FILE_SIZE_KB", NULL,
- &srv_log_file_size, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_log_file_size = srv_log_file_size / (UNIV_PAGE_SIZE / 1024);
-
- srv_log_group_home_dirs = ut_malloc(srv_n_log_files * sizeof(char*));
-
- for (i = 0; i < srv_n_log_groups; i++) {
-
- err = srv_read_init_val(initfile,
- "INNOBASE_LOG_GROUP_HOME_DIR",
- str_buf, NULL, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_log_group_home_dirs[i] = ut_malloc(ut_strlen(str_buf) + 1);
- ut_memcpy(srv_log_group_home_dirs[i], str_buf,
- ut_strlen(str_buf) + 1);
- }
-
- err = srv_read_init_val(initfile, "INNOBASE_LOG_ARCH_DIR",
- str_buf, NULL, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_arch_dir = ut_malloc(ut_strlen(str_buf) + 1);
- ut_memcpy(srv_arch_dir, str_buf, ut_strlen(str_buf) + 1);
-
- err = srv_read_init_val(initfile, "LOG_ARCHIVE_ON(1/0)", NULL,
- &srv_log_archive_on, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- err = srv_read_init_val(initfile, "LOG_BUFFER_SIZE_KB", NULL,
- &srv_log_buffer_size, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_log_buffer_size = srv_log_buffer_size / (UNIV_PAGE_SIZE / 1024);
-
- err = srv_read_init_val(initfile, "FLUSH_LOG_AT_TRX_COMMIT(1/0)", NULL,
- &srv_flush_log_at_trx_commit, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- err = srv_read_init_val(initfile, "BUFFER_POOL_SIZE_MB", NULL,
- &srv_pool_size, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_pool_size = srv_pool_size * ((1024 * 1024) / UNIV_PAGE_SIZE);
-
- err = srv_read_init_val(initfile, "ADDITIONAL_MEM_POOL_SIZE_MB", NULL,
- &srv_mem_pool_size, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- srv_mem_pool_size = srv_mem_pool_size * 1024 * 1024;
-
- srv_lock_table_size = 20 * srv_pool_size;
-
- err = srv_read_init_val(initfile, "NUMBER_OF_FILE_IO_THREADS", NULL,
- &srv_n_file_io_threads, FALSE);
- if (err != DB_SUCCESS) return(err);
-
- err = srv_read_init_val(initfile, "SRV_RECOVER_FROM_BACKUP",
- NULL, NULL, TRUE);
- if (err == DB_SUCCESS) {
- srv_archive_recovery = TRUE;
- srv_archive_recovery_limit_lsn = ut_dulint_max;
-
- err = srv_read_init_val(initfile, NULL, NULL, &val1, TRUE);
- err = srv_read_init_val(initfile, NULL, NULL, &val2, TRUE);
-
- if (err == DB_SUCCESS) {
- srv_archive_recovery_limit_lsn =
- ut_dulint_create(val1, val2);
- }
- }
-
- /* err = srv_read_init_val(initfile,
- "SYNC_NUMBER_OF_SPIN_WAIT_ROUNDS", NULL,
- &srv_n_spin_wait_rounds);
-
- err = srv_read_init_val(initfile, "SYNC_SPIN_WAIT_DELAY", NULL,
- &srv_spin_wait_delay); */
- return(DB_SUCCESS);
-}
-
-/*************************************************************************
-Reads keywords and a values from an initfile. In case of an error, exits
-from the process. */
-
-void
-srv_read_initfile(
-/*==============*/
- FILE* initfile) /* in: file pointer */
-{
- char str_buf[10000];
- ulint ulint_val;
-
- srv_read_init_val(initfile, FALSE, "SRV_ENDPOINT_NAME", str_buf,
- &ulint_val);
- ut_a(ut_strlen(str_buf) < COM_MAX_ADDR_LEN);
-
- ut_memcpy(srv_endpoint_name, str_buf, COM_MAX_ADDR_LEN);
-
- srv_read_init_val(initfile, TRUE, "SRV_N_COM_THREADS", str_buf,
- &srv_n_com_threads);
-
- srv_read_init_val(initfile, TRUE, "SRV_N_WORKER_THREADS", str_buf,
- &srv_n_worker_threads);
-
- srv_read_init_val(initfile, TRUE, "SYNC_N_SPIN_WAIT_ROUNDS", str_buf,
- &srv_n_spin_wait_rounds);
-
- srv_read_init_val(initfile, TRUE, "SYNC_SPIN_WAIT_DELAY", str_buf,
- &srv_spin_wait_delay);
-
- srv_read_init_val(initfile, TRUE, "THREAD_PRIORITY_BOOST", str_buf,
- &srv_priority_boost);
-
- srv_read_init_val(initfile, TRUE, "N_SPACES", str_buf, &srv_n_spaces);
- srv_read_init_val(initfile, TRUE, "N_FILES", str_buf, &srv_n_files);
- srv_read_init_val(initfile, TRUE, "FILE_SIZE", str_buf,
- &srv_file_size);
-
- srv_read_init_val(initfile, TRUE, "N_LOG_GROUPS", str_buf,
- &srv_n_log_groups);
- srv_read_init_val(initfile, TRUE, "N_LOG_FILES", str_buf,
- &srv_n_log_files);
- srv_read_init_val(initfile, TRUE, "LOG_FILE_SIZE", str_buf,
- &srv_log_file_size);
- srv_read_init_val(initfile, TRUE, "LOG_ARCHIVE_ON", str_buf,
- &srv_log_archive_on);
- srv_read_init_val(initfile, TRUE, "LOG_BUFFER_SIZE", str_buf,
- &srv_log_buffer_size);
- srv_read_init_val(initfile, TRUE, "FLUSH_LOG_AT_TRX_COMMIT", str_buf,
- &srv_flush_log_at_trx_commit);
-
-
- srv_read_init_val(initfile, TRUE, "POOL_SIZE", str_buf,
- &srv_pool_size);
- srv_read_init_val(initfile, TRUE, "MEM_POOL_SIZE", str_buf,
- &srv_mem_pool_size);
- srv_read_init_val(initfile, TRUE, "LOCK_TABLE_SIZE", str_buf,
- &srv_lock_table_size);
-
- srv_read_init_val(initfile, TRUE, "SIM_DISK_WAIT_PCT", str_buf,
- &srv_sim_disk_wait_pct);
-
- srv_read_init_val(initfile, TRUE, "SIM_DISK_WAIT_LEN", str_buf,
- &srv_sim_disk_wait_len);
-
- srv_read_init_val(initfile, TRUE, "SIM_DISK_WAIT_BY_YIELD", str_buf,
- &srv_sim_disk_wait_by_yield);
-
- srv_read_init_val(initfile, TRUE, "SIM_DISK_WAIT_BY_WAIT", str_buf,
- &srv_sim_disk_wait_by_wait);
-
- srv_read_init_val(initfile, TRUE, "MEASURE_CONTENTION", str_buf,
- &srv_measure_contention);
-
- srv_read_init_val(initfile, TRUE, "MEASURE_BY_SPIN", str_buf,
- &srv_measure_by_spin);
-
-
- srv_read_init_val(initfile, TRUE, "PRINT_THREAD_RELEASES", str_buf,
- &srv_print_thread_releases);
-
- srv_read_init_val(initfile, TRUE, "PRINT_LOCK_WAITS", str_buf,
- &srv_print_lock_waits);
- if (srv_print_lock_waits) {
- lock_print_waits = TRUE;
- }
-
- srv_read_init_val(initfile, TRUE, "PRINT_BUF_IO", str_buf,
- &srv_print_buf_io);
- if (srv_print_buf_io) {
- buf_debug_prints = TRUE;
- }
-
- srv_read_init_val(initfile, TRUE, "PRINT_LOG_IO", str_buf,
- &srv_print_log_io);
- if (srv_print_log_io) {
- log_debug_writes = TRUE;
- }
-
- srv_read_init_val(initfile, TRUE, "PRINT_PARSED_SQL", str_buf,
- &srv_print_parsed_sql);
- if (srv_print_parsed_sql) {
- pars_print_lexed = TRUE;
- }
-
- srv_read_init_val(initfile, TRUE, "PRINT_LATCH_WAITS", str_buf,
- &srv_print_latch_waits);
-
- srv_read_init_val(initfile, TRUE, "TEST_EXTRA_MUTEXES", str_buf,
- &srv_test_extra_mutexes);
- srv_read_init_val(initfile, TRUE, "TEST_NOCACHE", str_buf,
- &srv_test_nocache);
- srv_read_init_val(initfile, TRUE, "TEST_CACHE_EVICT", str_buf,
- &srv_test_cache_evict);
-
- srv_read_init_val(initfile, TRUE, "TEST_SYNC", str_buf,
- &srv_test_sync);
- srv_read_init_val(initfile, TRUE, "TEST_N_THREADS", str_buf,
- &srv_test_n_threads);
- srv_read_init_val(initfile, TRUE, "TEST_N_LOOPS", str_buf,
- &srv_test_n_loops);
- srv_read_init_val(initfile, TRUE, "TEST_N_FREE_RNDS", str_buf,
- &srv_test_n_free_rnds);
- srv_read_init_val(initfile, TRUE, "TEST_N_RESERVED_RNDS", str_buf,
- &srv_test_n_reserved_rnds);
- srv_read_init_val(initfile, TRUE, "TEST_N_MUTEXES", str_buf,
- &srv_test_n_mutexes);
- srv_read_init_val(initfile, TRUE, "TEST_ARRAY_SIZE", str_buf,
- &srv_test_array_size);
-}
-#endif
-
/*************************************************************************
Initializes the server. */
-
+static
void
srv_init(void)
/*==========*/
@@ -2100,7 +1183,9 @@ srv_table_reserve_slot_for_mysql(void)
srv_slot_t* slot;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
i = 0;
slot = srv_mysql_table + i;
@@ -2130,7 +1215,7 @@ srv_table_reserve_slot_for_mysql(void)
(ulong) difftime(ut_time(), slot->suspend_time));
}
- ut_a(0);
+ ut_error;
}
slot = srv_mysql_table + i;
@@ -2165,7 +1250,9 @@ srv_suspend_mysql_thread(
ibool had_dict_lock = FALSE;
ibool was_declared_inside_innodb = FALSE;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
trx = thr_get_trx(thr);
@@ -2284,7 +1371,9 @@ srv_release_mysql_thread_if_suspended(
srv_slot_t* slot;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
for (i = 0; i < OS_THREAD_MAX_N; i++) {
@@ -2380,6 +1469,13 @@ srv_sprintf_innodb_monitor(
buf = buf + strlen(buf);
ut_a(buf < buf_end + 1500);
+ /* Conceptually, srv_innodb_monitor_mutex has a very high latching
+ order level in sync0sync.h, while dict_foreign_err_mutex has a very
+ low level 135. Therefore we can reserve the latter mutex here without
+ a danger of a deadlock of threads. */
+
+ mutex_enter(&dict_foreign_err_mutex);
+
if (*dict_foreign_err_buf != '\0') {
buf += sprintf(buf,
"------------------------\n"
@@ -2391,18 +1487,7 @@ srv_sprintf_innodb_monitor(
}
}
- ut_a(buf < buf_end + 1500);
-
- if (*dict_unique_err_buf != '\0') {
- buf += sprintf(buf,
-"---------------------------------------------------------------\n"
-"LATEST UNIQUE KEY ERROR (is masked in REPLACE or INSERT IGNORE)\n"
-"---------------------------------------------------------------\n");
-
- if (buf_end - buf > 6000) {
- buf+= sprintf(buf, "%.4000s", dict_unique_err_buf);
- }
- }
+ mutex_exit(&dict_foreign_err_mutex);
ut_a(buf < buf_end + 1500);
@@ -2448,7 +1533,7 @@ srv_sprintf_innodb_monitor(
"----------------------\n");
buf += sprintf(buf,
"Total memory allocated " ULINTPF
- "; in additional pool allocated" ULINTPF "\n",
+ "; in additional pool allocated " ULINTPF "\n",
ut_total_allocated_memory,
mem_pool_get_reserved(mem_comm_pool));
@@ -2486,13 +1571,13 @@ srv_sprintf_innodb_monitor(
#ifdef UNIV_LINUX
buf += sprintf(buf,
- "Main thread process no. %lu, id %lu, state: %s\n",
+ "Main thread process no. %lu, id %lu, state: %.29s\n",
(ulong) srv_main_thread_process_no,
(ulong) srv_main_thread_id,
srv_main_thread_op_info);
#else
buf += sprintf(buf,
- "Main thread id %lu, state: %s\n",
+ "Main thread id %lu, state: %.29s\n",
(ulong) srv_main_thread_id,
srv_main_thread_op_info);
#endif
@@ -2765,13 +1850,6 @@ loop:
srv_refresh_innodb_monitor_stats();
}
-/* mem_print_new_info();
-
- if (cnt % 10 == 0) {
-
- mem_print_info();
- }
-*/
sync_array_print_long_waits();
/* Flush stdout and stderr so that a database user gets their output
@@ -3244,12 +2322,6 @@ flush_loop:
goto background_loop;
}
-/* mem_print_new_info();
- */
-
-#ifdef UNIV_SEARCH_PERF_STAT
-/* btr_search_print_info(); */
-#endif
/* There is no work for background operations either: suspend
master thread to wait for more server activity */
diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c
index e6fdc95fad0..7b50877709b 100644
--- a/innobase/srv/srv0start.c
+++ b/innobase/srv/srv0start.c
@@ -40,7 +40,6 @@ Created 2/16/1996 Heikki Tuuri
#include "rem0rec.h"
#include "srv0srv.h"
#include "que0que.h"
-#include "com0com.h"
#include "usr0sess.h"
#include "lock0lock.h"
#include "trx0roll.h"
@@ -447,9 +446,9 @@ io_handler_thread(
}
#ifdef __WIN__
-#define SRV_PATH_SEPARATOR "\\"
+#define SRV_PATH_SEPARATOR '\\'
#else
-#define SRV_PATH_SEPARATOR "/"
+#define SRV_PATH_SEPARATOR '/'
#endif
/*************************************************************************
@@ -477,31 +476,26 @@ srv_normalize_path_for_win(
Adds a slash or a backslash to the end of a string if it is missing
and the string is not empty. */
+static
char*
srv_add_path_separator_if_needed(
/*=============================*/
- /* out, own: string which has the separator if the
+ /* out: string which has the separator if the
string is not empty */
char* str) /* in: null-terminated character string */
{
char* out_str;
+ ulint len = ut_strlen(str);
- if (ut_strlen(str) == 0) {
+ if (len == 0 || str[len - 1] == SRV_PATH_SEPARATOR) {
return(str);
}
- if (str[ut_strlen(str) - 1] == SRV_PATH_SEPARATOR[0]) {
- out_str = ut_malloc(ut_strlen(str) + 1);
-
- sprintf(out_str, "%s", str);
-
- return(out_str);
- }
-
- out_str = ut_malloc(ut_strlen(str) + 2);
-
- sprintf(out_str, "%s%s", str, SRV_PATH_SEPARATOR);
+ out_str = ut_malloc(len + 2);
+ memcpy(out_str, str, len);
+ out_str[len] = SRV_PATH_SEPARATOR;
+ out_str[len + 1] = 0;
return(out_str);
}
@@ -908,80 +902,6 @@ skip_size_check:
return(DB_SUCCESS);
}
-#ifdef notdefined
-/*********************************************************************
-This thread is used to measure contention of latches. */
-static
-ulint
-test_measure_cont(
-/*==============*/
- void* arg)
-{
- ulint i, j;
- ulint pcount, kcount, s_scount, s_xcount, s_mcount, lcount;
-
- UT_NOT_USED(arg);
-
- fprintf(stderr, "Starting contention measurement\n");
-
- for (i = 0; i < 1000; i++) {
-
- pcount = 0;
- kcount = 0;
- s_scount = 0;
- s_xcount = 0;
- s_mcount = 0;
- lcount = 0;
-
- for (j = 0; j < 100; j++) {
-
- if (srv_measure_by_spin) {
- ut_delay(ut_rnd_interval(0, 20000));
- } else {
- os_thread_sleep(20000);
- }
-
- if (kernel_mutex.lock_word) {
- kcount++;
- }
-
- if (buf_pool->mutex.lock_word) {
- pcount++;
- }
-
- if (log_sys->mutex.lock_word) {
- lcount++;
- }
-
- if (btr_search_latch.reader_count) {
- s_scount++;
- }
-
- if (btr_search_latch.writer != RW_LOCK_NOT_LOCKED) {
- s_xcount++;
- }
-
- if (btr_search_latch.mutex.lock_word) {
- s_mcount++;
- }
- }
-
- fprintf(stderr,
- "Mutex res. l %lu, p %lu, k %lu s x %lu s s %lu s mut %lu of %lu\n",
- lcount, pcount, kcount, s_xcount, s_scount, s_mcount, j);
-
-/* sync_print_wait_info(); */
-
- fprintf(stderr,
- "log i/o %lu n non sea %lu n succ %lu n h fail %lu\n",
- log_sys->n_log_ios, btr_cur_n_non_sea,
- btr_search_n_succ, btr_search_n_hash_fail);
- }
-
- return(0);
-}
-#endif
-
/********************************************************************
Starts InnoDB and creates a new database if database files
are not found and the user wants. Server parameters are
@@ -1379,8 +1299,6 @@ NetWare. */
mutex_exit(&(log_sys->mutex));
}
- sess_sys_init_at_db_start();
-
if (create_new_db) {
mtr_start(&mtr);
diff --git a/innobase/srv/ts/makefile b/innobase/srv/ts/makefile
deleted file mode 100644
index 0b743e37a20..00000000000
--- a/innobase/srv/ts/makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tssrv: ..\srv.lib tssrv.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\srv.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\btr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tssrv.c $(LFL)
-
-
-
-
-
-
-
-
diff --git a/innobase/srv/ts/tsdbc.c b/innobase/srv/ts/tsdbc.c
deleted file mode 100644
index 83ba081959d..00000000000
--- a/innobase/srv/ts/tsdbc.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/************************************************************************
-Database client test program
-
-(c) 1995 Innobase Oy
-
-Created 10/10/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "com0com.h"
-#include "com0shm.h"
-#include "ut0ut.h"
-#include "mem0mem.h"
-#include "os0thread.h"
-#include "sync0ipm.h"
-#include "sync0sync.h"
-
-byte buf[10000];
-char addr[150];
-
-void
-test1(void)
-/*=======*/
-{
- com_endpoint_t* ep;
- ulint ret;
- ulint size;
- ulint len;
- ulint addr_len;
- ulint i, j;
- ulint tm, oldtm;
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000; i++) {
-
- ut_delay(100);
- }
-
- for (j = 0; j < i / 10; j++) {
-
- ut_delay(200);
- }
-
- tm = ut_clock();
- printf("Wall clock time for test without server %ld milliseconds\n",
- tm - oldtm);
- printf("%lu rounds\n", i);
-
- ep = com_endpoint_create(COM_SHM);
-
- ut_a(ep);
-
- size = 8192;
-
- ret = com_endpoint_set_option(ep, COM_OPT_MAX_DGRAM_SIZE,
- (byte*)&size, 0);
-
- ut_a(ret == 0);
-
- ret = com_bind(ep, "CLI", 3);
-
- ut_a(ret == 0);
-
- printf("Client endpoint created!\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 50000; i++) {
-
- ret = com_sendto(ep, (byte*)"Hello from client!\n", 18, "ibsrv", 5);
-
- ut_a(ret == 0);
-
- ret = com_recvfrom(ep, buf, 10000, &len, addr, 150, &addr_len);
-
- ut_a(ret == 0);
-
- buf[len] = '\0';
- addr[addr_len] = '\0';
-/*
- printf(
- "Message of len %lu\n%s \nreceived from address %s of len %lu\n",
- len, buf, addr, addr_len);
-*/
- }
-
-
- tm = ut_clock();
- printf("Wall clock time for test %ld milliseconds\n", tm - oldtm);
- printf("%lu message pairs\n", i);
-
-
- printf("System calls in com_shm %lu ip_mutex %lu mutex %lu\n",
- com_shm_system_call_count,
- ip_mutex_system_call_count,
- mutex_system_call_count);
-
-
- ret = com_endpoint_free(ep);
-
- ut_ad(ret == 0);
-}
-
-void
-main(void)
-/*======*/
-{
-
-
-
- sync_init();
- mem_init();
-
- test1();
-
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/srv/ts/tssrv.c b/innobase/srv/ts/tssrv.c
deleted file mode 100644
index 92b98c4554e..00000000000
--- a/innobase/srv/ts/tssrv.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/******************************************************
-Test for the database server
-
-(c) 1995 Innobase Oy
-
-Created 10/10/1995 Heikki Tuuri
-*******************************************************/
-
-#include "srv0srv.h"
-#include "os0proc.h"
-#include "ut0mem.h"
-
-
-/***************************************************************************
-The main function of the server. */
-
-void
-main(
-/*=*/
-#ifdef notdefined
-
- ulint argc, /* in: number of string arguments given on
- the command line */
- char* argv[]
-#endif
-) /* in: array of character pointers giving
- the arguments */
-{
-/*
- if (argc != 2) {
- printf("Error! Wrong number of command line arguments!\n");
- printf("Usage: ib <init-file-name>\n");
- os_process_exit(1);
- }
-*/
- srv_boot("init.ib"/*argv[1]*/);
-
- os_process_exit(0);
-}
diff --git a/innobase/sync/sync0arr.c b/innobase/sync/sync0arr.c
index 9bcee34a7d1..8082f598b0c 100644
--- a/innobase/sync/sync0arr.c
+++ b/innobase/sync/sync0arr.c
@@ -14,6 +14,7 @@ Created 9/5/1995 Heikki Tuuri
#include "sync0sync.h"
#include "sync0rw.h"
#include "os0sync.h"
+#include "os0file.h"
#include "srv0srv.h"
/*
@@ -99,6 +100,7 @@ struct sync_array_struct {
since creation of the array */
};
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
This function is called only in the debug version. Detects a deadlock
of one or more threads because of waits of semaphores. */
@@ -112,6 +114,7 @@ sync_array_detect_deadlock(
sync_cell_t* start, /* in: cell where recursive search started */
sync_cell_t* cell, /* in: cell to search */
ulint depth); /* in: recursion depth */
+#endif /* UNIV_SYNC_DEBUG */
/*********************************************************************
Gets the nth cell in array. */
@@ -464,13 +467,17 @@ sync_array_cell_print(
mutex = cell->old_wait_mutex;
buf += sprintf(buf,
- "Mutex at %lx created file %s line %lu, lock var %lu\n",
- (ulong) mutex, mutex->cfile_name,
- (ulong) mutex->cline, (ulong) mutex->lock_word);
- buf += sprintf(buf,
- "Last time reserved in file %s line %lu, waiters flag %lu\n",
- mutex->file_name, (ulong) mutex->line,
- (ulong) mutex->waiters);
+ "Mutex at %p created file %s line %lu, lock var %lu\n"
+#ifdef UNIV_SYNC_DEBUG
+ "Last time reserved in file %s line %lu, "
+#endif /* UNIV_SYNC_DEBUG */
+ "waiters flag %lu\n",
+ mutex, mutex->cfile_name, (ulong) mutex->cline,
+ (ulong) mutex->lock_word,
+#ifdef UNIV_SYNC_DEBUG
+ mutex->file_name, (ulong) mutex->line,
+#endif /* UNIV_SYNC_DEBUG */
+ (ulong) mutex->waiters);
} else if (type == RW_LOCK_EX || type == RW_LOCK_SHARED) {
@@ -522,6 +529,7 @@ sync_array_cell_print(
}
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Looks for a cell with the given thread id. */
static
@@ -693,7 +701,6 @@ sync_array_detect_deadlock(
sync_array_cell_print(buf, cell);
printf("rw-lock %lx %s ", (ulong) lock, buf);
rw_lock_debug_print(debug);
-
return(TRUE);
}
}
@@ -743,6 +750,7 @@ sync_array_detect_deadlock(
return(TRUE); /* Execution never reaches this line: for compiler
fooling only */
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Determines if we can wake up the thread waiting for a sempahore. */
@@ -936,7 +944,7 @@ sync_array_print_long_waits(void)
"InnoDB: We intentionally crash the server, because it appears to be hung.\n"
);
- ut_a(0);
+ ut_error;
}
}
@@ -945,6 +953,16 @@ sync_array_print_long_waits(void)
"InnoDB: ###### Starts InnoDB Monitor for 30 secs to print diagnostic info:\n");
old_val = srv_print_innodb_monitor;
+ /* If some crucial semaphore is reserved, then also the InnoDB
+ Monitor can hang, and we do not get diagnostics. Since in
+ many cases an InnoDB hang is caused by a pwrite() or a pread()
+ call hanging inside the operating system, let us print right
+ now the values of pending calls of these. */
+
+ fprintf(stderr,
+"InnoDB: Pending preads %lu, pwrites %lu\n", (ulong)os_file_n_pending_preads,
+ (ulong)os_file_n_pending_pwrites);
+
srv_print_innodb_monitor = TRUE;
os_event_set(srv_lock_timeout_thread_event);
diff --git a/innobase/sync/sync0rw.c b/innobase/sync/sync0rw.c
index f552af1d1f0..93fd9f14575 100644
--- a/innobase/sync/sync0rw.c
+++ b/innobase/sync/sync0rw.c
@@ -31,6 +31,7 @@ ulint rw_x_exit_count = 0;
rw_lock_list_t rw_lock_list;
mutex_t rw_lock_list_mutex;
+#ifdef UNIV_SYNC_DEBUG
/* The global mutex which protects debug info lists of all rw-locks.
To modify the debug info list of an rw-lock, this mutex has to be
acquired in addition to the mutex protecting the lock. */
@@ -76,6 +77,7 @@ rw_lock_debug_free(
{
mem_free(info);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Creates, or rather, initializes an rw-lock object in a specified memory
@@ -107,10 +109,12 @@ rw_lock_create_func(
lock->writer_is_wait_ex = FALSE;
+#ifdef UNIV_SYNC_DEBUG
UT_LIST_INIT(lock->debug_list);
- lock->magic_n = RW_LOCK_MAGIC_N;
lock->level = SYNC_LEVEL_NONE;
+#endif /* UNIV_SYNC_DEBUG */
+ lock->magic_n = RW_LOCK_MAGIC_N;
lock->cfile_name = cfile_name;
lock->cline = cline;
@@ -319,8 +323,9 @@ rw_lock_x_lock_low(
char* file_name,/* in: file name where lock requested */
ulint line) /* in: line where requested */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(rw_lock_get_mutex(lock)));
-
+#endif /* UNIV_SYNC_DEBUG */
if (rw_lock_get_writer(lock) == RW_LOCK_NOT_LOCKED) {
if (rw_lock_get_reader_count(lock) == 0) {
@@ -330,10 +335,10 @@ rw_lock_x_lock_low(
lock->writer_count++;
lock->pass = pass;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, pass, RW_LOCK_EX,
file_name, line);
- #endif
+#endif
lock->last_x_file_name = file_name;
lock->last_x_line = line;
@@ -346,10 +351,10 @@ rw_lock_x_lock_low(
lock->pass = pass;
lock->writer_is_wait_ex = TRUE;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, pass, RW_LOCK_WAIT_EX,
file_name, line);
- #endif
+#endif
return(RW_LOCK_WAIT_EX);
}
@@ -365,11 +370,11 @@ rw_lock_x_lock_low(
lock->pass = pass;
lock->writer_is_wait_ex = FALSE;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_remove_debug_info(lock, pass, RW_LOCK_WAIT_EX);
rw_lock_add_debug_info(lock, pass, RW_LOCK_EX,
file_name, line);
- #endif
+#endif
lock->last_x_file_name = file_name;
lock->last_x_line = line;
@@ -388,10 +393,10 @@ rw_lock_x_lock_low(
lock->writer_count++;
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, pass, RW_LOCK_EX, file_name,
line);
- #endif
+#endif
lock->last_x_file_name = file_name;
lock->last_x_line = line;
@@ -528,6 +533,7 @@ lock_loop:
goto lock_loop;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Acquires the debug mutex. We cannot use the mutex defined in sync0sync,
because the debug mutex is also acquired in sync0arr while holding the OS
@@ -653,6 +659,7 @@ rw_lock_remove_debug_info(
ut_error;
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Sets the rw-lock latching level field. */
@@ -666,6 +673,7 @@ rw_lock_set_level(
lock->level = level;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks if the thread has locked the rw-lock in the specified mode, with
the pass value == 0. */
@@ -683,9 +691,6 @@ rw_lock_own(
ut_ad(lock);
ut_ad(rw_lock_validate(lock));
-#ifndef UNIV_SYNC_DEBUG
- ut_error;
-#endif
mutex_enter(&(lock->mutex));
info = UT_LIST_GET_FIRST(lock->debug_list);
@@ -708,6 +713,7 @@ rw_lock_own(
return(FALSE);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Checks if somebody has locked the rw-lock in the specified mode. */
@@ -744,6 +750,7 @@ rw_lock_is_locked(
return(ret);
}
+#ifdef UNIV_SYNC_DEBUG
/*******************************************************************
Prints debug info of currently locked rw-locks. */
@@ -751,8 +758,6 @@ void
rw_lock_list_print_info(void)
/*=========================*/
{
-#ifndef UNIV_SYNC_DEBUG
-#else
rw_lock_t* lock;
ulint count = 0;
rw_lock_debug_t* info;
@@ -796,7 +801,6 @@ rw_lock_list_print_info(void)
printf("Total number of rw-locks %ld\n", count);
mutex_exit(&rw_lock_list_mutex);
-#endif
}
/*******************************************************************
@@ -807,11 +811,6 @@ rw_lock_print(
/*==========*/
rw_lock_t* lock __attribute__((unused))) /* in: rw-lock */
{
-#ifndef UNIV_SYNC_DEBUG
- printf(
- "Sorry, cannot give rw-lock info in non-debug version!\n");
-#else
- ulint count = 0;
rw_lock_debug_t* info;
printf("-------------\n");
@@ -834,7 +833,6 @@ rw_lock_print(
info = UT_LIST_GET_NEXT(list, info);
}
}
-#endif
}
/*************************************************************************
@@ -875,12 +873,6 @@ ulint
rw_lock_n_locked(void)
/*==================*/
{
-#ifndef UNIV_SYNC_DEBUG
- printf(
- "Sorry, cannot give rw-lock info in non-debug version!\n");
- ut_error;
- return(0);
-#else
rw_lock_t* lock;
ulint count = 0;
@@ -903,5 +895,5 @@ rw_lock_n_locked(void)
mutex_exit(&rw_lock_list_mutex);
return(count);
-#endif
}
+#endif /* UNIV_SYNC_DEBUG */
diff --git a/innobase/sync/sync0sync.c b/innobase/sync/sync0sync.c
index 424f5b1b35a..64f76f5ee77 100644
--- a/innobase/sync/sync0sync.c
+++ b/innobase/sync/sync0sync.c
@@ -159,7 +159,7 @@ struct sync_thread_struct{
};
/* Number of slots reserved for each OS thread in the sync level array */
-#define SYNC_THREAD_N_LEVELS 7000
+#define SYNC_THREAD_N_LEVELS 10000
struct sync_level_struct{
void* latch; /* pointer to a mutex or an rw-lock; NULL means that
@@ -167,46 +167,6 @@ struct sync_level_struct{
ulint level; /* level of the latch in the latching order */
};
-
-#if defined(notdefined) && defined(__GNUC__) && defined(UNIV_INTEL_X86)
-
-ulint
-sync_gnuc_intelx86_test_and_set(
- /* out: old value of the lock word */
- ulint* lw) /* in: pointer to the lock word */
-{
- ulint res;
-
- /* In assembly we use the so-called AT & T syntax where
- the order of operands is inverted compared to the ordinary Intel
- syntax. The 'l' after the mnemonics denotes a 32-bit operation.
- The line after the code tells which values come out of the asm
- code, and the second line tells the input to the asm code. */
-
- asm volatile("movl $1, %%eax; xchgl (%%ecx), %%eax" :
- "=eax" (res), "=m" (*lw) :
- "ecx" (lw));
- return(res);
-}
-
-void
-sync_gnuc_intelx86_reset(
- ulint* lw) /* in: pointer to the lock word */
-{
- /* In assembly we use the so-called AT & T syntax where
- the order of operands is inverted compared to the ordinary Intel
- syntax. The 'l' after the mnemonics denotes a 32-bit operation. */
-
- asm volatile("movl $0, %%eax; xchgl (%%ecx), %%eax" :
- "=m" (*lw) :
- "ecx" (lw) :
- "eax"); /* gcc does not seem to understand
- that our asm code resets eax: tell it
- explicitly that after the third ':' */
-}
-
-#endif
-
/**********************************************************************
Creates, or rather, initializes a mutex object in a specified memory
location (which must be appropriately aligned). The mutex is initialized
@@ -220,7 +180,7 @@ mutex_create_func(
char* cfile_name, /* in: file name where created */
ulint cline) /* in: file line where created */
{
-#if defined(_WIN32) && defined(UNIV_CAN_USE_X86_ASSEMBLER) && !defined(__NETWARE)
+#if defined(_WIN32) && defined(UNIV_CAN_USE_X86_ASSEMBLER)
mutex_reset_lock_word(mutex);
#else
os_fast_mutex_init(&(mutex->os_fast_mutex));
@@ -228,8 +188,10 @@ mutex_create_func(
#endif
mutex_set_waiters(mutex, 0);
mutex->magic_n = MUTEX_MAGIC_N;
+#ifdef UNIV_SYNC_DEBUG
mutex->line = 0;
mutex->file_name = (char *) "not yet reserved";
+#endif /* UNIV_SYNC_DEBUG */
mutex->level = SYNC_LEVEL_NONE;
mutex->cfile_name = cfile_name;
mutex->cline = cline;
@@ -306,20 +268,19 @@ mutex_enter_nowait(
/*===============*/
/* out: 0 if succeed, 1 if not */
mutex_t* mutex, /* in: pointer to mutex */
- char* file_name, /* in: file name where mutex
+ char* file_name __attribute__((unused)),
+ /* in: file name where mutex
requested */
- ulint line) /* in: line where requested */
+ ulint line __attribute__((unused)))
+ /* in: line where requested */
{
ut_ad(mutex_validate(mutex));
if (!mutex_test_and_set(mutex)) {
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
mutex_set_debug_info(mutex, file_name, line);
- #endif
-
- mutex->file_name = file_name;
- mutex->line = line;
+#endif
return(0); /* Succeeded! */
}
@@ -415,12 +376,9 @@ spin_loop:
if (mutex_test_and_set(mutex) == 0) {
/* Succeeded! */
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
mutex_set_debug_info(mutex, file_name, line);
- #endif
-
- mutex->file_name = file_name;
- mutex->line = line;
+#endif
return;
}
@@ -462,12 +420,9 @@ spin_loop:
sync_array_free_cell(sync_primary_wait_array, index);
- #ifdef UNIV_SYNC_DEBUG
+#ifdef UNIV_SYNC_DEBUG
mutex_set_debug_info(mutex, file_name, line);
- #endif
-
- mutex->file_name = file_name;
- mutex->line = line;
+#endif
if (srv_print_latch_waits) {
printf(
@@ -519,6 +474,7 @@ mutex_signal_object(
sync_array_signal_object(sync_primary_wait_array, mutex);
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Sets the debug information for a reserved mutex. */
@@ -556,7 +512,8 @@ mutex_get_debug_info(
*file_name = mutex->file_name;
*line = mutex->line;
*thread_id = mutex->thread_id;
-}
+}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Sets the mutex latching level field. */
@@ -570,6 +527,7 @@ mutex_set_level(
mutex->level = level;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks that the current thread owns the mutex. Works only in the debug
version. */
@@ -602,8 +560,6 @@ void
mutex_list_print_info(void)
/*=======================*/
{
-#ifndef UNIV_SYNC_DEBUG
-#else
mutex_t* mutex;
char* file_name;
ulint line;
@@ -636,7 +592,6 @@ mutex_list_print_info(void)
printf("Total number of mutexes %ld\n", count);
mutex_exit(&mutex_list_mutex);
-#endif
}
/**********************************************************************
@@ -646,12 +601,6 @@ ulint
mutex_n_reserved(void)
/*==================*/
{
-#ifndef UNIV_SYNC_DEBUG
- printf("Sorry, cannot give mutex info in non-debug version!\n");
- ut_error;
-
- return(0);
-#else
mutex_t* mutex;
ulint count = 0;
@@ -674,7 +623,6 @@ mutex_n_reserved(void)
return(count - 1); /* Subtract one, because this function itself
was holding one mutex (mutex_list_mutex) */
-#endif
}
/**********************************************************************
@@ -685,19 +633,9 @@ ibool
sync_all_freed(void)
/*================*/
{
- #ifdef UNIV_SYNC_DEBUG
- if (mutex_n_reserved() + rw_lock_n_locked() == 0) {
-
- return(TRUE);
- } else {
- return(FALSE);
- }
- #else
- ut_error;
-
- return(FALSE);
- #endif
+ return(mutex_n_reserved() + rw_lock_n_locked() == 0);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Gets the value in the nth slot in the thread level arrays. */
@@ -794,9 +732,6 @@ sync_thread_levels_g(
thread */
ulint limit) /* in: level limit */
{
- char* file_name;
- ulint line;
- os_thread_id_t thread_id;
sync_level_t* slot;
rw_lock_t* lock;
mutex_t* mutex;
@@ -821,18 +756,28 @@ sync_thread_levels_g(
(ulong) mutex->cline);
if (mutex_get_lock_word(mutex) != 0) {
+#ifdef UNIV_SYNC_DEBUG
+ char* file_name;
+ ulint line;
+ os_thread_id_t thread_id;
mutex_get_debug_info(mutex,
&file_name, &line, &thread_id);
- printf("InnoDB: Locked mutex: addr %lx thread %ld file %s line %ld\n",
- (ulong) mutex, (ulong) os_thread_pf(thread_id),
- file_name, (ulong) line);
+ fprintf(stderr,
+ "InnoDB: Locked mutex: addr %p thread %ld file %s line %ld\n",
+ mutex, os_thread_pf(thread_id), file_name, (ulong) line);
+#else /* UNIV_SYNC_DEBUG */
+ fprintf(stderr,
+ "InnoDB: Locked mutex: addr %p\n", mutex);
+#endif /* UNIV_SYNC_DEBUG */
} else {
- printf("Not locked\n");
+ fputs("Not locked\n", stderr);
}
} else {
+#ifdef UNIV_SYNC_DEBUG
rw_lock_print(lock);
+#endif /* UNIV_SYNC_DEBUG */
}
return(FALSE);
@@ -972,7 +917,9 @@ sync_thread_add_level(
if ((latch == (void*)&sync_thread_mutex)
|| (latch == (void*)&mutex_list_mutex)
+#ifdef UNIV_SYNC_DEBUG
|| (latch == (void*)&rw_lock_debug_mutex)
+#endif /* UNIV_SYNC_DEBUG */
|| (latch == (void*)&rw_lock_list_mutex)) {
return;
@@ -1152,7 +1099,9 @@ sync_thread_reset_level(
if ((latch == (void*)&sync_thread_mutex)
|| (latch == (void*)&mutex_list_mutex)
+#ifdef UNIV_SYNC_DEBUG
|| (latch == (void*)&rw_lock_debug_mutex)
+#endif /* UNIV_SYNC_DEBUG */
|| (latch == (void*)&rw_lock_list_mutex)) {
return(FALSE);
@@ -1238,11 +1187,13 @@ sync_init(void)
mutex_create(&rw_lock_list_mutex);
mutex_set_level(&rw_lock_list_mutex, SYNC_NO_ORDER_CHECK);
+#ifdef UNIV_SYNC_DEBUG
mutex_create(&rw_lock_debug_mutex);
mutex_set_level(&rw_lock_debug_mutex, SYNC_NO_ORDER_CHECK);
rw_lock_debug_event = os_event_create(NULL);
rw_lock_debug_waiters = FALSE;
+#endif /* UNIV_SYNC_DEBUG */
}
/**********************************************************************
@@ -1307,9 +1258,11 @@ sync_print(
char* buf, /* in/out: buffer where to print */
char* buf_end) /* in: buffer end */
{
+#ifdef UNIV_SYNC_DEBUG
mutex_list_print_info();
rw_lock_list_print_info();
+#endif /* UNIV_SYNC_DEBUG */
sync_array_print_info(buf, buf_end, sync_primary_wait_array);
diff --git a/innobase/sync/ts/makefile b/innobase/sync/ts/makefile
deleted file mode 100644
index 95011f51466..00000000000
--- a/innobase/sync/ts/makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tssync: ..\sync.lib tssync.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\sync.lib ..\..\mach.lib ..\..\ut.lib ..\..\mem.lib ..\..\os.lib tssync.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/sync/ts/tssync.c b/innobase/sync/ts/tssync.c
deleted file mode 100644
index bf30a603284..00000000000
--- a/innobase/sync/ts/tssync.c
+++ /dev/null
@@ -1,1366 +0,0 @@
-/************************************************************************
-The test module for the syncronization primitives
-
-(c) 1995 Innobase Oy
-
-Created 9/9/1995 Heikki Tuuri
-*************************************************************************/
-
-
-#include "../sync0sync.h"
-#include "../sync0rw.h"
-#include "../sync0arr.h"
-#include "../sync0ipm.h"
-#include "ut0ut.h"
-#include "mem0mem.h"
-#include "os0sync.h"
-#include "os0thread.h"
-#include "os0sync.h"
-
-mutex_t mutex;
-mutex_t mutex1;
-mutex_t mutex2;
-mutex_t mutex3;
-mutex_t mutex4;
-
-ip_mutex_t ip_mutex;
-
-ip_mutex_t ip_mutex1;
-ip_mutex_t ip_mutex2;
-ip_mutex_t ip_mutex3;
-ip_mutex_t ip_mutex4;
-
-ip_mutex_hdl_t* iph;
-
-ip_mutex_hdl_t* iph1;
-ip_mutex_hdl_t* iph2;
-ip_mutex_hdl_t* iph3;
-ip_mutex_hdl_t* iph4;
-
-
-rw_lock_t rw1;
-rw_lock_t rw2;
-rw_lock_t rw3;
-rw_lock_t rw4;
-
-rw_lock_t rw9;
-rw_lock_t rw10;
-mutex_t mutex9;
-
-os_mutex_t osm;
-
-ulint last_thr;
-ulint switch_count;
-ulint glob_count;
-ulint glob_inc;
-ulint rc;
-
-bool qprint = FALSE;
-
-/********************************************************************
-Start function for thread 1 in test1. */
-ulint
-thread1(void* arg)
-/*==============*/
-{
- ulint i, j;
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread1 started!\n");
-
- mutex_enter(&mutex);
-
- printf("Thread1 owns now the mutex!\n");
-
- j = 0;
-
- for (i = 1; i < 1000000; i++) {
- j += i;
- }
-
- printf("Thread1 releases now the mutex!\n");
-
- mutex_exit(&mutex);
-
- return(j);
-}
-
-/********************************************************************
-Start function for thread 2 in test1. */
-ulint
-thread2(void* arg)
-/*==============*/
-{
- ulint i, j;
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread2 started!\n");
-
- mutex_enter(&mutex);
-
- printf("Thread2 owns now the mutex!\n");
-
- j = 0;
-
- for (i = 1; i < 1000000; i++) {
- j += i;
- }
-
- printf("Thread2 releases now the mutex!\n");
-
- mutex_exit(&mutex);
-
- return(j);
-}
-
-/********************************************************************
-Start function for the competing threads in test2. The function tests
-the behavior lock-coupling through 4 mutexes. */
-
-ulint
-thread_n(volatile void* arg)
-/*========================*/
-{
- ulint i, j, k, n;
-
- n = *((ulint*)arg);
-
- printf("Thread %ld started!\n", n);
-
- for (k = 0; k < 2000 * UNIV_DBC; k++) {
-
- mutex_enter(&mutex1);
-
- if (last_thr != n) {
- switch_count++;
- last_thr = n;
- }
-
- j = 0;
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- mutex_enter(&mutex2);
-
- mutex_exit(&mutex1);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- mutex_enter(&mutex3);
-
- mutex_exit(&mutex2);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- mutex_enter(&mutex4);
-
- mutex_exit(&mutex3);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- mutex_exit(&mutex4);
- }
-
- printf("Thread %ld exits!\n", n);
-
- return(j);
-}
-
-/********************************************************************
-Start function for mutex exclusion checking in test3. */
-
-ulint
-thread_x(void* arg)
-/*===============*/
-{
- ulint k;
- void* arg2;
-
- arg2 = arg;
-
- printf("Starting thread!\n");
-
- for (k = 0; k < 200000 * UNIV_DBC; k++) {
-
- mutex_enter(&mutex);
-
- glob_count += glob_inc;
-
- mutex_exit(&mutex);
-
- }
-
- printf("Exiting thread!\n");
-
- return(0);
-}
-
-
-
-void
-test1(void)
-/*=======*/
-{
- os_thread_t thr1, thr2;
- os_thread_id_t id1, id2;
- ulint i, j;
- ulint tm, oldtm;
- ulint* lp;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 1. Test of mutexes.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
- osm = os_mutex_create(NULL);
-
- os_mutex_enter(osm);
- os_mutex_exit(osm);
-
- os_mutex_free(osm);
-
-
- mutex_create(&mutex);
-
- lp = &j;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000000; i++) {
- id1 = os_thread_get_curr_id();
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld thread_get_id %ld milliseconds\n",
- i, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000 * UNIV_DBC; i++) {
-
- mutex_enter(&mutex);
- mutex_exit(&mutex);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld mutex lock-unlock %ld milliseconds\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000000; i++) {
-
- mutex_fence();
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld fences %ld milliseconds\n",
- i, tm - oldtm);
-
- mutex_enter(&mutex);
-
- mutex_list_print_info();
-
- ut_ad(1 == mutex_n_reserved());
- ut_ad(FALSE == sync_all_freed());
-
- thr1 = os_thread_create(thread1,
- NULL,
- &id1);
-
- printf("Thread1 created, id %ld \n", id1);
-
- thr2 = os_thread_create(thread2,
- NULL,
- &id2);
-
- printf("Thread2 created, id %ld \n", id2);
-
-
- j = 0;
-
- for (i = 1; i < 20000000; i++) {
- j += i;
- }
-
- sync_print();
-
- sync_array_validate(sync_primary_wait_array);
-
- printf("Main thread releases now mutex!\n");
-
- mutex_exit(&mutex);
-
- os_thread_wait(thr2);
-
- os_thread_wait(thr1);
-}
-
-/******************************************************************
-Test function for possible convoy problem. */
-
-void
-test2(void)
-/*=======*/
-{
- os_thread_t thr1, thr2, thr3, thr4, thr5;
- os_thread_id_t id1, id2, id3, id4, id5;
- ulint tm, oldtm;
- ulint n1, n2, n3, n4, n5;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 2. Test of possible convoy problem.\n");
-
- printf("System call count %lu\n", mutex_system_call_count);
-
- mutex_create(&mutex1);
- mutex_create(&mutex2);
- mutex_create(&mutex3);
- mutex_create(&mutex4);
-
- switch_count = 0;
-
- oldtm = ut_clock();
-
- n1 = 1;
-
- thr1 = os_thread_create(thread_n,
- &n1,
- &id1);
-
- os_thread_wait(thr1);
-
-
- tm = ut_clock();
- printf("Wall clock time for single thread %ld milliseconds\n",
- tm - oldtm);
- printf("System call count %lu\n", mutex_system_call_count);
-
- switch_count = 0;
-
- oldtm = ut_clock();
-
- n1 = 1;
- thr1 = os_thread_create(thread_n,
- &n1,
- &id1);
- n2 = 2;
- thr2 = os_thread_create(thread_n,
- &n2,
- &id2);
- n3 = 3;
- thr3 = os_thread_create(thread_n,
- &n3,
- &id3);
- n4 = 4;
- thr4 = os_thread_create(thread_n,
- &n4,
- &id4);
- n5 = 5;
- thr5 = os_thread_create(thread_n,
- &n5,
- &id5);
-
-
- os_thread_wait(thr1);
- os_thread_wait(thr2);
- os_thread_wait(thr3);
- os_thread_wait(thr4);
- os_thread_wait(thr5);
-
-
- tm = ut_clock();
- printf("Wall clock time for 5 threads %ld milliseconds\n",
- tm - oldtm);
- printf("%ld thread switches occurred\n", switch_count);
-
- printf("If this is not 5 x single thread time, possibly convoy!\n");
-
- printf("System call count %lu\n", mutex_system_call_count);
-}
-
-/******************************************************************
-Test function for possible exclusion failure. */
-
-void
-test3(void)
-/*=======*/
-{
- os_thread_t thr1, thr2;
- os_thread_id_t id1, id2;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 3. Test of possible exclusion failure.\n");
-
- glob_count = 0;
- glob_inc = 1;
-
- thr1 = os_thread_create(thread_x,
- NULL,
- &id1);
- thr2 = os_thread_create(thread_x,
- NULL,
- &id2);
-
- os_thread_wait(thr2);
- os_thread_wait(thr1);
-
- ut_a(glob_count == 400000 * UNIV_DBC);
-}
-
-/******************************************************************
-Test function for measuring the spin wait loop cycle time. */
-
-void
-test4(void)
-/*=======*/
-{
-volatile ulint* ptr;
- ulint i, tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 4. Test of spin wait loop cycle time.\n");
- printf("Use this time to set the SYNC_SPIN_ROUNDS constant.\n");
-
-
- glob_inc = 1;
-
- ptr = &glob_inc;
-
- oldtm = ut_clock();
-
- i = 0;
-
- while ((*ptr != 0) && (i < 10000000)) {
- i++;
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld cycles %ld milliseconds\n",
- i, tm - oldtm);
-}
-
-/********************************************************************
-Start function for s-lock thread in test5. */
-ulint
-thread_srw(void* arg)
-/*==============*/
-{
- ulint i, j;
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread_srw started!\n");
-
- rw_lock_s_lock(&rw1);
-
- printf("Thread_srw has now s-lock!\n");
-
- j = 0;
-
- for (i = 1; i < 1000000; i++) {
- j += i;
- }
-
- printf("Thread_srw releases now the s-lock!\n");
-
- rw_lock_s_unlock(&rw1);
-
- return(j);
-}
-
-/********************************************************************
-Start function for x-lock thread in test5. */
-ulint
-thread_xrw(void* arg)
-/*==============*/
-{
- ulint i, j;
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread_xrw started!\n");
-
- rw_lock_x_lock(&rw1);
-
- printf("Thread_xrw has now x-lock!\n");
-
- j = 0;
-
- for (i = 1; i < 1000000; i++) {
- j += i;
- }
-
- printf("Thread_xrw releases now the x-lock!\n");
-
- rw_lock_x_unlock(&rw1);
-
- return(j);
-}
-
-
-void
-test5(void)
-/*=======*/
-{
- os_thread_t thr1, thr2;
- os_thread_id_t id1, id2;
- ulint i, j;
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 5. Test of read-write locks.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
-
- rw_lock_create(&rw1);
-
- oldtm = ut_clock();
-
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
-
- rw_lock_s_lock(&rw1);
-
- rw_lock_s_unlock(&rw1);
-
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld rw s-lock-unlock %ld milliseconds\n",
- i, tm - oldtm);
-
-
- oldtm = ut_clock();
-
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mutex_enter(&mutex);
- rc++;
- mutex_exit(&mutex);
-
- mutex_enter(&mutex);
- rc--;
- mutex_exit(&mutex);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld rw test %ld milliseconds\n",
- i, tm - oldtm);
-
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 10000 * UNIV_DBC * UNIV_DBC; i++) {
-
- rw_lock_x_lock(&rw1);
- rw_lock_x_unlock(&rw1);
-
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld rw x-lock-unlock %ld milliseconds\n",
- i, tm - oldtm);
-
-
- /* Test recursive x-locking */
- for (i = 0; i < 10000; i++) {
- rw_lock_x_lock(&rw1);
- }
-
- for (i = 0; i < 10000; i++) {
-
- rw_lock_x_unlock(&rw1);
- }
-
- /* Test recursive s-locking */
- for (i = 0; i < 10000; i++) {
-
- rw_lock_s_lock(&rw1);
- }
-
- for (i = 0; i < 10000; i++) {
-
- rw_lock_s_unlock(&rw1);
- }
-
- rw_lock_s_lock(&rw1);
-
- ut_ad(1 == rw_lock_n_locked());
-
- mem_print_info();
-
- rw_lock_list_print_info();
-
- thr2 = os_thread_create(thread_xrw,
- NULL,
- &id2);
-
- printf("Thread_xrw created, id %ld \n", id2);
-
-
- thr1 = os_thread_create(thread_srw,
- NULL,
- &id1);
-
- printf("Thread_srw created, id %ld \n", id1);
-
- j = 0;
-
- for (i = 1; i < 10000000; i++) {
- j += i;
- }
-
- rw_lock_list_print_info();
-
- sync_array_validate(sync_primary_wait_array);
-
- printf("Main thread releases now rw-lock!\n");
-
- rw_lock_s_unlock(&rw1);
-
- os_thread_wait(thr2);
-
- os_thread_wait(thr1);
-
- sync_array_print_info(sync_primary_wait_array);
-}
-
-/********************************************************************
-Start function for the competing s-threads in test6. The function tests
-the behavior lock-coupling through 4 rw-locks. */
-
-ulint
-thread_qs(volatile void* arg)
-/*========================*/
-{
- ulint i, j, k, n;
-
- arg = arg;
-
- n = os_thread_get_curr_id();
-
- printf("S-Thread %ld started, thread id %lu\n", n,
- os_thread_get_curr_id());
-
- for (k = 0; k < 1000 * UNIV_DBC; k++) {
-
- if (qprint)
- printf("S-Thread %ld starts round %ld!\n", n, k);
-
- rw_lock_s_lock(&rw1);
-
- if (qprint)
- printf("S-Thread %ld got lock 1 on round %ld!\n", n, k);
-
-
- if (last_thr != n) {
- switch_count++;
- last_thr = n;
- }
-
- j = 0;
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- rw_lock_s_lock(&rw2);
-
- if (qprint)
- printf("S-Thread %ld got lock 2 on round %ld!\n", n, k);
-
-
- rw_lock_s_unlock(&rw1);
-
- if (qprint)
- printf("S-Thread %ld released lock 1 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- rw_lock_s_lock(&rw3);
-
- if (qprint)
- printf("S-Thread %ld got lock 3 on round %ld!\n", n, k);
-
-
- rw_lock_s_unlock(&rw2);
- if (qprint)
- printf("S-Thread %ld released lock 2 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- rw_lock_s_lock(&rw4);
-
- if (qprint)
- printf("S-Thread %ld got lock 4 on round %ld!\n", n, k);
-
-
- rw_lock_s_unlock(&rw3);
- if (qprint)
- printf("S-Thread %ld released lock 3 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- rw_lock_s_unlock(&rw4);
- if (qprint)
- printf("S-Thread %ld released lock 4 on round %ld!\n", n, k);
-
- }
-
- printf("S-Thread %ld exits!\n", n);
-
- return(j);
-}
-
-/********************************************************************
-Start function for the competing x-threads in test6. The function tests
-the behavior lock-coupling through 4 rw-locks. */
-
-ulint
-thread_qx(volatile void* arg)
-/*========================*/
-{
- ulint i, j, k, n;
-
- arg = arg;
-
- n = os_thread_get_curr_id();
-
- printf("X-Thread %ld started, thread id %lu\n", n,
- os_thread_get_curr_id());
-
- for (k = 0; k < 1000 * UNIV_DBC; k++) {
-
- if (qprint)
- printf("X-Thread %ld round %ld!\n", n, k);
-
-
- rw_lock_x_lock(&rw1);
- if (qprint)
- printf("X-Thread %ld got lock 1 on round %ld!\n", n, k);
-
-
- if (last_thr != n) {
- switch_count++;
- last_thr = n;
- }
-
- j = 0;
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- rw_lock_x_lock(&rw2);
- if (qprint)
- printf("X-Thread %ld got lock 2 on round %ld!\n", n, k);
-
-
- rw_lock_x_unlock(&rw1);
- if (qprint)
- printf("X-Thread %ld released lock 1 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- rw_lock_x_lock(&rw3);
- if (qprint)
- printf("X-Thread %ld got lock 3 on round %ld!\n", n, k);
-
-
- rw_lock_x_unlock(&rw2);
- if (qprint)
- printf("X-Thread %ld released lock 2 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- rw_lock_x_lock(&rw4);
- if (qprint)
- printf("X-Thread %ld got lock 4 on round %ld!\n", n, k);
-
- rw_lock_x_unlock(&rw3);
- if (qprint)
- printf("X-Thread %ld released lock 3 on round %ld!\n", n, k);
-
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- rw_lock_x_unlock(&rw4);
- if (qprint)
- printf("X-Thread %ld released lock 4 on round %ld!\n", n, k);
-
- }
-
- printf("X-Thread %ld exits!\n", n);
-
- return(j);
-}
-
-/******************************************************************
-Test function for possible queuing problems with rw-locks. */
-
-void
-test6(void)
-/*=======*/
-{
- os_thread_t thr1, thr2, thr3, thr4, thr5;
- os_thread_id_t id1, id2, id3, id4, id5;
- ulint tm, oldtm;
- ulint n1, n2, n3, n4, n5;
-
- printf("-------------------------------------------\n");
- printf(
- "SYNC-TEST 6. Test of possible queuing problems with rw-locks.\n");
-/*
- sync_array_print_info(sync_primary_wait_array);
-*/
-
- rw_lock_create(&rw2);
- rw_lock_create(&rw3);
- rw_lock_create(&rw4);
-
- switch_count = 0;
-
-
- oldtm = ut_clock();
-
- n1 = 1;
-
- thr1 = os_thread_create(thread_qs,
- &n1,
- &id1);
-
- os_thread_wait(thr1);
-
-
- tm = ut_clock();
- printf("Wall clock time for single s-lock thread %ld milliseconds\n",
- tm - oldtm);
-
- oldtm = ut_clock();
-
- n1 = 1;
-
- thr1 = os_thread_create(thread_qx,
- &n1,
- &id1);
-
- os_thread_wait(thr1);
-
-
- tm = ut_clock();
- printf("Wall clock time for single x-lock thread %ld milliseconds\n",
- tm - oldtm);
-
- switch_count = 0;
-
- oldtm = ut_clock();
-
-
- n1 = 1;
- thr1 = os_thread_create(thread_qx,
- &n1,
- &id1);
-
- n2 = 2;
- thr2 = os_thread_create(thread_qs,
- &n2,
- &id2);
-
- n3 = 3;
- thr3 = os_thread_create(thread_qx,
- &n3,
- &id3);
-
-
- n4 = 4;
- thr4 = os_thread_create(thread_qs,
- &n4,
- &id4);
-
- n5 = 5;
- thr5 = os_thread_create(thread_qx,
- &n5,
- &id5);
-
- os_thread_wait(thr1);
-
- os_thread_wait(thr2);
-
- os_thread_wait(thr3);
-
- os_thread_wait(thr4);
-
- os_thread_wait(thr5);
-
-
- tm = ut_clock();
- printf("Wall clock time for 5 threads %ld milliseconds\n",
- tm - oldtm);
- printf("at least %ld thread switches occurred\n", switch_count);
-
- printf(
- "If this is not 2 x s-thread + 3 x x-thread time, possibly convoy!\n");
-
- rw_lock_list_print_info();
-
- sync_array_print_info(sync_primary_wait_array);
-
-}
-
-/********************************************************************
-Start function for thread in test7. */
-ulint
-ip_thread(void* arg)
-/*================*/
-{
- ulint i, j;
- void* arg2;
- ulint ret;
- ulint tm, oldtm;
-
- arg2 = arg;
-
- printf("Thread started!\n");
-
- oldtm = ut_clock();
-
- ret = ip_mutex_enter(iph, 100000);
-
-/* ut_a(ret == SYNC_TIME_EXCEEDED);
-*/
- tm = ut_clock();
-
- printf("Wall clock time for wait failure %ld ms\n", tm - oldtm);
-
- ret = ip_mutex_enter(iph, SYNC_INFINITE_TIME);
-
- ut_a(ret == 0);
-
- printf("Thread owns now the ip mutex!\n");
-
- j = 0;
-
- for (i = 1; i < 1000000; i++) {
- j += i;
- }
-
- printf("Thread releases now the ip mutex!\n");
-
- ip_mutex_exit(iph);
-
- return(j);
-}
-
-/*********************************************************************
-Test for interprocess mutex. */
-void
-test7(void)
-/*=======*/
-{
- os_thread_t thr1;
- os_thread_id_t id1;
- ulint i, j;
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 7. Test of ip mutex.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
- ip_mutex_create(&ip_mutex, "IPMUTEX", &iph);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 100000 * UNIV_DBC; i++) {
-
- ip_mutex_enter(iph, SYNC_INFINITE_TIME);
- ip_mutex_exit(iph);
- }
-
- tm = ut_clock();
- printf("Wall clock time for %ld ip mutex lock-unlock %ld ms\n",
- i, tm - oldtm);
-
-
- ip_mutex_enter(iph, SYNC_INFINITE_TIME);
-
- thr1 = os_thread_create(ip_thread,
- NULL,
- &id1);
-
- printf("Thread created, id %ld \n", id1);
-
-
- j = 0;
-
- for (i = 1; i < 100000000; i++) {
- j += i;
- }
-
- printf("Main thread releases now ip mutex!\n");
-
- ip_mutex_exit(iph);
-
- os_thread_wait(thr1);
-
- ip_mutex_free(iph);
-}
-
-/********************************************************************
-Start function for the competing threads in test8. The function tests
-the behavior lock-coupling through 4 ip mutexes. */
-
-ulint
-thread_ipn(volatile void* arg)
-/*========================*/
-{
- ulint i, j, k, n;
-
- n = *((ulint*)arg);
-
- printf("Thread %ld started!\n", n);
-
- for (k = 0; k < 2000 * UNIV_DBC; k++) {
-
- ip_mutex_enter(iph1, SYNC_INFINITE_TIME);
-
- if (last_thr != n) {
- switch_count++;
- last_thr = n;
- }
-
- j = 0;
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- ip_mutex_enter(iph2, SYNC_INFINITE_TIME);
-
- ip_mutex_exit(iph1);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- ip_mutex_enter(iph3, SYNC_INFINITE_TIME);
-
- ip_mutex_exit(iph2);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
- ip_mutex_enter(iph4, SYNC_INFINITE_TIME);
-
- ip_mutex_exit(iph3);
-
- for (i = 1; i < 400; i++) {
- j += i;
- }
-
- ip_mutex_exit(iph4);
- }
-
- printf("Thread %ld exits!\n", n);
-
- return(j);
-}
-
-/******************************************************************
-Test function for ip mutex. */
-
-void
-test8(void)
-/*=======*/
-{
- os_thread_t thr1, thr2, thr3, thr4, thr5;
- os_thread_id_t id1, id2, id3, id4, id5;
- ulint tm, oldtm;
- ulint n1, n2, n3, n4, n5;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 8. Test for ip mutex.\n");
-
-
- ip_mutex_create(&ip_mutex1, "jhfhk", &iph1);
- ip_mutex_create(&ip_mutex2, "jggfg", &iph2);
- ip_mutex_create(&ip_mutex3, "hfdx", &iph3);
- ip_mutex_create(&ip_mutex4, "kjghg", &iph4);
-
- switch_count = 0;
-
- oldtm = ut_clock();
-
- n1 = 1;
-
- thr1 = os_thread_create(thread_ipn,
- &n1,
- &id1);
-
- os_thread_wait(thr1);
-
-
- tm = ut_clock();
- printf("Wall clock time for single thread %lu milliseconds\n",
- tm - oldtm);
-
- switch_count = 0;
-
- oldtm = ut_clock();
-
- n1 = 1;
- thr1 = os_thread_create(thread_ipn,
- &n1,
- &id1);
- n2 = 2;
- thr2 = os_thread_create(thread_ipn,
- &n2,
- &id2);
- n3 = 3;
- thr3 = os_thread_create(thread_ipn,
- &n3,
- &id3);
- n4 = 4;
- thr4 = os_thread_create(thread_ipn,
- &n4,
- &id4);
- n5 = 5;
- thr5 = os_thread_create(thread_ipn,
- &n5,
- &id5);
-
- os_thread_wait(thr1);
- os_thread_wait(thr2);
- os_thread_wait(thr3);
- os_thread_wait(thr4);
- os_thread_wait(thr5);
-
-
- tm = ut_clock();
- printf("Wall clock time for 5 threads %ld milliseconds\n",
- tm - oldtm);
- printf("%ld thread switches occurred\n", switch_count);
-
- printf("If this is not 5 x single thread time, possibly convoy!\n");
-
- ip_mutex_free(iph1);
- ip_mutex_free(iph2);
- ip_mutex_free(iph3);
- ip_mutex_free(iph4);
-}
-
-
-/********************************************************************
-Start function for s-lock thread in test9. */
-ulint
-thread_srw9(void* arg)
-/*==================*/
-{
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread_srw9 started!\n");
-
- rw_lock_x_lock(&rw10);
-
- printf("Thread_srw9 has now x-lock on rw10, wait for mutex!\n");
-
- mutex_enter(&mutex9);
-
- return(0);
-}
-
-/********************************************************************
-Start function for x-lock thread in test9. */
-ulint
-thread_xrw9(void* arg)
-/*==================*/
-{
- void* arg2;
-
- arg2 = arg;
-
- printf("Thread_xrw started!\n");
-
- mutex_enter(&mutex9);
- printf("Thread_xrw9 has now mutex9, wait for rw9!\n");
-
- rw_lock_x_lock(&rw9);
-
- return(0);
-}
-
-void
-test9(void)
-/*=======*/
-{
- os_thread_t thr1, thr2;
- os_thread_id_t id1, id2;
-
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 9. Test of deadlock detection.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
- rw_lock_create(&rw9);
- rw_lock_create(&rw10);
- mutex_create(&mutex9);
-
- rw_lock_s_lock(&rw9);
- printf("Main thread has now s-lock on rw9\n");
-
- thr2 = os_thread_create(thread_xrw9,
- NULL,
- &id2);
-
- printf("Thread_xrw9 created, id %ld \n", id2);
-
- os_thread_sleep(1000000);
-
- thr1 = os_thread_create(thread_srw9,
- NULL,
- &id1);
-
- printf("Thread_srw9 created, id %ld \n", id1);
-
- os_thread_sleep(1000000);
-
- sync_array_print_info(sync_primary_wait_array);
-
- printf("Now we should have a deadlock of 3 threads:\n");
-
- rw_lock_s_lock(&rw10);
-}
-
-void
-test10(void)
-/*=======*/
-{
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 10. Test of deadlock detection on self-deadlock.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
- mutex_create(&mutex9);
-
- printf("Now we should have a deadlock of this thread on mutex:\n");
-
- mutex_enter(&mutex9);
- mutex_enter(&mutex9);
-}
-
-void
-test11(void)
-/*=======*/
-{
- printf("-------------------------------------------\n");
- printf("SYNC-TEST 11. Test of deadlock detection on self-deadlock.\n");
-
-
- printf("Main thread %ld starts!\n",
- os_thread_get_curr_id());
-
- rw_lock_create(&rw9);
-
- printf("Now we should have a deadlock of this thread on X-lock:\n");
-
- rw_lock_x_lock(&rw9);
- rw_lock_s_lock_gen(&rw9, 567);
-}
-
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
-
- oldtm = ut_clock();
-
- test1();
-
- test2();
-
- test3();
-
- test4();
-
- test5();
-
- test6();
-
- test7();
-
- test8();
-
- /* This test SHOULD result in assert on deadlock! */
-/* test9();*/
-
- /* This test SHOULD result in assert on deadlock! */
-/* test10();*/
-
- /* This test SHOULD result in assert on deadlock! */
-/* test11();*/
-
- ut_ad(0 == mutex_n_reserved());
- ut_ad(0 == rw_lock_n_locked());
- ut_ad(sync_all_freed());
-
-
- ut_ad(mem_all_freed());
-
- sync_close();
-
- tm = ut_clock();
- printf("Wall clock time for test %ld milliseconds\n", tm - oldtm);
- printf("System call count %lu\n", mutex_system_call_count);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
-
-
diff --git a/innobase/thr/thr0loc.c b/innobase/thr/thr0loc.c
index 839cb024f25..a17d09fcca6 100644
--- a/innobase/thr/thr0loc.c
+++ b/innobase/thr/thr0loc.c
@@ -46,10 +46,11 @@ struct thr_local_struct{
ibool in_ibuf;/* TRUE if the the thread is doing an ibuf
operation */
hash_node_t hash; /* hash chain node */
+#ifdef UNIV_DEBUG
ulint magic_n;
-};
-
#define THR_LOCAL_MAGIC_N 1231234
+#endif /* UNIV_DEBUG */
+};
/***********************************************************************
Returns the local storage struct for a thread. */
@@ -64,7 +65,9 @@ thr_local_get(
try_again:
ut_ad(thr_local_hash);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&thr_local_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* Look for the local struct in the hash table */
@@ -167,8 +170,9 @@ thr_local_create(void)
local->id = os_thread_get_curr_id();
local->handle = os_thread_get_curr();
+#ifdef UNIV_DEBUG
local->magic_n = THR_LOCAL_MAGIC_N;
-
+#endif /* UNIV_DEBUG */
local->in_ibuf = FALSE;
mutex_enter(&thr_local_mutex);
@@ -207,7 +211,7 @@ thr_local_free(
mutex_exit(&thr_local_mutex);
- ut_a(local->magic_n == THR_LOCAL_MAGIC_N);
+ ut_ad(local->magic_n == THR_LOCAL_MAGIC_N);
mem_free(local);
}
diff --git a/innobase/thr/ts/makefile b/innobase/thr/ts/makefile
deleted file mode 100644
index 517f50d197a..00000000000
--- a/innobase/thr/ts/makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tsthr: ..\thr.lib tsthr.c makefile
- $(CCOM) $(CFL) -I.. -I..\.. ..\thr.lib ..\..\ha.lib ..\..\sync.lib ..\..\ut.lib ..\..\mem.lib ..\..\os.lib tsthr.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/thr/ts/tsthr.c b/innobase/thr/ts/tsthr.c
deleted file mode 100644
index af5aaa54522..00000000000
--- a/innobase/thr/ts/tsthr.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/************************************************************************
-The test module for the thread management of Innobase
-
-(c) 1995 Innobase Oy
-
-Created 10/5/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "../thr0loc.h"
-#include "sync0sync.h"
-#include "mem0mem.h"
-#include "os0thread.h"
-#include "os0sync.h"
-#include "ut0ut.h"
-
-ulint val = 500;
-os_event_t event;
-
-/******************************************************************
-Thread start function in test1. */
-
-ulint
-thread1(
-/*====*/
- void* arg)
-{
- ulint n;
-
- thr_local_create();
-
- n = *((ulint*)arg);
-
- printf("Thread %lu starts\n", n);
-
- thr_local_set_slot_no(os_thread_get_curr_id(), n);
-
- ut_a(n == thr_local_get_slot_no(os_thread_get_curr_id()));
-
- os_event_wait(event);
-
- thr_local_free();
-
- os_thread_exit(0);
-
- return(0);
-}
-
-/******************************************************************
-Test function for local storage. */
-
-void
-test1(void)
-/*=======*/
-{
- os_thread_t thr1, thr2, thr3, thr4, thr5;
- os_thread_id_t id1, id2, id3, id4, id5;
- ulint tm, oldtm;
- ulint n1, n2, n3, n4, n5;
-
- printf("-------------------------------------------\n");
- printf("THR-TEST 1. Test of local storage\n");
-
- event = os_event_create(NULL);
-
- oldtm = ut_clock();
-
- n1 = 1;
- thr1 = os_thread_create(thread1,
- &n1,
- &id1);
- n2 = 2;
- thr2 = os_thread_create(thread1,
- &n2,
- &id2);
- n3 = 3;
- thr3 = os_thread_create(thread1,
- &n3,
- &id3);
- n4 = 4;
- thr4 = os_thread_create(thread1,
- &n4,
- &id4);
- n5 = 5;
- thr5 = os_thread_create(thread1,
- &n5,
- &id5);
-
- os_thread_sleep(500000);
-
- ut_a(n1 == thr_local_get_slot_no(id1));
- ut_a(n2 == thr_local_get_slot_no(id2));
- ut_a(n3 == thr_local_get_slot_no(id3));
- ut_a(n4 == thr_local_get_slot_no(id4));
- ut_a(n5 == thr_local_get_slot_no(id5));
-
- os_event_set(event);
-
- os_thread_wait(thr1);
- os_thread_wait(thr2);
- os_thread_wait(thr3);
- os_thread_wait(thr4);
- os_thread_wait(thr5);
-
- tm = ut_clock();
- printf("Wall clock time for 5 threads %ld milliseconds\n",
- tm - oldtm);
-}
-
-/************************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
-
- sync_init();
- mem_init();
- thr_local_init();
-
- oldtm = ut_clock();
-
- test1();
-
- thr_local_close();
-
- tm = ut_clock();
- printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/trx/trx0purge.c b/innobase/trx/trx0purge.c
index 31223aa280e..558a0825fd7 100644
--- a/innobase/trx/trx0purge.c
+++ b/innobase/trx/trx0purge.c
@@ -45,7 +45,9 @@ trx_purge_update_undo_must_exist(
the undo log still exists in the system */
dulint trx_id) /* in: transaction id */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
if (!read_view_sees_trx_id(purge_sys->view, trx_id)) {
@@ -195,9 +197,9 @@ void
trx_purge_sys_create(void)
/*======================*/
{
- com_endpoint_t* com_endpoint;
-
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
purge_sys = mem_alloc(sizeof(trx_purge_t));
@@ -219,9 +221,7 @@ trx_purge_sys_create(void)
purge_sys->arr = trx_undo_arr_create();
- com_endpoint = (com_endpoint_t*)purge_sys; /* This is a dummy non-NULL
- value */
- purge_sys->sess = sess_open(com_endpoint, (byte*)"purge_system", 13);
+ purge_sys->sess = sess_open();
purge_sys->trx = purge_sys->sess->trx;
@@ -262,7 +262,9 @@ trx_purge_add_update_undo_to_history(
ut_ad(undo);
rseg = undo->rseg;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
rseg_header = trx_rsegf_get(rseg->space, rseg->page_no, mtr);
@@ -276,7 +278,7 @@ trx_purge_add_update_undo_to_history(
if (undo->id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: undo->id is %lu\n", (ulong) undo->id);
- ut_a(0);
+ ut_error;
}
trx_rsegf_set_nth_undo(rseg_header, undo->id, FIL_NULL, mtr);
@@ -295,8 +297,7 @@ trx_purge_add_update_undo_to_history(
undo_header + TRX_UNDO_HISTORY_NODE, mtr);
/* Write the trx number to the undo log header */
- mlog_write_dulint(undo_header + TRX_UNDO_TRX_NO, trx->no, MLOG_8BYTES,
- mtr);
+ mlog_write_dulint(undo_header + TRX_UNDO_TRX_NO, trx->no, mtr);
/* Write information about delete markings to the undo log header */
if (!undo->del_marks) {
@@ -338,7 +339,9 @@ trx_purge_free_segment(
/* printf("Freeing an update undo log segment\n"); */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
loop:
mtr_start(&mtr);
mutex_enter(&(rseg->mutex));
@@ -434,7 +437,9 @@ trx_purge_truncate_rseg_history(
ulint n_removed_logs = 0;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
mutex_enter(&(rseg->mutex));
@@ -520,7 +525,9 @@ trx_purge_truncate_history(void)
dulint limit_trx_no;
dulint limit_undo_no;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx_purge_arr_get_biggest(purge_sys->arr, &limit_trx_no,
&limit_undo_no);
@@ -560,7 +567,9 @@ trx_purge_truncate_if_arr_empty(void)
/*=================================*/
/* out: TRUE if array empty */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (purge_sys->arr->n_used == 0) {
@@ -589,7 +598,9 @@ trx_purge_rseg_get_next_history_log(
ibool del_marks;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(rseg->mutex));
@@ -669,7 +680,9 @@ trx_purge_choose_next_log(void)
ulint offset = 0; /* remove warning (??? bug ???) */
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(purge_sys->next_stored == FALSE);
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
@@ -770,7 +783,9 @@ trx_purge_get_next_rec(
ulint cmpl_info;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(purge_sys->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(purge_sys->next_stored);
space = purge_sys->rseg->space;
@@ -1001,7 +1016,7 @@ trx_purge(void)
/* Should not happen */
- ut_a(0);
+ ut_error;
return(0);
}
@@ -1034,11 +1049,11 @@ trx_purge(void)
mutex_enter(&kernel_mutex);
- thr = que_fork_start_command(purge_sys->query, SESS_COMM_EXECUTE, 0);
+ thr = que_fork_start_command(purge_sys->query);
ut_ad(thr);
-/* thr2 = que_fork_start_command(purge_sys->query, SESS_COMM_EXECUTE, 0);
+/* thr2 = que_fork_start_command(purge_sys->query);
ut_ad(thr2); */
diff --git a/innobase/trx/trx0rec.c b/innobase/trx/trx0rec.c
index a0f500e51d7..bd37a4b506b 100644
--- a/innobase/trx/trx0rec.c
+++ b/innobase/trx/trx0rec.c
@@ -41,47 +41,6 @@ trx_undof_page_add_undo_rec_log(
byte* log_ptr;
ulint len;
-#ifdef notdefined
- ulint i;
- byte* prev_rec_ptr;
- byte* ptr;
- ulint min_len;
-
- ut_ad(new_free >= old_free + 4);
-
- i = 0;
- ptr = undo_page + old_free + 2;
-
- if (old_free > mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
- + TRX_UNDO_PAGE_START)) {
- prev_rec_ptr = undo_page + mach_read_from_2(ptr - 4) + 2;
-
- min_len = ut_min(new_free - old_free - 4,
- (undo_page + old_free - 2) - prev_rec_ptr);
- for (;;) {
- if (i >= min_len) {
-
- break;
- } else if ((*ptr == *prev_rec_ptr)
- || ((*ptr == *prev_rec_ptr + 1)
- && (ptr + 1 == suffix))) {
- i++;
- ptr++;
- prev_rec_ptr++;
- } else {
- break;
- }
- }
- }
-
- mlog_write_initial_log_record(undo_page, MLOG_UNDO_INSERT, mtr);
-
- mlog_catenate_ulint(mtr, old_free, MLOG_2BYTES);
-
- mlog_catenate_ulint_compressed(mtr, i);
-
- mlog_catenate_string(mtr, ptr, new_free - old_free - 2 - i);
-#endif
log_ptr = mlog_open(mtr, 30 + MLOG_BUF_MARGIN);
if (log_ptr == NULL) {
@@ -1111,7 +1070,9 @@ trx_undo_report_row_operation(
IB__FILE__, __LINE__,
&mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(undo_page, SYNC_TRX_UNDO_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
if (op_type == TRX_UNDO_INSERT_OP) {
offset = trx_undo_page_report_insert(undo_page, trx,
@@ -1238,7 +1199,9 @@ trx_undo_get_undo_rec(
trx_undo_rec_t** undo_rec, /* out, own: copy of the record */
mem_heap_t* heap) /* in: memory heap where copied */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
if (!trx_purge_update_undo_must_exist(trx_id)) {
@@ -1298,7 +1261,9 @@ trx_undo_prev_version_build(
ulint i;
char err_buf[1000];
+#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(mtr_memo_contains(index_mtr, buf_block_align(index_rec),
MTR_MEMO_PAGE_S_FIX) ||
mtr_memo_contains(index_mtr, buf_block_align(index_rec),
diff --git a/innobase/trx/trx0roll.c b/innobase/trx/trx0roll.c
index 1f053aeed89..6a25304c7ef 100644
--- a/innobase/trx/trx0roll.c
+++ b/innobase/trx/trx0roll.c
@@ -73,8 +73,7 @@ trx_general_rollback_for_mysql(
thr = pars_complete_graph_for_exec(roll_node, trx, heap);
- ut_a(thr == que_fork_start_command(que_node_get_parent(thr),
- SESS_COMM_EXECUTE, 0));
+ ut_a(thr == que_fork_start_command(que_node_get_parent(thr)));
que_run_threads(thr);
mutex_enter(&kernel_mutex);
@@ -354,8 +353,7 @@ trx_rollback_or_clean_all_without_sess(void)
/* Open a dummy session */
if (!trx_dummy_sess) {
- trx_dummy_sess = sess_open(NULL, (byte*)"Dummy sess",
- ut_strlen((char *) "Dummy sess"));
+ trx_dummy_sess = sess_open();
}
mutex_exit(&kernel_mutex);
@@ -418,7 +416,7 @@ loop:
trx->graph = fork;
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
+ ut_a(thr == que_fork_start_command(fork));
trx_roll_max_undo_no = ut_conv_dulint_to_longlong(trx->undo_no);
trx_roll_progress_printed_pct = 0;
@@ -678,8 +676,10 @@ trx_roll_try_truncate(
dulint limit;
dulint biggest;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
ut_ad(mutex_own(&((trx->rseg)->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx->pages_undone = 0;
@@ -722,7 +722,9 @@ trx_roll_pop_top_rec(
trx_undo_rec_t* prev_rec;
page_t* prev_rec_page;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
undo_page = trx_undo_page_get_s_latched(undo->space,
undo->top_page_no, mtr);
@@ -946,7 +948,9 @@ trx_rollback(
que_thr_t* thr;
/* que_thr_t* thr2; */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad((trx->undo_no_arr == NULL) || ((trx->undo_no_arr)->n_used == 0));
/* Initialize the rollback field in the transaction */
@@ -981,11 +985,11 @@ trx_rollback(
trx->graph = roll_graph;
trx->que_state = TRX_QUE_ROLLING_BACK;
- thr = que_fork_start_command(roll_graph, SESS_COMM_EXECUTE, 0);
+ thr = que_fork_start_command(roll_graph);
ut_ad(thr);
-/* thr2 = que_fork_start_command(roll_graph, SESS_COMM_EXECUTE, 0);
+/* thr2 = que_fork_start_command(roll_graph);
ut_ad(thr2); */
@@ -1015,7 +1019,9 @@ trx_roll_graph_build(
que_thr_t* thr;
/* que_thr_t* thr2; */
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
heap = mem_heap_create(512);
fork = que_fork_create(NULL, NULL, QUE_FORK_ROLLBACK, heap);
@@ -1042,7 +1048,9 @@ trx_finish_error_processing(
trx_sig_t* sig;
trx_sig_t* next_sig;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
sig = UT_LIST_GET_FIRST(trx->signals);
@@ -1075,14 +1083,16 @@ trx_finish_partial_rollback_off_kernel(
{
trx_sig_t* sig;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
sig = UT_LIST_GET_FIRST(trx->signals);
/* Remove the signal from the signal queue and send reply message
to it */
- trx_sig_reply(trx, sig, next_thr);
+ trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
trx->que_state = TRX_QUE_RUNNING;
@@ -1106,7 +1116,9 @@ trx_finish_rollback_off_kernel(
trx_sig_t* sig;
trx_sig_t* next_sig;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_a(trx->undo_no_arr == NULL || trx->undo_no_arr->n_used == 0);
@@ -1145,7 +1157,7 @@ trx_finish_rollback_off_kernel(
if (sig->type == TRX_SIG_TOTAL_ROLLBACK) {
- trx_sig_reply(trx, sig, next_thr);
+ trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
}
@@ -1213,7 +1225,7 @@ trx_rollback_step(
success = trx_sig_send(thr_get_trx(thr),
sig_no, TRX_SIG_SELF,
- TRUE, thr, savept, NULL);
+ thr, savept, NULL);
thr->state = QUE_THR_SIG_REPLY_WAIT;
diff --git a/innobase/trx/trx0rseg.c b/innobase/trx/trx0rseg.c
index b1fb8a9539c..e3885c86def 100644
--- a/innobase/trx/trx0rseg.c
+++ b/innobase/trx/trx0rseg.c
@@ -60,7 +60,9 @@ trx_rseg_header_create(
page_t* page;
ut_ad(mtr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space),
MTR_MEMO_X_LOCK));
sys_header = trx_sysf_get(mtr);
@@ -81,7 +83,9 @@ trx_rseg_header_create(
return(FIL_NULL);
}
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_RSEG_HEADER_NEW);
+#endif /* UNIV_SYNC_DEBUG */
page_no = buf_frame_get_page_no(page);
@@ -132,7 +136,9 @@ trx_rseg_mem_create(
fil_addr_t node_addr;
ulint sum_of_undo_sizes;
- ut_ad(mutex_own(&kernel_mutex));
+#ifdef UNIV_SYNC_DEBUG
+ ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
rseg = mem_alloc(sizeof(trx_rseg_t));
@@ -173,8 +179,7 @@ trx_rseg_mem_create(
+ node_addr.boffset;
rseg->last_trx_no = mtr_read_dulint(
- undo_log_hdr + TRX_UNDO_TRX_NO,
- MLOG_8BYTES, mtr);
+ undo_log_hdr + TRX_UNDO_TRX_NO, mtr);
rseg->last_del_marks = mtr_read_ulint(
undo_log_hdr + TRX_UNDO_DEL_MARKS,
MLOG_2BYTES, mtr);
diff --git a/innobase/trx/trx0sys.c b/innobase/trx/trx0sys.c
index d9eace5ad9a..57cfcef7d6f 100644
--- a/innobase/trx/trx0sys.c
+++ b/innobase/trx/trx0sys.c
@@ -134,7 +134,9 @@ trx_sys_mark_upgraded_to_multiple_tablespaces(void)
mtr_start(&mtr);
page = buf_page_get(TRX_SYS_SPACE, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
doublewrite = page + TRX_SYS_DOUBLEWRITE;
@@ -177,7 +179,9 @@ start_again:
mtr_start(&mtr);
page = buf_page_get(TRX_SYS_SPACE, TRX_SYS_PAGE_NO, RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
doublewrite = page + TRX_SYS_DOUBLEWRITE;
@@ -187,7 +191,7 @@ start_again:
just read in some numbers */
trx_doublewrite_init(doublewrite);
-
+
mtr_commit(&mtr);
} else {
fprintf(stderr,
@@ -211,7 +215,9 @@ start_again:
/* fseg_create acquires a second latch on the page,
therefore we must declare it: */
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page2, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
if (page2 == NULL) {
fprintf(stderr,
@@ -254,7 +260,9 @@ start_again:
new_page = buf_page_get(TRX_SYS_SPACE, page_no,
RW_X_LATCH, &mtr);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(new_page, SYNC_NO_ORDER_CHECK);
+#endif /* UNIV_SYNC_DEBUG */
/* Make a dummy change to the page to ensure it will
be written to disk in a flush */
@@ -510,7 +518,9 @@ trx_in_trx_list(
{
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
@@ -537,14 +547,16 @@ trx_sys_flush_max_trx_id(void)
trx_sysf_t* sys_header;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
sys_header = trx_sysf_get(&mtr);
mlog_write_dulint(sys_header + TRX_SYS_TRX_ID_STORE,
- trx_sys->max_trx_id, MLOG_8BYTES, &mtr);
+ trx_sys->max_trx_id, &mtr);
mtr_commit(&mtr);
}
@@ -736,7 +748,9 @@ trx_sysf_rseg_find_free(
ulint page_no;
ulint i;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(kernel_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
sys_header = trx_sysf_get(mtr);
@@ -782,13 +796,15 @@ trx_sysf_create(
mtr);
ut_a(buf_frame_get_page_no(page) == TRX_SYS_PAGE_NO);
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(page, SYNC_TRX_SYS_HEADER);
+#endif /* UNIV_SYNC_DEBUG */
sys_header = trx_sysf_get(mtr);
/* Start counting transaction ids from number 1 up */
mlog_write_dulint(sys_header + TRX_SYS_TRX_ID_STORE,
- ut_dulint_create(0, 1), MLOG_8BYTES, mtr);
+ ut_dulint_create(0, 1), mtr);
/* Reset the rollback segment slots */
for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
@@ -843,8 +859,7 @@ trx_sys_init_at_db_start(void)
trx_sys->max_trx_id = ut_dulint_add(
ut_dulint_align_up(
mtr_read_dulint(sys_header
- + TRX_SYS_TRX_ID_STORE,
- MLOG_8BYTES, &mtr),
+ + TRX_SYS_TRX_ID_STORE, &mtr),
TRX_SYS_TRX_ID_WRITE_MARGIN),
2 * TRX_SYS_TRX_ID_WRITE_MARGIN);
diff --git a/innobase/trx/trx0trx.c b/innobase/trx/trx0trx.c
index 3926cfa03c5..54358ad3d4c 100644
--- a/innobase/trx/trx0trx.c
+++ b/innobase/trx/trx0trx.c
@@ -73,7 +73,9 @@ trx_create(
{
trx_t* trx;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
trx = mem_alloc(sizeof(trx_t));
@@ -171,8 +173,7 @@ trx_allocate_for_mysql(void)
/* Open a dummy session */
if (!trx_dummy_sess) {
- trx_dummy_sess = sess_open(NULL, (byte*)"Dummy sess",
- ut_strlen((char *) "Dummy sess"));
+ trx_dummy_sess = sess_open();
}
trx = trx_create(trx_dummy_sess);
@@ -205,8 +206,7 @@ trx_allocate_for_background(void)
/* Open a dummy session */
if (!trx_dummy_sess) {
- trx_dummy_sess = sess_open(NULL, (byte*)"Dummy sess",
- ut_strlen("Dummy sess"));
+ trx_dummy_sess = sess_open();
}
trx = trx_create(trx_dummy_sess);
@@ -241,7 +241,9 @@ trx_free(
{
char err_buf[1000];
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (trx->declared_to_be_inside_innodb) {
ut_print_timestamp(stderr);
@@ -347,7 +349,9 @@ trx_list_insert_ordered(
{
trx_t* trx2;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
trx2 = UT_LIST_GET_FIRST(trx_sys->trx_list);
@@ -509,7 +513,9 @@ trx_assign_rseg(void)
{
trx_rseg_t* rseg = trx_sys->latest_rseg;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
loop:
/* Get next rseg in a round-robin fashion */
@@ -546,7 +552,9 @@ trx_start_low(
{
trx_rseg_t* rseg;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->rseg == NULL);
if (trx->type == TRX_PURGE) {
@@ -621,7 +629,9 @@ trx_commit_off_kernel(
ibool must_flush_log = FALSE;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
rseg = trx->rseg;
@@ -650,29 +660,6 @@ trx_commit_off_kernel(
if (undo) {
mutex_enter(&kernel_mutex);
-#ifdef notdefined
- /* !!!!!!!!! There is a bug here: purge and rollback
- need the whole stack of old record versions even if no
- consistent read would need them!! This is because they
- decide on the basis of the old versions when we can
- remove delete marked secondary index records! */
-
- if (!undo->del_marks && (undo->size == 1)
- && (UT_LIST_GET_LEN(trx_sys->view_list) == 1)) {
-
- /* There is no need to save the update undo
- log: discard it; note that &mtr gets committed
- while we must hold the kernel mutex and
- therefore this optimization may add to the
- contention of the kernel mutex. */
-
- lsn = trx_undo_update_cleanup_by_discard(trx,
- &mtr);
- mutex_exit(&(rseg->mutex));
-
- goto shortcut;
- }
-#endif
trx->no = trx_sys_get_new_trx_no();
mutex_exit(&kernel_mutex);
@@ -714,11 +701,13 @@ trx_commit_off_kernel(
TRX_SYS_MYSQL_MASTER_LOG_INFO, &mtr);
}
- /* If we did not take the shortcut, the following call
- commits the mini-transaction, making the whole transaction
- committed in the file-based world at this log sequence number;
- otherwise, we get the commit lsn from the call of
- trx_undo_update_cleanup_by_discard above.
+ /* The following call commits the mini-transaction, making the
+ whole transaction committed in the file-based world, at this
+ log sequence number. The transaction becomes 'durable' when
+ we write the log to disk, but in the logical sense the commit
+ in the file-based data structures (undo logs etc.) happens
+ here.
+
NOTE that transaction numbers, which are assigned only to
transactions with an update undo log, do not necessarily come
in exactly the same order as commit lsn's, if the transactions
@@ -738,7 +727,9 @@ trx_commit_off_kernel(
}
ut_ad(trx->conc_state == TRX_ACTIVE);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
/* The following assignment makes the transaction committed in memory
and makes its changes to data visible to other transactions.
@@ -827,7 +818,7 @@ trx_commit_off_kernel(
log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, FALSE);
} else {
- ut_a(0);
+ ut_error;
}
trx->commit_lsn = lsn;
@@ -918,7 +909,9 @@ trx_handle_commit_sig_off_kernel(
trx_sig_t* sig;
trx_sig_t* next_sig;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
trx->que_state = TRX_QUE_COMMITTING;
@@ -936,7 +929,7 @@ trx_handle_commit_sig_off_kernel(
if (sig->type == TRX_SIG_COMMIT) {
- trx_sig_reply(trx, sig, next_thr);
+ trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
}
@@ -958,7 +951,9 @@ trx_end_lock_wait(
{
que_thr_t* thr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
thr = UT_LIST_GET_FIRST(trx->wait_thrs);
@@ -985,7 +980,9 @@ trx_lock_wait_to_suspended(
{
que_thr_t* thr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
thr = UT_LIST_GET_FIRST(trx->wait_thrs);
@@ -1013,7 +1010,9 @@ trx_sig_reply_wait_to_suspended(
trx_sig_t* sig;
que_thr_t* thr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
sig = UT_LIST_GET_FIRST(trx->reply_signals);
@@ -1025,7 +1024,6 @@ trx_sig_reply_wait_to_suspended(
thr->state = QUE_THR_SUSPENDED;
sig->receiver = NULL;
- sig->reply = FALSE;
UT_LIST_REMOVE(reply_signals, trx->reply_signals, sig);
@@ -1047,7 +1045,9 @@ trx_sig_is_compatible(
{
trx_sig_t* sig;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (UT_LIST_GET_LEN(trx->signals) == 0) {
@@ -1119,13 +1119,9 @@ trx_sig_send(
ulint type, /* in: signal type */
ulint sender, /* in: TRX_SIG_SELF or
TRX_SIG_OTHER_SESS */
- ibool reply, /* in: TRUE if the sender of the signal
- wants reply after the operation induced
- by the signal is completed; if type
- is TRX_SIG_END_WAIT, this must be
- FALSE */
que_thr_t* receiver_thr, /* in: query thread which wants the
- reply, or NULL */
+ reply, or NULL; if type is
+ TRX_SIG_END_WAIT, this must be NULL */
trx_savept_t* savept, /* in: possible rollback savepoint, or
NULL */
que_thr_t** next_thr) /* in/out: next query thread to run;
@@ -1139,16 +1135,16 @@ trx_sig_send(
trx_t* receiver_trx;
ut_ad(trx);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (!trx_sig_is_compatible(trx, type, sender)) {
/* The signal is not compatible with the other signals in
the queue: do nothing */
- ut_a(0);
+ ut_error;
- /* sess_raise_error_low(trx, 0, 0, NULL, NULL, NULL, NULL,
- "Incompatible signal"); */
return(FALSE);
}
@@ -1171,7 +1167,6 @@ trx_sig_send(
sig->type = type;
sig->state = TRX_SIG_WAITING;
sig->sender = sender;
- sig->reply = reply;
sig->receiver = receiver_thr;
if (savept) {
@@ -1196,10 +1191,7 @@ trx_sig_send(
signal to the end of the queue, if the session is not yet
in the error state: */
- ut_a(0);
-
- sess_raise_error_low(trx, 0, 0, NULL, NULL, NULL, NULL,
- (char *) "Signal from another session, or a break execution signal");
+ ut_error;
}
/* If there were no other signals ahead in the queue, try to start
@@ -1224,7 +1216,9 @@ trx_end_signal_handling(
/*====================*/
trx_t* trx) /* in: trx */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(trx->handling_signals == TRUE);
trx->handling_signals = FALSE;
@@ -1258,7 +1252,9 @@ loop:
we can process immediately */
ut_ad(trx);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
if (trx->handling_signals && (UT_LIST_GET_LEN(trx->signals) == 0)) {
@@ -1333,7 +1329,7 @@ loop:
} else if (type == TRX_SIG_BREAK_EXECUTION) {
- trx_sig_reply(trx, sig, next_thr);
+ trx_sig_reply(sig, next_thr);
trx_sig_remove(trx, sig);
} else {
ut_error;
@@ -1349,7 +1345,6 @@ handled. */
void
trx_sig_reply(
/*==========*/
- trx_t* trx, /* in: trx handle */
trx_sig_t* sig, /* in: signal */
que_thr_t** next_thr) /* in/out: next query thread to run;
if the value which is passed in is
@@ -1359,11 +1354,12 @@ trx_sig_reply(
{
trx_t* receiver_trx;
- ut_ad(trx && sig);
+ ut_ad(sig);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
- if (sig->reply && (sig->receiver != NULL)) {
-
+ if (sig->receiver != NULL) {
ut_ad((sig->receiver)->state == QUE_THR_SIG_REPLY_WAIT);
receiver_trx = thr_get_trx(sig->receiver);
@@ -1374,18 +1370,8 @@ trx_sig_reply(
que_thr_end_wait(sig->receiver, next_thr);
- sig->reply = FALSE;
- sig->receiver = NULL;
-
- } else if (sig->reply) {
- /* In this case the reply should be sent to the client of
- the session of the transaction */
-
- sig->reply = FALSE;
sig->receiver = NULL;
- sess_srv_msg_send_simple(trx->sess, SESS_SRV_SUCCESS,
- SESS_NOT_RELEASE_KERNEL);
}
}
@@ -1399,9 +1385,10 @@ trx_sig_remove(
trx_sig_t* sig) /* in, own: signal */
{
ut_ad(trx && sig);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
- ut_ad(sig->reply == FALSE);
ut_ad(sig->receiver == NULL);
UT_LIST_REMOVE(signals, trx->signals, sig);
@@ -1463,8 +1450,7 @@ trx_commit_step(
/* Send the commit signal to the transaction */
success = trx_sig_send(thr_get_trx(thr), TRX_SIG_COMMIT,
- TRX_SIG_SELF, TRUE, thr, NULL,
- &next_thr);
+ TRX_SIG_SELF, thr, NULL, &next_thr);
mutex_exit(&kernel_mutex);
@@ -1550,7 +1536,7 @@ trx_commit_complete_for_mysql(
log_write_up_to(lsn, LOG_WAIT_ONE_GROUP, FALSE);
} else {
- ut_a(0);
+ ut_error;
}
trx->op_info = (char*)"";
diff --git a/innobase/trx/trx0undo.c b/innobase/trx/trx0undo.c
index f3f93734a49..0a47134c163 100644
--- a/innobase/trx/trx0undo.c
+++ b/innobase/trx/trx0undo.c
@@ -391,7 +391,9 @@ trx_undo_seg_create(
ibool success;
ut_ad(mtr && id && rseg_hdr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
/*
if (type == TRX_UNDO_INSERT) {
printf("Creating insert undo log segment\n");
@@ -431,7 +433,9 @@ trx_undo_seg_create(
return(NULL);
}
+#ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(undo_page, SYNC_TRX_UNDO_PAGE);
+#endif /* UNIV_SYNC_DEBUG */
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
@@ -737,13 +741,14 @@ trx_undo_add_page(
ulint n_reserved;
ibool success;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
ut_ad(!mutex_own(&kernel_mutex));
+ ut_ad(mutex_own(&(trx->rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
rseg = trx->rseg;
- ut_ad(mutex_own(&(rseg->mutex)));
-
if (rseg->curr_size == rseg->max_size) {
return(FIL_NULL);
@@ -813,8 +818,10 @@ trx_undo_free_page(
UT_NOT_USED(hdr_offset);
ut_a(hdr_page_no != page_no);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
undo_page = trx_undo_page_get(space, page_no, mtr);
@@ -861,7 +868,9 @@ trx_undo_free_page_in_rollback(
ulint last_page_no;
ut_ad(undo->hdr_page_no != page_no);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
last_page_no = trx_undo_free_page(undo->rseg, FALSE, undo->space,
undo->hdr_page_no, undo->hdr_offset,
@@ -915,12 +924,13 @@ trx_undo_truncate_end(
trx_rseg_t* rseg;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
+ ut_ad(mutex_own(&(trx->rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
rseg = trx->rseg;
- ut_ad(mutex_own(&(rseg->mutex)));
-
for (;;) {
mtr_start(&mtr);
@@ -994,7 +1004,9 @@ trx_undo_truncate_start(
ulint page_no;
mtr_t mtr;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (0 == ut_dulint_cmp(limit, ut_dulint_zero)) {
@@ -1060,8 +1072,9 @@ trx_undo_seg_free(
while (!finished) {
mtr_start(&mtr);
-
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(rseg->mutex));
seg_header = trx_undo_page_get(undo->space, undo->hdr_page_no,
@@ -1117,7 +1130,7 @@ trx_undo_mem_create_at_db_start(
if (id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: undo->id is %lu\n", (ulong) id);
- ut_a(0);
+ ut_error;
}
undo_page = trx_undo_page_get(rseg->space, page_no, mtr);
@@ -1134,8 +1147,7 @@ trx_undo_mem_create_at_db_start(
undo_header = undo_page + offset;
- trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, MLOG_8BYTES,
- mtr);
+ trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, mtr);
mutex_enter(&(rseg->mutex));
undo = trx_undo_mem_create(rseg, id, type, trx_id, page_no, offset);
@@ -1145,8 +1157,7 @@ trx_undo_mem_create_at_db_start(
undo->dict_operation = mtr_read_ulint(
undo_header + TRX_UNDO_DICT_OPERATION,
MLOG_2BYTES, mtr);
- undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID,
- MLOG_8BYTES, mtr);
+ undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID, mtr);
undo->state = state;
undo->size = flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr);
@@ -1270,12 +1281,14 @@ trx_undo_mem_create(
{
trx_undo_t* undo;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: undo->id is %lu\n", (ulong) id);
- ut_a(0);
+ ut_error;
}
undo = mem_alloc(sizeof(trx_undo_t));
@@ -1314,14 +1327,16 @@ trx_undo_mem_init_for_reuse(
is created */
ulint offset) /* in: undo log header byte offset on page */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&((undo->rseg)->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (undo->id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
(ulong) undo->id);
mem_analyze_corruption((byte*)undo);
- ut_a(0);
+ ut_error;
}
undo->state = TRX_UNDO_ACTIVE;
@@ -1345,7 +1360,7 @@ trx_undo_mem_free(
if (undo->id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: undo->id is %lu\n", (ulong) undo->id);
- ut_a(0);
+ ut_error;
}
mem_free(undo);
@@ -1373,7 +1388,9 @@ trx_undo_create(
trx_undo_t* undo;
page_t* undo_page;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (rseg->curr_size == rseg->max_size) {
@@ -1424,7 +1441,9 @@ trx_undo_reuse_cached(
page_t* undo_page;
ulint offset;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
+#endif /* UNIV_SYNC_DEBUG */
if (type == TRX_UNDO_INSERT) {
@@ -1448,13 +1467,12 @@ trx_undo_reuse_cached(
}
ut_ad(undo->size == 1);
- ut_ad(undo->hdr_page_no == undo->top_page_no);
if (undo->id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
(ulong) undo->id);
mem_analyze_corruption((byte*)undo);
- ut_a(0);
+ ut_error;
}
undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
@@ -1495,7 +1513,7 @@ trx_undo_mark_as_dict_operation(
trx->dict_operation, MLOG_2BYTES, mtr);
mlog_write_dulint(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
- trx->table_id, MLOG_8BYTES, mtr);
+ trx->table_id, mtr);
undo->dict_operation = trx->dict_operation;
undo->table_id = trx->table_id;
@@ -1522,11 +1540,15 @@ trx_undo_assign_undo(
rseg = trx->rseg;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(trx->undo_mutex)));
+#endif /* UNIV_SYNC_DEBUG */
mtr_start(&mtr);
+#ifdef UNIV_SYNC_DEBUG
ut_ad(!mutex_own(&kernel_mutex));
+#endif /* UNIV_SYNC_DEBUG */
mutex_enter(&(rseg->mutex));
undo = trx_undo_reuse_cached(rseg, type, trx->id, &mtr);
@@ -1587,7 +1609,7 @@ trx_undo_set_state_at_finish(
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
(ulong) undo->id);
mem_analyze_corruption((byte*)undo);
- ut_a(0);
+ ut_error;
}
undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
@@ -1632,8 +1654,9 @@ trx_undo_update_cleanup(
undo = trx->update_undo;
rseg = trx->rseg;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&(rseg->mutex)));
-
+#endif /* UNIV_SYNC_DEBUG */
trx_purge_add_update_undo_to_history(trx, undo_page, mtr);
UT_LIST_REMOVE(undo_list, rseg->update_undo_list, undo);
@@ -1650,54 +1673,6 @@ trx_undo_update_cleanup(
}
}
-/**************************************************************************
-Discards an undo log and puts the segment to the list of cached update undo
-log segments. This optimized function is called if there is no need to keep
-the update undo log because there exist no read views and the transaction
-made no delete markings, which would make purge necessary. We restrict this
-to undo logs of size 1 to make things simpler. */
-
-dulint
-trx_undo_update_cleanup_by_discard(
-/*===============================*/
- /* out: log sequence number at which mtr is
- committed */
- trx_t* trx, /* in: trx owning the update undo log */
- mtr_t* mtr) /* in: mtr */
-{
- trx_rseg_t* rseg;
- trx_undo_t* undo;
- page_t* undo_page;
-
- undo = trx->update_undo;
- rseg = trx->rseg;
-
- ut_ad(mutex_own(&(rseg->mutex)));
- ut_ad(mutex_own(&kernel_mutex));
- ut_ad(undo->size == 1);
- ut_ad(undo->del_marks == FALSE);
- ut_ad(UT_LIST_GET_LEN(trx_sys->view_list) == 1);
-
- /* NOTE: we must hold the kernel mutex, because we must prevent
- creation of new read views before mtr gets committed! */
-
- undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
-
- trx_undo_discard_latest_update_undo(undo_page, mtr);
-
- undo->state = TRX_UNDO_CACHED;
-
- UT_LIST_REMOVE(undo_list, rseg->update_undo_list, undo);
-
- trx->update_undo = NULL;
-
- UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
-
- mtr_commit(mtr);
-
- return(mtr->end_lsn);
-}
-
/**********************************************************************
Frees or caches an insert undo log after a transaction commit or rollback.
Knowledge of inserts is not needed after a commit or rollback, therefore
diff --git a/innobase/trx/ts/makefile b/innobase/trx/ts/makefile
deleted file mode 100644
index 48e4befcb27..00000000000
--- a/innobase/trx/ts/makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-include ..\..\makefile.i
-
-tstrx: ..\trx.lib tstrx.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\btr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tstrx.c $(LFL)
-
-
-
-
-
-
-
-
-
diff --git a/innobase/trx/ts/tstrx.c b/innobase/trx/ts/tstrx.c
deleted file mode 100644
index f69c02dd51e..00000000000
--- a/innobase/trx/ts/tstrx.c
+++ /dev/null
@@ -1,1663 +0,0 @@
-/************************************************************************
-Test for the transaction system
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "rem0rec.h"
-#include "srv0srv.h"
-#include "que0que.h"
-#include "com0com.h"
-#include "usr0sess.h"
-#include "lock0lock.h"
-#include "trx0roll.h"
-#include "row0ins.h"
-#include "row0upd.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 1
-#define N_FILES 1
-#define FILE_SIZE 1024 /* must be > 512 */
-#define POOL_SIZE 512
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- } else {
- ut_a(os_file_set_size(files[i], 8192 * FILE_SIZE, 0));
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space 0. */
-
-void
-init_space(void)
-/*============*/
-{
- mtr_t mtr;
-
- printf("Init space header\n");
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-/*********************************************************************
-Test for table creation. */
-
-ulint
-test1(
-/*==*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, 0, 2);
-
- dict_mem_index_add_field(index, "COL2", 0);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- /*-------------------------------------*/
- /* CREATE ANOTHER SECONDARY INDEX */
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, 0, 2);
-
- dict_mem_index_add_field(index, "COL2", 0);
- dict_mem_index_add_field(index, "COL1", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE2", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE2", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Another test for table creation. */
-
-ulint
-test1_6(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- dict_index_t* index;
- dict_table_t* table;
- que_fork_t* fork;
- que_thr_t* thr;
- trx_t* trx;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 1.5. CREATE TABLE WITH 3 COLUMNS AND WITH 1 INDEX\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- table = dict_mem_table_create("TS_TABLE3", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
- /*------------------------------------*/
- /* CREATE TABLE */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = tab_create_graph_create(fork, thr, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_TABLES");
- dict_table_print_by_name("SYS_COLUMNS"); */
- /*-------------------------------------*/
- /* CREATE CLUSTERED INDEX */
-
- index = dict_mem_index_create("TS_TABLE3", "IND1", 0, DICT_CLUSTERED,
- 2);
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = ind_create_graph_create(fork, thr, index, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* dict_table_print_by_name("SYS_INDEXES");
- dict_table_print_by_name("SYS_FIELDS"); */
-
- return(0);
-}
-
-/*********************************************************************
-Test for inserts. */
-
-ulint
-test2(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- byte buf[100];
- ulint count = 0;
- ins_node_t* node;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. MASSIVE INSERT\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* MASSIVE INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- node = ins_node_create(fork, thr, row, table, heap);
-
- thr->child = node;
-
- row_ins_init_sys_fields_at_sql_compile(node->row, node->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(node->row, node->table, trx);
-
- node->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- mem_print_info();
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- rnd = (rnd + 1) % 200000;
-
- dtuple_gen_test_tuple3(row, rnd, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- mem_print_info();
-
-/* dict_table_print_by_name("TS_TABLE1"); */
- /*-------------------------------------*/
- /* ROLLBACK */
-#ifdef notdefined
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu inserts %lu milliseconds\n",
- i, tm - oldtm);
- /*-------------------------------------*/
-#endif
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
- count++;
-
- if (count < 1) {
- goto loop;
- }
- return(0);
-}
-
-/*********************************************************************
-Test for updates. */
-
-ulint
-test3(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
- ulint err;
-
- UT_NOT_USED(arg);
-
- printf("-------------------------------------------------\n");
- printf("TEST 3. UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 3; i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, 1, DTUPLE_TEST_FIXED30, buf);
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(tree, entry, PAGE_CUR_G, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- ufield->col_no = 2;
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- ufield->col_no = 0;
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-#ifdef notdefined
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
- return(0);
-}
-
-/*********************************************************************
-Test for massive updates. */
-
-ulint
-test4(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- ulint j;
- ulint rnd;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- byte* ptr;
- ulint len;
- ulint err;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4. MASSIVE UPDATES\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-loop:
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu inserts %lu milliseconds\n", i, tm - oldtm);
-
-#ifdef notdefined
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* UPDATE ROWS */
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-#endif
- fork = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- update = upd_create(1, heap);
-
- node = upd_node_create(fork, thr, table, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = 0;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- for (j = 0; j < 2; j++) {
- for (i = 0; i < *((ulint*)arg); i++) {
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- index = dict_table_get_first_index(table);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(tree, entry, PAGE_CUR_G, BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_store_position(&pcur, &mtr);
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- btr_pcur_commit(&pcur);
-
- ufield = upd_get_nth_field(update, 0);
-
- ufield->col_no = 2;
- dfield_set_data(&(ufield->new_val), "updated field", 14);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
- }
- mtr_start(&mtr);
-
- ut_a(btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr));
-
- ptr = rec_get_nth_field(btr_pcur_get_rec(&pcur), 5, &len);
-
- ut_a(ut_memcmp(ptr, "updated field", 14) == 0);
-
- btr_pcur_commit(&pcur);
-
- dict_table_print_by_name("TS_TABLE1");
-
- ufield = upd_get_nth_field(update, 0);
-
- ufield->col_no = 0;
- dfield_set_data(&(ufield->new_val), "31415926", 9);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(
- thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- dict_table_print_by_name("TS_TABLE1");
- /*-------------------------------------*/
- /* ROLLBACK */
-
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = roll_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for rollback of %lu updates %lu milliseconds\n",
- i, tm - oldtm);
-#ifdef notdefined
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- oldtm = ut_clock();
-
- que_run_threads(thr);
-
- tm = ut_clock();
- printf("Wall time for commit %lu milliseconds\n", tm - oldtm);
-
- /*-------------------------------------*/
-#endif
- dict_table_print_by_name("TS_TABLE1");
- count++;
-
- if (count < 1) {
- goto loop;
- }
- return(0);
-}
-
-/*********************************************************************
-Init TS_TABLE2 for TPC-A transaction. */
-
-ulint
-test4_5(
-/*====*/
- void* arg)
-{
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork;
- dict_table_t* table;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- byte buf[100];
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 4_5. INIT FOR TPC-A\n");
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- /*-------------------------------------*/
- /* INSERT INTO TABLE TO UPDATE */
-
- for (i = 0; i < 100; i++) {
- fork = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- table = dict_table_get("TS_TABLE2", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- thr->child = ins_node_create(fork, thr, row, table, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- mutex_exit(&kernel_mutex);
-
- dtuple_gen_test_tuple3(row, i, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- }
-/* dict_table_print_by_name("TS_TABLE2"); */
-
- /*-------------------------------------*/
- /* COMMIT */
- fork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- fork->trx = trx;
-
- thr = que_thr_create(fork, fork, heap);
-
- thr->child = commit_node_create(fork, thr, heap);
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork, trx->sess);
-
- trx->graph = fork;
-
- ut_a(thr == que_fork_start_command(fork, SESS_COMM_EXECUTE, 0));
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-----------------------------------*/
-
- return(0);
-}
-
-/*********************************************************************
-Test for TPC-A transaction. */
-
-ulint
-test5(
-/*==*/
- void* arg)
-{
- ulint tm, oldtm;
- sess_t* sess;
- com_endpoint_t* com_endpoint;
- mem_heap_t* heap;
- que_fork_t* fork1;
- que_fork_t* fork2;
- que_fork_t* cfork;
- dict_table_t* table;
- dict_table_t* table2;
- que_thr_t* thr;
- trx_t* trx;
- ulint i;
- dtuple_t* row;
- dtuple_t* entry;
- byte buf[100];
- ulint count = 0;
- btr_pcur_t pcur;
- upd_t* update;
- upd_field_t* ufield;
- dict_tree_t* tree;
- dict_index_t* index;
- mtr_t mtr;
- upd_node_t* node;
- ulint err;
- ins_node_t* inode;
-
- arg = arg;
-
- printf("-------------------------------------------------\n");
- printf("TEST 5. TPC-A %lu \n", *((ulint*)arg));
-
- oldtm = ut_clock();
-
- heap = mem_heap_create(512);
-
- com_endpoint = (com_endpoint_t*)heap; /* This is a dummy non-NULL
- value */
- mutex_enter(&kernel_mutex);
-
- sess = sess_open(ut_dulint_zero, com_endpoint, (byte*)"user1", 6);
-
- trx = sess->trx;
-
- mutex_exit(&kernel_mutex);
-
- ut_a(trx_start(trx, ULINT_UNDEFINED));
- /*-----------------------------------*/
-
- fork1 = que_fork_create(NULL, NULL, QUE_FORK_INSERT, heap);
- fork1->trx = trx;
-
- thr = que_thr_create(fork1, fork1, heap);
-
- table = dict_table_get("TS_TABLE3", trx);
-
- row = dtuple_create(heap, 3 + DATA_N_SYS_COLS);
-
- dict_table_copy_types(row, table);
-
- inode = ins_node_create(fork1, thr, row, table, heap);
-
- thr->child = inode;
-
- row_ins_init_sys_fields_at_sql_compile(inode->row, inode->table, heap);
- row_ins_init_sys_fields_at_sql_prepare(inode->row, inode->table, trx);
-
- inode->init_all_sys_fields = FALSE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork1, trx->sess);
-
- trx->graph = fork1;
-
- mutex_exit(&kernel_mutex);
-
- fork2 = que_fork_create(NULL, NULL, QUE_FORK_UPDATE, heap);
- fork2->trx = trx;
-
- thr = que_thr_create(fork2, fork2, heap);
-
- table2 = dict_table_get("TS_TABLE2", trx);
-
- update = upd_create(1, heap);
-
- entry = dtuple_create(heap, 2);
- dfield_copy(dtuple_get_nth_field(entry, 0),
- dtuple_get_nth_field(row, 0));
- dfield_copy(dtuple_get_nth_field(entry, 1),
- dtuple_get_nth_field(row, 1));
-
- node = upd_node_create(fork2, thr, table2, &pcur, update, heap);
- thr->child = node;
-
- node->cmpl_info = UPD_NODE_NO_ORD_CHANGE | UPD_NODE_NO_SIZE_CHANGE;
-
- mutex_enter(&kernel_mutex);
-
- que_graph_publish(fork2, trx->sess);
-
- trx->graph = fork2;
-
- mutex_exit(&kernel_mutex);
-
- cfork = que_fork_create(NULL, NULL, QUE_FORK_EXECUTE, heap);
- cfork->trx = trx;
-
- thr = que_thr_create(cfork, cfork, heap);
-
- thr->child = commit_node_create(cfork, thr, heap);
-
- oldtm = ut_clock();
-loop:
- /*-------------------------------------*/
- /* INSERT */
-
-/* printf("Trx %lu %lu starts, thr %lu\n",
- ut_dulint_get_low(trx->id),
- (ulint)trx,
- *((ulint*)arg)); */
-
- dtuple_gen_test_tuple3(row, count, DTUPLE_TEST_FIXED30, buf);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork1, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- /*-------------------------------------*/
- /* 3 UPDATES */
-
- for (i = 0; i < 3; i++) {
-
- dtuple_gen_search_tuple3(entry, *((ulint*)arg), buf);
-
- index = dict_table_get_first_index(table2);
- tree = dict_index_get_tree(index);
-
- btr_pcur_set_mtr(&pcur, &mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_open(tree, entry, PAGE_CUR_G, BTR_MODIFY_LEAF, &pcur, &mtr);
-
-/* btr_pcur_store_position(&pcur, &mtr); */
-
- err = lock_clust_rec_read_check_and_lock(0, btr_pcur_get_rec(&pcur),
- index, LOCK_X, thr);
- ut_a(err == DB_SUCCESS);
-
- ufield = upd_get_nth_field(update, 0);
-
- ufield->col_no = 2;
- dfield_set_data(&(ufield->new_val),
- "updated field1234567890123456", 30);
-
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(fork2, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
- } /* for (i = ... */
-
- /*-------------------------------------*/
- /* COMMIT */
-#ifdef notdefined
- mutex_enter(&kernel_mutex);
-
- thr = que_fork_start_command(cfork, SESS_COMM_EXECUTE, 0);
-
- mutex_exit(&kernel_mutex);
-
- que_run_threads(thr);
-
-/* printf("Trx %lu %lu committed\n", ut_dulint_get_low(trx->id),
- (ulint)trx); */
-#endif
- count++;
-
- if (count < 1000) {
- ut_a(trx_start(trx, ULINT_UNDEFINED));
-
- goto loop;
- }
-
- tm = ut_clock();
- printf("Wall time for TPC-A %lu trxs %lu milliseconds\n",
- count, tm - oldtm);
-
- /*-------------------------------------*/
-/* dict_table_print_by_name("TS_TABLE2");
- dict_table_print_by_name("TS_TABLE3"); */
-
- return(0);
-}
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- os_thread_id_t id[5];
- ulint n1000[5];
- ulint i;
- ulint n5000 = 500;
-
- srv_boot("initfile");
- os_aio_init(160, 5);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
-
- create_files();
- init_space();
-
- sess_sys_init_at_db_start();
-
- trx_sys_create();
-
- lock_sys_create(1024);
-
- dict_create();
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1(NULL);
- test1_5(NULL);
- test1_6(NULL);
- test4_5(NULL);
-
- for (i = 1; i < 5; i++) {
- n1000[i] = i;
- id[i] = id[i];
-/* os_thread_create(test5, n1000 + i, id + i); */
- }
-
-/* mem_print_info(); */
-
-/* test2(&n5000); */
-
- n5000 = 30;
-
- test5(&n5000);
-
- n5000 = 30;
-/* test5(&n5000); */
-
-/* mem_print_info(); */
-
-/* dict_table_print_by_name("TS_TABLE1"); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/trx/ts/tsttrxold.c b/innobase/trx/ts/tsttrxold.c
deleted file mode 100644
index 13faa7ac79f..00000000000
--- a/innobase/trx/ts/tsttrxold.c
+++ /dev/null
@@ -1,1089 +0,0 @@
-/************************************************************************
-Test for the transaction system
-
-(c) 1994-1997 Innobase Oy
-
-Created 2/16/1996 Heikki Tuuri
-*************************************************************************/
-
-#include "sync0sync.h"
-#include "ut0mem.h"
-#include "mem0mem.h"
-#include "data0data.h"
-#include "data0type.h"
-#include "dict0dict.h"
-#include "buf0buf.h"
-#include "os0file.h"
-#include "fil0fil.h"
-#include "fsp0fsp.h"
-#include "rem0rec.h"
-#include "rem0cmp.h"
-#include "mtr0mtr.h"
-#include "log0log.h"
-#include "page0page.h"
-#include "page0cur.h"
-#include "trx0trx.h"
-#include "dict0boot.h"
-#include "trx0sys.h"
-#include "dict0crea.h"
-#include "btr0btr.h"
-#include "btr0pcur.h"
-#include "rem0rec.h"
-
-os_file_t files[1000];
-
-mutex_t ios_mutex;
-ulint ios;
-ulint n[10];
-
-mutex_t incs_mutex;
-ulint incs;
-
-byte bigbuf[1000000];
-
-#define N_SPACES 1
-#define N_FILES 1
-#define FILE_SIZE 4000 /* must be > 512 */
-#define POOL_SIZE 1000
-#define COUNTER_OFFSET 1500
-
-#define LOOP_SIZE 150
-#define N_THREADS 5
-
-
-ulint zero = 0;
-
-buf_block_t* bl_arr[POOL_SIZE];
-
-/************************************************************************
-Io-handler thread function. */
-
-ulint
-handler_thread(
-/*===========*/
- void* arg)
-{
- ulint segment;
- void* mess;
- ulint i;
- bool ret;
-
- segment = *((ulint*)arg);
-
- printf("Io handler thread %lu starts\n", segment);
-
- for (i = 0;; i++) {
- ret = fil_aio_wait(segment, &mess);
- ut_a(ret);
-
- buf_page_io_complete((buf_block_t*)mess);
-
- mutex_enter(&ios_mutex);
- ios++;
- mutex_exit(&ios_mutex);
-
- }
-
- return(0);
-}
-
-/*************************************************************************
-Creates the files for the file system test and inserts them to
-the file system. */
-
-void
-create_files(void)
-/*==============*/
-{
- bool ret;
- ulint i, k;
- char name[20];
- os_thread_t thr[5];
- os_thread_id_t id[5];
-
- printf("--------------------------------------------------------\n");
- printf("Create or open database files\n");
-
- strcpy(name, "tsfile00");
-
- for (k = 0; k < N_SPACES; k++) {
- for (i = 0; i < N_FILES; i++) {
-
- name[6] = (char)((ulint)'0' + k);
- name[7] = (char)((ulint)'0' + i);
-
- files[i] = os_file_create(name, OS_FILE_CREATE,
- OS_FILE_TABLESPACE, &ret);
-
- if (ret == FALSE) {
- ut_a(os_file_get_last_error() ==
- OS_FILE_ALREADY_EXISTS);
-
- files[i] = os_file_create(
- name, OS_FILE_OPEN,
- OS_FILE_TABLESPACE, &ret);
-
- ut_a(ret);
- }
-
- ret = os_file_close(files[i]);
- ut_a(ret);
-
- if (i == 0) {
- fil_space_create(name, k, OS_FILE_TABLESPACE);
- }
-
- ut_a(fil_validate());
-
- fil_node_create(name, FILE_SIZE, k);
- }
- }
-
- ios = 0;
-
- mutex_create(&ios_mutex);
-
- for (i = 0; i < 5; i++) {
- n[i] = i;
-
- thr[i] = os_thread_create(handler_thread, n + i, id + i);
- }
-}
-
-/************************************************************************
-Inits space header of space 0. */
-
-void
-init_space(void)
-/*============*/
-{
- mtr_t mtr;
-
- printf("Init space header\n");
-
- mtr_start(&mtr);
-
- fsp_header_init(0, FILE_SIZE * N_FILES, &mtr);
-
- mtr_commit(&mtr);
-}
-
-#ifdef notdefined
-
-/*********************************************************************
-Test for index page. */
-
-void
-test1(void)
-/*=======*/
-{
- dtuple_t* tuple;
- mem_heap_t* heap;
- mem_heap_t* heap2;
- ulint rnd = 0;
- dict_index_t* index;
- dict_table_t* table;
- byte buf[16];
- ulint i, j;
- ulint tm, oldtm;
- trx_t* trx;
-/* dict_tree_t* tree;*/
- btr_pcur_t pcur;
- btr_pcur_t pcur2;
- mtr_t mtr;
- mtr_t mtr2;
- byte* field;
- ulint len;
- dtuple_t* search_tuple;
- dict_tree_t* index_tree;
- rec_t* rec;
-
- UT_NOT_USED(len);
- UT_NOT_USED(field);
- UT_NOT_USED(pcur2);
-/*
- printf("\n\n\nPress 2 x enter to start test\n");
-
- while (EOF == getchar()) {
-
- }
-
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 1. CREATE TABLE WITH 3 COLUMNS AND WITH 3 INDEXES\n");
-
- heap = mem_heap_create(1024);
- heap2 = mem_heap_create(1024);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- table = dict_mem_table_create("TS_TABLE1", 0, 3);
-
- dict_mem_table_add_col(table, "COL1", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL2", DATA_VARCHAR,
- DATA_ENGLISH, 10, 0);
- dict_mem_table_add_col(table, "COL3", DATA_VARCHAR,
- DATA_ENGLISH, 100, 0);
-
- ut_a(TRUE == dict_create_table(table, trx));
-
- index = dict_mem_index_create("TS_TABLE1", "IND1", 75046,
- DICT_CLUSTERED, 2);
-
- dict_mem_index_add_field(index, "COL1", 0);
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- index = dict_mem_index_create("TS_TABLE1", "IND2", 0, DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-
- trx = trx_start(ULINT_UNDEFINED);
-
- index = dict_mem_index_create("TS_TABLE1", "IND3", 0, DICT_UNIQUE, 1);
-
- dict_mem_index_add_field(index, "COL2", 0);
-
- ut_a(mem_heap_validate(index->heap));
-
- ut_a(TRUE == dict_create_index(index, trx));
-
- trx_commit(trx);
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-*/
- dict_table_print(table);
-
- /*---------------------------------------------------------*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 2. INSERT 1 ROW TO THE TABLE\n");
-
- trx = trx_start(ULINT_UNDEFINED);
-
- tuple = dtuple_create(heap, 3);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- dtuple_gen_test_tuple3(tuple, 0, buf);
- tcur_insert(tuple, table, heap2, trx);
-
- trx_commit(trx);
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 3. INSERT MANY ROWS TO THE TABLE IN A SINGLE TRX\n");
-
- rnd = 0;
- oldtm = ut_clock();
-
- trx = trx_start(ULINT_UNDEFINED);
- for (i = 0; i < 300 * UNIV_DBC * UNIV_DBC; i++) {
-
- if (i % 5000 == 0) {
- /* dict_table_print(table);
- buf_print();
- buf_LRU_print();
- printf("%lu rows inserted\n", i); */
- }
-
- table = dict_table_get("TS_TABLE1", trx);
-
- if (i == 2180) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 1) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- tcur_insert(tuple, table, heap2, trx);
-
- mem_heap_empty(heap2);
-
- if (i % 4 == 3) {
- }
- }
- trx_commit(trx);
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows inserted\n", i);
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 4. PRINT PART OF CONTENTS OF EACH INDEX TREE\n");
-
-/*
- mem_print_info();
-*/
-
-/*
- tree = dict_index_get_tree(dict_table_get_first_index(table));
-
- btr_print_tree(tree, 10);
-
- tree = dict_index_get_tree(dict_table_get_next_index(
- dict_table_get_first_index(table)));
-
- btr_print_tree(tree, 5);
-*/
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
-/* mem_print_info(); */
-
- os_thread_sleep(5000000);
-
- for (j = 0; j < 5; j++) {
- printf("-------------------------------------------------\n");
- printf("TEST 5. CALCULATE THE JOIN OF THE TABLE WITH ITSELF\n");
-
- i = 0;
-
- oldtm = ut_clock();
-
- mtr_start(&mtr);
-
- index_tree = dict_index_get_tree(UT_LIST_GET_FIRST(table->indexes));
-
- search_tuple = dtuple_create(heap, 2);
-
- dtuple_gen_search_tuple3(search_tuple, i, buf);
-
- btr_pcur_open(index_tree, search_tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &pcur, &mtr);
-
- ut_a(btr_pcur_move_to_next(&pcur, &mtr));
-
- while (!btr_pcur_is_after_last_in_tree(&pcur, &mtr)) {
-
- if (i % 20000 == 0) {
- printf("%lu rows joined\n", i);
- }
-
- index_tree = dict_index_get_tree(
- UT_LIST_GET_FIRST(table->indexes));
-
- rec = btr_pcur_get_rec(&pcur);
-
- rec_copy_prefix_to_dtuple(search_tuple, rec, 2, heap2);
-
- mtr_start(&mtr2);
-
- btr_pcur_open(index_tree, search_tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &pcur2, &mtr2);
-
- btr_pcur_move_to_next(&pcur2, &mtr2);
-
- rec = btr_pcur_get_rec(&pcur2);
-
- field = rec_get_nth_field(rec, 1, &len);
-
- ut_a(len == 8);
-
- ut_a(ut_memcmp(field, dfield_get_data(
- dtuple_get_nth_field(search_tuple, 1)),
- len) == 0);
-
- btr_pcur_close(&pcur2, &mtr);
-
- mem_heap_empty(heap2);
-
- mtr_commit(&mtr2);
-
- btr_pcur_store_position(&pcur, &mtr);
- mtr_commit(&mtr);
-
- mtr_start(&mtr);
-
- btr_pcur_restore_position(BTR_SEARCH_LEAF, &pcur, &mtr);
-
- btr_pcur_move_to_next(&pcur, &mtr);
- i++;
- }
-
- btr_pcur_close(&pcur, &mtr);
- mtr_commit(&mtr);
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows joined\n", i);
- }
-
- oldtm = ut_clock();
-
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 6. INSERT MANY ROWS TO THE TABLE IN SEPARATE TRXS\n");
-
- rnd = 200000;
-
- for (i = 0; i < 350; i++) {
-
- if (i % 4 == 0) {
- }
- trx = trx_start(ULINT_UNDEFINED);
-
- table = dict_table_get("TS_TABLE1", trx);
-
- if (i == 2180) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 1) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- tcur_insert(tuple, table, heap2, trx);
-
- trx_commit(trx);
-
- mem_heap_empty(heap2);
- if (i % 4 == 3) {
- }
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("%lu rows inserted in %lu transactions\n", i, i);
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 7. PRINT MEMORY ALLOCATION INFO\n");
-
- mem_print_info();
-/*
- printf("\n\n\nPress 2 x enter to continue test\n");
-
- while (EOF == getchar()) {
-
- }
- getchar();
-*/
- printf("-------------------------------------------------\n");
- printf("TEST 8. PRINT SEMAPHORE INFO\n");
-
- sync_print();
-
-#endif
-
-#ifdef notdefined
- rnd = 90000;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- if (i == 50000) {
- rnd = rnd % 200000;
- }
-
- rnd = (rnd + 595659561) % 200000;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- btr_pcur_open(tree, tuple, PAGE_CUR_GE,
- BTR_SEARCH_LEAF, &cursor, &mtr);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
- rnd = 0;
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- rnd = (rnd + 35608971) % 200000 + 1;
-
- dtuple_gen_test_tuple3(tuple, rnd, buf);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
-
-/* btr_print_tree(tree, 3); */
-
-#endif
-/*
- mem_heap_free(heap);
-}
-*/
-
-#ifdef notdefined
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 534671) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
-/* page_print_list(page, 151); */
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 7771) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_get_n_recs(page) == 0);
-
- ut_a(page_validate(page, index));
- page = page_create(frame, &mtr);
-
- rnd = 311;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 217;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd + 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
- page = page_create(frame, &mtr);
-
- rnd = 291;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 512);
-
- rnd = 277;
-
- for (i = 0; i < 512; i++) {
-
- rnd = (rnd - 1) % 512;
-
- if (i % 27 == 0) {
- ut_a(page_validate(page, index));
- }
-
- dtuple_gen_test_tuple(tuple, rnd);
-
-/* dtuple_print(tuple);*/
-
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
-
- ut_a(rec);
-
- rec_validate(rec);
-/* page_print_list(page, 151); */
- }
-
- ut_a(page_validate(page, index));
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- mem_heap_free(heap);
-}
-
-/*********************************************************************
-Test for index page. */
-
-void
-test2(void)
-/*=======*/
-{
- page_t* page;
- dtuple_t* tuple;
- mem_heap_t* heap;
- ulint i, j;
- ulint rnd = 0;
- rec_t* rec;
- page_cur_t cursor;
- dict_index_t* index;
- dict_table_t* table;
- buf_block_t* block;
- buf_frame_t* frame;
- ulint tm, oldtm;
- byte buf[8];
- mtr_t mtr;
-
- printf("-------------------------------------------------\n");
- printf("TEST 2. Speed test\n");
-
- oldtm = ut_clock();
-
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf, bigbuf + 800, 800);
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- oldtm = ut_clock();
-
- rnd = 0;
- for (i = 0; i < 1000 * UNIV_DBC * UNIV_DBC; i++) {
- ut_memcpy(bigbuf + rnd, bigbuf + rnd + 800, 800);
- rnd += 1600;
- if (rnd > 995000) {
- rnd = 0;
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu mem copys of 800 bytes %lu millisecs\n",
- i, tm - oldtm);
-
- heap = mem_heap_create(0);
-
- table = dict_table_create("TS_TABLE2", 2);
-
- dict_table_add_col(table, "COL1", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
- dict_table_add_col(table, "COL2", DATA_VARCHAR, DATA_ENGLISH, 10, 0);
-
- ut_a(0 == dict_table_publish(table));
-
- index = dict_index_create("TS_TABLE2", "IND2", 0, 2, 0);
-
- dict_index_add_field(index, "COL1", 0);
- dict_index_add_field(index, "COL2", 0);
-
- ut_a(0 == dict_index_publish(index));
-
- index = dict_index_get("TS_TABLE2", "IND2");
- ut_a(index);
-
- tuple = dtuple_create(heap, 2);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_get(0, 5, &mtr);
- buf_page_s_lock(block, &mtr);
-
- page = buf_block_get_frame(block);
- ut_a(page_validate(page, index));
- mtr_commit(&mtr);
-
- oldtm = ut_clock();
-
- rnd = 677;
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for %lu empty loops with page create %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 100;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for sequential insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 500;
- for (j = 0; j < 250; j++) {
- rnd = (rnd - 1) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf(
- "Wall time for descend. seq. insertion of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
-
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- page_cur_delete_rec(&cursor, &mtr);
- }
- ut_a(page_get_n_recs(page) == 0);
-
- mtr_commit(&mtr);
- }
-
- tm = ut_clock();
- printf("Wall time for insert and delete of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- mtr_start(&mtr);
-
- block = buf_page_create(0, 5, &mtr);
- buf_page_x_lock(block, &mtr);
-
- frame = buf_block_get_frame(block);
-
- page = page_create(frame, &mtr);
-
- rnd = 677;
-
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
-
- rec = page_cur_insert_rec(&cursor, tuple, NULL, &mtr);
- ut_a(rec);
- }
- ut_a(page_validate(page, index));
- mtr_print(&mtr);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- page_cur_search(page, tuple, PAGE_CUR_G, &cursor);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for search of %lu recs %lu milliseconds\n",
- i * j, tm - oldtm);
-
- oldtm = ut_clock();
-
- for (i = 0; i < 4 * UNIV_DBC * UNIV_DBC; i++) {
- rnd = 677;
- for (j = 0; j < 250; j++) {
- rnd = (rnd + 54841) % 1000;
- dtuple_gen_test_tuple2(tuple, rnd, buf);
- }
- }
-
- tm = ut_clock();
- printf("Wall time for %lu empty loops %lu milliseconds\n",
- i * j, tm - oldtm);
- mtr_commit(&mtr);
-}
-
-#endif
-
-/********************************************************************
-Main test function. */
-
-void
-main(void)
-/*======*/
-{
- ulint tm, oldtm;
- mtr_t mtr;
-
- sync_init();
- mem_init();
- os_aio_init(160, 5);
- fil_init(25);
- buf_pool_init(POOL_SIZE, POOL_SIZE);
- fsp_init();
- log_init();
-
- create_files();
- init_space();
-
- mtr_start(&mtr);
-
- trx_sys_create(&mtr);
- dict_create(&mtr);
-
- mtr_commit(&mtr);
-
-
- oldtm = ut_clock();
-
- ut_rnd_set_seed(19);
-
- test1();
-
-/* mem_print_info(); */
-
- tm = ut_clock();
- printf("Wall time for test %lu milliseconds\n", tm - oldtm);
- printf("TESTS COMPLETED SUCCESSFULLY!\n");
-}
diff --git a/innobase/usr/usr0sess.c b/innobase/usr/usr0sess.c
index d74153e323f..359c1552421 100644
--- a/innobase/usr/usr0sess.c
+++ b/innobase/usr/usr0sess.c
@@ -12,327 +12,54 @@ Created 6/25/1996 Heikki Tuuri
#include "usr0sess.ic"
#endif
-#include "ut0rnd.h"
-#include "mach0data.h"
-#include "ha0ha.h"
#include "trx0trx.h"
-#include "que0que.h"
-#include "pars0pars.h"
-#include "pars0sym.h"
-#include "dict0dict.h"
-#include "dict0mem.h"
-#include "odbc0odbc.h"
-
-#define SESS_ERR_BUF_SIZE 8192
-
-/* The session system global data structure */
-sess_sys_t* sess_sys = NULL;
-
-/*************************************************************************
-Communicates an error message to the client. If sess->client_waits is not
-TRUE, puts the session to error state and does not try to send the error
-message. */
-static
-void
-sess_srv_msg_send_error(
-/*====================*/
- sess_t* sess); /* in: session object */
-/*************************************************************************
-Copies error info to a session. Sends to the transaction a signal which will
-rollback the latest incomplete SQL statement and then send the error message
-to the client. NOTE: This function will take care of the freeing of the error
-string, thus the caller must supply a copy of the error string. */
-static
-void
-sess_error_low(
-/*===========*/
- sess_t* sess, /* in: session object */
- ulint err_no, /* in: error number */
- char* err_str);/* in, own: error string or NULL;
- NOTE: the function will take care of freeing of the
- string! */
-
-/*************************************************************************
-Folds a session id to a ulint. Because this function is used also in
-calculating a checksum for the id to write in the message, it is performs
-also a XOR operation to mix the values more thoroughly. */
-UNIV_INLINE
-ulint
-sess_id_fold(
-/*=========*/
- /* out: folded value; can be used also as the checksum
- for id */
- dulint id) /* in: session id */
-{
- return(ut_fold_dulint(id) ^ 2945794411U);
-}
/*************************************************************************
-Sets the session id in a client message. */
-
-void
-sess_cli_msg_set_sess(
-/*==================*/
- byte* str, /* in/out: message string */
- dulint sess_id)/* in: session id */
-{
- ulint fold;
-
- mach_write_to_8(str + SESS_CLI_MSG_SESS_ID, sess_id);
-
- fold = sess_id_fold(sess_id);
-
- mach_write_to_4(str + SESS_CLI_MSG_SESS_ID_CHECK, fold);
-}
-
-/*************************************************************************
-Returns the session to which a message from a client is addressed.
-NOTE: this function does not assume that the message is uncorrupted. */
+Closes a session, freeing the memory occupied by it. */
static
-sess_t*
-sess_cli_msg_get_sess(
-/*==================*/
- /* out: session, NULL if not found */
- byte* str, /* in: message string */
- ulint len) /* in: message string length */
-{
- sess_t* sess;
- ulint fold;
- dulint id;
-
- ut_ad(mutex_own(&kernel_mutex));
-
- if (len < SESS_CLI_MSG_SESS_ID_CHECK + 4) {
-
- return(NULL);
- }
-
- id = mach_read_from_8(str + SESS_CLI_MSG_SESS_ID);
-
- fold = sess_id_fold(id);
-
- if (fold != mach_read_from_4(str + SESS_CLI_MSG_SESS_ID_CHECK)) {
-
- return(NULL);
- }
-
- HASH_SEARCH(hash, sess_sys->hash, fold, sess,
- UT_DULINT_EQ(id, sess->id));
- return(sess);
-}
-
-/***************************************************************************
-Decrements the reference count of a session and closes it, if desired. */
-UNIV_INLINE
-void
-sess_refer_count_dec(
-/*=================*/
- sess_t* sess) /* in: session */
-{
- ut_ad(mutex_own(&kernel_mutex));
- ut_ad(sess->refer_count > 0);
-
- sess->refer_count--;
-
- if (sess->disconnecting && (sess->refer_count == 0)) {
-
- sess_close(sess);
- }
-}
-
-/***************************************************************************
-Increments the reference count of a session. */
-UNIV_INLINE
void
-sess_refer_count_inc(
-/*=================*/
- sess_t* sess) /* in: session */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- sess->refer_count++;
-}
-
-/***************************************************************************
-Creates a session system at a database start. */
-
-void
-sess_sys_init_at_db_start(void)
-/*===========================*/
-{
- sess_sys = mem_alloc(sizeof(sess_sys_t));
-
- sess_sys->state = SESS_SYS_RUNNING;
- sess_sys->free_sess_id = ut_dulint_create(0, 1);
- sess_sys->hash = hash_create(SESS_HASH_SIZE);
-}
-
-/***************************************************************************
-Gets the message type of a message from client. */
-UNIV_INLINE
-ulint
-sess_cli_msg_get_type(
-/*==================*/
- /* out: message type */
- byte* str) /* in: message string */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- return(mach_read_from_4(str + SESS_CLI_MSG_TYPE));
-}
-
-/***************************************************************************
-Gets the message number of a message from client. */
-UNIV_INLINE
-dulint
-sess_cli_msg_get_msg_no(
-/*====================*/
- /* out: message number */
- byte* str) /* in: message string */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- return(mach_read_from_8(str + SESS_CLI_MSG_NO));
-}
-
-/***************************************************************************
-Gets the continue field of a message from client. */
-UNIV_INLINE
-ulint
-sess_cli_msg_get_continue(
-/*======================*/
- /* out: SESS_MSG_SINGLE_PART, ... */
- byte* str) /* in: message string */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- return(mach_read_from_4(str + SESS_CLI_MSG_CONTINUE));
-}
-
-/***************************************************************************
-Gets the size of a big message in kilobytes. */
-UNIV_INLINE
-ulint
-sess_cli_msg_get_cont_size(
-/*=======================*/
- /* out: size in kilobytes */
- byte* str) /* in: message string */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- return(mach_read_from_4(str + SESS_CLI_MSG_CONT_SIZE));
-}
-
-/*************************************************************************
-Checks the consistency of a message from a client. */
-UNIV_INLINE
-ibool
-sess_cli_msg_check_consistency(
-/*===========================*/
- /* out: TRUE if ok */
- byte* str, /* in: message string */
- ulint len) /* in: message string length */
-{
- ulint fold;
-
- ut_ad(mutex_own(&kernel_mutex));
-
- if (len < SESS_CLI_MSG_DATA) {
-
- return(FALSE);
- }
-
- ut_ad(SESS_CLI_MSG_CHECKSUM == 0);
-
- fold = ut_fold_binary(str + 4, len - 4);
-
- if (mach_read_from_4(str + SESS_CLI_MSG_CHECKSUM) != fold) {
-
- return(FALSE);
- }
-
- return(TRUE);
-}
+sess_close(
+/*=======*/
+ sess_t* sess); /* in, own: session object */
/*************************************************************************
Opens a session. */
sess_t*
-sess_open(
-/*======*/
+sess_open(void)
+/*===========*/
/* out, own: session object */
- com_endpoint_t* endpoint, /* in: communication endpoint used
- for receiving messages from the client,
- or NULL if no client */
- byte* addr_buf, /* in: client address (= user name) */
- ulint addr_len) /* in: client address length */
{
sess_t* sess;
- ulint fold;
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-
+#endif /* UNIV_SYNC_DEBUG */
sess = mem_alloc(sizeof(sess_t));
- sess->id = sess_sys->free_sess_id;
- UT_DULINT_INC(sess_sys->free_sess_id);
-
sess->state = SESS_ACTIVE;
- sess->disconnecting = FALSE;
- sess->msgs_sent = ut_dulint_zero;
- sess->msgs_recv = ut_dulint_zero;
- sess->client_waits = TRUE;
- sess->err_no = 0;
- sess->err_str = NULL;
- sess->error_count = ut_dulint_zero;
-
- sess->big_msg = NULL;
sess->trx = trx_create(sess);
- sess->next_graph_id = 0;
-
UT_LIST_INIT(sess->graphs);
- fold = sess_id_fold(sess->id);
-
- HASH_INSERT(sess_t, hash, sess_sys->hash, fold, sess);
-
- sess->endpoint = endpoint;
- sess->addr_buf = mem_alloc(addr_len);
-
- ut_memcpy(sess->addr_buf, addr_buf, addr_len);
-
- sess->addr_len = addr_len;
-
return(sess);
}
/*************************************************************************
Closes a session, freeing the memory occupied by it. */
+static
void
sess_close(
/*=======*/
sess_t* sess) /* in, own: session object */
{
- ulint fold;
-
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
- ut_ad(sess->disconnecting);
+#endif /* UNIV_SYNC_DEBUG */
ut_ad(sess->trx == NULL);
- ut_ad(sess->refer_count == 0);
-
- fold = ut_fold_dulint(sess->id);
- HASH_DELETE(sess_t, hash, sess_sys->hash, fold, sess);
-
-/* sess_reply_to_client_rel_kernel(sess); */
-
- if (sess->err_str != NULL) {
- mem_free(sess->err_str);
- }
- mem_free(sess->addr_buf);
mem_free(sess);
}
@@ -346,10 +73,10 @@ sess_try_close(
/* out: TRUE if closed */
sess_t* sess) /* in, own: session object */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
-
- if (sess->disconnecting && (UT_LIST_GET_LEN(sess->graphs) == 0)
- && (sess->refer_count == 0)) {
+#endif /* UNIV_SYNC_DEBUG */
+ if (UT_LIST_GET_LEN(sess->graphs) == 0) {
sess_close(sess);
return(TRUE);
@@ -357,818 +84,3 @@ sess_try_close(
return(FALSE);
}
-
-/*************************************************************************
-Initializes the first fields of a message to client. */
-
-void
-sess_srv_msg_init(
-/*==============*/
- sess_t* sess, /* in: session object */
- byte* buf, /* in: message buffer, must be at least of size
- SESS_SRV_MSG_DATA */
- ulint type) /* in: message type */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- sess->msgs_sent = ut_dulint_add(sess->msgs_sent, 1);
-
- mach_write_to_8(buf + SESS_SRV_MSG_SESS_ID, sess->id);
- mach_write_to_4(buf + SESS_SRV_MSG_TYPE, type);
- mach_write_to_8(buf + SESS_SRV_MSG_NO, sess->msgs_sent);
-
- ut_ad(com_endpoint_get_max_size(sess->endpoint) >= SESS_SRV_MSG_DATA);
-}
-
-/*************************************************************************
-Sends a message to the client. */
-static
-ulint
-sess_srv_msg_send_low(
-/*==================*/
- /* out: 0 if success, else error number */
- sess_t* sess, /* in: session object */
- byte* buf, /* in: message buffer */
- ulint len, /* in: message length */
- ulint rel_ker)/* in: SESS_RELEASE_KERNEL if the kernel mutex should
- be temporarily released in the call; otherwise
- SESS_NOT_RELEASE_KERNEL */
-{
- ulint ret;
-
- ut_ad((rel_ker == SESS_NOT_RELEASE_KERNEL)
- || (rel_ker == SESS_RELEASE_KERNEL));
- ut_ad(mutex_own(&kernel_mutex));
- ut_ad(len <= com_endpoint_get_max_size(sess->endpoint));
- ut_ad(len >= SESS_SRV_MSG_DATA);
-
- if (sess->client_waits == FALSE) {
- sess_error_low(sess, SESS_ERR_EXTRANEOUS_SRV_MSG, NULL);
-
- return(1);
- }
-
- /* The client will now receive an error message: if the session is
- in the error state, we can reset it to the normal state */
-
- if (sess->state == SESS_ERROR) {
- sess->state = SESS_ACTIVE;
- }
-
- /* We reset the client_waits flag to FALSE, regardless of whether the
- message gets delivered to the client or not. This convention makes
- things simpler. */
-
- sess->client_waits = FALSE;
-
- if (rel_ker == SESS_RELEASE_KERNEL) {
-
- mutex_exit(&kernel_mutex);
- }
-
- ret = com_sendto(sess->endpoint, buf, len, sess->addr_buf,
- sess->addr_len);
- if (rel_ker == SESS_RELEASE_KERNEL) {
-
- mutex_enter(&kernel_mutex);
- }
-
- if (ret != 0) {
- sess_error_low(sess, SESS_ERR_REPLY_FAILED, NULL);
- }
-
- return(ret);
-}
-
-/*************************************************************************
-Sends a message to the client. If the session is in the error state, sends
-the error message instead of buf. */
-static
-ulint
-sess_srv_msg_send(
-/*==============*/
- /* out: 0 if success, else error number */
- sess_t* sess, /* in: session object */
- byte* buf, /* in: message buffer */
- ulint len, /* in: message length */
- ulint rel_ker)/* in: SESS_RELEASE_KERNEL if the kernel mutex should
- be temporarily released in the call; otherwise
- SESS_NOT_RELEASE_KERNEL */
-{
- ulint ret;
-
- ut_ad(mutex_own(&kernel_mutex));
-
- if (sess->state == SESS_ERROR) {
-
- sess_srv_msg_send_error(sess);
-
- return(2);
- }
-
- ret = sess_srv_msg_send_low(sess, buf, len, rel_ker);
-
- return(ret);
-}
-
-/*************************************************************************
-Sends a simple message to client. */
-
-void
-sess_srv_msg_send_simple(
-/*=====================*/
- sess_t* sess, /* in: session object */
- ulint type, /* in: message type */
- ulint rel_kernel) /* in: SESS_RELEASE_KERNEL or
- SESS_NOT_RELEASE_KERNEL */
-{
- byte buf[SESS_SRV_MSG_DATA];
-
- ut_ad(mutex_own(&kernel_mutex));
-
- sess_srv_msg_init(sess, buf, type);
-
- sess_srv_msg_send(sess, buf, SESS_SRV_MSG_DATA, rel_kernel);
-}
-
-/*************************************************************************
-Communicates an error message to the client. If sess->client_waits is not
-TRUE, puts the session to error state and does not try to send the error
-message. */
-static
-void
-sess_srv_msg_send_error(
-/*====================*/
- sess_t* sess) /* in: session object */
-{
- ulint err_no;
- byte* err_str;
- ulint err_len;
- ulint max_len;
- byte buf[SESS_ERR_BUF_SIZE];
- ulint ret;
-
- ut_ad(sess->client_waits);
- ut_ad(mutex_own(&kernel_mutex));
- ut_ad(sess->state == SESS_ERROR);
- ut_ad(!UT_LIST_GET_FIRST((sess->trx)->signals));
-
- if (!sess->client_waits) {
- /* Cannot send the error message now: leave the session to
- the error state and send it later */
-
- return;
- }
-
- err_no = sess->err_no;
- err_str = (byte*)sess->err_str;
- err_len = sess->err_len;
-
- max_len = ut_min(SESS_ERR_BUF_SIZE,
- com_endpoint_get_max_size(sess->endpoint));
-
- sess_srv_msg_init(sess, buf, SESS_SRV_ERROR);
-
- if (err_len + SESS_SRV_MSG_DATA > max_len) {
-
- err_len = max_len - SESS_SRV_MSG_DATA;
- }
-
- ut_memcpy(buf + SESS_SRV_MSG_DATA, err_str, err_len);
-
- ret = sess_srv_msg_send_low(sess, buf, SESS_SRV_MSG_DATA + err_len,
- SESS_NOT_RELEASE_KERNEL);
-}
-
-/*************************************************************************
-Copies error info to a session. Sends to the transaction a signal which will
-rollback the latest incomplete SQL statement and then send the error message
-to the client. NOTE: This function will take care of the freeing of the error
-string, thus the caller must supply a copy of the error string. */
-static
-void
-sess_error_low(
-/*===========*/
- sess_t* sess, /* in: session object */
- ulint err_no, /* in: error number */
- char* err_str)/* in, own: error string or NULL;
- NOTE: the function will take care of freeing of the
- string! */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- UT_DULINT_INC(sess->error_count);
-
- printf("Error string::: %s\n", err_str);
-
- if (sess->state == SESS_ERROR) {
- /* Ignore the error because the session is already in the
- error state */
-
- if (err_str) {
- mem_free(err_str);
- }
-
- return;
- }
-
- sess->err_no = err_no;
-
- if (sess->err_str) {
- mem_free(sess->err_str);
- }
-
- sess->err_str = err_str;
- sess->err_len = ut_strlen(err_str);
- sess->state = SESS_ERROR;
-
- if (sess->big_msg) {
-
- mem_free(sess->big_msg);
- }
-
- /* Send a signal which will roll back the latest incomplete SQL
- statement: the error message will be sent to the client by the error
- handling mechanism after the rollback is completed. */
-
- trx_sig_send(sess->trx, TRX_SIG_ERROR_OCCURRED, TRX_SIG_SELF, FALSE,
- NULL, NULL, NULL);
-}
-
-/*************************************************************************
-Raises an SQL error. */
-
-void
-sess_raise_error_low(
-/*=================*/
- trx_t* trx, /* in: transaction */
- ulint err_no, /* in: error number */
- ulint type, /* in: more info of the error, or 0 */
- dict_table_t* table, /* in: dictionary table or NULL */
- dict_index_t* index, /* in: table index or NULL */
- dtuple_t* tuple, /* in: tuple to insert or NULL */
- rec_t* rec, /* in: record or NULL */
- char* err_str)/* in: arbitrary null-terminated error string,
- or NULL */
-{
- char* str;
- ulint len;
-
- ut_ad(mutex_own(&kernel_mutex));
-
- str = mem_alloc(64000);
-
- len = 0;
-
- len += sprintf(str + len, "Error number: %lu", (ulong) err_no);
-
- if (type) {
- len += sprintf(str + len, ", type: %lu", (ulong) type);
- }
-
- if (table) {
- len += sprintf(str + len, ", table: %s", table->name);
- }
-
- if (index) {
- len += sprintf(str + len, ", index: %s", index->name);
- }
-
- if (tuple) {
- len += sprintf(str + len, ", tuple:");
- len += dtuple_sprintf(str + len, 8192, tuple);
- }
-
- if (rec) {
- len += sprintf(str + len, ", record:");
- len += rec_sprintf(str + len, 8192, rec);
- }
-
- if (err_str) {
- len += sprintf(str + len, ", %s", err_str);
- }
-
- str[len] = '\0';
-
- ut_a(len < 64000);
-
- if (trx->sess) {
- sess_error_low(trx->sess, err_no, str);
- } else {
- mem_free(str);
- }
-}
-
-/***************************************************************************
-Processes a client message which is part of a bigger message. */
-static
-ibool
-sess_receive_msg_part(
-/*==================*/
- /* TRUE if message completed */
- sess_t* sess, /* in: session */
- byte* str, /* in: message string */
- ulint len) /* in: message length */
-{
- ulint cont;
-
- cont = sess_cli_msg_get_continue(str);
-
- ut_ad(cont != SESS_MSG_SINGLE_PART);
-
- if (cont == SESS_MSG_FIRST_PART) {
- if (sess->big_msg) {
- sess_error_low(sess, SESS_ERR_MSG_LOST, NULL);
-
- return(FALSE);
- }
-
- sess->big_msg_size = 1024 * sess_cli_msg_get_cont_size(str);
- sess->big_msg = mem_alloc(sess->big_msg_size);
-
- if (sess->big_msg == NULL) {
- sess_error_low(sess, SESS_ERR_OUT_OF_MEMORY, NULL);
-
- return(FALSE);
- }
-
- ut_memcpy(sess->big_msg, str, len);
- sess->big_msg_len = len;
-
- return(FALSE);
- } else {
- if (sess->big_msg == NULL) {
- sess_error_low(sess, SESS_ERR_MSG_LOST, NULL);
-
- return(FALSE);
- }
-
- ut_memcpy(sess->big_msg + sess->big_msg_len,
- str + SESS_CLI_MSG_DATA, len - SESS_CLI_MSG_DATA);
-
- sess->big_msg_len += len - SESS_CLI_MSG_DATA;
-
- if (cont == SESS_MSG_MIDDLE_PART) {
-
- return(FALSE);
- }
-
- return(TRUE);
- }
-}
-
-/***************************************************************************
-Processes a client message which requires SQL parsing. This function decodes
-the client message built in SQLPrepare. NOTE: The kernel mutex is temporarily
-released within this function. */
-static
-void
-sess_receive_prepare(
-/*=================*/
- sess_t* sess, /* in: session */
- byte* cli_msg,/* in: client message */
- ulint len) /* in: message length */
-{
- dulint error_count;
- que_t* graph;
- byte msg[ODBC_DATAGRAM_SIZE];
-
- UT_NOT_USED(len);
-
- ut_ad(mutex_own(&kernel_mutex));
-
- error_count = sess->error_count;
-
- /* Make sure the session object is not freed during the parsing */
-
- sess_refer_count_inc(sess);
-
- /* We release the kernel mutex before parsing the command: this is
- to reduce contention on the kernel mutex */
-
- mutex_exit(&kernel_mutex);
-
-/* printf("To parse query %s\n", (char*)(cli_msg + SESS_CLI_MSG_DATA)); */
-
- graph = pars_sql((char*)(cli_msg + SESS_CLI_MSG_DATA));
-
- mutex_enter(&kernel_mutex);
-
- if (graph == NULL) {
- /* Error in parsing */
- sess_error_low(sess, SESS_ERR_SQL_ERROR, NULL);
-
- sess_refer_count_dec(sess);
-
- ut_error;
-
- return;
- }
-
- if (!UT_DULINT_EQ(error_count, sess->error_count)) {
-
- /* An error, or an asyncronous signal on the session happened
- when the kernel mutex was not reserved: discard graph */
-
- graph->state = QUE_FORK_INVALID;
-
- que_graph_try_free(graph);
-
- sess_refer_count_dec(sess);
-
- ut_error;
-
- return;
- }
-
- UT_LIST_ADD_LAST(graphs, sess->graphs, graph);
-
- graph->id = sess->next_graph_id;
- sess->next_graph_id++;
-
- /* Tell the client that the preparation succeeded and communicate info
- about the possible query parameters: the message will be decoded in
- SQLPrepare */
-
- ut_ad(sess->client_waits);
-
- sess_srv_msg_init(sess, msg, SESS_SRV_SUCCESS);
-
- mach_write_to_4(msg + SESS_SRV_MSG_DATA, graph->id);
-
- mutex_exit(&kernel_mutex);
-
- len = pars_write_query_param_info(msg + SESS_SRV_MSG_DATA + 4, graph);
-
- mutex_enter(&kernel_mutex);
-
- sess_srv_msg_send(sess, msg, SESS_SRV_MSG_DATA + 4 + len,
- SESS_RELEASE_KERNEL);
- sess_refer_count_dec(sess);
-}
-
-/***************************************************************************
-Processes a client message which does not require SQL parsing. This function
-decodes the client message built in SQLExecute. */
-static
-void
-sess_receive_command(
-/*=================*/
- sess_t* sess, /* in: session */
- byte* cli_msg,/* in: client message */
- ulint len, /* in: message length */
- ulint type) /* in: message type */
-{
- proc_node_t* proc_node;
- call_node_t* call_node;
- dict_proc_t* dict_proc;
- que_thr_t* thr;
- que_t* graph;
- ulint stat_id;
-
- UT_NOT_USED(len);
- UT_NOT_USED(type);
-
- ut_ad(mutex_own(&kernel_mutex));
-
- sess->client_waits = TRUE;
-
- stat_id = mach_read_from_4(cli_msg + SESS_CLI_MSG_DATA);
-
- /* Look for the statement from the list of query graphs */
-
- graph = UT_LIST_GET_FIRST(sess->graphs);
-
- while (graph != NULL) {
-
- if (graph->id == stat_id) {
-
- break;
- }
-
- graph = UT_LIST_GET_NEXT(graphs, graph);
- }
-
- if (graph == NULL) {
- /* Could not find the right graph: error */
- sess_error_low(sess, SESS_ERR_STMT_NOT_FOUND, NULL);
-
- return;
- }
-
- if (graph->state != QUE_FORK_COMMAND_WAIT) {
- sess_error_low(sess, SESS_ERR_STMT_NOT_READY, NULL);
-
- return;
- }
-
-/* printf("To execute stat %lu\n", stat_id); */
-
- if (graph->fork_type == QUE_FORK_PROCEDURE_CALL) {
- /* It is a stored procedure call: retrieve a parsed copy of
- the procedure from the dictionary cache */
-
- mutex_exit(&kernel_mutex);
-
- call_node = que_fork_get_child(graph);
-
- graph = dict_procedure_reserve_parsed_copy(
- call_node->procedure_def);
- graph->trx = sess->trx;
-
- /* Retrieve the procedure input parameters from the message */
-
- pars_proc_read_input_params_from_buf(graph,
- cli_msg + SESS_CLI_MSG_DATA + 4);
- mutex_enter(&kernel_mutex);
- } else {
- /* It is a create procedure command: add the procedure to the
- dictionary cache */
- ut_ad(graph->fork_type == QUE_FORK_PROCEDURE);
-
- mutex_exit(&kernel_mutex);
-
- proc_node = que_fork_get_child(graph);
-
- dict_proc = dict_mem_procedure_create(proc_node->proc_id->name,
- proc_node->sym_tab->sql_string,
- graph);
-
- dict_procedure_add_to_cache(dict_proc);
-
- mutex_enter(&kernel_mutex);
-
- sess_srv_msg_send_simple(sess, SESS_SRV_SUCCESS,
- SESS_RELEASE_KERNEL);
- return;
- }
-
- /* Choose a query thread for execution */
- thr = que_fork_start_command(graph, SESS_COMM_EXECUTE, 0);
-
- ut_ad(thr);
-
- sess->trx->graph = graph;
-
- mutex_exit(&kernel_mutex);
-
- /* Run query threads with the kernel mutex released */
-
- que_run_threads(thr);
-
- mutex_enter(&kernel_mutex);
-}
-
-/***************************************************************************
-When a command has been completed, this function sends the message about it
-to the client. */
-
-void
-sess_command_completed_message(
-/*===========================*/
- sess_t* sess, /* in: session */
- byte* msg, /* in: message buffer */
- ulint len) /* in: message data length */
-{
- mutex_enter(&kernel_mutex);
-
- sess_srv_msg_send(sess, msg, SESS_SRV_MSG_DATA + len,
- SESS_RELEASE_KERNEL);
- mutex_exit(&kernel_mutex);
-}
-
-/***************************************************************************
-Processes a break message from the client. */
-static
-void
-sess_receive_break(
-/*===============*/
- sess_t* sess) /* in: session */
-{
- ut_ad(mutex_own(&kernel_mutex));
-
- /* Rollback the latest incomplete SQL statement */
-
- sess_error_low(sess, SESS_ERR_BREAK_BY_CLIENT, NULL);
-}
-
-/***************************************************************************
-Processes a message from a client. NOTE: Releases the kernel mutex temporarily
-when parsing an SQL string. */
-
-void
-sess_receive_msg_rel_kernel(
-/*========================*/
- sess_t* sess, /* in: session */
- byte* str, /* in: message string */
- ulint len) /* in: message length */
-{
- dulint msg_no;
- ulint msg_type;
- ulint cont;
- ibool is_big_msg = FALSE;
- ibool client_waited;
-
- ut_ad(mutex_own(&kernel_mutex));
- ut_ad(!sess->disconnecting);
-
- client_waited = sess->client_waits;
-
- sess->client_waits = TRUE;
-
- if (sess->state == SESS_ERROR) {
-
- /* Send a buffered error message */
- sess_srv_msg_send_error(sess);
-
- return;
- }
-
- if (FALSE == sess_cli_msg_check_consistency(str, len)) {
- /* Message from the client was corrupted */
-
- sess_error_low(sess, SESS_ERR_MSG_CORRUPTED, NULL);
-
- return;
- }
-
- msg_no = sess_cli_msg_get_msg_no(str);
-
- UT_DULINT_INC(sess->msgs_recv);
-
- if (!UT_DULINT_EQ(msg_no, sess->msgs_recv)) {
-
- sess_error_low(sess, SESS_ERR_MSG_LOST, NULL);
-
- sess->msgs_recv = msg_no;
-
- return;
- }
-
- msg_type = sess_cli_msg_get_type(str);
-
- if (msg_type == SESS_CLI_BREAK_EXECUTION) {
-
- sess_receive_break(sess);
-
- return;
- }
-
- if (client_waited) {
- /* Client sent an extraneous message which is not a break
- command: an error */
-
- sess_error_low(sess, SESS_ERR_EXTRANEOUS_MSG, NULL);
-
- return;
- }
-
- /*-----------------------------------------------------------*/
- /* Handle big messages */
-
- cont = sess_cli_msg_get_continue(str);
-
- if (cont == SESS_MSG_SINGLE_PART) {
- if (sess->big_msg) {
-
- sess_error_low(sess, SESS_ERR_MSG_LOST, NULL);
-
- return;
- }
- } else {
- ut_error; /* Not in use */
-
- is_big_msg = sess_receive_msg_part(sess, str, len);
-
- if (is_big_msg) {
- str = sess->big_msg;
- len = sess->big_msg_len;
- sess->big_msg = NULL;
- } else {
- return;
- }
- }
-
- /*-----------------------------------------------------------*/
- /* The session has received a complete message from the client */
-
- ut_ad(!UT_LIST_GET_FIRST((sess->trx)->signals));
-
- if (msg_type == SESS_CLI_PREPARE) {
- /* Note that the kernel mutex is temporarily released when
- the SQL string is parsed */
-
- sess_receive_prepare(sess, str, len);
- } else {
- /* Note that the kernel mutex is temporarily released when the
- command is executed */
-
- sess_receive_command(sess, str, len, msg_type);
- }
-
- if (is_big_msg) {
- mem_free(str);
- }
-}
-
-/***********************************************************************
-Opens a new connection and creates a session. */
-static
-ibool
-sess_open_connection(
-/*=================*/
- byte* str, /* in: message string */
- ulint len, /* in: string length */
- byte* addr, /* in: user address string */
- ulint alen) /* in: user address length */
-{
- dulint sess_id;
- sess_t* sess;
-
- sess_id = mach_read_from_8(str + SESS_CLI_MSG_SESS_ID);
-
- if (!(UT_DULINT_EQ(sess_id, ut_dulint_zero))
- || !(sess_cli_msg_get_type(str) == SESS_CLI_CONNECT)) {
-
- /* It is not a valid connect message */
-
- return(FALSE);
- }
-
- ut_a(len == SESS_CLI_MSG_DATA);
-
- sess = sess_open(srv_sys->endpoint, addr, alen);
-
- sess_srv_msg_send_simple(sess, SESS_SRV_ACCEPT_CONNECT,
- SESS_NOT_RELEASE_KERNEL);
- return(TRUE);
-}
-
-/***********************************************************************
-Starts a new connection and a session, or starts a query based on a client
-message. This is called by a SRV_COM thread. */
-
-void
-sess_process_cli_msg(
-/*=================*/
- byte* str, /* in: message string */
- ulint len, /* in: string length */
- byte* addr, /* in: address string */
- ulint alen) /* in: address length */
-{
- sess_t* sess;
- ibool success;
-
- UT_NOT_USED(addr);
- UT_NOT_USED(alen);
-
- mutex_enter(&kernel_mutex);
-
- sess = sess_cli_msg_get_sess(str, len);
-
- if (sess == NULL) {
- /* There was no matching session */
-
- if (sess_cli_msg_check_consistency(str, len)) {
-
- /* As the message is consistent, it may be a connect
- message */
-
- /* printf("%s\n", addr); */
-
- success = sess_open_connection(str, len, addr, alen);
-
- if (success) {
- mutex_exit(&kernel_mutex);
-
- return;
- }
- }
-
- /* Could not make sense of the message: write an error entry
- to the system error log */
-
- /* srv_err_log_insert(
- "MESSAGE SENT TO AN UNKNOWN SESSION");*/
- ut_error;
-
- mutex_exit(&kernel_mutex);
-
- return;
- }
-
- if (sess->disconnecting) {
-
- /* srv_err_log_insert(
- "MESSAGE SENT TO A DISCONNECTING SESSION");*/
- ut_error;
-
- mutex_exit(&kernel_mutex);
-
- return;
- }
-
- sess_receive_msg_rel_kernel(sess, str, len);
-
- mutex_exit(&kernel_mutex);
-}
diff --git a/innobase/ut/ts/makefile b/innobase/ut/ts/makefile
deleted file mode 100644
index 5ef15ade794..00000000000
--- a/innobase/ut/ts/makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-include ..\..\makefile.i
-
-tsut: ..\ut.lib tsut.c
- $(CCOM) $(CFL) -I.. -I..\.. ..\ut.lib ..\..\os.lib tsut.c $(LFL)
-
-
-
-
-
-
-
diff --git a/innobase/ut/ts/tsut.c b/innobase/ut/ts/tsut.c
deleted file mode 100644
index 81c9ff79f96..00000000000
--- a/innobase/ut/ts/tsut.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/************************************************************************
-The test module for the utilities
-
-(c) 1995 Innobase Oy
-
-Created 10/28/1995 Heikki Tuuri
-*************************************************************************/
-
-#include "../ut0lst.h"
-#include "../ut0mem.h"
-#include "../ut0byte.h"
-#include "../ut0sort.h"
-#include "../ut0rnd.h"
-
-typedef struct node_struct node_t;
-struct node_struct {
- ulint index;
- ulint zyx;
- UT_LIST_NODE_T(node_t) list1;
- ulint yzx;
- UT_LIST_NODE_T(node_t) list2;
-};
-
-/* Arrays to be sorted */
-ulint uarr[100000];
-ulint aux_uarr[100000];
-dulint duarr[100000];
-dulint aux_duarr[100000];
-
-/*********************************************************************
-Tests for two-way lists. */
-
-void
-test1(void)
-/*=======*/
-{
- ulint i;
- UT_LIST_BASE_NODE_T(node_t) base1;
- UT_LIST_BASE_NODE_T(node_t) base2;
- node_t* node;
- node_t* node2;
-
- printf("-------------------------------------------\n");
- printf("TEST 1. Test of two-way lists \n");
-
- UT_LIST_INIT(base1);
- UT_LIST_INIT(base2);
-
- for (i = 0; i < 1000; i++) {
- node = ut_malloc(sizeof(node_t));
-
- node->index = 999 - i;
-
- UT_LIST_ADD_FIRST(list1, base1, node);
- UT_LIST_ADD_LAST(list2, base2, node);
- }
-
- UT_LIST_VALIDATE(list1, node_t, base1);
- UT_LIST_VALIDATE(list2, node_t, base2);
-
- node = UT_LIST_GET_FIRST(base1);
-
- for (i = 0; i < 1000; i++) {
-
- ut_a(node);
- ut_a(node->index == i);
-
- node = UT_LIST_GET_NEXT(list1, node);
- }
-
- ut_a(node == NULL);
-
- node = UT_LIST_GET_FIRST(base2);
-
- for (i = 0; i < 1000; i++) {
-
- ut_a(node);
- ut_a(node->index == 999 - i);
-
- node = UT_LIST_GET_NEXT(list2, node);
- }
-
- ut_a(node == NULL);
-
- UT_LIST_VALIDATE(list1, node_t, base1);
- UT_LIST_VALIDATE(list2, node_t, base2);
-
- node = UT_LIST_GET_FIRST(base1);
-
- for (i = 0; i < 500; i++) {
-
- ut_a(node);
- ut_a(node->index == i);
-
- node = UT_LIST_GET_NEXT(list1, node);
- }
-
- for (i = 0; i < 100; i++) {
- node2 = ut_malloc(sizeof(node_t));
-
- node2->index = 99 - i;
-
- UT_LIST_INSERT_AFTER(list1, base1, node, node2);
- UT_LIST_VALIDATE(list1, node_t, base1);
- }
-
- node2 = ut_malloc(sizeof(node_t));
- node2->index = 1000;
- UT_LIST_INSERT_AFTER(list1, base1, UT_LIST_GET_LAST(base1), node2);
-
- node2 = node;
-
- for (i = 0; i < 100; i++) {
- node2 = UT_LIST_GET_NEXT(list1, node2);
-
- ut_a(node2);
- ut_a(node2->index == i);
- }
-
- UT_LIST_VALIDATE(list1, node_t, base1);
-
- for (i = 0; i < 600; i++) {
-
- node2 = UT_LIST_GET_NEXT(list1, node);
-
- UT_LIST_REMOVE(list1, base1, node2);
- UT_LIST_VALIDATE(list1, node_t, base1);
- }
-
- node2 = UT_LIST_GET_NEXT(list1, node);
-
- UT_LIST_VALIDATE(list1, node_t, base1);
- UT_LIST_VALIDATE(list2, node_t, base2);
-
- ut_a(UT_LIST_GET_LEN(base1) == 501);
-
- ut_a(UT_LIST_GET_LAST(base1) == node);
-
- for (i = 0; i < 500; i++) {
-
- node = UT_LIST_GET_PREV(list1, node);
- }
-
- ut_a(UT_LIST_GET_FIRST(base1) == node);
-
- for (i = 0; i < 501; i++) {
-
- node2 = UT_LIST_GET_FIRST(base1);
-
- UT_LIST_REMOVE(list1, base1, node2);
- }
-
- UT_LIST_VALIDATE(list1, node_t, base1);
- UT_LIST_VALIDATE(list2, node_t, base2);
-
- ut_a(UT_LIST_GET_LEN(base1) == 0);
- ut_a(UT_LIST_GET_LEN(base2) == 1000);
-}
-
-/*********************************************************************
-Tests for dulints. */
-
-void
-test2(void)
-/*=======*/
-{
- dulint a, b;
-
- printf("-------------------------------------------\n");
- printf("TEST 2. Test of dulints \n");
-
- a = ut_dulint_create(0xFFFFFFFF, 0xFFFFFFFF);
-
- b = a;
-
- ut_a(ut_dulint_cmp(a, b) == 0);
-
- ut_a(ut_dulint_get_low(b) == 0xFFFFFFFF);
- ut_a(ut_dulint_get_high(b) == 0xFFFFFFFF);
-
- a = ut_dulint_create(0xFFFFFFFE, 0xFFFFFFFF);
- ut_a(ut_dulint_cmp(a, b) == -1);
- ut_a(ut_dulint_cmp(b, a) == 1);
-
- a = ut_dulint_create(0xFFFFFFFF, 0xFFFFFFFE);
- ut_a(ut_dulint_cmp(a, b) == -1);
- ut_a(ut_dulint_cmp(b, a) == 1);
-
- a = ut_dulint_create(5, 0xFFFFFFFF);
-
- a = ut_dulint_add(a, 5);
-
- ut_a(ut_dulint_get_low(a) == 4);
- ut_a(ut_dulint_get_high(a) == 6);
-
- a = ut_dulint_create(5, 0x80000000);
-
- a = ut_dulint_add(a, 0x80000000);
-
- ut_a(ut_dulint_get_low(a) == 0);
- ut_a(ut_dulint_get_high(a) == 6);
-
- a = ut_dulint_create(5, 10);
-
- a = ut_dulint_add(a, 20);
-
- ut_a(ut_dulint_get_low(a) == 30);
- ut_a(ut_dulint_get_high(a) == 5);
-}
-
-/***************************************************************
-Comparison function for ulints. */
-UNIV_INLINE
-int
-cmp_ulint(ulint a, ulint b)
-/*=======================*/
-{
- if (a < b) {
- return(-1);
- } else if (b < a) {
- return(1);
- } else {
- return(0);
- }
-}
-
-/****************************************************************
-Sort function for ulint arrays. */
-void
-sort_ulint(ulint* arr, ulint* aux_arr, ulint low, ulint high)
-/*=========================================================*/
-{
- ut_ad(high <= 100000);
-
- UT_SORT_FUNCTION_BODY(sort_ulint, arr, aux_arr, low, high,
- cmp_ulint);
-}
-
-/****************************************************************
-Sort function for dulint arrays. */
-void
-sort_dulint(dulint* arr, dulint* aux_arr, ulint low, ulint high)
-/*=========================================================*/
-{
- ut_ad(high <= 100000);
-
- UT_SORT_FUNCTION_BODY(sort_dulint, arr, aux_arr, low, high,
- ut_dulint_cmp);
-}
-
-/*********************************************************************
-Tests for sorting. */
-
-void
-test3(void)
-/*=======*/
-{
- ulint i, j;
- ulint tm, oldtm;
-
- printf("-------------------------------------------\n");
- printf("TEST 3. Test of sorting \n");
-
- for (i = 0; i < 100000; i++) {
- uarr[i] = ut_rnd_gen_ulint();
- }
-
- oldtm = ut_clock();
-
- for (j = 0; j < 1; j++) {
- i = 100000;
-
- sort_ulint(uarr, aux_uarr, 0, i);
- }
-
- tm = ut_clock();
-
- printf("Wall clock time for sort of %lu ulints %lu millisecs\n",
- j * i, tm - oldtm);
-
- for (i = 1; i < 100000; i++) {
- ut_a(uarr[i - 1] < uarr[i]);
- }
-
- for (i = 0; i < 100000; i++) {
- uarr[i] = 99999 - i;
- }
-
- sort_ulint(uarr, aux_uarr, 0, 100000);
-
- for (i = 1; i < 100000; i++) {
- ut_a(uarr[i] == i);
- }
-
- sort_ulint(uarr, aux_uarr, 0, 100000);
-
- for (i = 1; i < 100000; i++) {
- ut_a(uarr[i] == i);
- }
-
- sort_ulint(uarr, aux_uarr, 5, 6);
-
- for (i = 1; i < 100000; i++) {
- ut_a(uarr[i] == i);
- }
-
- for (i = 0; i < 100000; i++) {
- uarr[i] = 5;
- }
-
- sort_ulint(uarr, aux_uarr, 0, 100000);
-
- for (i = 1; i < 100000; i++) {
- ut_a(uarr[i] == 5);
- }
-
- for (i = 0; i < 100000; i++) {
- duarr[i] = ut_dulint_create(ut_rnd_gen_ulint() & 0xFFFFFFFF,
- ut_rnd_gen_ulint() & 0xFFFFFFFF);
- }
-
- oldtm = ut_clock();
-
- i = 100000;
-
- sort_dulint(duarr, aux_duarr, 0, i);
-
- tm = ut_clock();
-
- printf("Wall clock time for sort of %lu dulints %lu millisecs\n",
- j * i, tm - oldtm);
-
- for (i = 1; i < 100000; i++) {
- ut_a(ut_dulint_cmp(duarr[i - 1], duarr[i]) < 0);
- }
-
-}
-
-void
-main(void)
-{
- test1();
- test2();
- test3();
-
- printf("TEST SUCCESSFULLY COMPLETED!\n");
-}
diff --git a/innobase/ut/ut0dbg.c b/innobase/ut/ut0dbg.c
index 6cd0ed62454..3697e31050f 100644
--- a/innobase/ut/ut0dbg.c
+++ b/innobase/ut/ut0dbg.c
@@ -23,6 +23,11 @@ const char* ut_dbg_msg_assert_fail =
"InnoDB: Assertion failure in thread %lu in file %s line %lu\n";
const char* ut_dbg_msg_trap =
"InnoDB: We intentionally generate a memory trap.\n"
-"InnoDB: Send a detailed bug report to mysql@lists.mysql.com.\n";
+"InnoDB: Send a detailed bug report to mysql@lists.mysql.com.\n"
+"InnoDB: If you get repeated assertion failures or crashes, even\n"
+"InnoDB: immediately after the mysqld startup, there may be\n"
+"InnoDB: corruption in the InnoDB tablespace. See section 6.1 of\n"
+"InnoDB: http://www.innodb.com/ibman.php about forcing recovery.\n";
+
const char* ut_dbg_msg_stop =
"InnoDB: Thread %lu stopped in file %s line %lu\n";
diff --git a/innobase/ut/ut0mem.c b/innobase/ut/ut0mem.c
index c367ea10ee1..f7c0e1be9bd 100644
--- a/innobase/ut/ut0mem.c
+++ b/innobase/ut/ut0mem.c
@@ -258,3 +258,51 @@ ut_str_catenate(
return(str);
}
+
+/**************************************************************************
+Checks if a null-terminated string contains a certain character. */
+
+ibool
+ut_str_contains(
+/*============*/
+ char* str, /* in: null-terminated string */
+ char c) /* in: character */
+{
+ ulint len;
+ ulint i;
+
+ len = ut_strlen(str);
+
+ for (i = 0; i < len; i++) {
+ if (str[i] == c) {
+
+ return(TRUE);
+ }
+ }
+
+ return(FALSE);
+}
+
+/**************************************************************************
+Return a copy of the given string. The returned string must be freed
+using mem_free. */
+
+char*
+ut_strdup(
+/*======*/
+ /* out, own: cnull-terminated string */
+ char* str) /* in: null-terminated string */
+{
+ ulint len;
+ char* copy;
+
+ len = ut_strlen(str);
+
+ copy = mem_alloc(len + 1);
+
+ ut_memcpy(copy, str, len);
+
+ copy[len] = 0;
+
+ return(copy);
+}