Files
mongo/test/format/format.h

263 lines
7.5 KiB
C
Raw Normal View History

/*-
* Public Domain 2008-2014 WiredTiger, Inc.
2012-02-01 15:32:36 +00:00
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef BDB
#include <db.h>
#endif
#include <wiredtiger.h>
#include <gcc.h> /* WiredTiger internal */
#include <wiredtiger_ext.h>
extern WT_EXTENSION_API *wt_api;
#define EXTPATH "../../ext/" /* Extensions path */
#define BZIP_PATH \
EXTPATH "compressors/bzip2/.libs/libwiredtiger_bzip2.so"
#define SNAPPY_PATH \
EXTPATH "compressors/snappy/.libs/libwiredtiger_snappy.so"
#define REVERSE_PATH \
EXTPATH "collators/reverse/.libs/libwiredtiger_reverse_collator.so"
#define KVS_BDB_PATH \
EXTPATH "test/kvs_bdb/.libs/libwiredtiger_kvs_bdb.so"
#define HELIUM_PATH \
EXTPATH "test/helium/.libs/libwiredtiger_helium.so"
#define LZO_PATH ".libs/lzo_compress.so"
#define RAW_PATH ".libs/raw_compress.so"
#undef M
#define M(v) ((v) * 1000000) /* Million */
#undef MEGABYTE
#define MEGABYTE(v) ((v) * 1048576)
#undef GIGABYTE
#define GIGABYTE(v) ((v) * 1073741824ULL)
/* Get a random value between a min/max pair. */
2013-12-07 10:48:52 -05:00
#define MMRAND(min, max) (rng() % (((max) + 1) - (min)) + (min))
#define WT_NAME "wt" /* Object name */
#define DATASOURCE(v) (strcmp(v, g.c_data_source) == 0 ? 1 : 0)
#define SINGLETHREADED (g.c_threads == 1)
typedef struct {
char *progname; /* Program name */
char *home; /* Home directory */
char *home_init; /* Initialize home command */
char *home_backup; /* Hot-backup directory */
char *home_backup_init; /* Initialize backup command */
char *home_bdb; /* BDB directory */
char *home_kvs; /* KVS directory */
char *home_log; /* Operation log file path */
char *home_rand; /* RNG log file path */
char *home_run; /* Run file path */
char *home_stats; /* Statistics file path */
char *home_salvage_copy; /* Salvage copy command */
void *bdb; /* BDB comparison handle */
Intermediate commit of new cursor code: this commit has mostly working row-store cursor code, but completely broken column-store cursors (I haven't done any work on them yet). I'm about to try and re-work the general-purpose walk code, and I want to have a solid reference point to revert to. Here's the laundry list: Re-write the row-store cursor-next/cursor-prev functions to interact cleanly with the other cursor functions, specifically after any cursor operation returns successfully, a subsequent cursor-next/prev call is supported. The fundamental trick here is choosing the fields that a cursor-search call sets, and then filling in the rest of the fields a traversal requires as soon as cursor-next/prev is called. The state of a cursor is set in the WT_CURSOR_BTREE->iter_state field. There's a new "walk" function that fills in the walk stack from the root to a specified page. As part of this, the SESSION.srch structure will go away, replaced by the WT_CURSOR_BTREE structure. Implement cursor semantics for row-store: update fails if the key doesn't exist, otherwise overwrites the value; insert fails if the key exists, otherwise inserts a new record, unless the configuration boolean "overwrite" is set, in which case insert inserts a new record if the record doesn't exist, and overwrites any existing record; remove fails if the key doesn't exist, otherwise removes the record. Fail in all cases if the application hasn't yet set a cursor key. Flush memory after reading the page's write-generation value to ensure that we do the read before reading anything from the page. This is necessary but not sufficient: the page's write-generation value could still be cache, and that would be bad. We need to either do an additional memory flush before the read, in order to flush our registers, or mark the write-generation field volatile. Cursors now hold hazard references across calls (the page cannot be discarded if a cursor references it). This is necessary for the future change where cursor will return pointers to in-memory page data. The __wt_walk_first/__wt_walk_last functions no longer support starting at a random page, no current callers of those functions used that feature. Write versions of the serial insert/update functions that don't take SESSION.srch pointers, instead, they pass the specific fields they need, in some cases taken from the WT_CURSOR_BTREE structure. Write a version of the return-value function to use information from the WT_CURSOR_BTREE structure instead of information from the SESSION.srch structure. Delete the WT_CURSOR structure WT_CURSTD_POSITIONED flag (never used), add the WT_CURSTD_OVERWRITE flag to support the cursor->insert boolean "overwrite". Delete the WT_TOOSMALL error, no longer used by compression. Add support to the format test program to test prev/next cursor movements after operations. Configure the format test program to configure the boolean "overwrite" value on its cursors, that matches the old BDB DB.put semantics the test program wants. Change the format test program to close its cursor before calling WT_SESSION.sync, now that cursors hold hazard references across calls, WT_SESSION.sync will hang. Add statistics to track read-next/read-prev calls, separate from read (search-near) calls. --HG-- extra : rebase_source : a7b386152cef2a2744df26121b06536e7066fc95
2011-08-26 15:08:10 +00:00
void *dbc; /* BDB cursor handle */
2010-03-01 09:04:12 +11:00
WT_CONNECTION *wts_conn;
WT_EXTENSION_API *wt_api;
2013-12-07 10:48:52 -05:00
int rand_log_stop; /* Logging turned off */
FILE *rand_log; /* Random number log */
uint32_t run_cnt; /* Run counter */
enum {
LOG_FILE=1, /* Use a log file */
LOG_OPS=2 /* Log all operations */
} logging;
FILE *logfp; /* Log file */
int replay; /* Replaying a run. */
int track; /* Track progress */
int threads_finished; /* Operations completed */
pthread_rwlock_t backup_lock; /* Hot backup running */
/*
* We have a list of records that are appended, but not yet "resolved",
* that is, we haven't yet incremented the g.rows value to reflect the
* new records.
*/
uint64_t *append; /* Appended records */
size_t append_max; /* Maximum unresolved records */
size_t append_cnt; /* Current unresolved records */
pthread_rwlock_t append_lock; /* Single-thread resolution */
char *uri; /* Object name */
char *config_open; /* Command-line configuration */
uint32_t c_auto_throttle; /* Config values */
uint32_t c_bitcnt;
uint32_t c_bloom;
uint32_t c_bloom_bit_count;
uint32_t c_bloom_hash_count;
uint32_t c_bloom_oldest;
uint32_t c_cache;
uint32_t c_compact;
char *c_checksum;
uint32_t c_chunk_size;
char *c_compression;
char *c_config_open;
uint32_t c_data_extend;
char *c_data_source;
uint32_t c_delete_pct;
uint32_t c_dictionary;
uint32_t c_firstfit;
uint32_t c_hot_backups;
char *c_file_type;
uint32_t c_huffman_key;
uint32_t c_huffman_value;
uint32_t c_insert_pct;
uint32_t c_internal_key_truncation;
uint32_t c_intl_page_max;
uint32_t c_key_gap;
uint32_t c_key_max;
uint32_t c_key_min;
uint32_t c_leaf_page_max;
uint32_t c_merge_max;
uint32_t c_merge_threads;
uint32_t c_ops;
uint32_t c_prefix_compression;
uint32_t c_prefix_compression_min;
uint32_t c_repeat_data_pct;
uint32_t c_reverse;
uint32_t c_rows;
uint32_t c_runs;
uint32_t c_split_pct;
uint32_t c_statistics;
uint32_t c_threads;
uint32_t c_value_max;
uint32_t c_value_min;
uint32_t c_write_pct;
#define FIX 1
#define ROW 2
#define VAR 3
u_int type; /* File type's flag value */
#define CHECKSUM_OFF 1
#define CHECKSUM_ON 2
#define CHECKSUM_UNCOMPRESSED 3
u_int c_checksum_flag; /* Checksum flag value */
#define COMPRESS_NONE 1
#define COMPRESS_BZIP 2
#define COMPRESS_LZO 3
#define COMPRESS_RAW 4
#define COMPRESS_SNAPPY 5
u_int c_compression_flag; /* Compression flag value */
2013-06-18 12:19:25 +10:00
uint64_t key_cnt; /* Keys loaded so far */
uint64_t rows; /* Total rows */
uint32_t key_rand_len[1031]; /* Key lengths */
} GLOBAL;
extern GLOBAL g;
typedef struct {
uint64_t search; /* operations */
uint64_t insert;
uint64_t update;
uint64_t remove;
uint64_t commit; /* transaction resolution */
uint64_t rollback;
uint64_t deadlock;
int id; /* simple thread ID */
pthread_t tid; /* thread ID */
#define TINFO_RUNNING 1 /* Running */
#define TINFO_COMPLETE 2 /* Finished */
#define TINFO_JOINED 3 /* Resolved */
volatile int state; /* state */
} TINFO;
void bdb_close(void);
void bdb_insert(const void *, size_t, const void *, size_t);
void bdb_np(int, void *, size_t *, void *, size_t *, int *);
void bdb_open(void);
void bdb_read(uint64_t, void *, size_t *, int *);
void bdb_remove(uint64_t, int *);
void bdb_update(const void *, size_t, const void *, size_t, int *);
void *compact(void *);
void config_clear(void);
void config_error(void);
void config_file(const char *);
void config_print(int);
void config_setup(void);
void config_single(const char *, int);
void die(int, const char *, ...);
void *hot_backup(void *);
void key_len_setup(void);
void key_gen_setup(uint8_t **);
void key_gen(uint8_t *, size_t *, uint64_t, int);
void path_setup(const char *);
2013-12-07 10:48:52 -05:00
uint32_t rng(void);
void rng_init(void);
void syserr(const char *);
void track(const char *, uint64_t, TINFO *);
void val_gen_setup(uint8_t **);
void value_gen(uint8_t *, size_t *, uint64_t);
void wts_close(void);
void wts_create(void);
void wts_dump(const char *, int);
void wts_load(void);
void wts_open(const char *, int, WT_CONNECTION **);
void wts_ops(void);
void wts_read_scan(void);
void wts_salvage(void);
void wts_stats(void);
void wts_verify(const char *);