summaryrefslogtreecommitdiff
path: root/src/btree/bt_misc.c
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2011-02-01 09:24:17 +1100
committerMichael Cahill <michael.cahill@wiredtiger.com>2011-02-01 09:24:17 +1100
commit7ebbbf1d52c1ed989cfe5f4fde3b98e983db2e63 (patch)
tree0e0fd0f6b190dbcd283ca3c4040b5dcd89a94014 /src/btree/bt_misc.c
parent6f87637341366fb90f890a5ef860e90c57b36d1f (diff)
downloadmongo-7ebbbf1d52c1ed989cfe5f4fde3b98e983db2e63.tar.gz
Restructure the tree to ease merge.
refs #27 --HG-- branch : keith rename : lint/fl => dist/lint/fl rename : lint/lint.current => dist/lint/lint.current rename : inc_posix/bitstring.h => include/bitstring.h rename : inc_posix/btree.h => include/btree.h rename : inc_posix/cache.h => include/cache.h rename : inc_posix/debug.h => include/debug.h rename : inc_posix/extern.h => include/extern.h rename : inc_posix/fh.h => include/fh.h rename : inc_posix/mem.h => include/mem.h rename : inc_posix/misc.h => include/misc.h rename : inc_posix/mutex.h => include/mutex.h rename : inc_posix/queue.h => include/queue.h rename : inc_posix/serial.h => include/serial.h rename : inc_posix/stat.h => include/stat.h rename : inc_posix/util.h => include/util.h rename : inc_posix/walk.h => include/walk.h rename : inc_posix/wiredtiger.in => include/wiredtiger.in rename : inc_posix/wt_internal.in => include/wt_internal.in rename : btree/bt_alloc.c => src/btree/bt_alloc.c rename : btree/bt_bulk.c => src/btree/bt_bulk.c rename : btree/bt_cache.c => src/btree/bt_cache.c rename : btree/bt_close.c => src/btree/bt_close.c rename : btree/bt_cmp.c => src/btree/bt_cmp.c rename : btree/bt_debug.c => src/btree/bt_debug.c rename : btree/bt_desc.c => src/btree/bt_desc.c rename : btree/bt_discard.c => src/btree/bt_discard.c rename : btree/bt_dump.c => src/btree/bt_dump.c rename : btree/bt_evict.c => src/btree/bt_evict.c rename : btree/bt_misc.c => src/btree/bt_misc.c rename : btree/bt_open.c => src/btree/bt_open.c rename : btree/bt_ovfl.c => src/btree/bt_ovfl.c rename : btree/bt_page.c => src/btree/bt_page.c rename : btree/bt_read.c => src/btree/bt_read.c rename : btree/bt_reconcile.c => src/btree/bt_reconcile.c rename : btree/bt_ret.c => src/btree/bt_ret.c rename : btree/bt_rw.c => src/btree/bt_rw.c rename : btree/bt_stat.c => src/btree/bt_stat.c rename : btree/bt_sync.c => src/btree/bt_sync.c rename : btree/bt_vrfy.c => src/btree/bt_vrfy.c rename : btree/bt_walk.c => src/btree/bt_walk.c rename : btree/c_drain.c => src/btree/c_drain.c rename : btree/c_init.c => src/btree/c_init.c rename : btree/c_page.c => src/btree/c_page.c rename : btree/c_read.c => src/btree/c_read.c rename : btree/col_get.c => src/btree/col_get.c rename : btree/col_put.c => src/btree/col_put.c rename : btree/col_srch.c => src/btree/col_srch.c rename : btree/row_get.c => src/btree/row_get.c rename : btree/row_put.c => src/btree/row_put.c rename : btree/row_srch.c => src/btree/row_srch.c rename : db/db_err.c => src/db/db_err.c rename : db/db_getset.c => src/db/db_getset.c rename : db/db_handle.c => src/db/db_handle.c rename : db/db_huffman.c => src/db/db_huffman.c rename : db/db_open.c => src/db/db_open.c rename : db/db_stat.c => src/db/db_stat.c rename : db/db_sync.c => src/db/db_sync.c rename : env/env_err.c => src/env/env_err.c rename : env/env_getset.c => src/env/env_getset.c rename : env/env_global.c => src/env/env_global.c rename : env/env_handle.c => src/env/env_handle.c rename : env/env_init.c => src/env/env_init.c rename : env/env_msg.c => src/env/env_msg.c rename : env/env_open.c => src/env/env_open.c rename : env/env_stat.c => src/env/env_stat.c rename : env/env_sync.c => src/env/env_sync.c rename : env/env_toc.c => src/env/env_toc.c rename : env/env_workq.c => src/env/env_workq.c rename : os_posix/os_abort.c => src/os_posix/os_abort.c rename : os_posix/os_alloc.c => src/os_posix/os_alloc.c rename : os_posix/os_filesize.c => src/os_posix/os_filesize.c rename : os_posix/os_fsync.c => src/os_posix/os_fsync.c rename : os_posix/os_mtx.c => src/os_posix/os_mtx.c rename : os_posix/os_open.c => src/os_posix/os_open.c rename : os_posix/os_rw.c => src/os_posix/os_rw.c rename : os_posix/os_sleep.c => src/os_posix/os_sleep.c rename : os_posix/os_thread.c => src/os_posix/os_thread.c rename : os_posix/os_yield.c => src/os_posix/os_yield.c rename : support/api.c => src/support/api.c rename : support/cksum.c => src/support/cksum.c rename : support/err.c => src/support/err.c rename : support/hazard.c => src/support/hazard.c rename : support/huffman.c => src/support/huffman.c rename : support/pow.c => src/support/pow.c rename : support/prime.c => src/support/prime.c rename : support/progress.c => src/support/progress.c rename : support/scratch.c => src/support/scratch.c rename : support/serial.c => src/support/serial.c rename : support/simple_setup.c => src/support/simple_setup.c rename : support/stat.c => src/support/stat.c rename : support/strerror.c => src/support/strerror.c rename : support/version.c => src/support/version.c rename : utilities/db_dump/util_dump.c => src/utilities/db_dump/util_dump.c rename : utilities/db_load/util_load.c => src/utilities/db_load/util_load.c rename : utilities/db_stat/util_stat.c => src/utilities/db_stat/util_stat.c rename : utilities/db_verify/util_verify.c => src/utilities/db_verify/util_verify.c
Diffstat (limited to 'src/btree/bt_misc.c')
-rw-r--r--src/btree/bt_misc.c175
1 files changed, 175 insertions, 0 deletions
diff --git a/src/btree/bt_misc.c b/src/btree/bt_misc.c
new file mode 100644
index 00000000000..c0f58002522
--- /dev/null
+++ b/src/btree/bt_misc.c
@@ -0,0 +1,175 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2008-2011 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * $Id$
+ */
+
+#include "wt_internal.h"
+
+/*
+ * __wt_bt_build_verify --
+ * Verify the Btree build itself.
+ */
+int
+__wt_bt_build_verify(void)
+{
+ static const struct {
+ char *name;
+ u_int size, expected;
+ } size_check[] = {
+ { "WT_COL", sizeof(WT_COL), WT_COL_SIZE },
+ { "WT_ITEM", sizeof(WT_ITEM), WT_ITEM_SIZE },
+ { "WT_OFF", sizeof(WT_OFF), WT_OFF_SIZE },
+ { "WT_OVFL", sizeof(WT_OVFL), WT_OVFL_SIZE },
+ { "WT_PAGE", sizeof(WT_PAGE), WT_PAGE_SIZE },
+ { "WT_PAGE_DESC", sizeof(WT_PAGE_DESC), WT_PAGE_DESC_SIZE },
+ { "WT_PAGE_DISK", sizeof(WT_PAGE_DISK), WT_PAGE_DISK_SIZE },
+ { "WT_ROW", sizeof(WT_ROW), WT_ROW_SIZE }
+ };
+ static const struct {
+ char *name;
+ u_int size, align;
+ } align_check[] = {
+ { "WT_OFF", sizeof(WT_OFF), sizeof(uint32_t) },
+ { "WT_OVFL", sizeof(WT_OVFL), sizeof(uint32_t) },
+ { "WT_PAGE_DISK", sizeof(WT_PAGE_DISK), sizeof(uint32_t) },
+ { "WT_TOC_UPDATE", sizeof(WT_TOC_UPDATE), sizeof(uint32_t) }
+ };
+ u_int i;
+
+ /*
+ * The compiler had better not have padded our structures -- make
+ * sure the page header structure is exactly what we expect.
+ */
+ for (i = 0; i < WT_ELEMENTS(size_check); ++i) {
+ if (size_check[i].size == size_check[i].expected)
+ continue;
+ __wt_api_env_errx(NULL,
+ "WiredTiger build failed, the %s header structure is not "
+ "the correct size (expected %u, got %u)",
+ size_check[i].name,
+ size_check[i].expected, size_check[i].size);
+ return (WT_ERROR);
+ }
+
+ /* There are also structures that must be aligned correctly. */
+ for (i = 0; i < WT_ELEMENTS(align_check); ++i) {
+ if (WT_ALIGN(align_check[i].size,
+ align_check[i].align) == align_check[i].size)
+ continue;
+ __wt_api_env_errx(NULL,
+ "Build verification failed, the %s structure is not"
+ " correctly aligned", align_check[i].name);
+ return (WT_ERROR);
+ }
+
+ /*
+ * We mix-and-match 32-bit unsigned values and size_t's, mostly because
+ * we allocate and handle 32-bit objects, and lots of the underlying C
+ * library expects size_t values for the length of memory objects. We
+ * check, just to be sure.
+ */
+ if (sizeof(size_t) < sizeof(uint32_t)) {
+ __wt_api_env_errx(NULL, "%s",
+ "Build verification failed, a size_t is smaller than "
+ "4-bytes");
+ return (WT_ERROR);
+ }
+
+ return (0);
+}
+
+/*
+ * __wt_set_ff_and_sa_from_offset --
+ * Set first-free and space-available values from an address positioned
+ * one past the last used byte on the page.
+ */
+inline void
+__wt_set_ff_and_sa_from_offset(WT_PAGE *page,
+ void *p, uint8_t **first_freep, uint32_t *space_availp)
+{
+ *first_freep = (uint8_t *)p;
+ *space_availp =
+ page->size - (uint32_t)((uint8_t *)p - (uint8_t *)page->dsk);
+}
+
+/*
+ * __wt_page_write_gen_check --
+ * Confirm the page's write generation number is correct.
+ */
+inline int
+__wt_page_write_gen_check(WT_PAGE *page, uint32_t write_gen)
+{
+ return (page->write_gen == write_gen ? 0 : WT_RESTART);
+}
+
+/*
+ * __wt_page_type_string --
+ * Return a string representing the page type.
+ */
+const char *
+__wt_page_type_string(WT_PAGE_DISK *dsk)
+{
+ switch (dsk->type) {
+ case WT_PAGE_INVALID:
+ return ("invalid");
+ case WT_PAGE_COL_FIX:
+ return ("column-store fixed-length leaf");
+ case WT_PAGE_COL_INT:
+ return ("column-store internal");
+ case WT_PAGE_COL_RLE:
+ return ("column-store fixed-length run-length encoded leaf");
+ case WT_PAGE_COL_VAR:
+ return ("column-store variable-length leaf");
+ case WT_PAGE_DUP_INT:
+ return ("duplicate tree internal");
+ case WT_PAGE_DUP_LEAF:
+ return ("duplicate tree leaf");
+ case WT_PAGE_OVFL:
+ return ("overflow");
+ case WT_PAGE_ROW_INT:
+ return ("row-store internal");
+ case WT_PAGE_ROW_LEAF:
+ return ("row-store leaf");
+ default:
+ break;
+ }
+ return ("unknown");
+}
+
+/*
+ * __wt_item_type_string --
+ * Return a string representing the item type.
+ */
+const char *
+__wt_item_type_string(WT_ITEM *item)
+{
+ switch (WT_ITEM_TYPE(item)) {
+ case WT_ITEM_KEY:
+ return ("key");
+ case WT_ITEM_KEY_OVFL:
+ return ("key-overflow");
+ case WT_ITEM_KEY_DUP:
+ return ("key-duplicate");
+ case WT_ITEM_KEY_DUP_OVFL:
+ return ("key-duplicate-overflow");
+ case WT_ITEM_DATA:
+ return ("data");
+ case WT_ITEM_DATA_OVFL:
+ return ("data-overflow");
+ case WT_ITEM_DATA_DUP:
+ return ("data-duplicate");
+ case WT_ITEM_DATA_DUP_OVFL:
+ return ("data-duplicate-overflow");
+ case WT_ITEM_DEL:
+ return ("deleted");
+ case WT_ITEM_OFF:
+ return ("off-page");
+ default:
+ break;
+ }
+ return ("unknown");
+}