mirror of https://gitee.com/bigwinds/arangodb
added collection.revision() method
This commit is contained in:
parent
7be548ab5d
commit
485d10ad51
|
@ -1,6 +1,8 @@
|
|||
v1.2.alpha (XXXX-XX-XX)
|
||||
-----------------------
|
||||
|
||||
* added collection.revision() method to determine whether a collection has changed
|
||||
|
||||
* issue #346: adaptively determine NUMBER_HEADERS_PER_BLOCK
|
||||
|
||||
* issue #338: arangosh cursor positioning problems
|
||||
|
|
|
@ -4474,6 +4474,7 @@ static v8::Handle<v8::Value> JS_NameVocbaseCol (v8::Arguments const& argv) {
|
|||
return scope.Close(v8::ThrowException(v8::String::New("illegal collection pointer")));
|
||||
}
|
||||
|
||||
// TODO: protect this against race conditions (parallel rename operation)
|
||||
return scope.Close(v8::String::New(collection->_name));
|
||||
}
|
||||
|
||||
|
@ -4984,6 +4985,37 @@ static v8::Handle<v8::Value> JS_StatusVocbaseCol (v8::Arguments const& argv) {
|
|||
return scope.Close(v8::Number::New((int) status));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the revision id of a collection
|
||||
/// the revision id is updated when the document data in a collection changes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static v8::Handle<v8::Value> JS_RevisionVocbaseCol (v8::Arguments const& argv) {
|
||||
v8::HandleScope scope;
|
||||
|
||||
v8::Handle<v8::Object> err;
|
||||
TRI_vocbase_col_t const* collection = UseCollection(argv.Holder(), &err);
|
||||
|
||||
if (collection == 0) {
|
||||
return scope.Close(v8::ThrowException(err));
|
||||
}
|
||||
|
||||
TRI_primary_collection_t* primary = collection->_collection;
|
||||
|
||||
if (! TRI_IS_DOCUMENT_COLLECTION(collection->_type)) {
|
||||
TRI_ReleaseCollection(collection);
|
||||
return scope.Close(v8::ThrowException(TRI_CreateErrorObject(TRI_ERROR_INTERNAL, "unknown collection type")));
|
||||
}
|
||||
|
||||
primary->beginRead(primary);
|
||||
TRI_voc_rid_t rid = primary->base._info._rid;
|
||||
primary->endRead(primary);
|
||||
|
||||
TRI_ReleaseCollection(collection);
|
||||
|
||||
return scope.Close(v8::Number::New(rid));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief truncates a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -6268,6 +6300,7 @@ v8::Handle<v8::Value> TRI_WrapShapedJson (TRI_vocbase_col_t const* collection,
|
|||
// store the document reference
|
||||
TRI_voc_rid_t rid = document->_rid;
|
||||
|
||||
// TODO: protect this against race conditions (parallel rename)
|
||||
result->Set(v8g->DidKey, DocumentId(collection->_name, document->_key), v8::ReadOnly);
|
||||
result->Set(v8g->RevKey, v8::Number::New(rid), v8::ReadOnly);
|
||||
result->Set(v8g->KeyKey, v8::String::New(document->_key), v8::ReadOnly);
|
||||
|
@ -6499,6 +6532,7 @@ TRI_v8_global_t* TRI_InitV8VocBridge (v8::Handle<v8::Context> context,
|
|||
TRI_AddMethodVocbase(rt, "name", JS_NameVocbaseCol);
|
||||
TRI_AddMethodVocbase(rt, "properties", JS_PropertiesVocbaseCol);
|
||||
TRI_AddMethodVocbase(rt, "remove", JS_RemoveVocbaseCol);
|
||||
TRI_AddMethodVocbase(rt, "revision", JS_RevisionVocbaseCol);
|
||||
TRI_AddMethodVocbase(rt, "rename", JS_RenameVocbaseCol);
|
||||
TRI_AddMethodVocbase(rt, "setAttribute", JS_SetAttributeVocbaseCol, true);
|
||||
TRI_AddMethodVocbase(rt, "status", JS_StatusVocbaseCol);
|
||||
|
|
|
@ -482,14 +482,15 @@ void TRI_InitCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
assert(parameter);
|
||||
memset(parameter, 0, sizeof(TRI_col_info_t));
|
||||
|
||||
parameter->_version = TRI_COL_VERSION;
|
||||
parameter->_type = type;
|
||||
parameter->_cid = 0;
|
||||
parameter->_version = TRI_COL_VERSION;
|
||||
parameter->_type = type;
|
||||
parameter->_cid = 0;
|
||||
parameter->_rid = 0;
|
||||
|
||||
parameter->_deleted = false;
|
||||
parameter->_isVolatile = false;
|
||||
parameter->_isSystem = false;
|
||||
parameter->_maximalSize = (maximalSize / PageSize) * PageSize;
|
||||
parameter->_deleted = false;
|
||||
parameter->_isVolatile = false;
|
||||
parameter->_isSystem = false;
|
||||
parameter->_maximalSize = (maximalSize / PageSize) * PageSize;
|
||||
if (parameter->_maximalSize == 0 && maximalSize != 0) {
|
||||
parameter->_maximalSize = PageSize;
|
||||
}
|
||||
|
@ -501,7 +502,7 @@ void TRI_InitCollectionInfo (TRI_vocbase_t* vocbase,
|
|||
parameter->_options = options;
|
||||
}
|
||||
else {
|
||||
parameter->_options = 0;
|
||||
parameter->_options = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,13 +514,14 @@ void TRI_CopyCollectionInfo (TRI_col_info_t* dst, TRI_col_info_t* src) {
|
|||
assert(dst);
|
||||
memset(dst, 0, sizeof(TRI_col_info_t));
|
||||
|
||||
dst->_version = src->_version;
|
||||
dst->_type = src->_type;
|
||||
dst->_cid = src->_cid;
|
||||
dst->_version = src->_version;
|
||||
dst->_type = src->_type;
|
||||
dst->_cid = src->_cid;
|
||||
dst->_rid = src->_rid;
|
||||
|
||||
dst->_deleted = src->_deleted;
|
||||
dst->_isSystem = src->_isSystem;
|
||||
dst->_isVolatile = src->_isVolatile;
|
||||
dst->_deleted = src->_deleted;
|
||||
dst->_isSystem = src->_isSystem;
|
||||
dst->_isVolatile = src->_isVolatile;
|
||||
dst->_maximalSize = src->_maximalSize;
|
||||
TRI_CopyString(dst->_name, src->_name, sizeof(dst->_name));
|
||||
dst->_waitForSync = src->_waitForSync;
|
||||
|
@ -528,7 +530,7 @@ void TRI_CopyCollectionInfo (TRI_col_info_t* dst, TRI_col_info_t* src) {
|
|||
dst->_options = TRI_CopyJson(TRI_UNKNOWN_MEM_ZONE, src->_options);
|
||||
}
|
||||
else {
|
||||
dst->_options = 0;
|
||||
dst->_options = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,7 +541,7 @@ void TRI_CopyCollectionInfo (TRI_col_info_t* dst, TRI_col_info_t* src) {
|
|||
void TRI_FreeCollectionInfoOptions (TRI_col_info_t* parameter) {
|
||||
if (parameter->_options) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, parameter->_options);
|
||||
parameter->_options = 0;
|
||||
parameter->_options = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -218,10 +218,11 @@ typedef struct TRI_col_info_s {
|
|||
TRI_col_version_t _version; // collection version
|
||||
TRI_col_type_e _type; // collection type
|
||||
TRI_voc_cid_t _cid; // collection identifier
|
||||
struct TRI_json_s* _options; // optional collection options
|
||||
TRI_voc_rid_t _rid; // last revision id
|
||||
TRI_voc_size_t _maximalSize; // maximal size of memory mapped file
|
||||
|
||||
char _name[TRI_COL_PATH_LENGTH]; // name of the collection
|
||||
struct TRI_json_s* _options; // optional collection options
|
||||
|
||||
// flags
|
||||
bool _deleted : 1; // if true, collection has been deleted
|
||||
|
@ -250,7 +251,7 @@ typedef struct TRI_collection_s {
|
|||
TRI_vector_pointer_t _datafiles; // all datafiles
|
||||
TRI_vector_pointer_t _journals; // all journals
|
||||
TRI_vector_pointer_t _compactors; // all compactor files
|
||||
TRI_vector_string_t _indexFiles; // all index filenames
|
||||
TRI_vector_string_t _indexFiles; // all index filenames
|
||||
}
|
||||
TRI_collection_t;
|
||||
|
||||
|
|
|
@ -143,6 +143,19 @@ static bool IsVisible (TRI_doc_mptr_t const* header,
|
|||
return (header != NULL && header->_validTo == 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set the collection revision id with the marker's tick value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void CollectionRevisionUpdate (TRI_document_collection_t* document,
|
||||
const TRI_df_marker_t* const marker) {
|
||||
TRI_col_info_t* info = &document->base.base._info;
|
||||
|
||||
if (marker->_tick > info->_rid) {
|
||||
info->_rid = marker->_tick;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -295,6 +308,8 @@ static int WriteElement (TRI_document_collection_t* document,
|
|||
return res;
|
||||
}
|
||||
|
||||
CollectionRevisionUpdate(document, marker);
|
||||
|
||||
TRI_LOCK_JOURNAL_ENTRIES_DOC_COLLECTION(document);
|
||||
|
||||
journal->_written = ((char*) result) + marker->_size;
|
||||
|
@ -1437,6 +1452,8 @@ static bool OpenIterator (TRI_df_marker_t const* marker, void* data, TRI_datafil
|
|||
|
||||
primary = &collection->base;
|
||||
|
||||
CollectionRevisionUpdate(collection, marker);
|
||||
|
||||
// new or updated document
|
||||
if (marker->_type == TRI_DOC_MARKER_KEY_EDGE ||
|
||||
marker->_type == TRI_DOC_MARKER_KEY_DOCUMENT) {
|
||||
|
|
Loading…
Reference in New Issue