added remove().

git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@2547 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe
This commit is contained in:
michim 2011-05-12 20:56:04 +00:00
parent 5291a25dce
commit 129342b42c
3 changed files with 28 additions and 17 deletions

View file

@ -437,6 +437,11 @@ datatuple * logtable<TUPLE>::findTuple(int xid, const datatuple::key_t key, size
rwlc_unlock(header_mut); rwlc_unlock(header_mut);
datatuple::freetuple(search_tuple); datatuple::freetuple(search_tuple);
if (ret_tuple != NULL && ret_tuple->isDelete()) {
// this is a tombstone. don't return it
datatuple::freetuple(ret_tuple);
return NULL;
}
return ret_tuple; return ret_tuple;
} }
@ -529,7 +534,13 @@ datatuple * logtable<TUPLE>::findTuple_first(int xid, datatuple::key_t key, size
} }
datatuple::freetuple(search_tuple); datatuple::freetuple(search_tuple);
if (ret_tuple != NULL && ret_tuple->isDelete()) {
// this is a tombstone. don't return it
datatuple::freetuple(ret_tuple);
return NULL;
}
return ret_tuple; return ret_tuple;
} }

View file

@ -246,7 +246,8 @@ get(datatuple* tuple)
{ {
// -1 is invalid txn id // -1 is invalid txn id
//return ltable_->findTuple_first(-1, tuple->strippedkey(), tuple->strippedkeylen()); //return ltable_->findTuple_first(-1, tuple->strippedkey(), tuple->strippedkeylen());
return ltable_->findTuple_first(-1, tuple->rawkey(), tuple->rawkeylen()); datatuple* tup = ltable_->findTuple_first(-1, tuple->rawkey(), tuple->rawkeylen());
return tup;
} }
void LSMServerHandler:: void LSMServerHandler::
@ -349,7 +350,6 @@ update(const std::string& databaseName,
const std::string& recordBody) const std::string& recordBody)
{ {
uint32_t id = getDatabaseId(databaseName); uint32_t id = getDatabaseId(databaseName);
std::cout << "michim: enter update" << std::endl;
if (id == 0) { if (id == 0) {
return sherpa::ResponseCode::DatabaseNotFound; return sherpa::ResponseCode::DatabaseNotFound;
} }
@ -357,7 +357,6 @@ update(const std::string& databaseName,
if (oldRecordBody == NULL) { if (oldRecordBody == NULL) {
return sherpa::ResponseCode::RecordNotFound; return sherpa::ResponseCode::RecordNotFound;
} }
std::cout << "michim: updating record" << std::endl;
datatuple::freetuple(oldRecordBody); datatuple::freetuple(oldRecordBody);
datatuple* tup = buildTuple(id, recordName, recordBody); datatuple* tup = buildTuple(id, recordName, recordBody);
return insert(tup); return insert(tup);
@ -366,22 +365,17 @@ update(const std::string& databaseName,
ResponseCode::type LSMServerHandler:: ResponseCode::type LSMServerHandler::
remove(const std::string& databaseName, const std::string& recordName) remove(const std::string& databaseName, const std::string& recordName)
{ {
/* uint32_t id = getDatabaseId(databaseName);
uint32_t id; if (id == 0) {
ResponseCode::type rc = getDatabaseId(databaseName, id); return sherpa::ResponseCode::DatabaseNotFound;
if (rc != sherpa::ResponseCode::Ok) {
return rc;
} }
insertDatabaseId(const_cast<std::string&>(recordName), id); datatuple* oldRecordBody = get(id, recordName);
Bdb::ResponseCode dbrc = db_[id % numPartitions_]->remove(recordName); if (oldRecordBody == NULL) {
if (dbrc == Bdb::Ok) {
return sherpa::ResponseCode::Ok;
} else if (dbrc == Bdb::KeyNotFound) {
return sherpa::ResponseCode::RecordNotFound; return sherpa::ResponseCode::RecordNotFound;
} else {
} }
*/ datatuple::freetuple(oldRecordBody);
return sherpa::ResponseCode::Error; datatuple* tup = buildTuple(id, recordName);
return insert(tup);
} }
/* /*

View file

@ -103,6 +103,12 @@ int main(int argc, char **argv) {
client.get(getResponse, db, "new key"); client.get(getResponse, db, "new key");
cout << getResponse.responseCode << endl; cout << getResponse.responseCode << endl;
cout << getResponse.value << endl; cout << getResponse.value << endl;
cout << client.remove(db1, "new key") << endl;
client.get(getResponse, db1, "new key");
cout << getResponse.responseCode << endl;
cout << client.remove(db1, "new key") << endl;
return 0; return 0;
/* /*