1
0
Fork 0

some mini-modifications for slightly higher throughput

This commit is contained in:
Jan Steemann 2013-02-19 09:54:36 +01:00
parent 19d90b8899
commit 4f37fada0d
11 changed files with 85 additions and 70 deletions

View File

@ -336,7 +336,7 @@ bool RestDocumentHandler::createDocument () {
////////////////////////////////////////////////////////////////////////////////
bool RestDocumentHandler::readDocument () {
size_t len = _request->suffix().size();
const size_t len = _request->suffix().size();
switch (len) {
case 0:
@ -403,10 +403,6 @@ bool RestDocumentHandler::readDocument () {
bool RestDocumentHandler::readSingleDocument (bool generateBody) {
vector<string> const& suffix = _request->suffix();
/// check for an etag
TRI_voc_rid_t ifNoneRid = extractRevision("if-none-match", 0);
TRI_voc_rid_t ifRid = extractRevision("if-match", "rev");
// split the document reference
const string& collection = suffix[0];
const string& key = suffix[1];
@ -451,7 +447,10 @@ bool RestDocumentHandler::readSingleDocument (bool generateBody) {
assert(document);
assert(document->_key);
TRI_voc_rid_t rid = document->_rid;
const TRI_voc_rid_t rid = document->_rid;
// check for an etag
const TRI_voc_rid_t ifNoneRid = extractRevision("if-none-match", 0);
const TRI_voc_rid_t ifRid = extractRevision("if-match", "rev");
if (ifNoneRid == 0) {
if (ifRid == 0 || ifRid == rid) {
@ -772,10 +771,11 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) {
}
// extract the revision
TRI_voc_rid_t revision = extractRevision("if-match", "rev");
const TRI_voc_rid_t revision = extractRevision("if-match", "rev");
// extract or chose the update policy
TRI_doc_update_policy_e policy = extractUpdatePolicy();
const TRI_doc_update_policy_e policy = extractUpdatePolicy();
const bool waitForSync = extractWaitForSync();
TRI_doc_mptr_t* document = 0;
@ -839,13 +839,13 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) {
if (holder.registerJson(TRI_UNKNOWN_MEM_ZONE, patchedJson)) {
// do not acquire an extra lock
res = trx.updateDocument(key, &document, patchedJson, policy, extractWaitForSync(), revision, &rid, false);
res = trx.updateDocument(key, &document, patchedJson, policy, waitForSync, revision, &rid, false);
}
}
}
else {
// replacing an existing document, using a lock
res = trx.updateDocument(key, &document, json, policy, extractWaitForSync(), revision, &rid, true);
res = trx.updateDocument(key, &document, json, policy, waitForSync, revision, &rid, true);
}
res = trx.finish(res);
@ -934,10 +934,11 @@ bool RestDocumentHandler::deleteDocument () {
const string& key = suffix[1];
// extract the revision
TRI_voc_rid_t revision = extractRevision("if-match", "rev");
const TRI_voc_rid_t revision = extractRevision("if-match", "rev");
// extract or choose the update policy
TRI_doc_update_policy_e policy = extractUpdatePolicy();
const TRI_doc_update_policy_e policy = extractUpdatePolicy();
const bool waitForSync = extractWaitForSync();
if (policy == TRI_DOC_UPDATE_ILLEGAL) {
generateError(HttpResponse::BAD,
@ -961,7 +962,7 @@ bool RestDocumentHandler::deleteDocument () {
const TRI_voc_cid_t cid = trx.cid();
TRI_voc_rid_t rid = 0;
res = trx.deleteDocument(key, policy, extractWaitForSync(), revision, &rid);
res = trx.deleteDocument(key, policy, waitForSync, revision, &rid);
if (res == TRI_ERROR_NO_ERROR) {
res = trx.commit();
}

View File

@ -207,9 +207,9 @@ void RestVocbaseBaseHandler::generate20x (const HttpResponse::HttpResponseCode r
if (responseCode != HttpResponse::OK) {
// 200 OK is sent is case of delete or update.
// in these cases we do not return etag nor location
_response->setHeader("ETag", "\"" + rev + "\"");
_response->setHeader("etag", 4, "\"" + rev + "\"");
// handle does not need to be RFC 2047-encoded
_response->setHeader("location", DOCUMENT_PATH + "/" + handle);
_response->setHeader("location", 8, DOCUMENT_PATH + "/" + handle);
}
// _id and _key are safe and do not need to be JSON-encoded
@ -297,7 +297,7 @@ void RestVocbaseBaseHandler::generateNotModified (const TRI_voc_rid_t rid) {
const string rev = StringUtils::itoa(rid);
_response = createResponse(HttpResponse::NOT_MODIFIED);
_response->setHeader("ETag", "\"" + rev + "\"");
_response->setHeader("etag", 4, "\"" + rev + "\"");
}
////////////////////////////////////////////////////////////////////////////////
@ -315,13 +315,10 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
return;
}
// add document identifier to buffer
TRI_string_buffer_t buffer;
string id = DocumentHelper::assembleDocumentId(_resolver.getCollectionName(cid), document->_key);
const string id = DocumentHelper::assembleDocumentId(_resolver.getCollectionName(cid), document->_key);
TRI_json_t augmented;
TRI_InitArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented);
TRI_Init2ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, 8);
TRI_json_t* _id = TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, id.c_str());
@ -330,7 +327,7 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
}
// convert rid from uint64_t to string
string rid = StringUtils::itoa(document->_rid);
const string rid = StringUtils::itoa(document->_rid);
TRI_json_t* _rev = TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, rid.c_str(), rid.size());
if (_rev) {
@ -354,6 +351,9 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, "_to", TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, to.c_str()));
}
// add document identifier to buffer
TRI_string_buffer_t buffer;
// convert object to string
TRI_InitStringBuffer(&buffer, TRI_UNKNOWN_MEM_ZONE);
@ -378,7 +378,7 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
// and generate a response
_response = createResponse(HttpResponse::OK);
_response->setContentType("application/json; charset=utf-8");
_response->setHeader("ETag", "\"" + StringUtils::itoa(document->_rid) + "\"");
_response->setHeader("etag", 4, "\"" + rid + "\"");
if (generateBody) {
_response->body().appendText(TRI_BeginStringBuffer(&buffer), TRI_LengthStringBuffer(&buffer));
@ -447,7 +447,8 @@ void RestVocbaseBaseHandler::generateTransactionError (const string& collectionN
/// @brief extracts the revision
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t RestVocbaseBaseHandler::extractRevision (char const* header, char const* parameter) {
TRI_voc_rid_t RestVocbaseBaseHandler::extractRevision (char const* header,
char const* parameter) {
bool found;
char const* etag = _request->header(header, found);

View File

@ -292,7 +292,7 @@ namespace triagens {
/// @note @FA{header} must be lowercase.
////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t extractRevision (char const* header, char const* parameter);
TRI_voc_rid_t extractRevision (char const*, char const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief extracts the update policy

View File

@ -101,10 +101,12 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
const TRI_vocbase_col_t* getCollectionStruct (const string& name) const {
map<string, const TRI_vocbase_col_t*>::iterator it = _resolvedNames.find(name);
if (it != _resolvedNames.end()) {
return (*it).second;
if (_resolvedNames.size() > 0) {
map<string, const TRI_vocbase_col_t*>::const_iterator it = _resolvedNames.find(name);
if (it != _resolvedNames.end()) {
return (*it).second;
}
}
const TRI_vocbase_col_t* collection = TRI_LookupCollectionByNameVocBase(_vocbase, name.c_str());
@ -120,11 +122,13 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
string getCollectionName (const TRI_voc_cid_t cid) const {
map<TRI_voc_cid_t, string>::iterator it = _resolvedIds.find(cid);
if (_resolvedIds.size() > 0) {
map<TRI_voc_cid_t, string>::const_iterator it = _resolvedIds.find(cid);
if (it != _resolvedIds.end()) {
return (*it).second;
}
if (it != _resolvedIds.end()) {
return (*it).second;
}
}
char* n = TRI_GetCollectionNameByIdVocBase(_vocbase, cid);
if (n == 0) {

View File

@ -120,7 +120,7 @@ namespace triagens {
/// @brief get the underlying collection's id
////////////////////////////////////////////////////////////////////////////////
inline TRI_voc_cid_t cid () {
inline TRI_voc_cid_t cid () const {
return this->_cid;
}

View File

@ -452,6 +452,17 @@ void TRI_InitArrayJson (TRI_memory_zone_t* zone, TRI_json_t* result) {
TRI_InitVector(&result->_value._objects, zone, sizeof(TRI_json_t));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises an array, using a specific initial size
////////////////////////////////////////////////////////////////////////////////
void TRI_Init2ArrayJson (TRI_memory_zone_t* zone,
TRI_json_t* result,
size_t initialSize) {
result->_type = TRI_JSON_ARRAY;
TRI_InitVector2(&result->_value._objects, zone, sizeof(TRI_json_t), initialSize);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a json object, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////

View File

@ -173,6 +173,12 @@ TRI_json_t* TRI_CreateArrayJson (TRI_memory_zone_t*);
void TRI_InitArrayJson (TRI_memory_zone_t*, TRI_json_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises an array, using a specific initial size
////////////////////////////////////////////////////////////////////////////////
void TRI_Init2ArrayJson (TRI_memory_zone_t*, TRI_json_t*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a json object, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////

View File

@ -71,7 +71,6 @@ void TRI_InitVector (TRI_vector_t* vector, TRI_memory_zone_t* zone, size_t eleme
vector->_buffer = NULL;
vector->_length = 0;
vector->_capacity = 0;
vector->_growthFactor = GROW_FACTOR;
}
////////////////////////////////////////////////////////////////////////////////
@ -81,15 +80,10 @@ void TRI_InitVector (TRI_vector_t* vector, TRI_memory_zone_t* zone, size_t eleme
int TRI_InitVector2 (TRI_vector_t* vector,
TRI_memory_zone_t* zone,
size_t elementSize,
size_t initialCapacity,
double growthFactor) {
size_t initialCapacity) {
// init vector as usual
TRI_InitVector(vector, zone, elementSize);
if (growthFactor > 1.0) {
vector->_growthFactor = growthFactor;
}
if (initialCapacity != 0) {
vector->_buffer = (char*) TRI_Allocate(vector->_memoryZone, (initialCapacity * vector->_elementSize), false);
if (vector->_buffer == NULL) {
@ -252,7 +246,7 @@ int TRI_ResizeVector (TRI_vector_t* vector, size_t n) {
int TRI_PushBackVector (TRI_vector_t* vector, void const* element) {
if (vector->_length == vector->_capacity) {
char* newBuffer;
size_t newSize = (size_t) (1 + (vector->_growthFactor * vector->_capacity));
size_t newSize = (size_t) (1 + (GROW_FACTOR * vector->_capacity));
newBuffer = (char*) TRI_Reallocate(vector->_memoryZone, vector->_buffer, newSize * vector->_elementSize);
@ -312,7 +306,7 @@ void TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t positio
// ...........................................................................
if (vector->_length >= vector->_capacity || position >= vector->_length) {
size_t newSize = (size_t) (1 + (vector->_growthFactor * vector->_capacity));
size_t newSize = (size_t) (1 + (GROW_FACTOR * vector->_capacity));
if (position >= newSize) {
newSize = position + 1;

View File

@ -57,7 +57,6 @@ typedef struct TRI_vector_s {
char * _buffer;
size_t _length;
size_t _capacity;
double _growthFactor;
}
TRI_vector_t;
@ -87,8 +86,7 @@ void TRI_InitVector (TRI_vector_t*, TRI_memory_zone_t*, size_t elementSize);
int TRI_InitVector2 (TRI_vector_t*,
TRI_memory_zone_t*,
size_t elementSize,
size_t initialCapacity,
double growthFactor);
size_t initialCapacity);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a vector, but does not free the pointer

View File

@ -89,7 +89,6 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@ -213,11 +212,6 @@ typedef void* yyscan_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
@ -240,6 +234,11 @@ typedef size_t yy_size_t;
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
@ -257,7 +256,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
yy_size_t yy_n_chars;
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
@ -336,7 +335,7 @@ static void tri_jsp__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscann
YY_BUFFER_STATE tri_jsp__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE tri_jsp__scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
YY_BUFFER_STATE tri_jsp__scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
YY_BUFFER_STATE tri_jsp__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
void *tri_jsp_alloc (yy_size_t ,yyscan_t yyscanner );
void *tri_jsp_realloc (void *,yy_size_t ,yyscan_t yyscanner );
@ -387,7 +386,7 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*/
#define YY_DO_BEFORE_ACTION \
yyg->yytext_ptr = yy_bp; \
yyleng = (yy_size_t) (yy_cp - yy_bp); \
yyleng = (size_t) (yy_cp - yy_bp); \
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
@ -534,8 +533,8 @@ static yyconst flex_int16_t yy_chk[152] =
#define STRING_CONSTANT_ASCII 13
struct jsonData {
char const* _message;
TRI_memory_zone_t* _memoryZone;
char const* _message;
};
#define YY_FATAL_ERROR(a) \
@ -566,8 +565,8 @@ struct yyguts_t
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
yy_size_t yy_n_chars;
yy_size_t yyleng_r;
int yy_n_chars;
int yyleng_r;
char *yy_c_buf_p;
int yy_init;
int yy_start;
@ -614,7 +613,7 @@ FILE *tri_jsp_get_out (yyscan_t yyscanner );
void tri_jsp_set_out (FILE * out_str ,yyscan_t yyscanner );
yy_size_t tri_jsp_get_leng (yyscan_t yyscanner );
int tri_jsp_get_leng (yyscan_t yyscanner );
char *tri_jsp_get_text (yyscan_t yyscanner );
@ -673,7 +672,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
yy_size_t n; \
int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@ -1129,7 +1128,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{
yy_size_t num_to_read =
int num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
@ -1143,7 +1142,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( b->yy_is_our_buffer )
{
yy_size_t new_size = b->yy_buf_size * 2;
int new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
@ -1174,7 +1173,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
yyg->yy_n_chars, num_to_read );
yyg->yy_n_chars, (int) num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
}
@ -1299,7 +1298,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@ -1323,7 +1322,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
case EOB_ACT_END_OF_FILE:
{
if ( tri_jsp_wrap(yyscanner ) )
return 0;
return EOF;
if ( ! yyg->yy_did_buffer_switch_on_eof )
YY_NEW_FILE;
@ -1585,7 +1584,7 @@ void tri_jsp_pop_buffer_state (yyscan_t yyscanner)
*/
static void tri_jsp_ensure_buffer_stack (yyscan_t yyscanner)
{
yy_size_t num_to_alloc;
int num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@ -1683,11 +1682,12 @@ YY_BUFFER_STATE tri_jsp__scan_string (yyconst char * yystr , yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE tri_jsp__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
YY_BUFFER_STATE tri_jsp__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n, i;
yy_size_t n;
int i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
@ -1797,7 +1797,7 @@ FILE *tri_jsp_get_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
yy_size_t tri_jsp_get_leng (yyscan_t yyscanner)
int tri_jsp_get_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;

View File

@ -70,8 +70,8 @@ PLUS [+]
#define STRING_CONSTANT_ASCII 13
struct jsonData {
char const* _message;
TRI_memory_zone_t* _memoryZone;
char const* _message;
};
#define YY_FATAL_ERROR(a) \