Created
January 3, 2012 14:57
-
-
Save tinnefeld/1555231 to your computer and use it in GitHub Desktop.
ScanOperator in RAMCloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
MasterService::scan(const ScanRpc::Request& reqHdr, | |
ScanRpc::Response& respHdr, | |
Rpc& rpc) | |
{ | |
LOG(NOTICE, "Running scan operation on master service!"); | |
LOG(NOTICE, "Scan PARAMS: table=%i, column=%i, comaparator=%i, operand=%i", | |
(int)reqHdr.tableId, (int)reqHdr.id, (int)reqHdr.comparator, (int)reqHdr.operand); | |
getTable(reqHdr.tableId, reqHdr.id); | |
LogEntryHandle handle = objectMap.lookup(reqHdr.tableId, reqHdr.id); | |
if (handle == NULL || handle->type() != LOG_ENTRY_TYPE_OBJ) { | |
throw ObjectDoesntExistException(HERE); | |
} | |
const Object* obj = handle->userData<Object>(); | |
int64_t* data = (int64_t*)obj->data; | |
uint64_t length = obj->dataLength(handle->length()) / sizeof(int64_t); | |
std::vector<int64_t>* result = new std::vector<int64_t>(); | |
/*scan operation */ | |
for (uint64_t i = 0; i < length;i++) | |
{ | |
LOG(NOTICE, "SCAN: Checking %i at %i", (int)data[i], (int)i); | |
if((reqHdr.comparator == 0 && data[i] == reqHdr.operand) || | |
(reqHdr.comparator == -1 && data[i] <= reqHdr.operand) || | |
(reqHdr.comparator == -2 && data[i] < reqHdr.operand) || | |
(reqHdr.comparator == 1 && data[i] >= reqHdr.operand) || | |
(reqHdr.comparator == 2 && data[i] > reqHdr.operand)) | |
{ | |
LOG(NOTICE, "SCAN: Adding matching value %i at position %i to result.", (int)data[i], (int)i); | |
result->push_back(data[i]); | |
} | |
} | |
uint32_t resultLength = (uint32_t)result->size() * (uint32_t)sizeof(int64_t); | |
LOG(NOTICE, "SCAN: ResultLength: %i", (int)resultLength); | |
LOG(NOTICE, "SCAN: First Result Value: %i", (int)result->at(0)); | |
/*appending to buffer */ | |
Buffer::Chunk::appendToBuffer(&rpc.replyPayload, &(result->at(0)), resultLength); | |
int64_t check = 0; | |
rpc.replyPayload.copy(sizeof(ScanRpc::Response), sizeof(int64_t), &check); | |
LOG(NOTICE, "SCAN: Check First Value: %i", (int)check); | |
respHdr.length = resultLength; | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment