1
0
Fork 0

moved attribute names to defines

This commit is contained in:
Jan Steemann 2013-07-05 14:41:23 +02:00
parent ebb121b44a
commit d79d95a3a7
15 changed files with 88 additions and 43 deletions

View File

@ -346,14 +346,14 @@ TRI_aql_index_t* TRI_DetermineIndexAql (TRI_aql_context_t* const context,
if (idx->_type == TRI_IDX_TYPE_PRIMARY_INDEX) {
// primary index key names must be treated differently. _id and _key are the same
if (! TRI_EqualString("_id", fieldName) && ! TRI_EqualString("_key", fieldName)) {
if (! TRI_EqualString("_id", fieldName) && ! TRI_EqualString(TRI_VOC_ATTRIBUTE_KEY, fieldName)) {
continue;
}
}
else if (idx->_type == TRI_IDX_TYPE_EDGE_INDEX) {
// edge index key names must be treated differently. _from and _to can be used independently
if (! TRI_EqualString("_from", fieldName) &&
! TRI_EqualString("_to", fieldName)) {
if (! TRI_EqualString(TRI_VOC_ATTRIBUTE_FROM, fieldName) &&
! TRI_EqualString(TRI_VOC_ATTRIBUTE_TO, fieldName)) {
continue;
}
}

View File

@ -238,6 +238,7 @@ int ReplicationFetcher::applyMarker (TRI_transaction_collection_t* trxCollection
if (res == TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND) {
// insert
const TRI_voc_rid_t rid = StringUtils::uint64(JsonHelper::getStringValue(json, TRI_VOC_ATTRIBUTE_REV, ""));
if (type[7] == 'e') {
// edge
@ -248,8 +249,9 @@ int ReplicationFetcher::applyMarker (TRI_transaction_collection_t* trxCollection
res = TRI_ERROR_NO_ERROR;
}
string from = JsonHelper::getStringValue(json, "_from", "");
string to = JsonHelper::getStringValue(json, "_to", "");
string from = JsonHelper::getStringValue(json, TRI_VOC_ATTRIBUTE_FROM, "");
string to = JsonHelper::getStringValue(json, TRI_VOC_ATTRIBUTE_TO, "");
// parse _from
TRI_document_edge_t edge;
@ -263,7 +265,7 @@ int ReplicationFetcher::applyMarker (TRI_transaction_collection_t* trxCollection
}
if (res == TRI_ERROR_NO_ERROR) {
res = primary->insert(trxCollection, key, &mptr, TRI_DOC_MARKER_KEY_EDGE, shaped, &edge, false, false);
res = primary->insert(trxCollection, key, rid, &mptr, TRI_DOC_MARKER_KEY_EDGE, shaped, &edge, false, false);
}
}
else {
@ -272,7 +274,7 @@ int ReplicationFetcher::applyMarker (TRI_transaction_collection_t* trxCollection
res = TRI_ERROR_ARANGO_COLLECTION_TYPE_INVALID;
}
else {
res = primary->insert(trxCollection, key, &mptr, TRI_DOC_MARKER_KEY_DOCUMENT, shaped, 0, false, false);
res = primary->insert(trxCollection, key, rid, &mptr, TRI_DOC_MARKER_KEY_DOCUMENT, shaped, 0, false, false);
}
}
}

View File

@ -275,7 +275,7 @@ bool RestImportHandler::createByDocumentsLines () {
TRI_doc_mptr_t document;
if (isEdgeCollection) {
const char* from = extractJsonStringValue(values, "_from");
const char* from = extractJsonStringValue(values, TRI_VOC_ATTRIBUTE_FROM);
if (from == 0) {
LOGGER_WARNING("missing '_from' attribute at position " << i);
@ -284,7 +284,7 @@ bool RestImportHandler::createByDocumentsLines () {
continue;
}
const char* to = extractJsonStringValue(values, "_to");
const char* to = extractJsonStringValue(values, TRI_VOC_ATTRIBUTE_TO);
if (to == 0) {
LOGGER_WARNING("missing '_to' attribute at position " << i);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, values);
@ -454,7 +454,7 @@ bool RestImportHandler::createByDocumentsList () {
TRI_doc_mptr_t document;
if (isEdgeCollection) {
const char* from = extractJsonStringValue(values, "_from");
const char* from = extractJsonStringValue(values, TRI_VOC_ATTRIBUTE_FROM);
if (from == 0) {
LOGGER_WARNING("missing '_from' attribute at position " << (i + 1));
@ -462,7 +462,7 @@ bool RestImportHandler::createByDocumentsList () {
continue;
}
const char* to = extractJsonStringValue(values, "_to");
const char* to = extractJsonStringValue(values, TRI_VOC_ATTRIBUTE_TO);
if (to == 0) {
LOGGER_WARNING("missing '_to' attribute at position " << (i + 1));
++numError;
@ -696,7 +696,7 @@ bool RestImportHandler::createByKeyValueList () {
TRI_doc_mptr_t document;
if (isEdgeCollection) {
const char* from = extractJsonStringValue(json, "_from");
const char* from = extractJsonStringValue(json, TRI_VOC_ATTRIBUTE_FROM);
if (from == 0) {
LOGGER_WARNING("missing '_from' attribute at line " << lineNumber);
@ -705,7 +705,7 @@ bool RestImportHandler::createByKeyValueList () {
continue;
}
const char* to = extractJsonStringValue(json, "_to");
const char* to = extractJsonStringValue(json, TRI_VOC_ATTRIBUTE_TO);
if (to == 0) {
LOGGER_WARNING("missing '_to' attribute at line " << lineNumber);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);

View File

@ -234,9 +234,9 @@ void RestVocbaseBaseHandler::generate20x (const HttpResponse::HttpResponseCode r
_response->body()
.appendText("{\"error\":false,\"_id\":\"")
.appendText(handle)
.appendText("\",\"_rev\":\"")
.appendText("\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"")
.appendText(rev)
.appendText("\",\"_key\":\"")
.appendText("\",\"" TRI_VOC_ATTRIBUTE_KEY "\":\"")
.appendText(key)
.appendText("\"}");
}
@ -292,9 +292,9 @@ void RestVocbaseBaseHandler::generatePreconditionFailed (const TRI_voc_cid_t cid
.appendText(",\"errorMessage\":\"precondition failed\"")
.appendText(",\"_id\":\"")
.appendText(DocumentHelper::assembleDocumentId(_resolver.getCollectionName(cid), key))
.appendText("\",\"_rev\":\"")
.appendText("\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"")
.appendText(StringUtils::itoa(rid))
.appendText("\",\"_key\":\"")
.appendText("\",\"" TRI_VOC_ATTRIBUTE_KEY "\":\"")
.appendText(key)
.appendText("\"}");
}
@ -341,13 +341,13 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
TRI_json_t* _rev = TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, rid.c_str(), rid.size());
if (_rev) {
TRI_Insert2ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, "_rev", _rev);
TRI_Insert2ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, TRI_VOC_ATTRIBUTE_REV, _rev);
}
TRI_json_t* _key = TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, document->_key, strlen(document->_key));
if (_key) {
TRI_Insert2ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, "_key", _key);
TRI_Insert2ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, TRI_VOC_ATTRIBUTE_KEY, _key);
}
TRI_df_marker_type_t type = ((TRI_df_marker_t*) document->_data)->_type;
@ -357,8 +357,8 @@ void RestVocbaseBaseHandler::generateDocument (const TRI_voc_cid_t cid,
const string from = DocumentHelper::assembleDocumentId(_resolver.getCollectionName(marker->_fromCid), string((char*) marker + marker->_offsetFromKey));
const string to = DocumentHelper::assembleDocumentId(_resolver.getCollectionName(marker->_toCid), string((char*) marker + marker->_offsetToKey));
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, "_from", TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, from.c_str(), from.size()));
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, "_to", TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, to.c_str(), to.size()));
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, TRI_VOC_ATTRIBUTE_FROM, TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, from.c_str(), from.size()));
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, &augmented, TRI_VOC_ATTRIBUTE_TO, TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, to.c_str(), to.size()));
}
// add document identifier to buffer

View File

@ -136,7 +136,7 @@ int DocumentHelper::getKey (TRI_json_t const* json,
}
// check _key is there
const TRI_json_t* k = TRI_LookupArrayJson((TRI_json_t*) json, "_key");
const TRI_json_t* k = TRI_LookupArrayJson((TRI_json_t*) json, TRI_VOC_ATTRIBUTE_KEY);
if (k == 0) {
return TRI_ERROR_NO_ERROR;

View File

@ -175,7 +175,7 @@ namespace triagens {
return TRI_ERROR_TRANSACTION_INTERNAL;
}
return this->create(this->trxCollection(), TRI_DOC_MARKER_KEY_DOCUMENT, key, mptr, shaped, 0, forceSync);
return this->create(this->trxCollection(), key, 0, TRI_DOC_MARKER_KEY_DOCUMENT, mptr, shaped, 0, forceSync);
}
////////////////////////////////////////////////////////////////////////////////
@ -191,7 +191,7 @@ namespace triagens {
return TRI_ERROR_TRANSACTION_INTERNAL;
}
return this->create(this->trxCollection(), TRI_DOC_MARKER_KEY_EDGE, key, mptr, shaped, data, forceSync);
return this->create(this->trxCollection(), key, 0, TRI_DOC_MARKER_KEY_EDGE, mptr, shaped, data, forceSync);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -719,8 +719,9 @@ namespace triagens {
}
res = create(trxCollection,
markerType,
key,
0,
markerType,
mptr,
shaped,
data,
@ -736,8 +737,9 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
inline int create (TRI_transaction_collection_t* trxCollection,
const TRI_df_marker_type_e markerType,
const TRI_voc_key_t key,
TRI_voc_rid_t rid,
const TRI_df_marker_type_e markerType,
TRI_doc_mptr_t* mptr,
TRI_shaped_json_t const* shaped,
void const* data,
@ -747,6 +749,7 @@ namespace triagens {
int res = primary->insert(trxCollection,
key,
rid,
mptr,
markerType,
shaped,

View File

@ -7479,7 +7479,7 @@ static v8::Handle<v8::Integer> PropertyQueryShapedJson (v8::Local<v8::String> na
}
if (key[0] == '_') {
if (key == "_id" || key == "_rev" || key == "_key") {
if (key == "_id" || key == TRI_VOC_ATTRIBUTE_REV || key == TRI_VOC_ATTRIBUTE_KEY) {
return scope.Close(v8::Handle<v8::Integer>(v8::Integer::New(v8::ReadOnly)));
}
}

View File

@ -1227,6 +1227,7 @@ int TRI_WriteElementDatafile (TRI_datafile_t* datafile,
if (datafile->_tickMin == 0) {
datafile->_tickMin = tick;
}
datafile->_tickMax = tick;
assert(markerSize > 0);

View File

@ -396,6 +396,7 @@ static int CloneDocumentMarker (TRI_voc_tid_t tid,
static int CreateDocumentMarker (TRI_primary_collection_t* primary,
TRI_voc_tid_t tid,
TRI_voc_tick_t tick,
TRI_doc_document_key_marker_t** result,
TRI_voc_size_t* totalSize,
char** keyBody,
@ -408,7 +409,6 @@ static int CreateDocumentMarker (TRI_primary_collection_t* primary,
char* position;
char keyBuffer[TRI_VOC_KEY_MAX_LENGTH + 1];
TRI_voc_size_t keyBodySize;
TRI_voc_tick_t tick;
size_t markerSize;
size_t keySize;
size_t fromSize;
@ -416,7 +416,10 @@ static int CreateDocumentMarker (TRI_primary_collection_t* primary,
int res;
*result = NULL;
tick = TRI_NewTickVocBase();
if (tick == 0) {
tick = TRI_NewTickVocBase();
}
// generate the key
keyGenerator = (TRI_key_generator_t*) primary->_keyGenerator;
@ -1477,6 +1480,7 @@ static int NotifyTransaction (TRI_primary_collection_t* primary,
static int InsertShapedJson (TRI_transaction_collection_t* trxCollection,
const TRI_voc_key_t key,
TRI_voc_rid_t rid,
TRI_doc_mptr_t* mptr,
TRI_df_marker_type_e markerType,
TRI_shaped_json_t const* shaped,
@ -1502,7 +1506,8 @@ static int InsertShapedJson (TRI_transaction_collection_t* trxCollection,
// this does not require any locks
res = CreateDocumentMarker(primary,
TRI_GetMarkerIdTransaction(trxCollection->_transaction),
TRI_GetMarkerIdTransaction(trxCollection->_transaction),
(TRI_voc_tick_t) rid,
&marker,
&totalSize,
&keyBody,

View File

@ -746,8 +746,8 @@ static TRI_json_t* JsonEdge (TRI_index_t* idx, TRI_primary_collection_t const* p
json = TRI_JsonIndex(TRI_CORE_MEM_ZONE, idx);
fields = TRI_CreateListJson(TRI_CORE_MEM_ZONE);
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, "_from"));
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, "_to"));
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, TRI_VOC_ATTRIBUTE_FROM));
TRI_PushBack3ListJson(TRI_CORE_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, TRI_VOC_ATTRIBUTE_TO));
TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "fields", fields);
return json;
@ -800,7 +800,7 @@ TRI_index_t* TRI_CreateEdgeIndex (struct TRI_primary_collection_s* primary) {
idx = &edgeIndex->base;
TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);
id = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, "_from");
id = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, TRI_VOC_ATTRIBUTE_FROM);
TRI_PushBackVectorString(&idx->_fields, id);
idx->typeName = TypeNameEdge;

View File

@ -317,7 +317,7 @@ typedef struct TRI_primary_collection_s {
#endif
int (*notifyTransaction) (struct TRI_primary_collection_s*, TRI_transaction_status_e);
int (*insert) (struct TRI_transaction_collection_s*, const TRI_voc_key_t, TRI_doc_mptr_t*, TRI_df_marker_type_e, TRI_shaped_json_t const*, void const*, const bool, const bool);
int (*insert) (struct TRI_transaction_collection_s*, const TRI_voc_key_t, TRI_voc_rid_t, TRI_doc_mptr_t*, TRI_df_marker_type_e, TRI_shaped_json_t const*, void const*, const bool, const bool);
int (*read) (struct TRI_transaction_collection_s*, const TRI_voc_key_t, TRI_doc_mptr_t*, const bool);

View File

@ -365,6 +365,7 @@ static int LogEvent (TRI_replication_logger_t* logger,
res = primary->insert(logger->_trxCollection,
NULL,
0,
&mptr,
TRI_DOC_MARKER_KEY_DOCUMENT,
shaped,
@ -631,9 +632,9 @@ static bool StringifyDocumentOperation (TRI_string_buffer_t* buffer,
APPEND_STRING(buffer, "\",\"doc\":{");
// common document meta-data
APPEND_STRING(buffer, "\"_key\":\"");
APPEND_STRING(buffer, "\"" TRI_VOC_ATTRIBUTE_KEY "\":\"");
APPEND_STRING(buffer, key);
APPEND_STRING(buffer, "\",\"_rev\":\"");
APPEND_STRING(buffer, "\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"");
APPEND_UINT64(buffer, (uint64_t) rid);
APPEND_CHAR(buffer, '"');
@ -642,11 +643,11 @@ static bool StringifyDocumentOperation (TRI_string_buffer_t* buffer,
TRI_voc_key_t fromKey = ((char*) e) + e->_offsetFromKey;
TRI_voc_key_t toKey = ((char*) e) + e->_offsetToKey;
APPEND_STRING(buffer, ",\"_from\":\"");
APPEND_STRING(buffer, ",\"" TRI_VOC_ATTRIBUTE_FROM "\":\"");
APPEND_UINT64(buffer, (uint64_t) e->_fromCid);
APPEND_CHAR(buffer, '/');
APPEND_STRING(buffer, fromKey);
APPEND_STRING(buffer, "\",\"_to\":\"");
APPEND_STRING(buffer, "\",\"" TRI_VOC_ATTRIBUTE_TO "\":\"");
APPEND_UINT64(buffer, (uint64_t) e->_toCid);
APPEND_CHAR(buffer, '/');
APPEND_STRING(buffer, toKey);
@ -767,9 +768,9 @@ static bool StringifyMarkerReplication (TRI_string_buffer_t* buffer,
APPEND_STRING(buffer, "\",\"doc\":{");
// common document meta-data
APPEND_STRING(buffer, "\"_key\":\"");
APPEND_STRING(buffer, "\"" TRI_VOC_ATTRIBUTE_KEY "\":\"");
APPEND_STRING(buffer, key);
APPEND_STRING(buffer, "\",\"_rev\":\"");
APPEND_STRING(buffer, "\",\"" TRI_VOC_ATTRIBUTE_REV "\":\"");
APPEND_UINT64(buffer, (uint64_t) rid);
APPEND_CHAR(buffer, '"');
@ -778,11 +779,11 @@ static bool StringifyMarkerReplication (TRI_string_buffer_t* buffer,
TRI_voc_key_t fromKey = ((char*) e) + e->_offsetFromKey;
TRI_voc_key_t toKey = ((char*) e) + e->_offsetToKey;
APPEND_STRING(buffer, ",\"_from\":\"");
APPEND_STRING(buffer, ",\"" TRI_VOC_ATTRIBUTE_FROM "\":\"");
APPEND_UINT64(buffer, (uint64_t) e->_fromCid);
APPEND_CHAR(buffer, '/');
APPEND_STRING(buffer, fromKey);
APPEND_STRING(buffer, "\",\"_to\":\"");
APPEND_STRING(buffer, "\",\"" TRI_VOC_ATTRIBUTE_TO "\":\"");
APPEND_UINT64(buffer, (uint64_t) e->_toCid);
APPEND_CHAR(buffer, '/');
APPEND_STRING(buffer, toKey);

View File

@ -725,7 +725,16 @@ static int InsertTrxCallback (TRI_transaction_collection_t* trxCollection,
return TRI_ERROR_OUT_OF_MEMORY;
}
res = primary->insert(trxCollection, coordinator->_key, &coordinator->_mptr, TRI_DOC_MARKER_KEY_DOCUMENT, shaped, NULL, false, false);
res = primary->insert(trxCollection,
coordinator->_key,
0,
&coordinator->_mptr,
TRI_DOC_MARKER_KEY_DOCUMENT,
shaped,
NULL,
false,
false);
TRI_FreeShapedJson(primary->_shaper, shaped);
return res;

View File

@ -189,6 +189,30 @@ struct TRI_transaction_context_s;
extern size_t PageSize;
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _from attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_FROM "_from"
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _to attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_TO "_to"
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _key attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_KEY "_key"
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the _rev attribute
////////////////////////////////////////////////////////////////////////////////
#define TRI_VOC_ATTRIBUTE_REV "_rev"
////////////////////////////////////////////////////////////////////////////////
/// @brief name of the system database
////////////////////////////////////////////////////////////////////////////////