From c5103e28b3909b666274534c8d47285e1881975b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 22 May 2014 11:27:17 +0200 Subject: [PATCH] fixed edges --- arangod/V8Server/v8-vocbase.cpp | 8 ++- arangod/VocBase/document-collection.cpp | 5 ++ arangod/Wal/Marker.cpp | 60 +++++++++------- arangod/Wal/Marker.h | 95 ++++++++++++++++++++----- 4 files changed, 127 insertions(+), 41 deletions(-) diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 8854ebe30d..6b03fd82e3 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -10009,11 +10009,17 @@ static v8::Handle AddBasicDocumentAttributes (T& trx, TRI_df_marker_type_t type = ((TRI_df_marker_t*) document->_data)->_type; if (type == TRI_DOC_MARKER_KEY_EDGE) { - TRI_doc_edge_key_marker_t* marker = (TRI_doc_edge_key_marker_t*) document->_data; + TRI_doc_edge_key_marker_t const* marker = static_cast(document->_data); result->Set(v8g->_FromKey, V8DocumentId(trx.resolver().getCollectionNameCluster(marker->_fromCid), ((char*) marker) + marker->_offsetFromKey)); result->Set(v8g->_ToKey, V8DocumentId(trx.resolver().getCollectionNameCluster(marker->_toCid), ((char*) marker) + marker->_offsetToKey)); } + else if (type == TRI_WAL_MARKER_EDGE) { + triagens::wal::edge_marker_t const* marker = static_cast(document->_data); + + result->Set(v8g->_FromKey, V8DocumentId(trx.resolver().getCollectionNameCluster(marker->_fromCid), ((char const*) marker) + marker->_offsetFromKey)); + result->Set(v8g->_ToKey, V8DocumentId(trx.resolver().getCollectionNameCluster(marker->_toCid), ((char const*) marker) + marker->_offsetToKey)); + } return scope.Close(result); } diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp index 0e36a310f0..2f092776d2 100644 --- a/arangod/VocBase/document-collection.cpp +++ b/arangod/VocBase/document-collection.cpp @@ -2209,6 +2209,11 @@ static int RemoveDocumentShapedJson (TRI_transaction_collection_t* trxCollection bool lock, bool forceSync) { assert(key != nullptr); + + if (rid == 0) { + // generate new revision id + rid = static_cast(TRI_NewTickServer()); + } TRI_primary_collection_t* primary = trxCollection->_collection->_collection; diff --git a/arangod/Wal/Marker.cpp b/arangod/Wal/Marker.cpp index b499c7fdfb..f74dce64f8 100644 --- a/arangod/Wal/Marker.cpp +++ b/arangod/Wal/Marker.cpp @@ -69,7 +69,7 @@ Marker::Marker (TRI_df_marker_type_e type, : _buffer(new char[size]), _size(size) { - TRI_df_marker_t* m = reinterpret_cast(base()); + TRI_df_marker_t* m = reinterpret_cast(begin()); m->_type = type; m->_size = static_cast(size); m->_crc = 0; @@ -97,7 +97,7 @@ Marker::~Marker () { void Marker::storeSizedString (size_t offset, char const* value, size_t length) { - char* p = static_cast(base()) + offset; + char* p = static_cast(begin()) + offset; // store actual key memcpy(p, value, length); @@ -122,7 +122,7 @@ BeginTransactionMarker::BeginTransactionMarker (TRI_voc_tick_t databaseId, : Marker(TRI_WAL_MARKER_BEGIN_TRANSACTION, sizeof(transaction_begin_marker_t)) { - transaction_begin_marker_t* m = reinterpret_cast(base()); + transaction_begin_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_transactionId = transactionId; @@ -152,7 +152,7 @@ CommitTransactionMarker::CommitTransactionMarker (TRI_voc_tick_t databaseId, : Marker(TRI_WAL_MARKER_COMMIT_TRANSACTION, sizeof(transaction_commit_marker_t)) { - transaction_commit_marker_t* m = reinterpret_cast(base()); + transaction_commit_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_transactionId = transactionId; @@ -182,7 +182,7 @@ AbortTransactionMarker::AbortTransactionMarker (TRI_voc_tick_t databaseId, : Marker(TRI_WAL_MARKER_ABORT_TRANSACTION, sizeof(transaction_abort_marker_t)) { - transaction_abort_marker_t* m = reinterpret_cast(base()); + transaction_abort_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_transactionId = transactionId; @@ -216,7 +216,7 @@ DocumentMarker::DocumentMarker (TRI_voc_tick_t databaseId, TRI_shaped_json_t const* shapedJson) : Marker(TRI_WAL_MARKER_DOCUMENT, sizeof(document_marker_t) + alignedSize(key.size() + 1) + legend.getSize() + shapedJson->_data.length) { - document_marker_t* m = reinterpret_cast(base()); + document_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_collectionId = collectionId; m->_rid = revisionId; @@ -230,13 +230,13 @@ DocumentMarker::DocumentMarker (TRI_voc_tick_t databaseId, // store legend { - char* p = static_cast(base()) + m->_offsetLegend; + char* p = static_cast(begin()) + m->_offsetLegend; legend.dump(p); } // store shapedJson { - char* p = static_cast(base()) + m->_offsetJson; + char* p = static_cast(begin()) + m->_offsetJson; memcpy(p, shapedJson->_data.data, static_cast(shapedJson->_data.length)); } @@ -255,7 +255,7 @@ DocumentMarker::~DocumentMarker () { //////////////////////////////////////////////////////////////////////////////// void DocumentMarker::dump () const { - document_marker_t* m = reinterpret_cast(base()); + document_marker_t* m = reinterpret_cast(begin()); std::cout << "WAL DOCUMENT MARKER FOR DB " << m->_databaseId << ", COLLECTION " << m->_collectionId @@ -265,12 +265,10 @@ void DocumentMarker::dump () const { << ", OFFSETKEY: " << m->_offsetKey << ", OFFSETLEGEND: " << m->_offsetLegend << ", OFFSETJSON: " << m->_offsetJson - << ", KEYLENGTH: " << keyLength() << ", SIZE: " << size() << "\n"; - std::cout << "BINARY: '" << stringifyPart(base(), size()) << "'\n"; - std::cout << "KEY: '" << stringifyPart(key(), keyLength()) << "'\n"; + std::cout << "BINARY: '" << stringifyPart(begin(), size()) << "'\n"; std::cout << "LEGEND: '" << stringifyPart(legend(), legendLength()) << "'\n"; std::cout << "LEGEND HEX: '" << hexifyPart(legend(), legendLength()) << "'\n"; std::cout << "JSON: '" << stringifyPart(json(), jsonLength()) << "'\n"; @@ -342,7 +340,7 @@ EdgeMarker::EdgeMarker (TRI_voc_tick_t databaseId, : Marker(TRI_WAL_MARKER_EDGE, sizeof(edge_marker_t) + alignedSize(key.size() + 1) + alignedSize(strlen(edge->_fromKey) + 1) + alignedSize(strlen(edge->_toKey) + 1) + legend.getSize() + shapedJson->_data.length) { - edge_marker_t* m = reinterpret_cast(base()); + edge_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_collectionId = collectionId; @@ -364,13 +362,13 @@ EdgeMarker::EdgeMarker (TRI_voc_tick_t databaseId, // store legend { - char* p = static_cast(base()) + m->_offsetLegend; + char* p = static_cast(begin()) + m->_offsetLegend; legend.dump(p); } // store shapedJson { - char* p = static_cast(base()) + m->_offsetJson; + char* p = static_cast(begin()) + m->_offsetJson; memcpy(p, shapedJson->_data.data, static_cast(shapedJson->_data.length)); } @@ -389,18 +387,30 @@ EdgeMarker::~EdgeMarker () { //////////////////////////////////////////////////////////////////////////////// void EdgeMarker::dump () const { - edge_marker_t* m = reinterpret_cast(base()); + edge_marker_t* m = reinterpret_cast(begin()); std::cout << "WAL EDGE MARKER FOR DB " << m->_databaseId << ", COLLECTION " << m->_collectionId - << ", REV: " << m->_rid - << ", TRX: " << m->_tid - << ", KEY: " << ((char*) base() + m->_offsetKey) + << ", REV: " << rid() + << ", TRX: " << tid() + << ", KEY: " << key() << ", FROMCID " << m->_fromCid << ", TOCID " << m->_toCid - << ", FROMKEY: " << ((char*) base() + m->_offsetFromKey) - << ", TOKEY: " << ((char*) base() + m->_offsetFromKey) + << ", FROMKEY: " << fromKey() + << ", TOKEY: " << toKey() + << ", OFFSETKEY: " << m->_offsetKey + << ", OFFSETFROM: " << m->_offsetFromKey + << ", OFFSETTO: " << m->_offsetToKey + << ", OFFSETLEGEND: " << m->_offsetLegend + << ", OFFSETJSON: " << m->_offsetJson + << ", SIZE: " << size() << "\n"; + + std::cout << "BINARY: '" << stringifyPart(begin(), size()) << "'\n"; + std::cout << "LEGEND: '" << stringifyPart(legend(), legendLength()) << "'\n"; + std::cout << "LEGEND HEX: '" << hexifyPart(legend(), legendLength()) << "'\n"; + std::cout << "JSON: '" << stringifyPart(json(), jsonLength()) << "'\n"; + std::cout << "JSON HEX: '" << hexifyPart(json(), jsonLength()) << "'\n"; } //////////////////////////////////////////////////////////////////////////////// @@ -480,7 +490,7 @@ RemoveMarker::RemoveMarker (TRI_voc_tick_t databaseId, std::string const& key) : Marker(TRI_WAL_MARKER_REMOVE, sizeof(remove_marker_t) + alignedSize(key.size() + 1)) { - remove_marker_t* m = reinterpret_cast(base()); + remove_marker_t* m = reinterpret_cast(begin()); m->_databaseId = databaseId; m->_collectionId = collectionId; m->_rid = revisionId; @@ -503,14 +513,16 @@ RemoveMarker::~RemoveMarker () { //////////////////////////////////////////////////////////////////////////////// void RemoveMarker::dump () const { - remove_marker_t* m = reinterpret_cast(base()); + remove_marker_t* m = reinterpret_cast(begin()); std::cout << "WAL REMOVE MARKER FOR DB " << m->_databaseId << ", COLLECTION " << m->_collectionId << ", REV: " << m->_rid << ", TRX: " << m->_tid - << ", KEY: " << (((char*) base()) + sizeof(remove_marker_t)) + << ", KEY: " << key() << "\n"; + + std::cout << "BINARY: '" << stringifyPart(begin(), size()) << "'\n"; } // Local Variables: diff --git a/arangod/Wal/Marker.h b/arangod/Wal/Marker.h index a331d9067c..da4b628767 100644 --- a/arangod/Wal/Marker.h +++ b/arangod/Wal/Marker.h @@ -150,12 +150,16 @@ namespace triagens { return static_cast(_buffer); } - inline char* base () const { + inline char* begin () const { return _buffer; } + + inline char* end () const { + return _buffer + _size; + } inline char* payload () const { - return base() + sizeof(TRI_df_marker_t); + return begin() + sizeof(TRI_df_marker_t); } inline uint32_t size () const { @@ -268,36 +272,41 @@ namespace triagens { ~DocumentMarker (); public: + + inline TRI_voc_rid_t rid () const { + document_marker_t const* m = reinterpret_cast(begin()); + return m->_rid; + } + + inline TRI_voc_rid_t tid () const { + document_marker_t const* m = reinterpret_cast(begin()); + return m->_tid; + } inline char const* key () const { // pointer to key - return base() + sizeof(document_marker_t); + return begin() + sizeof(document_marker_t); } - inline size_t keyLength () const { - document_marker_t const* m = reinterpret_cast(base()); - return static_cast(m->_offsetLegend - m->_offsetKey); - } - inline char const* legend () const { // pointer to legend - document_marker_t const* m = reinterpret_cast(base()); - return base() + m->_offsetLegend; + document_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetLegend; } inline size_t legendLength () const { - document_marker_t const* m = reinterpret_cast(base()); + document_marker_t const* m = reinterpret_cast(begin()); return static_cast(m->_offsetJson - m->_offsetLegend); } inline char const* json () const { // pointer to json - document_marker_t const* m = reinterpret_cast(base()); - return base() + m->_offsetJson; + document_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetJson; } inline size_t jsonLength () const { - document_marker_t const* m = reinterpret_cast(base()); + document_marker_t const* m = reinterpret_cast(begin()); return static_cast(size() - m->_offsetJson); } @@ -330,6 +339,55 @@ namespace triagens { TRI_shaped_json_t const*); ~EdgeMarker (); + + inline TRI_voc_rid_t rid () const { + edge_marker_t const* m = reinterpret_cast(begin()); + return m->_rid; + } + + inline TRI_voc_rid_t tid () const { + edge_marker_t const* m = reinterpret_cast(begin()); + return m->_tid; + } + + inline char const* key () const { + // pointer to key + return begin() + sizeof(edge_marker_t); + } + + inline char const* fromKey () const { + // pointer to _from key + edge_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetFromKey; + } + + inline char const* toKey () const { + // pointer to _to key + edge_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetToKey; + } + + inline char const* legend () const { + // pointer to legend + edge_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetLegend; + } + + inline size_t legendLength () const { + edge_marker_t const* m = reinterpret_cast(begin()); + return static_cast(m->_offsetJson - m->_offsetLegend); + } + + inline char const* json () const { + // pointer to json + edge_marker_t const* m = reinterpret_cast(begin()); + return begin() + m->_offsetJson; + } + + inline size_t jsonLength () const { + edge_marker_t const* m = reinterpret_cast(begin()); + return static_cast(size() - m->_offsetJson); + } void dump () const; @@ -362,11 +420,16 @@ namespace triagens { inline char const* key () const { // pointer to key - return base() + sizeof(remove_marker_t); + return begin() + sizeof(remove_marker_t); + } + + inline TRI_voc_rid_t tid () const { + remove_marker_t const* m = reinterpret_cast(begin()); + return m->_tid; } inline TRI_voc_rid_t rid () const { - remove_marker_t const* m = reinterpret_cast(base()); + remove_marker_t const* m = reinterpret_cast(begin()); return m->_rid; }