Commit 86646f79 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4740], remove fifo->memory_start

git-svn-id: file:///svn/toku/tokudb@42746 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0657bfdf
......@@ -10,7 +10,6 @@ struct fifo {
int n_items_in_fifo;
char *memory; // An array of bytes into which fifo_entries are embedded.
int memory_size; // How big is fifo_memory
int memory_start; // Where is the first used byte?
int memory_used; // How many bytes are in use?
};
......@@ -19,7 +18,6 @@ static void fifo_init(struct fifo *fifo) {
fifo->n_items_in_fifo = 0;
fifo->memory = 0;
fifo->memory_size = 0;
fifo->memory_start = 0;
fifo->memory_used = 0;
}
......@@ -29,11 +27,6 @@ static int fifo_entry_size(struct fifo_entry *entry) {
- sizeof(XIDS_S); //Prevent double counting from fifo_entry+xids_get_size
}
static struct fifo_entry *fifo_peek(struct fifo *fifo) {
if (fifo->n_items_in_fifo == 0) return NULL;
else return (struct fifo_entry *)(fifo->memory+fifo->memory_start);
}
int toku_fifo_create(FIFO *ptr) {
struct fifo *XMALLOC(fifo);
if (fifo == 0) return ENOMEM;
......@@ -63,13 +56,6 @@ static int next_power_of_two (int n) {
return r;
}
void toku_fifo_size_hint(FIFO fifo, size_t size) {
if (fifo->memory == NULL) {
fifo->memory_size = next_power_of_two(size);
fifo->memory = toku_xmalloc(fifo->memory_size);
}
}
int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *data, unsigned int datalen, enum brt_msg_type type, MSN msn, XIDS xids, bool is_fresh, long *dest) {
int need_space_here = sizeof(struct fifo_entry)
+ keylen + datalen
......@@ -80,7 +66,7 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
fifo->memory_size = next_power_of_two(need_space_total);
fifo->memory = toku_xmalloc(fifo->memory_size);
}
if (fifo->memory_start+need_space_total > fifo->memory_size) {
if (need_space_total > fifo->memory_size) {
// Out of memory at the end.
int next_2 = next_power_of_two(need_space_total);
if ((2*next_2 > fifo->memory_size)
......@@ -89,20 +75,13 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
char *newmem = toku_xmalloc(next_2);
char *oldmem = fifo->memory;
if (newmem==0) return ENOMEM;
memcpy(newmem, oldmem+fifo->memory_start, fifo->memory_used);
memcpy(newmem, oldmem, fifo->memory_used);
fifo->memory_size = next_2;
assert(fifo->memory_start == 0);
fifo->memory_start = 0;
fifo->memory = newmem;
toku_free(oldmem);
} else {
// slide things over
memmove(fifo->memory, fifo->memory+fifo->memory_start, fifo->memory_used);
assert(fifo->memory_start == 0);
fifo->memory_start = 0;
}
}
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_start + fifo->memory_used);
struct fifo_entry *entry = (struct fifo_entry *)(fifo->memory + fifo->memory_used);
fifo_entry_set_msg_type(entry, type);
entry->msn = msn;
xids_cpy(&entry->xids_s, xids);
......@@ -113,7 +92,6 @@ int toku_fifo_enq(FIFO fifo, const void *key, unsigned int keylen, const void *d
entry->vallen = datalen;
memcpy(e_key + keylen, data, datalen);
if (dest) {
assert(fifo->memory_start == 0);
*dest = fifo->memory_used;
}
fifo->n_items_in_fifo++;
......@@ -125,22 +103,6 @@ int toku_fifo_enq_cmdstruct (FIFO fifo, const BRT_MSG cmd, bool is_fresh, long *
return toku_fifo_enq(fifo, cmd->u.id.key->data, cmd->u.id.key->size, cmd->u.id.val->data, cmd->u.id.val->size, cmd->type, cmd->msn, cmd->xids, is_fresh, dest);
}
/* peek at the head (the oldest entry) of the fifo */
int toku_fifo_peek(FIFO fifo, bytevec *key, unsigned int *keylen, bytevec *data, unsigned int *datalen, enum brt_msg_type *type, MSN *msn, XIDS *xids, bool *is_fresh) {
struct fifo_entry *entry = fifo_peek(fifo);
if (entry == 0) return -1;
unsigned char *e_key = xids_get_end_of_array(&entry->xids_s);
*key = e_key;
*keylen = entry->keylen;
*data = e_key + entry->keylen;
*datalen = entry->vallen;
*type = fifo_entry_get_msg_type(entry);
*msn = entry->msn;
*xids = &entry->xids_s;
*is_fresh = entry->is_fresh;
return 0;
}
#if 0
// fill in the BRT_MSG, using the two DBTs for the DBT part.
int toku_fifo_peek_cmdstruct (FIFO fifo, BRT_MSG cmd, DBT*key, DBT*data) {
......@@ -158,26 +120,8 @@ int toku_fifo_peek_cmdstruct (FIFO fifo, BRT_MSG cmd, DBT*key, DBT*data) {
}
#endif
int toku_fifo_deq(FIFO fifo) {
if (fifo->n_items_in_fifo==0) return -1;
struct fifo_entry * e = fifo_peek(fifo);
assert(e);
int used_here = fifo_entry_size(e);
fifo->n_items_in_fifo--;
fifo->memory_start+=used_here;
fifo->memory_used -=used_here;
return 0;
}
int toku_fifo_empty(FIFO fifo) {
assert(fifo->memory_start == 0);
fifo->memory_used = 0;
fifo->n_items_in_fifo = 0;
return 0;
}
int toku_fifo_iterate_internal_start(FIFO fifo) { return fifo->memory_start; }
int toku_fifo_iterate_internal_has_more(FIFO fifo, int off) { return off < fifo->memory_start + fifo->memory_used; }
int toku_fifo_iterate_internal_start(FIFO UU(fifo)) { return 0; }
int toku_fifo_iterate_internal_has_more(FIFO fifo, int off) { return off < fifo->memory_used; }
int toku_fifo_iterate_internal_next(FIFO fifo, int off) {
struct fifo_entry *e = (struct fifo_entry *)(fifo->memory + off);
return off + fifo_entry_size(e);
......@@ -194,23 +138,22 @@ void toku_fifo_iterate (FIFO fifo, void(*f)(bytevec key,ITEMLEN keylen,bytevec d
void toku_fifo_size_is_stabilized(FIFO fifo) {
if (fifo->memory_used < fifo->memory_size/2) {
char *old_memory = fifo->memory;
int new_memory_size = fifo->memory_used*2;
char *new_memory = toku_xmalloc(new_memory_size);
memcpy(new_memory, old_memory+fifo->memory_start, fifo->memory_used);
fifo->memory = new_memory;
fifo->memory_start = 0;
fifo->memory_size = new_memory_size;
toku_free(old_memory);
char *old_memory = fifo->memory;
int new_memory_size = fifo->memory_used*2;
char *new_memory = toku_xmalloc(new_memory_size);
memcpy(new_memory, old_memory, fifo->memory_used);
fifo->memory = new_memory;
fifo->memory_size = new_memory_size;
toku_free(old_memory);
}
}
unsigned long toku_fifo_memory_size_in_use(FIFO fifo) {
return sizeof(*fifo)+fifo->memory_start+fifo->memory_used;
return sizeof(*fifo)+fifo->memory_used;
}
unsigned long toku_fifo_memory_footprint(FIFO fifo) {
size_t size_used = toku_memory_footprint(fifo->memory, fifo->memory_start+fifo->memory_used);
size_t size_used = toku_memory_footprint(fifo->memory, fifo->memory_used);
long rval = sizeof(*fifo) + size_used;
return rval;
}
......@@ -231,14 +174,21 @@ void toku_fifo_clone(FIFO orig_fifo, FIFO* cloned_fifo) {
struct fifo *XMALLOC(new_fifo);
assert(new_fifo);
new_fifo->n_items_in_fifo = orig_fifo->n_items_in_fifo;
new_fifo->memory_start = 0;
new_fifo->memory_used = orig_fifo->memory_used - orig_fifo->memory_start;
new_fifo->memory_used = orig_fifo->memory_used;
new_fifo->memory_size = new_fifo->memory_used;
new_fifo->memory = toku_xmalloc(new_fifo->memory_size);
memcpy(
new_fifo->memory,
orig_fifo->memory + orig_fifo->memory_start,
orig_fifo->memory,
new_fifo->memory_size
);
*cloned_fifo = new_fifo;
}
BOOL toku_are_fifos_same(FIFO fifo1, FIFO fifo2) {
return (
fifo1->memory_used == fifo2->memory_used &&
memcmp(fifo1->memory, fifo2->memory, fifo1->memory_used) == 0
);
}
......@@ -54,10 +54,6 @@ int toku_fifo_create(FIFO *);
void toku_fifo_free(FIFO *);
// Use the size hint to size the storage for the fifo entries in anticipation of putting a bunch of them
// into the fifo.
void toku_fifo_size_hint(FIFO, size_t size_hint);
void toku_fifo_size_is_stabilized(FIFO);
// Effect: Tell the FIFO that we may have just inserted or removed a bunch of stuff, and now may be a good time to resize memory.
......@@ -67,13 +63,8 @@ int toku_fifo_enq_cmdstruct (FIFO fifo, const BRT_MSG cmd, bool is_fresh, long *
int toku_fifo_enq (FIFO, const void *key, ITEMLEN keylen, const void *data, ITEMLEN datalen, enum brt_msg_type type, MSN msn, XIDS xids, bool is_fresh, long *dest);
int toku_fifo_peek (FIFO, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen, u_int32_t *type, MSN *msn, XIDS *xids, bool *is_fresh);
// int toku_fifo_peek_cmdstruct (FIFO, BRT_MSG, DBT*, DBT*); // fill in the BRT_MSG, using the two DBTs for the DBT part.
int toku_fifo_deq(FIFO); // we cannot deq items anymore, since their offsets are indexed.
// THIS ONLY REMAINS FOR TESTING, DO NOT USE IT IN CODE
int toku_fifo_empty(FIFO); // don't deallocate the memory for the fifo
unsigned long toku_fifo_memory_size_in_use(FIFO fifo); // return how much memory in the fifo holds useful data
unsigned long toku_fifo_memory_footprint(FIFO fifo); // return how much memory the fifo occupies
......@@ -112,6 +103,8 @@ const struct fifo_entry *toku_fifo_get_entry(FIFO fifo, long off);
void toku_fifo_clone(FIFO orig_fifo, FIFO* cloned_fifo);
BOOL toku_are_fifos_same(FIFO fifo1, FIFO fifo2);
#if defined(__cplusplus) || defined(__cilkplusplus)
};
#endif
......
......@@ -1281,85 +1281,10 @@ test_serialize_nonleaf(enum brtnode_verify_type bft, BOOL do_clone) {
FIFO src_fifo_2 = BNC(&sn, 1)->buffer;
FIFO dest_fifo_1 = BNC(dn, 0)->buffer;
FIFO dest_fifo_2 = BNC(dn, 1)->buffer;
bytevec src_key,src_val, dest_key, dest_val;
ITEMLEN src_keylen, src_vallen;
u_int32_t src_type;
MSN src_msn;
XIDS src_xids;
ITEMLEN dest_keylen, dest_vallen;
u_int32_t dest_type;
MSN dest_msn;
XIDS dest_xids;
bool src_is_fresh;
bool dest_is_fresh;
r = toku_fifo_peek(src_fifo_1, &src_key, &src_keylen, &src_val, &src_vallen, &src_type, &src_msn, &src_xids, &src_is_fresh);
assert(r==0);
r = toku_fifo_peek(dest_fifo_1, &dest_key, &dest_keylen, &dest_val, &dest_vallen, &dest_type, &dest_msn, &dest_xids, &dest_is_fresh);
assert(r==0);
assert(src_keylen == dest_keylen);
assert(src_keylen == 2);
assert(src_vallen == dest_vallen);
assert(src_vallen == 5);
assert(src_type == dest_type);
assert(src_msn.msn == dest_msn.msn);
assert(strcmp(src_key, "a") == 0);
assert(strcmp(dest_key, "a") == 0);
assert(strcmp(src_val, "aval") == 0);
assert(strcmp(dest_val, "aval") == 0);
assert(src_is_fresh == dest_is_fresh);
r = toku_fifo_deq(src_fifo_1);
assert(r==0);
r = toku_fifo_deq(dest_fifo_1);
assert(r==0);
r = toku_fifo_peek(src_fifo_1, &src_key, &src_keylen, &src_val, &src_vallen, &src_type, &src_msn, &src_xids, &src_is_fresh);
assert(r==0);
r = toku_fifo_peek(dest_fifo_1, &dest_key, &dest_keylen, &dest_val, &dest_vallen, &dest_type, &dest_msn, &dest_xids, &dest_is_fresh);
assert(r==0);
assert(src_keylen == dest_keylen);
assert(src_keylen == 2);
assert(src_vallen == dest_vallen);
assert(src_vallen == 5);
assert(src_type == dest_type);
assert(src_msn.msn == dest_msn.msn);
assert(strcmp(src_key, "b") == 0);
assert(strcmp(dest_key, "b") == 0);
assert(strcmp(src_val, "bval") == 0);
assert(strcmp(dest_val, "bval") == 0);
assert(src_is_fresh == dest_is_fresh);
r = toku_fifo_deq(src_fifo_1);
assert(r==0);
r = toku_fifo_deq(dest_fifo_1);
assert(r==0);
r = toku_fifo_peek(src_fifo_1, &src_key, &src_keylen, &src_val, &src_vallen, &src_type, &src_msn, &src_xids, &src_is_fresh);
assert(r!=0);
r = toku_fifo_peek(dest_fifo_1, &dest_key, &dest_keylen, &dest_val, &dest_vallen, &dest_type, &dest_msn, &dest_xids, &dest_is_fresh);
assert(r!=0);
r = toku_fifo_peek(src_fifo_2, &src_key, &src_keylen, &src_val, &src_vallen, &src_type, &src_msn, &src_xids, &src_is_fresh);
assert(r==0);
r = toku_fifo_peek(dest_fifo_2, &dest_key, &dest_keylen, &dest_val, &dest_vallen, &dest_type, &dest_msn, &dest_xids, &dest_is_fresh);
assert(r==0);
assert(src_keylen == dest_keylen);
assert(src_keylen == 2);
assert(src_vallen == dest_vallen);
assert(src_vallen == 5);
assert(src_type == dest_type);
assert(src_msn.msn == dest_msn.msn);
assert(strcmp(src_key, "x") == 0);
assert(strcmp(dest_key, "x") == 0);
assert(strcmp(src_val, "xval") == 0);
assert(strcmp(dest_val, "xval") == 0);
assert(src_is_fresh == dest_is_fresh);
r = toku_fifo_deq(src_fifo_2);
assert(r==0);
r = toku_fifo_deq(dest_fifo_2);
assert(r==0);
r = toku_fifo_peek(src_fifo_2, &src_key, &src_keylen, &src_val, &src_vallen, &src_type, &src_msn, &src_xids, &src_is_fresh);
assert(r!=0);
r = toku_fifo_peek(dest_fifo_2, &dest_key, &dest_keylen, &dest_val, &dest_vallen, &dest_type, &dest_msn, &dest_xids, &dest_is_fresh);
assert(r!=0);
assert(toku_are_fifos_same(src_fifo_1, dest_fifo_1));
assert(toku_are_fifos_same(src_fifo_2, dest_fifo_2));
toku_brtnode_free(&dn);
kv_pair_free(sn.childkeys[0]);
......
......@@ -80,9 +80,6 @@ test_fifo_enq (int n) {
if (thekey) toku_free(thekey);
if (theval) toku_free(theval);
while (toku_fifo_deq(f) == 0)
;
toku_fifo_free(&f);
assert(f == 0);
}
......
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