Skip to content

Commit

Permalink
WT-2531: in-memory tables are wasting space in truncation
Browse files Browse the repository at this point in the history
The in-memory truncate call wasn't extending the file (by setting the
size of the WT_ITEM after truncation extended it).
  • Loading branch information
keithbostic committed Apr 4, 2016
1 parent 1d340e2 commit 659c977
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/os_common/os_fs_inmemory.c
Expand Up @@ -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);
Expand Down

0 comments on commit 659c977

Please sign in to comment.