2010-09-15 21:53:51 +00:00
|
|
|
#include "PersistentParent.h"
|
|
|
|
#include "LSMPersistentStoreImpl.h"
|
|
|
|
#include "TabletMetadata.h"
|
|
|
|
#include "tcpclient.h"
|
|
|
|
|
2010-09-29 17:58:34 +00:00
|
|
|
#include <dht/LogUtils.h>
|
|
|
|
|
|
|
|
// Initialize the logger
|
|
|
|
static log4cpp::Category &log =
|
|
|
|
log4cpp::Category::getInstance("dht.su."__FILE__);
|
2010-09-15 21:53:51 +00:00
|
|
|
|
|
|
|
class LSMPersistentParent : PersistentParent {
|
|
|
|
public:
|
|
|
|
|
|
|
|
LSMPersistentParent() : ordered(true), hashed(false) {
|
|
|
|
} // we ignore the ordered flag...
|
2010-09-29 17:58:34 +00:00
|
|
|
~LSMPersistentParent() {
|
|
|
|
DHT_DEBUG_STREAM() << "~LSMPersistentParent called";
|
|
|
|
}
|
2010-09-15 21:53:51 +00:00
|
|
|
SuCode::ResponseCode install(const SectionConfig& config) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM install called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return SuCode::SuOk;
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode init(const SectionConfig& config) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM init called";
|
2010-09-15 21:53:51 +00:00
|
|
|
ordered.init(config);
|
|
|
|
hashed.init(config);
|
|
|
|
return SuCode::SuOk;
|
|
|
|
}
|
|
|
|
PersistentStore *getHashedStore() {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getHashedStore called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return &hashed;
|
|
|
|
}
|
|
|
|
PersistentStore *getOrderedStore() {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getOrderedStore called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return &ordered;
|
|
|
|
}
|
|
|
|
bool ping() {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM ping called";
|
|
|
|
return ordered.ping();
|
|
|
|
}
|
2010-09-15 21:53:51 +00:00
|
|
|
std::string getName() {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getName called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return "logstore";
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode getFreeSpaceBytes(double & freeSpaceBytes) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getFreeSpaceBytes called";
|
2010-09-15 21:53:51 +00:00
|
|
|
freeSpaceBytes = 1024.0 *1024.0 * 1024.0; // XXX stub
|
|
|
|
return SuCode::SuOk;
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode getDiskMaxBytes(double & diskMaxBytes) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getDiskMaxBytes called";
|
2010-09-15 21:53:51 +00:00
|
|
|
diskMaxBytes = 10.0 * 1024.0 *1024.0 * 1024.0; // XXX stub
|
|
|
|
return SuCode::SuOk;
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode cleanupTablet(uint64_t uniqId,
|
|
|
|
const std::string & tableName,
|
|
|
|
const std::string & tabletName) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM cleanupTablet called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return SuCode::SuOk; // XXX stub
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode getTabletMappingList(TabletList & tabletList) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getTabletMappingList called";
|
2010-09-15 21:53:51 +00:00
|
|
|
|
|
|
|
std::string metadata_table = std::string("ydht_metadata_table");
|
|
|
|
std::string metadata_tablet = std::string("0");
|
|
|
|
std::string metadata_tabletEnd = std::string("1");
|
|
|
|
|
|
|
|
size_t startlen;
|
|
|
|
size_t endlen;
|
|
|
|
|
|
|
|
unsigned char * start_tup = ordered.my_strcat(metadata_table, metadata_tablet, "", &startlen);
|
|
|
|
unsigned char * end_tup = ordered.my_strcat(metadata_table, metadata_tabletEnd, "", &endlen);
|
|
|
|
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "start tup = " << start_tup;
|
|
|
|
DHT_DEBUG_STREAM() << "end tup = " << end_tup;
|
2010-09-15 21:53:51 +00:00
|
|
|
|
|
|
|
datatuple * starttup = datatuple::create(start_tup, startlen);
|
|
|
|
datatuple * endtup = datatuple::create(end_tup, endlen);
|
|
|
|
|
|
|
|
free(start_tup);
|
|
|
|
free(end_tup);
|
|
|
|
|
|
|
|
uint8_t rcode = logstore_client_op_returns_many(ordered.l_, OP_SCAN, starttup, endtup, 0); // 0 = no limit.
|
|
|
|
|
|
|
|
datatuple::freetuple(starttup);
|
|
|
|
datatuple::freetuple(endtup);
|
|
|
|
|
|
|
|
datatuple * next;
|
|
|
|
|
|
|
|
TabletMetadata m;
|
|
|
|
if(rcode == LOGSTORE_RESPONSE_SENDING_TUPLES) {
|
|
|
|
while((next = logstore_client_next_tuple(ordered.l_))) {
|
|
|
|
ordered.metadata_buf(m, next->key(), next->keylen());
|
|
|
|
|
|
|
|
struct ydht_maptable_schema md;
|
2010-09-29 17:58:34 +00:00
|
|
|
std::string cat = m.table() + m.tablet();
|
2010-09-15 21:53:51 +00:00
|
|
|
md.uniq_id = 0;
|
2010-09-29 17:58:34 +00:00
|
|
|
for(int i = 0; i < cat.length(); i++) {
|
|
|
|
md.uniq_id += ((unsigned char)cat[i]); // XXX obviously, this is a terrible hack (and a poor hash function)
|
|
|
|
}
|
2010-09-15 21:53:51 +00:00
|
|
|
md.tableName = m.table();
|
|
|
|
md.tabletName = m.tablet();
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << md.uniq_id << " : " << md.tableName << " : " << md.tabletName;
|
2010-09-15 21:53:51 +00:00
|
|
|
tabletList.push_back(md);
|
|
|
|
datatuple::freetuple(next);
|
|
|
|
}
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "getTabletMappingListreturns";
|
2010-09-15 21:53:51 +00:00
|
|
|
} else {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_ERROR_STREAM() << "error " << (int)rcode << " in getTabletMappingList.";
|
2010-09-15 21:53:51 +00:00
|
|
|
return SuCode::PStoreUnexpectedError; // XXX should be "connection closed error" or something...
|
|
|
|
}
|
|
|
|
|
|
|
|
return SuCode::SuOk;
|
|
|
|
}
|
|
|
|
SuCode::ResponseCode getApproximateTableSize
|
|
|
|
(const std::string& tableId,
|
|
|
|
int64_t& tableSize, int64_t & rowCount) {
|
2010-09-29 17:58:34 +00:00
|
|
|
DHT_DEBUG_STREAM() << "LSM getApproximateTableSize called";
|
2010-09-15 21:53:51 +00:00
|
|
|
return ordered.getApproximateTableSize(tableId, tableSize, rowCount);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
LSMPersistentStoreImpl ordered;
|
|
|
|
LSMPersistentStoreImpl hashed;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void * lsmsherpa_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
static LSMPersistentParent pp;
|
|
|
|
void * lsmsherpa_init() {
|
|
|
|
return &pp;
|
|
|
|
}
|