Commit ed9b5fc6 authored by John Esmet's avatar John Esmet

fixes #140 Pre-size the fifo before appending data during nonleaf

serialization. Assume the fifo is about 1kb larger than the read buffer
(in practice, the fifo is 5 bytes smaller than the read buffer).
parent 84fa905d
......@@ -135,6 +135,11 @@ int toku_fifo_create(FIFO *ptr) {
return 0;
}
void toku_fifo_resize(FIFO fifo, size_t new_size) {
XREALLOC_N(new_size, fifo->memory);
fifo->memory_size = new_size;
}
void toku_fifo_free(FIFO *ptr) {
FIFO fifo = *ptr;
if (fifo->memory) toku_free(fifo->memory);
......@@ -162,16 +167,10 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
+ xids_get_size(xids)
- sizeof(XIDS_S); //Prevent double counting
int need_space_total = fifo->memory_used+need_space_here;
if (fifo->memory == NULL) {
fifo->memory_size = next_power_of_two(need_space_total);
XMALLOC_N(fifo->memory_size, fifo->memory);
}
if (need_space_total > fifo->memory_size) {
// Out of memory at the end.
if (fifo->memory == NULL || need_space_total > fifo->memory_size) {
// resize the fifo to the next power of 2 greater than the needed space
int next_2 = next_power_of_two(need_space_total);
// resize the fifo
XREALLOC_N(next_2, fifo->memory);
fifo->memory_size = next_2;
toku_fifo_resize(fifo, next_2);
}
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used);
fifo_entry_set_msg_type(entry, type);
......
......@@ -136,6 +136,8 @@ typedef struct fifo *FIFO;
int toku_fifo_create(FIFO *);
void toku_fifo_resize(FIFO fifo, size_t new_size);
void toku_fifo_free(FIFO *);
int toku_fifo_n_entries(FIFO);
......
......@@ -1055,6 +1055,7 @@ deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf,
XMALLOC_N(n_in_this_buffer, fresh_offsets);
XMALLOC_N(n_in_this_buffer, broadcast_offsets);
}
toku_fifo_resize(bnc->buffer, rbuf->size + 64);
for (int i = 0; i < n_in_this_buffer; i++) {
bytevec key; ITEMLEN keylen;
bytevec val; ITEMLEN vallen;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment