diff options
author | dormando <dormando@rydia.net> | 2017-09-27 23:05:29 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2017-11-28 14:18:05 -0800 |
commit | ce79ff67c08f1eb33f87da58289db3949c639a43 (patch) | |
tree | ee5d86ad51a4c2842ef2b817835389cd7891c8bf /extstore.c | |
parent | 2891d61f699983a4e8c4458fc704d8ffb001d23c (diff) | |
download | memcached-ce79ff67c08f1eb33f87da58289db3949c639a43.tar.gz |
extstore: split write into write_request+write
write_request returns a buffer to write into, which lets us not corrupt the
active item with the hash and crc.
"technically" we can save 24 bytes per item in storage but I'll leave that
for a later optimization, in case we want to stuff more data into the header.
Diffstat (limited to 'extstore.c')
-rw-r--r-- | extstore.c | 44 |
1 files changed, 28 insertions, 16 deletions
@@ -405,7 +405,7 @@ static void _submit_wbuf(store_engine *e, store_page *p) { * new page. best if used from a background thread that can harmlessly retry. */ -int extstore_write(void *ptr, unsigned int bucket, obj_io *io) { +int extstore_write_request(void *ptr, unsigned int bucket, obj_io *io) { store_engine *e = (store_engine *)ptr; store_page *p; int ret = -1; @@ -444,23 +444,12 @@ int extstore_write(void *ptr, unsigned int bucket, obj_io *io) { _allocate_wbuf(e, p); } - // memcpy into wbuf + // hand over buffer for caller to copy into + // leaves p locked. if (p->wbuf && !p->wbuf->full && p->wbuf->free >= io->len) { - memcpy(p->wbuf->buf_pos, io->buf, io->len); + io->buf = p->wbuf->buf_pos; io->page_id = p->id; - io->offset = p->wbuf->offset + (p->wbuf->size - p->wbuf->free); - io->page_version = p->version; - p->wbuf->buf_pos += io->len; - p->wbuf->free -= io->len; - p->bytes_used += io->len; - p->obj_count++; - STAT_L(e); - e->stats.bytes_written += io->len; - e->stats.bytes_used += io->len; - e->stats.objects_written++; - e->stats.objects_used++; - STAT_UL(e); - ret = 0; + return 0; } pthread_mutex_unlock(&p->mutex); @@ -468,6 +457,29 @@ int extstore_write(void *ptr, unsigned int bucket, obj_io *io) { return ret; } +/* _must_ be called after a successful write_request. + * fills the rest of io structure. + */ +void extstore_write(void *ptr, obj_io *io) { + store_engine *e = (store_engine *)ptr; + store_page *p = &e->pages[io->page_id]; + + io->offset = p->wbuf->offset + (p->wbuf->size - p->wbuf->free); + io->page_version = p->version; + p->wbuf->buf_pos += io->len; + p->wbuf->free -= io->len; + p->bytes_used += io->len; + p->obj_count++; + STAT_L(e); + e->stats.bytes_written += io->len; + e->stats.bytes_used += io->len; + e->stats.objects_written++; + e->stats.objects_used++; + STAT_UL(e); + + pthread_mutex_unlock(&p->mutex); +} + /* engine submit function; takes engine, item_io stack. * lock io_thread context and add stack? * signal io thread to wake. |