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) { ...@@ -135,6 +135,11 @@ int toku_fifo_create(FIFO *ptr) {
return 0; 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) { void toku_fifo_free(FIFO *ptr) {
FIFO fifo = *ptr; FIFO fifo = *ptr;
if (fifo->memory) toku_free(fifo->memory); 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 ...@@ -162,16 +167,10 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
+ xids_get_size(xids) + xids_get_size(xids)
- sizeof(XIDS_S); //Prevent double counting - sizeof(XIDS_S); //Prevent double counting
int need_space_total = fifo->memory_used+need_space_here; int need_space_total = fifo->memory_used+need_space_here;
if (fifo->memory == NULL) { if (fifo->memory == NULL || need_space_total > fifo->memory_size) {
fifo->memory_size = next_power_of_two(need_space_total); // resize the fifo to the next power of 2 greater than the needed space
XMALLOC_N(fifo->memory_size, fifo->memory);
}
if (need_space_total > fifo->memory_size) {
// Out of memory at the end.
int next_2 = next_power_of_two(need_space_total); int next_2 = next_power_of_two(need_space_total);
// resize the fifo toku_fifo_resize(fifo, next_2);
XREALLOC_N(next_2, fifo->memory);
fifo->memory_size = next_2;
} }
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used); struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used);
fifo_entry_set_msg_type(entry, type); fifo_entry_set_msg_type(entry, type);
......
...@@ -136,6 +136,8 @@ typedef struct fifo *FIFO; ...@@ -136,6 +136,8 @@ typedef struct fifo *FIFO;
int toku_fifo_create(FIFO *); int toku_fifo_create(FIFO *);
void toku_fifo_resize(FIFO fifo, size_t new_size);
void toku_fifo_free(FIFO *); void toku_fifo_free(FIFO *);
int toku_fifo_n_entries(FIFO); int toku_fifo_n_entries(FIFO);
......
...@@ -1055,6 +1055,7 @@ deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf, ...@@ -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, fresh_offsets);
XMALLOC_N(n_in_this_buffer, broadcast_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++) { for (int i = 0; i < n_in_this_buffer; i++) {
bytevec key; ITEMLEN keylen; bytevec key; ITEMLEN keylen;
bytevec val; ITEMLEN vallen; 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