summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2016-04-04 10:04:14 -0400
committerKeith Bostic <keith@wiredtiger.com>2016-04-04 10:04:14 -0400
commit659c977eb08d9c08ef903f5d876ac242daf424cc (patch)
tree59690cdaf59146fea5fcf1bbd8b6a1820d5e93eb
parent1d340e2ce9d3f06adb64fe82cf610cc09e610c5f (diff)
downloadmongo-659c977eb08d9c08ef903f5d876ac242daf424cc.tar.gz
WT-2531: in-memory tables are wasting space in truncation
The in-memory truncate call wasn't extending the file (by setting the size of the WT_ITEM after truncation extended it).
-rw-r--r--src/os_common/os_fs_inmemory.c16
1 files changed, 12 insertions, 4 deletions
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);