void IndexCursor::_prelockBounds() { BufBuilder startKeyBuilder(512); BufBuilder endKeyBuilder(512); const vector<FieldRange> &ranges = _bounds->ranges(); const int n = ranges.size(); dassert( n == _idx.keyPattern().nFields() ); if ( n == 1 ) { // When there's only one field range, we can just prelock each interval. // Single field indexes are common so we handle this case manually for // performance (instead of using the recursive _prelockCompoundBounds()) BSONObjBuilder startKey(startKeyBuilder); BSONObjBuilder endKey(endKeyBuilder); const vector<FieldInterval> &intervals = ranges[0].intervals(); for ( vector<FieldInterval>::const_iterator i = intervals.begin(); i != intervals.end(); i++ ) { startKey.appendAs( i->_lower._bound, "" ); endKey.appendAs( i->_upper._bound, "" ); _prelockRange( startKey.done(), endKey.done() ); } } else { // When there's more than one field range, we need to prelock combinations // of intervals in the compound key space. verify( n > 1 ); vector<const FieldInterval *> combo; combo.reserve( n ); _prelockCompoundBounds( 0, combo, startKeyBuilder, endKeyBuilder ); } }
void IndexCursor::_prelockCompoundBounds(const int currentRange, vector<const FieldInterval *> &combo, BufBuilder &startKeyBuilder, BufBuilder &endKeyBuilder) { const vector<FieldRange> &ranges = _bounds->ranges(); if ( currentRange == (int) ranges.size() ) { startKeyBuilder.reset(512); endKeyBuilder.reset(512); BSONObjBuilder startKey(startKeyBuilder); BSONObjBuilder endKey(endKeyBuilder); for ( vector<const FieldInterval *>::const_iterator i = combo.begin(); i != combo.end(); i++ ) { startKey.appendAs( (*i)->_lower._bound, "" ); endKey.appendAs( (*i)->_upper._bound, "" ); } _prelockRange( startKey.done(), endKey.done() ); } else { const vector<FieldInterval> &intervals = ranges[currentRange].intervals(); for ( vector<FieldInterval>::const_iterator i = intervals.begin(); i != intervals.end(); i++ ) { const FieldInterval &interval = *i; combo.push_back( &interval ); _prelockCompoundBounds( currentRange + 1, combo, startKeyBuilder, endKeyBuilder ); combo.pop_back(); } } }
int Keyspace_DirtyListKeyValues(ClientObj client_, const std::string& prefix_, const std::string& startKey_, uint64_t count_, bool next_, bool forward_) { Keyspace::Client* client = (Keyspace::Client *) client_; ByteString prefix(prefix_.length(), prefix_.length(), prefix_.c_str()); ByteString startKey(startKey_.length(), startKey_.length(), startKey_.c_str()); return client->DirtyListKeyValues(prefix, startKey, count_, next_, forward_); }
TableCursor::TableCursor(Database &db , const TableCursorParam ¶m , const Tuple *beginKey, const Tuple *endKey) : m_db(db) { m_keyCursor = NULL; m_sequenceNo = param.m_sequenceNo; const TableInfo &tableInfo = m_db.getTableInfo(m_sequenceNo); m_indexOnly = param.m_indexOnly; int usedIndex = tableInfo.findIndexNo(param.m_indexName); if(usedIndex < 0) throwSqlError(SQL_NOINDEX,_T("Index %s doesn't exist for table %s"),param.m_indexName,tableInfo.getTableName().cstr()); KeyFileDefinition keydef = tableInfo.getKeyFileDefinition(usedIndex); if(!m_indexOnly) { m_fieldSet = param.m_fieldSet; } else { m_fieldSet = tableInfo.genFieldSet(usedIndex,param.m_fieldSet); } TableCursorKey startKey(keydef,beginKey,param.m_beginFieldCount, param.m_beginRelOp); TableCursorKey stopKey( keydef,endKey ,param.m_endFieldCount , param.m_endRelOp ); #ifdef DEBUGMODULE if(beginKey) { _tprintf(_T("starttup:")); beginKey->dump(); } if(endKey ) { _tprintf(_T("endKey :")); endKey->dump(); } _tprintf(_T("startKey (%d,%s):"),param.m_beginFieldCount,relOpString(param.m_beginRelOp)); startKey.dump(); _tprintf(_T("stopKey (%d,%s):"),param.m_endFieldCount ,relOpString(param.m_endRelOp )); stopKey.dump(); #endif if((startKey.m_relop == RELOP_FALSE) || (stopKey.m_relop == RELOP_FALSE)) return; KeyFile keyFile(m_db,tableInfo.getIndex(usedIndex).m_fileName,DBFMODE_READONLY,false); m_keyCursor = new KeyCursor(keyFile, startKey.m_relop, &startKey.m_key, startKey.m_fieldCount, stopKey.m_relop, &stopKey.m_key, stopKey.m_fieldCount, param.m_dir); }
int Keyspace_DirtyListKeyValuesStr(ClientObj client_, const std::string& prefix_, const std::string& startKey_, const std::string& count_, bool next_, bool forward_) { Keyspace::Client* client = (Keyspace::Client *) client_; ByteString prefix(prefix_.length(), prefix_.length(), prefix_.c_str()); ByteString startKey(startKey_.length(), startKey_.length(), startKey_.c_str()); unsigned read; uint64_t count; count = strntouint64(count_.c_str(), count_.length(), &read); if (read != count_.length()) return KEYSPACE_API_ERROR; return client->DirtyListKeyValues(prefix, startKey, count, next_, forward_); }
void JsonStreamingParser::parse(char c) { //System.out.print(c); // valid whitespace characters in JSON (from RFC4627 for JSON) include: // space, horizontal tab, line feed or new line, and carriage return. // thanks: // http://stackoverflow.com/questions/16042274/definition-of-whitespace-in-json if ((c == ' ' || c == '\t' || c == '\n' || c == '\r') && !(state == STATE_IN_STRING || state == STATE_UNICODE || state == STATE_START_ESCAPE || state == STATE_IN_NUMBER || state == STATE_DONE)) { return; } switch (state) { case STATE_IN_STRING: if (c == '"') { endString(); } else if (c == '\\') { state = STATE_START_ESCAPE; } else if ((c < 0x1f) || (c == 0x7f)) { //throw new RuntimeException("Unescaped control character encountered: " + c + " at position" + characterCounter); } else { buffer[bufferPos] = c; bufferPos++; } break; case STATE_IN_ARRAY: if (c == ']') { endArray(); } else { startValue(c); } break; case STATE_IN_OBJECT: if (c == '}') { endObject(); } else if (c == '"') { startKey(); } else { //throw new RuntimeException("Start of string expected for object key. Instead got: " + c + " at position" + characterCounter); } break; case STATE_END_KEY: if (c != ':') { //throw new RuntimeException("Expected ':' after key. Instead got " + c + " at position" + characterCounter); } state = STATE_AFTER_KEY; break; case STATE_AFTER_KEY: startValue(c); break; case STATE_START_ESCAPE: processEscapeCharacters(c); break; case STATE_UNICODE: processUnicodeCharacter(c); break; case STATE_UNICODE_SURROGATE: unicodeEscapeBuffer[unicodeEscapeBufferPos] = c; unicodeEscapeBufferPos++; if (unicodeEscapeBufferPos == 2) { endUnicodeSurrogateInterstitial(); } break; case STATE_AFTER_VALUE: { // not safe for size == 0!!! int within = stack[stackPos - 1]; if (within == STACK_OBJECT) { if (c == '}') { endObject(); } else if (c == ',') { state = STATE_IN_OBJECT; } else { //throw new RuntimeException("Expected ',' or '}' while parsing object. Got: " + c + ". " + characterCounter); } } else if (within == STACK_ARRAY) { if (c == ']') { endArray(); } else if (c == ',') { state = STATE_IN_ARRAY; } else { //throw new RuntimeException("Expected ',' or ']' while parsing array. Got: " + c + ". " + characterCounter); } } else { //throw new RuntimeException("Finished a literal, but unclear what state to move to. Last state: " + characterCounter); } }break; case STATE_IN_NUMBER: if (c >= '0' && c <= '9') { buffer[bufferPos] = c; bufferPos++; } else if (c == '.') { if (doesCharArrayContain(buffer, bufferPos, '.')) { //throw new RuntimeException("Cannot have multiple decimal points in a number. " + characterCounter); } else if (doesCharArrayContain(buffer, bufferPos, 'e')) { //throw new RuntimeException("Cannot have a decimal point in an exponent." + characterCounter); } buffer[bufferPos] = c; bufferPos++; } else if (c == 'e' || c == 'E') { if (doesCharArrayContain(buffer, bufferPos, 'e')) { //throw new RuntimeException("Cannot have multiple exponents in a number. " + characterCounter); } buffer[bufferPos] = c; bufferPos++; } else if (c == '+' || c == '-') { char last = buffer[bufferPos - 1]; if (!(last == 'e' || last == 'E')) { //throw new RuntimeException("Can only have '+' or '-' after the 'e' or 'E' in a number." + characterCounter); } buffer[bufferPos] = c; bufferPos++; } else { endNumber(); // we have consumed one beyond the end of the number parse(c); } break; case STATE_IN_TRUE: buffer[bufferPos] = c; bufferPos++; if (bufferPos == 4) { endTrue(); } break; case STATE_IN_FALSE: buffer[bufferPos] = c; bufferPos++; if (bufferPos == 5) { endFalse(); } break; case STATE_IN_NULL: buffer[bufferPos] = c; bufferPos++; if (bufferPos == 4) { endNull(); } break; case STATE_DONE: myListener->startDocument(); if (c == '[') { startArray(); } else if (c == '{') { startObject(); } else { // throw new ParsingError($this->_line_number, // $this->_char_number, // "Document must start with object or array."); } break; //case STATE_DONE: // throw new ParsingError($this->_line_number, $this->_char_number, // "Expected end of document."); //default: // throw new ParsingError($this->_line_number, $this->_char_number, // "Internal error. Reached an unknown state: ".$this->_state); } characterCounter++; }