diff options
author | Alex Gorrod <alexander.gorrod@mongodb.com> | 2016-04-05 11:01:48 +1000 |
---|---|---|
committer | Alex Gorrod <alexander.gorrod@mongodb.com> | 2016-04-05 11:01:48 +1000 |
commit | 7a5fce2b618d51e0bb42a12b0a2e44a3632d3d10 (patch) | |
tree | 4c2eef7e0498a6e115d2fb6d95a26ce1c62acd5d | |
parent | 47b5268e9d1239ccc6a923ea9915a820645080df (diff) | |
parent | af4e3f14bd51f3c4149f64bcf4e2e249c61c5136 (diff) | |
download | mongo-7a5fce2b618d51e0bb42a12b0a2e44a3632d3d10.tar.gz |
Merge pull request #2629 from wiredtiger/wt-2531
WT-2531: in-memory tables are wasting space in truncation
-rw-r--r-- | src/block/block_ckpt.c | 5 | ||||
-rw-r--r-- | src/os_common/os_fs_inmemory.c | 16 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/block/block_ckpt.c b/src/block/block_ckpt.c index a0aadb43b93..a861a21876b 100644 --- a/src/block/block_ckpt.c +++ b/src/block/block_ckpt.c @@ -135,8 +135,11 @@ __wt_block_checkpoint_load(WT_SESSION_IMPL *session, WT_BLOCK *block, * that was done when the checkpoint was first written (re-writing the * checkpoint might possibly make it relevant here, but it's unlikely * enough I don't bother). + * + * If in-memory, we don't read or write the object, and the truncate + * will unnecessarily allocate buffer space. */ - if (!checkpoint) { + if (!checkpoint && !F_ISSET(S2C(session), WT_CONN_IN_MEMORY)) { /* * The truncate might fail if there's a file mapping (if there's * an open checkpoint on the file), that's OK. diff --git a/src/os_common/os_fs_inmemory.c b/src/os_common/os_fs_inmemory.c index 5b9c849d225..218deb15d29 100644 --- a/src/os_common/os_fs_inmemory.c +++ b/src/os_common/os_fs_inmemory.c @@ -334,17 +334,25 @@ __im_handle_sync(WT_SESSION_IMPL *session, WT_FH *fh, bool block) * POSIX ftruncate. */ static int -__im_handle_truncate(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t len) +__im_handle_truncate(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset) { WT_DECL_RET; WT_IM *im; + size_t off; im = S2C(session)->inmemory; __wt_spin_lock(session, &im->lock); - WT_ERR(__wt_buf_grow(session, &fh->buf, (size_t)len)); - memset((uint8_t *) - fh->buf.mem + fh->buf.size, 0, fh->buf.memsize - fh->buf.size); + /* + * Grow the buffer as necessary, clear any new space in the file, + * and reset the file's data length. + */ + off = (size_t)offset; + WT_ERR(__wt_buf_grow(session, &fh->buf, off)); + if (fh->buf.size < off) + memset((uint8_t *) + fh->buf.data + fh->buf.size, 0, off - fh->buf.size); + fh->buf.size = off; err: __wt_spin_unlock(session, &im->lock); return (ret); |