summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDon Anderson <dda@ddanderson.com>2015-09-13 21:57:42 -0400
committerDon Anderson <dda@ddanderson.com>2015-09-13 21:57:42 -0400
commit0225351bb6d937309f0bccb800c46e72e1aa4b82 (patch)
tree95998c9b83fe07fef1642cc281f814e4f25831f0 /examples
parent4c663725867d2f9434298d30883c58a0d96deaa9 (diff)
parente1d6886824058b333495236b776b10fcd8fb74ae (diff)
downloadmongo-0225351bb6d937309f0bccb800c46e72e1aa4b82.tar.gz
Merge branch 'develop' into index-create-lsm3
Diffstat (limited to 'examples')
-rw-r--r--examples/c/ex_all.c3
-rw-r--r--examples/c/ex_log.c31
-rwxr-xr-xexamples/python/ex_access.py2
-rwxr-xr-xexamples/python/ex_stat.py30
4 files changed, 44 insertions, 22 deletions
diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c
index 6905169c4c2..213e058d4cc 100644
--- a/examples/c/ex_all.c
+++ b/examples/c/ex_all.c
@@ -1064,7 +1064,8 @@ main(void)
home = NULL;
/*! [Open a connection] */
- ret = wiredtiger_open(home, NULL, "create,cache_size=500M", &conn);
+ ret = wiredtiger_open(home, NULL,
+ "create,cache_size=5GB,log=(enabled,recover=on)", &conn);
/*! [Open a connection] */
if (ret == 0)
diff --git a/examples/c/ex_log.c b/examples/c/ex_log.c
index 136cca900cd..d5a8f32487d 100644
--- a/examples/c/ex_log.c
+++ b/examples/c/ex_log.c
@@ -128,20 +128,22 @@ print_record(WT_LSN *lsn, uint32_t opcount,
* A simple walk of the log.
*/
static int
-simple_walk_log(WT_SESSION *session)
+simple_walk_log(WT_SESSION *session, int count_min)
{
WT_CURSOR *cursor;
WT_LSN lsn;
WT_ITEM logrec_key, logrec_value;
uint64_t txnid;
uint32_t fileid, opcount, optype, rectype;
- int ret;
+ int count, ret;
/*! [log cursor open] */
ret = session->open_cursor(session, "log:", NULL, NULL, &cursor);
/*! [log cursor open] */
+ count = 0;
while ((ret = cursor->next(cursor)) == 0) {
+ count++;
/*! [log cursor get_key] */
ret = cursor->get_key(cursor, &lsn.file, &lsn.offset, &opcount);
/*! [log cursor get_key] */
@@ -156,6 +158,12 @@ simple_walk_log(WT_SESSION *session)
if (ret == WT_NOTFOUND)
ret = 0;
ret = cursor->close(cursor);
+ if (count < count_min) {
+ fprintf(stderr,
+ "Expected minimum %d records, found %d\n",
+ count_min, count);
+ abort();
+ }
return (ret);
}
/*! [log cursor walk] */
@@ -206,11 +214,13 @@ walk_log(WT_SESSION *session)
/*
* If the operation is a put, replay it here on the backup
- * connection. Note, we cheat by looking only for fileid 1
- * in this example. The metadata is fileid 0.
+ * connection.
+ *
+ * !!!
+ * Minor cheat: the metadata is fileid 0, skip its records.
*/
- if (fileid == 1 && rectype == WT_LOGREC_COMMIT &&
- optype == WT_LOGOP_ROW_PUT) {
+ if (fileid != 0 &&
+ rectype == WT_LOGREC_COMMIT && optype == WT_LOGOP_ROW_PUT) {
if (!in_txn) {
ret = session2->begin_transaction(session2,
NULL);
@@ -276,9 +286,10 @@ main(void)
WT_CONNECTION *wt_conn;
WT_CURSOR *cursor;
WT_SESSION *session;
- int i, record_count, ret;
+ int count_min, i, record_count, ret;
char cmd_buf[256], k[16], v[16];
+ count_min = 0;
snprintf(cmd_buf, sizeof(cmd_buf), "rm -rf %s %s && mkdir %s %s",
home1, home2, home1, home2);
if ((ret = system(cmd_buf)) != 0) {
@@ -293,6 +304,7 @@ main(void)
ret = wt_conn->open_session(wt_conn, NULL, NULL, &session);
ret = session->create(session, uri, "key_format=S,value_format=S");
+ count_min++;
ret = session->open_cursor(session, uri, NULL, NULL, &cursor);
/*
@@ -304,6 +316,7 @@ main(void)
cursor->set_key(cursor, k);
cursor->set_value(cursor, v);
ret = cursor->insert(cursor);
+ count_min++;
}
ret = session->begin_transaction(session, NULL);
/*
@@ -317,10 +330,12 @@ main(void)
ret = cursor->insert(cursor);
}
ret = session->commit_transaction(session, NULL);
+ count_min++;
ret = cursor->close(cursor);
/*! [log cursor printf] */
ret = session->log_printf(session, "Wrote %d records", record_count);
+ count_min++;
/*! [log cursor printf] */
/*
@@ -336,7 +351,7 @@ main(void)
}
ret = wt_conn->open_session(wt_conn, NULL, NULL, &session);
- ret = simple_walk_log(session);
+ ret = simple_walk_log(session, count_min);
ret = walk_log(session);
ret = wt_conn->close(wt_conn, NULL);
return (ret);
diff --git a/examples/python/ex_access.py b/examples/python/ex_access.py
index 8eeefd56cf7..2940ac63625 100755
--- a/examples/python/ex_access.py
+++ b/examples/python/ex_access.py
@@ -50,6 +50,6 @@ cursor.insert()
# Iterate through the records
cursor.reset()
for key, value in cursor:
- print('Got record: ' + key + ' : ' + value)
+ print('Got record: %s : %s' % (key, value))
conn.close()
diff --git a/examples/python/ex_stat.py b/examples/python/ex_stat.py
index e27177403cc..af2c4f7a1a7 100755
--- a/examples/python/ex_stat.py
+++ b/examples/python/ex_stat.py
@@ -32,6 +32,7 @@
import os
from wiredtiger import wiredtiger_open,WIREDTIGER_VERSION_STRING,stat
+
def main():
# Create a clean test directory for this run of the test program
os.system('rm -rf WT_HOME')
@@ -39,16 +40,16 @@ def main():
# Connect to the database and open a session
conn = wiredtiger_open('WT_HOME', 'create,statistics=(all)')
session = conn.open_session()
-
+
# Create a simple table
session.create('table:access', 'key_format=S,value_format=S')
-
+
# Open a cursor and insert a record
cursor = session.open_cursor('table:access', None)
- cursor['key'] = 'value'
+ cursor['key'] = 'value'
cursor.close()
-
+
session.checkpoint()
print WIREDTIGER_VERSION_STRING
print_database_stats(session)
@@ -57,46 +58,51 @@ def main():
print_derived_stats(session)
conn.close()
+
def print_database_stats(session):
statcursor = session.open_cursor("statistics:")
print_cursor(statcursor)
statcursor.close()
+
def print_file_stats(session):
fstatcursor = session.open_cursor("statistics:table:access")
print_cursor(fstatcursor)
fstatcursor.close()
+
def print_overflow_pages(session):
ostatcursor = session.open_cursor("statistics:table:access")
val = ostatcursor[stat.dsrc.btree_overflow]
- if val != 0 :
- print str(val[0]) + '=' + str(val[1])
+ if val != 0:
+ print '%s=%s' % (str(val[0]), str(val[1]))
ostatcursor.close()
+
def print_derived_stats(session):
dstatcursor = session.open_cursor("statistics:table:access")
ckpt_size = dstatcursor[stat.dsrc.block_checkpoint_size][1]
file_size = dstatcursor[stat.dsrc.block_size][1]
percent = 0
- if file_size != 0 :
+ if file_size != 0:
percent = 100 * ((float(file_size) - float(ckpt_size)) / float(file_size))
- print "Table is %" + str(percent) + " fragmented"
+ print "Table is %%%s fragmented" % str(percent)
app_insert = int(dstatcursor[stat.dsrc.cursor_insert_bytes][1])
app_remove = int(dstatcursor[stat.dsrc.cursor_remove_bytes][1])
app_update = int(dstatcursor[stat.dsrc.cursor_update_bytes][1])
- fs_writes = int(dstatcursor[stat.dsrc.cache_bytes_write][1])
+ fs_writes = int(dstatcursor[stat.dsrc.cache_bytes_write][1])
- if(app_insert + app_remove + app_update != 0):
+ if app_insert + app_remove + app_update != 0:
print "Write amplification is " + '{:.2f}'.format(fs_writes / (app_insert + app_remove + app_update))
dstatcursor.close()
+
def print_cursor(mycursor):
while mycursor.next() == 0:
val = mycursor.get_value()
- if val[1] != '0' :
- print str(val[0]) + '=' + str(val[1])
+ if val[1] != '0':
+ print '%s=%s' % (str(val[0]), str(val[1]))
if __name__ == "__main__":
main()