From 18b58aa484b7201a6317da92e10f1bfe5b97b279 Mon Sep 17 00:00:00 2001 From: sears Date: Mon, 9 Jan 2012 19:29:17 +0000 Subject: [PATCH] add missing methods to thrift server; temporary CMake fix git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@3535 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- CMakeLists.txt | 6 +-- sherpa/LSMServerHandler.cc | 78 +++++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00a21de..40da6b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ Project(Stasis) SET(PACKAGE_VERSION 1) -SUBDIRS(test util benchmarks) +SUBDIRS(test util benchmarks main) # Main decisions SET(BUILD_SHARED_LIBS ON) @@ -79,10 +79,8 @@ ELSE( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" ) ENDIF ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" ) #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) - IF ( HAVE_STASIS ) ADD_LIBRARY(logstore requestDispatch.cpp simpleServer.cpp logserver.cpp logstore.cpp diskTreeComponent.cpp memTreeComponent.cpp datapage.cpp merger.cpp tuplemerger.cpp mergeStats.cpp mergeManager.cpp bloomFilter.c) - CREATE_EXECUTABLE(server) - CREATE_EXECUTABLE(newserver) ENDIF ( HAVE_STASIS ) + ADD_LIBRARY(logstore_client tcpclient.cpp) diff --git a/sherpa/LSMServerHandler.cc b/sherpa/LSMServerHandler.cc index 21b54d1..ebdacba 100644 --- a/sherpa/LSMServerHandler.cc +++ b/sherpa/LSMServerHandler.cc @@ -38,6 +38,10 @@ LSMServerHandler(int argc, char **argv) stasis_buffer_manager_size = (1024LL * 1024LL * 1024LL * 2LL) / PAGE_SIZE; // 10GB total c0_size = 1024LL * 1024LL * 1024LL * 8LL; printf("note: running w/ 10GB of memory for benchmarking\n"); // XXX build a separate test server and deployment server? + } else if(!strcmp(argv[i], "--benchmark-small")) { + stasis_buffer_manager_size = (1024LL * 1024LL * 1024LL * 2LL) / PAGE_SIZE; // 5GB total + c0_size = 1024LL * 1024LL * 1024LL * 3LL; + printf("note: running w/ 5GB of memory for benchmarking on small box\n"); } else if(!strcmp(argv[i], "--log-mode")) { i++; log_mode = atoi(argv[i]); @@ -47,7 +51,7 @@ LSMServerHandler(int argc, char **argv) i++; expiry_delta = atoi(argv[i]); } else { - fprintf(stderr, "Usage: %s [--test|--benchmark] [--log-mode ] [--expiry-delta ]", argv[0]); + fprintf(stderr, "Usage: %s [--test|--benchmark|--benchmark-small] [--log-mode ] [--expiry-delta ]", argv[0]); abort(); } } @@ -162,30 +166,65 @@ addMap(const std::string& databaseName) return insert(tup); } -/** - * TODO: - * Don't just remove database from databaseIds. You need to delete - * all the records! - */ ResponseCode::type LSMServerHandler:: dropMap(const std::string& databaseName) { -#if 0 - Bdb::ResponseCode rc = databaseIds_.remove(databaseName); - if (rc == Bdb::KeyNotFound) { - return mapkeeper::ResponseCode::MapNotFound; - } else if (rc != Bdb::Success) { - return mapkeeper::ResponseCode::Error; - } else { - return mapkeeper::ResponseCode::Success; + uint32_t id = getDatabaseId(databaseName); + if(id == 0) { + return mapkeeper::ResponseCode::MapNotFound; + } + datatuple * tup = buildTuple(0, databaseName); + datatuple * exists = get(tup); + + if(exists) { + datatuple::freetuple(exists); + + datatuple * startKey = buildTuple(id, ""); + logtable::iterator * itr = new logtable::iterator(ltable_, startKey); + datatuple::freetuple(startKey); + datatuple * current; + + // insert tombstone; deletes metadata entry for map; frees tup + insert(tup); + + while(NULL != (current = itr->getnext())) { + if(*((uint32_t*)current->strippedkey()) != id) { + datatuple::freetuple(current); + break; + } + datatuple * del = datatuple::create(current->strippedkey(), current->strippedkeylen()); + ltable_->insertTuple(del); + datatuple::freetuple(del); + datatuple::freetuple(current); } -#endif - return mapkeeper::ResponseCode::Success; + delete itr; + return mapkeeper::ResponseCode::Success; + } else { + datatuple::freetuple(tup); + return mapkeeper::ResponseCode::MapNotFound; + } } void LSMServerHandler:: listMaps(StringListResponse& _return) { + datatuple * startKey = buildTuple(0, ""); + logtable::iterator * itr = new logtable::iterator(ltable_, startKey); + datatuple::freetuple(startKey); + datatuple * current; + while(NULL != (current = itr->getnext())) { + if(*((uint32_t*)current->strippedkey()) != 0) { + datatuple::freetuple(current); + break; + } + _return.values.push_back( + std::string((char*)(current->strippedkey()) + sizeof(uint32_t), + current->strippedkeylen() - sizeof(uint32_t))); + datatuple::freetuple(current); + } + delete itr; + + _return.responseCode = mapkeeper::ResponseCode::Success; } void LSMServerHandler:: @@ -308,7 +347,12 @@ put(const std::string& databaseName, const std::string& recordName, const std::string& recordBody) { - return mapkeeper::ResponseCode::Success; + uint32_t id = getDatabaseId(databaseName); + if (id == 0) { + return mapkeeper::ResponseCode::MapNotFound; + } + datatuple* tup = buildTuple(id, recordName, recordBody); + return insert(tup); } ResponseCode::type LSMServerHandler::