stasis-bLSM/tuplemerger.cpp
sears 7c2397340c Fixed a bunch of iterator bugs and racy merges. Added drop_database utility.
Bugfixes:
 - Atomically deallocate regions and update the logstore object
 - Proactively invalidate iterators after each merge (before, it would simply set a not-valid bit.  This doesn't work because iterators hold page pins, which breaks force-writes)
 - Clarify semantics of opening iterators mid-stream:  All calls now return iterators that return first key >= the requested one.  revalidate() needs the key > the requested one, so it calls peek(), then (if necessary) getnext().
 - Add asserts to check that the header is latched at update, and that tuples returned by iterators are strictly monotonically increasing'
 - Improve error handling in network.h  We still get (and terminate on) SIGPIPE.

Refactoring:
 - Add dispatch function to network.h.



git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@620 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
2010-02-25 01:29:32 +00:00

55 lines
1.3 KiB
C++

#include "tuplemerger.h"
#include "logstore.h"
// XXX make the imputs 'const'
// XXX test / reason about this...
datatuple* tuplemerger::merge(datatuple *t1, datatuple *t2)
{
datatuple *t;
if(t1->isDelete() && t2->isDelete()) {
t = t2->create_copy();
} else if(t1->isDelete()) //delete -> t2
{
t = t2->create_copy();
}
else if(t2->isDelete())
{
t = t2->create_copy();
}
else //neither is a delete
{
t = (*merge_fp)(t1,t2);
}
return t;
}
/**
* appends the data in t2 to data from t1
*
* deletes are handled by the tuplemerger::merge function
* so here neither t1 nor t2 is a delete datatuple
**/
datatuple* append_merger(datatuple *t1, datatuple *t2)
{
assert(!(t1->isDelete() || t2->isDelete()));
len_t keylen = t1->keylen();
len_t datalen = t1->datalen() + t2->datalen();
byte * data = (byte*)malloc(datalen);
memcpy(data, t1->data(), t1->datalen());
memcpy(data + t1->datalen(), t2->data(), t2->datalen());
return datatuple::create(t1->key(), keylen, data, datalen);
}
/**
* replaces the data with data from t2
*
* deletes are handled by the tuplemerger::merge function
* so here neither t1 nor t2 is a delete datatuple
**/
datatuple* replace_merger(datatuple *t1, datatuple *t2)
{
return t2->create_copy();
}