mirror of https://gitee.com/bigwinds/arangodb
uint32_t => uint64_t
This commit is contained in:
parent
b71c880bbd
commit
7540059f36
|
@ -674,7 +674,7 @@ namespace triagens {
|
|||
TRI_ASSERT(v == nullptr || strlen(v) <= length);
|
||||
|
||||
value.value._string = v;
|
||||
value.length = length;
|
||||
value.length = static_cast<uint32_t>(length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -95,7 +95,7 @@ size_t Collection::count () const {
|
|||
// local case
|
||||
auto document = documentCollection();
|
||||
// cache the result
|
||||
numDocuments = static_cast<int64_t>(document->size(document));
|
||||
numDocuments = static_cast<int64_t>(document->size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ int RandomCollectionScanner::scan (std::vector<TRI_doc_mptr_copy_t>& docs,
|
|||
docs,
|
||||
initialPosition,
|
||||
position,
|
||||
static_cast<TRI_voc_size_t>(batchSize),
|
||||
static_cast<uint64_t>(batchSize),
|
||||
&step,
|
||||
&totalCount);
|
||||
}
|
||||
|
@ -106,9 +106,9 @@ int LinearCollectionScanner::scan (std::vector<TRI_doc_mptr_copy_t>& docs,
|
|||
return trx->readIncremental(trxCollection,
|
||||
docs,
|
||||
position,
|
||||
static_cast<TRI_voc_size_t>(batchSize),
|
||||
static_cast<uint64_t>(batchSize),
|
||||
0,
|
||||
TRI_QRY_NO_LIMIT,
|
||||
UINT64_MAX,
|
||||
&totalCount);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ namespace triagens {
|
|||
|
||||
triagens::arango::AqlTransaction* trx;
|
||||
TRI_transaction_collection_t* trxCollection;
|
||||
uint32_t totalCount;
|
||||
TRI_voc_size_t position;
|
||||
uint64_t totalCount;
|
||||
uint64_t position;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -86,8 +86,8 @@ namespace triagens {
|
|||
|
||||
void reset () override;
|
||||
|
||||
uint32_t initialPosition;
|
||||
uint32_t step;
|
||||
uint64_t initialPosition;
|
||||
uint64_t step;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace triagens {
|
|||
_doLock(false) {
|
||||
|
||||
if (doLock) {
|
||||
_document->beginRead(_document);
|
||||
_document->beginRead();
|
||||
_doLock = true;
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace triagens {
|
|||
|
||||
inline void unlock () {
|
||||
if (_doLock) {
|
||||
_document->endRead(_document);
|
||||
_document->endRead();
|
||||
_doLock = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace triagens {
|
|||
_doLock(false) {
|
||||
|
||||
if (doLock) {
|
||||
_document->beginWrite(_document);
|
||||
_document->beginWrite();
|
||||
_doLock = true;
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace triagens {
|
|||
|
||||
inline void unlock () {
|
||||
if (_doLock) {
|
||||
_document->endWrite(_document);
|
||||
_document->endWrite();
|
||||
_doLock = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,9 +250,9 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int read (std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
TRI_voc_ssize_t skip,
|
||||
TRI_voc_size_t limit,
|
||||
uint32_t* total) {
|
||||
int64_t skip,
|
||||
uint64_t limit,
|
||||
uint64_t* total) {
|
||||
|
||||
return this->readSlice(this->trxCollection(), docs, skip, limit, total);
|
||||
}
|
||||
|
@ -272,11 +272,11 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int readOffset (std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
TRI_voc_size_t& internalSkip,
|
||||
TRI_voc_size_t batchSize,
|
||||
TRI_voc_ssize_t skip,
|
||||
TRI_voc_size_t limit,
|
||||
uint32_t* total) {
|
||||
uint64_t& internalSkip,
|
||||
uint64_t batchSize,
|
||||
int64_t skip,
|
||||
uint64_t limit,
|
||||
uint64_t* total) {
|
||||
|
||||
return this->readIncremental(this->trxCollection(), docs, internalSkip, batchSize, skip, limit, total);
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ namespace triagens {
|
|||
int readPartition (std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
uint64_t partitionId,
|
||||
uint64_t numberOfPartitions,
|
||||
uint32_t* total) {
|
||||
uint64_t* total) {
|
||||
|
||||
return this->readNth(this->trxCollection(), docs, partitionId, numberOfPartitions, total);
|
||||
}
|
||||
|
|
|
@ -398,11 +398,11 @@ namespace triagens {
|
|||
|
||||
int readIncremental (TRI_transaction_collection_t* trxCollection,
|
||||
std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
TRI_voc_size_t& internalSkip,
|
||||
TRI_voc_size_t batchSize,
|
||||
TRI_voc_ssize_t skip,
|
||||
TRI_voc_size_t limit,
|
||||
uint32_t* total) {
|
||||
uint64_t& internalSkip,
|
||||
uint64_t batchSize,
|
||||
int64_t skip,
|
||||
uint64_t limit,
|
||||
uint64_t* total) {
|
||||
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection);
|
||||
|
||||
|
@ -436,8 +436,8 @@ namespace triagens {
|
|||
}
|
||||
|
||||
void** ptr = beg;
|
||||
uint32_t count = 0;
|
||||
*total = (uint32_t) primaryIndex->_nrUsed;
|
||||
uint64_t count = 0;
|
||||
*total = primaryIndex->_nrUsed;
|
||||
|
||||
try {
|
||||
if (batchSize > 2048) {
|
||||
|
@ -483,11 +483,11 @@ namespace triagens {
|
|||
|
||||
int readRandom (TRI_transaction_collection_t* trxCollection,
|
||||
std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
uint32_t& initialPosition,
|
||||
uint32_t& position,
|
||||
TRI_voc_size_t batchSize,
|
||||
uint32_t* step,
|
||||
uint32_t* total) {
|
||||
uint64_t& initialPosition,
|
||||
uint64_t& position,
|
||||
uint64_t batchSize,
|
||||
uint64_t* step,
|
||||
uint64_t* total) {
|
||||
if (initialPosition > 0 && position == initialPosition) {
|
||||
// already read all documents
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
|
@ -516,14 +516,14 @@ namespace triagens {
|
|||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
*total = (uint32_t) primaryIndex->_nrAlloc;
|
||||
*total = primaryIndex->_nrAlloc;
|
||||
if (*step == 0) {
|
||||
TRI_ASSERT(initialPosition == 0);
|
||||
|
||||
// find a co-prime for total
|
||||
while (true) {
|
||||
*step = TRI_UInt32Random() % *total;
|
||||
if (*step > 10 && triagens::basics::binaryGcd<uint32_t>(*total, *step) == 1) {
|
||||
if (*step > 10 && triagens::basics::binaryGcd<uint64_t>(*total, *step) == 1) {
|
||||
while (initialPosition == 0) {
|
||||
initialPosition = TRI_UInt32Random() % *total;
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ namespace triagens {
|
|||
}
|
||||
}
|
||||
|
||||
TRI_voc_size_t numRead = 0;
|
||||
uint64_t numRead = 0;
|
||||
do {
|
||||
auto d = static_cast<TRI_doc_mptr_t*>(primaryIndex->_table[position]);
|
||||
|
||||
|
@ -876,8 +876,8 @@ namespace triagens {
|
|||
return TRI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
uint32_t total = (uint32_t) primaryIndex->_nrAlloc;
|
||||
uint32_t pos = TRI_UInt32Random() % total;
|
||||
uint64_t total = primaryIndex->_nrAlloc;
|
||||
uint64_t pos = TRI_UInt32Random() % total;
|
||||
void** beg = primaryIndex->_table;
|
||||
|
||||
while (beg[pos] == nullptr) {
|
||||
|
@ -1010,9 +1010,9 @@ namespace triagens {
|
|||
|
||||
int readSlice (TRI_transaction_collection_t* trxCollection,
|
||||
std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
TRI_voc_ssize_t skip,
|
||||
TRI_voc_size_t limit,
|
||||
uint32_t* total) {
|
||||
int64_t skip,
|
||||
uint64_t limit,
|
||||
uint64_t* total) {
|
||||
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection);
|
||||
|
||||
|
@ -1044,9 +1044,9 @@ namespace triagens {
|
|||
void** beg = primaryIndex->_table;
|
||||
void** ptr = beg;
|
||||
void** end = ptr + primaryIndex->_nrAlloc;
|
||||
uint32_t count = 0;
|
||||
uint64_t count = 0;
|
||||
|
||||
*total = (uint32_t) primaryIndex->_nrUsed;
|
||||
*total = primaryIndex->_nrUsed;
|
||||
|
||||
// apply skip
|
||||
if (skip > 0) {
|
||||
|
@ -1147,7 +1147,7 @@ namespace triagens {
|
|||
std::vector<TRI_doc_mptr_copy_t>& docs,
|
||||
uint64_t partitionId,
|
||||
uint64_t numberOfPartitions,
|
||||
uint32_t* total) {
|
||||
uint64_t* total) {
|
||||
|
||||
TRI_document_collection_t* document = documentCollection(trxCollection);
|
||||
|
||||
|
@ -1169,7 +1169,7 @@ namespace triagens {
|
|||
|
||||
void** ptr = primaryIndex->_table;
|
||||
void** end = ptr + primaryIndex->_nrAlloc;
|
||||
*total = (uint32_t) primaryIndex->_nrUsed;
|
||||
*total = primaryIndex->_nrUsed;
|
||||
|
||||
// fetch documents, taking partition into account
|
||||
for (; ptr < end; ++ptr) {
|
||||
|
|
|
@ -1680,7 +1680,7 @@ static TRI_doc_collection_info_t* GetFigures (TRI_vocbase_col_t* collection) {
|
|||
trx.lockRead();
|
||||
|
||||
TRI_document_collection_t* document = collection->_collection;
|
||||
TRI_doc_collection_info_t* info = document->figures(document);
|
||||
TRI_doc_collection_info_t* info = document->figures();
|
||||
|
||||
trx.finish(res);
|
||||
// READ-LOCK end
|
||||
|
@ -4247,12 +4247,12 @@ static void JS_CountVocbaseCol (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
// READ-LOCK start
|
||||
trx.lockRead();
|
||||
|
||||
const TRI_voc_size_t s = document->size(document);
|
||||
uint64_t const s = document->size();
|
||||
|
||||
trx.finish(res);
|
||||
// READ-LOCK end
|
||||
|
||||
TRI_V8_RETURN(v8::Number::New(isolate, (double) s));
|
||||
TRI_V8_RETURN(v8::Number::New(isolate, static_cast<double>(s)));
|
||||
TRI_V8_TRY_CATCH_END
|
||||
}
|
||||
|
||||
|
|
|
@ -119,18 +119,18 @@ static v8::Handle<v8::Value> EmptyResult (v8::Isolate* isolate) {
|
|||
|
||||
static void ExtractSkipAndLimit (const v8::FunctionCallbackInfo<v8::Value>& args,
|
||||
size_t pos,
|
||||
TRI_voc_ssize_t& skip,
|
||||
TRI_voc_size_t& limit) {
|
||||
int64_t& skip,
|
||||
uint64_t& limit) {
|
||||
|
||||
skip = TRI_QRY_NO_SKIP;
|
||||
limit = TRI_QRY_NO_LIMIT;
|
||||
skip = 0;
|
||||
limit = UINT64_MAX;
|
||||
|
||||
if (pos < (size_t) args.Length() && ! args[(int) pos]->IsNull() && ! args[(int) pos]->IsUndefined()) {
|
||||
skip = (TRI_voc_ssize_t) TRI_ObjectToDouble(args[(int) pos]);
|
||||
skip = TRI_ObjectToInt64(args[(int) pos]);
|
||||
}
|
||||
|
||||
if (pos + 1 < (size_t) args.Length() && ! args[(int) pos + 1]->IsNull() && ! args[(int) pos + 1]->IsUndefined()) {
|
||||
limit = (TRI_voc_size_t) TRI_ObjectToDouble(args[(int) pos + 1]);
|
||||
limit = TRI_ObjectToUInt64(args[(int) pos + 1], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,19 +139,19 @@ static void ExtractSkipAndLimit (const v8::FunctionCallbackInfo<v8::Value>& args
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void CalculateSkipLimitSlice (size_t length,
|
||||
TRI_voc_ssize_t skip,
|
||||
TRI_voc_size_t limit,
|
||||
size_t& s,
|
||||
size_t& e) {
|
||||
int64_t skip,
|
||||
int64_t limit,
|
||||
uint64_t& s,
|
||||
uint64_t& e) {
|
||||
s = 0;
|
||||
e = length;
|
||||
e = static_cast<uint64_t>(length);
|
||||
|
||||
// skip from the beginning
|
||||
if (0 < skip) {
|
||||
s = (size_t) skip;
|
||||
s = static_cast<uint64_t>(skip);
|
||||
|
||||
if (e < s) {
|
||||
s = (size_t) e;
|
||||
s = e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,20 +159,21 @@ static void CalculateSkipLimitSlice (size_t length,
|
|||
else if (skip < 0) {
|
||||
skip = -skip;
|
||||
|
||||
if ((size_t) skip < e) {
|
||||
if (skip < static_cast<decltype(skip)>(e)) {
|
||||
s = e - skip;
|
||||
}
|
||||
}
|
||||
|
||||
// apply limit
|
||||
if (s + limit < e) {
|
||||
int64_t sum = (int64_t) s + (int64_t) limit;
|
||||
if (sum < (int64_t) e) {
|
||||
if (sum >= (int64_t) TRI_QRY_NO_LIMIT) {
|
||||
e = TRI_QRY_NO_LIMIT;
|
||||
int64_t sum = static_cast<int64_t>(s) + static_cast<int64_t>(limit);
|
||||
|
||||
if (sum < static_cast<int64_t>(e)) {
|
||||
if (sum >= INT64_MAX) {
|
||||
e = UINT64_MAX;
|
||||
}
|
||||
else {
|
||||
e = (size_t) sum;
|
||||
e = static_cast<uint64_t>(sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -546,8 +547,7 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
reverse = TRI_ObjectToBoolean(args[4]);
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -567,9 +567,8 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
auto shaper = document->getShaper(); // PROTECTED by trx here
|
||||
|
||||
// extract skip and limit
|
||||
TRI_voc_ssize_t skip;
|
||||
TRI_voc_size_t limit;
|
||||
|
||||
int64_t skip;
|
||||
uint64_t limit;
|
||||
ExtractSkipAndLimit(args, 2, skip, limit);
|
||||
|
||||
// setup result
|
||||
|
@ -584,7 +583,6 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
|
||||
trx.lockRead();
|
||||
|
||||
|
||||
// extract the index
|
||||
auto idx = TRI_LookupIndexByHandle(isolate, trx.resolver(), col, args[0], false);
|
||||
|
||||
|
@ -620,8 +618,8 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_NO_INDEX);
|
||||
}
|
||||
|
||||
TRI_voc_ssize_t total = 0;
|
||||
TRI_voc_size_t count = 0;
|
||||
int64_t total = 0;
|
||||
uint64_t count = 0;
|
||||
bool error = false;
|
||||
|
||||
if (trx.orderDitch(trx.trxCollection()) == nullptr) {
|
||||
|
@ -648,7 +646,7 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
break;
|
||||
}
|
||||
else {
|
||||
documents->Set((uint32_t) count, doc);
|
||||
documents->Set(static_cast<uint32_t>(count), doc);
|
||||
|
||||
if (++count >= limit) {
|
||||
break;
|
||||
|
@ -667,8 +665,8 @@ static void ExecuteSkiplistQuery (const v8::FunctionCallbackInfo<v8::Value>& arg
|
|||
// free data allocated by skiplist index result
|
||||
TRI_FreeSkiplistIterator(skiplistIterator);
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, (double) total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(count)));
|
||||
|
||||
if (error) {
|
||||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
|
@ -687,12 +685,7 @@ static int StoreGeoResult (v8::Isolate* isolate,
|
|||
GeoCoordinates* cors,
|
||||
v8::Handle<v8::Array>& documents,
|
||||
v8::Handle<v8::Array>& distances) {
|
||||
GeoCoordinate* end;
|
||||
GeoCoordinate* ptr;
|
||||
double* dtr;
|
||||
geo_coordinate_distance_t* gtr;
|
||||
geo_coordinate_distance_t* tmp;
|
||||
uint32_t i;
|
||||
|
||||
if (trx.orderDitch(trx.trxCollection()) == nullptr) {
|
||||
GeoIndex_CoordinatesFree(cors);
|
||||
|
@ -707,7 +700,7 @@ static int StoreGeoResult (v8::Isolate* isolate,
|
|||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
gtr = (tmp = (geo_coordinate_distance_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(geo_coordinate_distance_t) * n, false));
|
||||
geo_coordinate_distance_t* gtr = (tmp = (geo_coordinate_distance_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(geo_coordinate_distance_t) * n, false));
|
||||
|
||||
if (gtr == nullptr) {
|
||||
GeoIndex_CoordinatesFree(cors);
|
||||
|
@ -717,10 +710,10 @@ static int StoreGeoResult (v8::Isolate* isolate,
|
|||
|
||||
geo_coordinate_distance_t* gnd = tmp + n;
|
||||
|
||||
ptr = cors->coordinates;
|
||||
end = cors->coordinates + n;
|
||||
GeoCoordinate* ptr = cors->coordinates;
|
||||
GeoCoordinate* end = cors->coordinates + n;
|
||||
|
||||
dtr = cors->distances;
|
||||
double* dtr = cors->distances;
|
||||
|
||||
for (; ptr < end; ++ptr, ++dtr, ++gtr) {
|
||||
gtr->_distance = *dtr;
|
||||
|
@ -737,6 +730,7 @@ static int StoreGeoResult (v8::Isolate* isolate,
|
|||
|
||||
// copy the documents
|
||||
bool error = false;
|
||||
uint32_t i;
|
||||
for (gtr = tmp, i = 0; gtr < gnd; ++gtr, ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, collection->_cid, ((TRI_doc_mptr_t const*) gtr->_data)->getDataPtr());
|
||||
|
||||
|
@ -775,8 +769,7 @@ static void EdgesQuery (TRI_edge_direction_e direction,
|
|||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -834,14 +827,13 @@ static void EdgesQuery (TRI_edge_direction_e direction,
|
|||
documents = v8::Array::New(isolate);
|
||||
v8::Handle<v8::Array> vertices = v8::Handle<v8::Array>::Cast(args[0]);
|
||||
uint32_t count = 0;
|
||||
const uint32_t len = vertices->Length();
|
||||
uint32_t const len = vertices->Length();
|
||||
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
TRI_voc_cid_t cid;
|
||||
std::unique_ptr<char[]> key;
|
||||
|
||||
res = TRI_ParseVertex(args, trx.resolver(), cid, key,
|
||||
vertices->Get(i));
|
||||
res = TRI_ParseVertex(args, trx.resolver(), cid, key, vertices->Get(i));
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
// error is just ignored
|
||||
|
@ -887,17 +879,18 @@ static void EdgesQuery (TRI_edge_direction_e direction,
|
|||
|
||||
trx.finish(res);
|
||||
|
||||
uint32_t const n = static_cast<uint32_t>(edges.size());
|
||||
size_t const n = edges.size();
|
||||
documents = v8::Array::New(isolate, static_cast<int>(n));
|
||||
for (size_t j = 0; j < n; ++j) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, edges[j].getDataPtr());
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, edges[i].getDataPtr());
|
||||
|
||||
if (doc.IsEmpty()) {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
documents->Set(static_cast<uint32_t>(j), doc);
|
||||
documents->Set(static_cast<uint32_t>(i), doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -940,11 +933,11 @@ static void JS_AllQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_THROW_SHARDING_COLLECTION_NOT_YET_IMPLEMENTED(col);
|
||||
|
||||
// extract skip and limit
|
||||
TRI_voc_ssize_t skip;
|
||||
TRI_voc_size_t limit;
|
||||
int64_t skip;
|
||||
uint64_t limit;
|
||||
ExtractSkipAndLimit(args, 0, skip, limit);
|
||||
|
||||
uint32_t total = 0;
|
||||
uint64_t total = 0;
|
||||
vector<TRI_doc_mptr_copy_t> docs;
|
||||
|
||||
SingleCollectionReadOnlyTransaction trx(new V8TransactionContext(true), col->_vocbase, col->_cid);
|
||||
|
@ -964,28 +957,27 @@ static void JS_AllQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION(res);
|
||||
}
|
||||
|
||||
size_t const n = docs.size();
|
||||
uint32_t count = 0;
|
||||
uint64_t const n = static_cast<uint64_t>(docs.size());
|
||||
|
||||
// setup result
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
v8::Handle<v8::Array> documents = v8::Array::New(isolate, (int) n);
|
||||
v8::Handle<v8::Array> documents = v8::Array::New(isolate, static_cast<int>(n));
|
||||
// reserve full capacity in one go
|
||||
result->Set(TRI_V8_ASCII_STRING("documents"), documents);
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
for (uint64_t i = 0; i < n; ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, docs[i].getDataPtr());
|
||||
|
||||
if (doc.IsEmpty()) {
|
||||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
}
|
||||
else {
|
||||
documents->Set(count++, doc);
|
||||
documents->Set(static_cast<uint32_t>(i), doc);
|
||||
}
|
||||
}
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(n)));
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
TRI_V8_TRY_CATCH_END
|
||||
|
@ -1005,8 +997,7 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_USAGE("NTH(<partitionId>, <numberOfPartitions>)");
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1021,7 +1012,7 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_PARAMETER("invalid value for <partitionId> or <numberOfPartitions>");
|
||||
}
|
||||
|
||||
uint32_t total = 0;
|
||||
uint64_t total = 0;
|
||||
vector<TRI_doc_mptr_copy_t> docs;
|
||||
|
||||
SingleCollectionReadOnlyTransaction trx(new V8TransactionContext(true), col->_vocbase, col->_cid);
|
||||
|
@ -1042,7 +1033,6 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
}
|
||||
|
||||
size_t const n = docs.size();
|
||||
uint32_t count = 0;
|
||||
|
||||
// setup result
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
|
@ -1057,12 +1047,12 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
}
|
||||
else {
|
||||
documents->Set(count++, doc);
|
||||
documents->Set(static_cast<uint32_t>(i), doc);
|
||||
}
|
||||
}
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(n)));
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
TRI_V8_TRY_CATCH_END
|
||||
|
@ -1082,8 +1072,7 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_USAGE("NTH2(<partitionId>, <numberOfPartitions>)");
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1098,7 +1087,7 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_PARAMETER("invalid value for <partitionId> or <numberOfPartitions>");
|
||||
}
|
||||
|
||||
uint32_t total = 0;
|
||||
uint64_t total = 0;
|
||||
vector<TRI_doc_mptr_copy_t> docs;
|
||||
|
||||
SingleCollectionReadOnlyTransaction trx(new V8TransactionContext(true), col->_vocbase, col->_cid);
|
||||
|
@ -1119,7 +1108,6 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
}
|
||||
|
||||
size_t const n = docs.size();
|
||||
uint32_t count = 0;
|
||||
|
||||
// setup result
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
|
@ -1129,42 +1117,16 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
char const* key = TRI_EXTRACT_MARKER_KEY(static_cast<TRI_df_marker_t const*>(docs[i].getDataPtr()));
|
||||
documents->Set(count++, TRI_V8_STRING(key));
|
||||
documents->Set(static_cast<uint32_t>(i), TRI_V8_STRING(key));
|
||||
}
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(n)));
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
TRI_V8_TRY_CATCH_END
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief @mchacki
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void JS_Nth3Query (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
// expecting two arguments
|
||||
if (args.Length() != 2 || ! args[0]->IsString() || ! args[1]->IsNumber()) {
|
||||
TRI_V8_THROW_EXCEPTION_USAGE("NTH3(<key>, <numberOfPartitions>)");
|
||||
}
|
||||
|
||||
std::string const key(TRI_ObjectToString(args[0]));
|
||||
uint64_t const numberOfPartitions = TRI_ObjectToUInt64(args[1], false);
|
||||
|
||||
if (numberOfPartitions == 0) {
|
||||
TRI_V8_THROW_EXCEPTION_PARAMETER("invalid value for <numberOfPartitions>");
|
||||
}
|
||||
|
||||
uint64_t hash = TRI_FnvHashPointer(static_cast<void const*>(key.c_str()), key.size());
|
||||
|
||||
TRI_V8_RETURN(v8::Number::New(isolate, static_cast<int>(hash % numberOfPartitions)));
|
||||
TRI_V8_TRY_CATCH_END
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief selects documents from a collection, using an offset into the
|
||||
/// primary index. this can be used for incremental access
|
||||
|
@ -1179,8 +1141,7 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_USAGE("OFFSET(<internalSkip>, <batchSize>, <skip>, <limit>)");
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1188,15 +1149,15 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
|
||||
TRI_THROW_SHARDING_COLLECTION_NOT_YET_IMPLEMENTED(col);
|
||||
|
||||
TRI_voc_size_t internalSkip = (TRI_voc_size_t) TRI_ObjectToDouble(args[0]);
|
||||
TRI_voc_size_t batchSize = (TRI_voc_size_t) TRI_ObjectToDouble(args[1]);
|
||||
uint64_t internalSkip = TRI_ObjectToUInt64(args[0], false);
|
||||
uint64_t batchSize = TRI_ObjectToUInt64(args[1], false);
|
||||
|
||||
// extract skip and limit
|
||||
TRI_voc_ssize_t skip;
|
||||
TRI_voc_size_t limit;
|
||||
int64_t skip;
|
||||
uint64_t limit;
|
||||
ExtractSkipAndLimit(args, 2, skip, limit);
|
||||
|
||||
uint32_t total = 0;
|
||||
uint64_t total = 0;
|
||||
vector<TRI_doc_mptr_copy_t> docs;
|
||||
|
||||
SingleCollectionReadOnlyTransaction trx(new V8TransactionContext(true), col->_vocbase, col->_cid);
|
||||
|
@ -1217,11 +1178,10 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
}
|
||||
|
||||
size_t const n = docs.size();
|
||||
uint32_t count = 0;
|
||||
|
||||
// setup result
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
v8::Handle<v8::Array> documents = v8::Array::New(isolate, (int) n);
|
||||
v8::Handle<v8::Array> documents = v8::Array::New(isolate, static_cast<int>(n));
|
||||
// reserve full capacity in one go
|
||||
result->Set(TRI_V8_ASCII_STRING("documents"), documents);
|
||||
|
||||
|
@ -1232,12 +1192,12 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
}
|
||||
else {
|
||||
documents->Set(count++, document);
|
||||
documents->Set(static_cast<uint32_t>(i), document);
|
||||
}
|
||||
}
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(n)));
|
||||
result->Set(TRI_V8_ASCII_STRING("skip"), v8::Number::New(isolate, internalSkip));
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
|
@ -1264,8 +1224,7 @@ static void JS_AnyQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1322,9 +1281,7 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
TRI_V8_THROW_TYPE_ERROR("<example> must be an object");
|
||||
}
|
||||
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1346,8 +1303,8 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
v8::Handle<v8::Object> example = args[0]->ToObject();
|
||||
|
||||
// extract skip and limit
|
||||
TRI_voc_ssize_t skip;
|
||||
TRI_voc_size_t limit;
|
||||
int64_t skip;
|
||||
uint64_t limit;
|
||||
ExtractSkipAndLimit(args, 1, skip, limit);
|
||||
|
||||
// extract sub-documents
|
||||
|
@ -1400,18 +1357,16 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
// ...........................................................................
|
||||
|
||||
// convert to list of shaped jsons
|
||||
size_t total = filtered.size();
|
||||
size_t count = 0;
|
||||
uint64_t const total = static_cast<uint64_t>(filtered.size());
|
||||
uint64_t count = 0;
|
||||
bool error = false;
|
||||
|
||||
if (0 < total) {
|
||||
size_t s;
|
||||
size_t e;
|
||||
|
||||
uint64_t s, e;
|
||||
CalculateSkipLimitSlice(filtered.size(), skip, limit, s, e);
|
||||
|
||||
if (s < e) {
|
||||
for (size_t j = s; j < e; ++j) {
|
||||
for (uint64_t j = s; j < e; ++j) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, filtered[j].getDataPtr());
|
||||
|
||||
if (doc.IsEmpty()) {
|
||||
|
@ -1419,14 +1374,14 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo<v8::Value>& args)
|
|||
break;
|
||||
}
|
||||
else {
|
||||
documents->Set((uint32_t) count++, doc);
|
||||
documents->Set(static_cast<uint32_t>(count++), doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Integer::New(isolate, (int32_t) total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Integer::New(isolate, (int32_t) count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Integer::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Integer::New(isolate, static_cast<double>(count)));
|
||||
|
||||
if (error) {
|
||||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
|
@ -1465,9 +1420,8 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx,
|
|||
}
|
||||
|
||||
// extract skip and limit
|
||||
TRI_voc_ssize_t skip;
|
||||
TRI_voc_size_t limit;
|
||||
|
||||
int64_t skip;
|
||||
uint64_t limit;
|
||||
ExtractSkipAndLimit(args, 2, skip, limit);
|
||||
|
||||
// setup result
|
||||
|
@ -1511,28 +1465,26 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx,
|
|||
DestroySearchValue(shaper->memoryZone(), searchValue);
|
||||
|
||||
// convert result
|
||||
size_t total = TRI_LengthVectorPointer(&list);
|
||||
size_t count = 0;
|
||||
uint64_t total = static_cast<size_t>(TRI_LengthVectorPointer(&list));
|
||||
uint64_t count = 0;
|
||||
bool error = false;
|
||||
|
||||
if (0 < total) {
|
||||
size_t s;
|
||||
size_t e;
|
||||
|
||||
uint64_t s, e;
|
||||
CalculateSkipLimitSlice(total, skip, limit, s, e);
|
||||
|
||||
if (s < e) {
|
||||
for (size_t i = s; i < e; ++i) {
|
||||
for (uint64_t i = s; i < e; ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx,
|
||||
collection->_cid,
|
||||
static_cast<TRI_doc_mptr_t*>(TRI_AtVectorPointer(&list, i))->getDataPtr());
|
||||
static_cast<TRI_doc_mptr_t*>(TRI_AtVectorPointer(&list, static_cast<size_t>(i)))->getDataPtr());
|
||||
|
||||
if (doc.IsEmpty()) {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
documents->Set((uint32_t) count++, doc);
|
||||
documents->Set(static_cast<uint32_t>(count++), doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1541,8 +1493,8 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx,
|
|||
// free data allocated by hash index result
|
||||
TRI_DestroyVectorPointer(&list);
|
||||
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, (double) total));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, (double) count));
|
||||
result->Set(TRI_V8_ASCII_STRING("total"), v8::Number::New(isolate, static_cast<double>(total)));
|
||||
result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, static_cast<double>(count)));
|
||||
|
||||
if (error) {
|
||||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
|
@ -1559,8 +1511,7 @@ static void JS_ByExampleHashIndex (const v8::FunctionCallbackInfo<v8::Value>& ar
|
|||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1726,8 +1677,7 @@ static void JS_ChecksumCollection (const v8::FunctionCallbackInfo<v8::Value>& ar
|
|||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_CLUSTER_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -1962,9 +1912,7 @@ static void JS_FirstQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
size_t const n = documents.size();
|
||||
|
||||
if (returnList) {
|
||||
v8::Handle<v8::Array> result = v8::Array::New(isolate, (int) n);
|
||||
|
||||
uint32_t j = 0;
|
||||
v8::Handle<v8::Array> result = v8::Array::New(isolate, static_cast<int>(n));
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, documents[i].getDataPtr());
|
||||
|
@ -1974,7 +1922,7 @@ static void JS_FirstQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
}
|
||||
|
||||
result->Set(j++, doc);
|
||||
result->Set(static_cast<uint32_t>(i), doc);
|
||||
}
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
|
@ -2128,8 +2076,7 @@ static void JS_FulltextQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -2189,8 +2136,7 @@ static void JS_LastQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_PARAMETER("invalid value for <count>");
|
||||
}
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -2210,14 +2156,12 @@ static void JS_LastQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
res = trx.readPositional(documents, -1, count);
|
||||
trx.finish(res);
|
||||
|
||||
size_t const n = documents.size();
|
||||
uint64_t const n = static_cast<uint64_t>(documents.size());
|
||||
|
||||
if (returnList) {
|
||||
v8::Handle<v8::Array> result = v8::Array::New(isolate, (int) n);
|
||||
v8::Handle<v8::Array> result = v8::Array::New(isolate, static_cast<int>(n));
|
||||
|
||||
uint32_t j = 0;
|
||||
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
for (uint64_t i = 0; i < n; ++i) {
|
||||
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, documents[i].getDataPtr());
|
||||
|
||||
if (doc.IsEmpty()) {
|
||||
|
@ -2225,7 +2169,7 @@ static void JS_LastQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_THROW_EXCEPTION_MEMORY();
|
||||
}
|
||||
|
||||
result->Set(j++, doc);
|
||||
result->Set(static_cast<uint32_t>(i), doc);
|
||||
}
|
||||
|
||||
TRI_V8_RETURN(result);
|
||||
|
@ -2277,7 +2221,7 @@ static void NearQuery (SingleCollectionReadOnlyTransaction& trx,
|
|||
double longitude = TRI_ObjectToDouble(args[2]);
|
||||
|
||||
// extract the limit
|
||||
TRI_voc_ssize_t limit = (TRI_voc_ssize_t) TRI_ObjectToDouble(args[3]);
|
||||
int64_t limit = TRI_ObjectToInt64(args[3]);
|
||||
|
||||
// setup result
|
||||
v8::Handle<v8::Object> result = v8::Object::New(isolate);
|
||||
|
@ -2309,8 +2253,7 @@ static void JS_NearQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -2406,8 +2349,7 @@ static void JS_WithinQuery (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_TRY_CATCH_BEGIN(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
TRI_vocbase_col_t const* col;
|
||||
col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
TRI_vocbase_col_t const* col = TRI_UnwrapClass<TRI_vocbase_col_t>(args.Holder(), TRI_GetVocBaseColType());
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||
|
@ -2657,7 +2599,6 @@ void TRI_InitV8Queries (v8::Isolate* isolate,
|
|||
// internal methods. not intended to be used by end-users
|
||||
TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH"), JS_NthQuery, true);
|
||||
TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH2"), JS_Nth2Query, true);
|
||||
TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH3"), JS_Nth3Query, true);
|
||||
TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("OFFSET"), JS_OffsetQuery, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ static int EnhanceJsonIndexCap (v8::Isolate* isolate,
|
|||
if (obj->Has(TRI_V8_ASCII_STRING("size")) && obj->Get(TRI_V8_ASCII_STRING("size"))->IsNumber()) {
|
||||
int64_t value = TRI_ObjectToInt64(obj->Get(TRI_V8_ASCII_STRING("size")));
|
||||
|
||||
if (value < 0 || value > UINT32_MAX) {
|
||||
if (value < 0 || value > INT64_MAX) {
|
||||
return TRI_ERROR_BAD_PARAMETER;
|
||||
}
|
||||
count = (size_t) value;
|
||||
|
|
|
@ -134,6 +134,258 @@ TRI_document_collection_t::~TRI_document_collection_t () {
|
|||
delete _keyGenerator;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read locks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::beginRead () {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginRead blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginRead: " << document->_info._name << std::endl;
|
||||
TRI_READ_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read unlocks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::endRead () {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndRead blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndRead: " << document->_info._name << std::endl;
|
||||
TRI_READ_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write locks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::beginWrite () {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWrite blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING_DEBUG
|
||||
// std::cout << "BeginWrite: " << document->_info._name << std::endl;
|
||||
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write unlocks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::endWrite () {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndWrite blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndWrite: " << document->_info._name << std::endl;
|
||||
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read locks a collection, with a timeout (in µseconds)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::beginReadTimed (uint64_t timeout,
|
||||
uint64_t sleepPeriod) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginReadTimed blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
uint64_t waited = 0;
|
||||
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginReadTimed: " << document->_info._name << std::endl;
|
||||
while (! TRI_TRY_READ_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this)) {
|
||||
#ifdef _WIN32
|
||||
usleep((unsigned long) sleepPeriod);
|
||||
#else
|
||||
usleep((useconds_t) sleepPeriod);
|
||||
#endif
|
||||
|
||||
waited += sleepPeriod;
|
||||
|
||||
if (waited > timeout) {
|
||||
return TRI_ERROR_LOCK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write locks a collection, with a timeout
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int TRI_document_collection_t::beginWriteTimed (uint64_t timeout,
|
||||
uint64_t sleepPeriod) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWriteTimed blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
uint64_t waited = 0;
|
||||
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWriteTimed: " << document->_info._name << std::endl;
|
||||
while (! TRI_TRY_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(this)) {
|
||||
#ifdef _WIN32
|
||||
usleep((unsigned long) sleepPeriod);
|
||||
#else
|
||||
usleep((useconds_t) sleepPeriod);
|
||||
#endif
|
||||
|
||||
waited += sleepPeriod;
|
||||
|
||||
if (waited > timeout) {
|
||||
return TRI_ERROR_LOCK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the number of documents in collection
|
||||
///
|
||||
/// the caller must have read-locked the collection!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_document_collection_t::size () {
|
||||
return static_cast<uint64_t>(_numberDocuments);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns information about the collection
|
||||
/// note: the collection lock must be held when calling this function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_doc_collection_info_t* TRI_document_collection_t::figures () {
|
||||
// prefill with 0's to init counters
|
||||
TRI_doc_collection_info_t* info = static_cast<TRI_doc_collection_info_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_collection_info_t), true));
|
||||
|
||||
if (info == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _datafileInfo._nrAlloc; ++i) {
|
||||
auto d = static_cast<TRI_doc_datafile_info_t const*>(_datafileInfo._table[i]);
|
||||
|
||||
if (d != nullptr) {
|
||||
info->_numberAlive += d->_numberAlive;
|
||||
info->_numberDead += d->_numberDead;
|
||||
info->_numberDeletion += d->_numberDeletion;
|
||||
info->_numberShapes += d->_numberShapes;
|
||||
info->_numberAttributes += d->_numberAttributes;
|
||||
info->_numberTransactions += d->_numberTransactions;
|
||||
|
||||
info->_sizeAlive += d->_sizeAlive;
|
||||
info->_sizeDead += d->_sizeDead;
|
||||
info->_sizeShapes += d->_sizeShapes;
|
||||
info->_sizeAttributes += d->_sizeAttributes;
|
||||
info->_sizeTransactions += d->_sizeTransactions;
|
||||
}
|
||||
}
|
||||
|
||||
// add the file sizes for datafiles and journals
|
||||
TRI_collection_t* base = this;
|
||||
|
||||
for (size_t i = 0; i < base->_datafiles._length; ++i) {
|
||||
auto df = static_cast<TRI_datafile_t const*>(base->_datafiles._buffer[i]);
|
||||
|
||||
info->_datafileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberDatafiles;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < base->_journals._length; ++i) {
|
||||
auto df = static_cast<TRI_datafile_t const*>(base->_journals._buffer[i]);
|
||||
|
||||
info->_journalfileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberJournalfiles;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < base->_compactors._length; ++i) {
|
||||
auto df = static_cast<TRI_datafile_t const*>(base->_compactors._buffer[i]);
|
||||
|
||||
info->_compactorfileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberCompactorfiles;
|
||||
}
|
||||
|
||||
// add index information
|
||||
info->_numberIndexes = 0;
|
||||
info->_sizeIndexes = 0;
|
||||
|
||||
if (_headersPtr != nullptr) {
|
||||
info->_sizeIndexes += static_cast<int64_t>(_headersPtr->memory());
|
||||
}
|
||||
|
||||
for (auto& idx : allIndexes()) {
|
||||
info->_sizeIndexes += idx->memory();
|
||||
info->_numberIndexes++;
|
||||
}
|
||||
|
||||
// get information about shape files (DEPRECATED, thus hard-coded to 0)
|
||||
info->_shapefileSize = 0;
|
||||
info->_numberShapefiles = 0;
|
||||
|
||||
info->_uncollectedLogfileEntries = _uncollectedLogfileEntries;
|
||||
info->_tickMax = _tickMax;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief add an index to the collection
|
||||
/// note: this may throw. it's the caller's responsibility to catch and clean up
|
||||
|
@ -343,16 +595,6 @@ static void FreeDatafileInfo (TRI_doc_datafile_info_t* dfi) {
|
|||
TRI_Free(TRI_UNKNOWN_MEM_ZONE, dfi);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief size of a primary collection
|
||||
///
|
||||
/// the caller must have read-locked the collection!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static TRI_voc_size_t Count (TRI_document_collection_t* document) {
|
||||
return (TRI_voc_size_t) document->_numberDocuments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set the collection tick with the marker's tick value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -968,174 +1210,6 @@ static int CloneMarkerNoLegend (triagens::wal::Marker*& marker,
|
|||
return TRI_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read locks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int BeginRead (TRI_document_collection_t* document) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginRead blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginRead: " << document->_info._name << std::endl;
|
||||
TRI_READ_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read unlocks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int EndRead (TRI_document_collection_t* document) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndRead blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndRead: " << document->_info._name << std::endl;
|
||||
TRI_READ_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write locks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int BeginWrite (TRI_document_collection_t* document) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWrite blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING_DEBUG
|
||||
// std::cout << "BeginWrite: " << document->_info._name << std::endl;
|
||||
TRI_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write unlocks a collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int EndWrite (TRI_document_collection_t* document) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndWrite blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "EndWrite: " << document->_info._name << std::endl;
|
||||
TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document);
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief read locks a collection, with a timeout (in µseconds)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int BeginReadTimed (TRI_document_collection_t* document,
|
||||
uint64_t timeout,
|
||||
uint64_t sleepPeriod) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginReadTimed blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
uint64_t waited = 0;
|
||||
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginReadTimed: " << document->_info._name << std::endl;
|
||||
while (! TRI_TRY_READ_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document)) {
|
||||
#ifdef _WIN32
|
||||
usleep((unsigned long) sleepPeriod);
|
||||
#else
|
||||
usleep((useconds_t) sleepPeriod);
|
||||
#endif
|
||||
|
||||
waited += sleepPeriod;
|
||||
|
||||
if (waited > timeout) {
|
||||
return TRI_ERROR_LOCK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief write locks a collection, with a timeout
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int BeginWriteTimed (TRI_document_collection_t* document,
|
||||
uint64_t timeout,
|
||||
uint64_t sleepPeriod) {
|
||||
if (triagens::arango::Transaction::_makeNolockHeaders != nullptr) {
|
||||
std::string collName(document->_info._name);
|
||||
auto it = triagens::arango::Transaction::_makeNolockHeaders->find(collName);
|
||||
if (it != triagens::arango::Transaction::_makeNolockHeaders->end()) {
|
||||
// do not lock by command
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWriteTimed blocked: " << document->_info._name << std::endl;
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
}
|
||||
uint64_t waited = 0;
|
||||
|
||||
// LOCKING-DEBUG
|
||||
// std::cout << "BeginWriteTimed: " << document->_info._name << std::endl;
|
||||
while (! TRI_TRY_WRITE_LOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document)) {
|
||||
#ifdef _WIN32
|
||||
usleep((unsigned long) sleepPeriod);
|
||||
#else
|
||||
usleep((useconds_t) sleepPeriod);
|
||||
#endif
|
||||
|
||||
waited += sleepPeriod;
|
||||
|
||||
if (waited > timeout) {
|
||||
return TRI_ERROR_LOCK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return TRI_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- DOCUMENT COLLECTION
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- Open iterator
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1962,85 +2036,6 @@ static bool OpenIndexIterator (char const* filename,
|
|||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns information about the collection
|
||||
/// note: the collection lock must be held when calling this function
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static TRI_doc_collection_info_t* Figures (TRI_document_collection_t* document) {
|
||||
// prefill with 0's to init counters
|
||||
TRI_doc_collection_info_t* info = static_cast<TRI_doc_collection_info_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_collection_info_t), true));
|
||||
|
||||
if (info == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < document->_datafileInfo._nrAlloc; ++i) {
|
||||
TRI_doc_datafile_info_t* d = static_cast<TRI_doc_datafile_info_t*>(document->_datafileInfo._table[i]);
|
||||
|
||||
if (d != nullptr) {
|
||||
info->_numberAlive += d->_numberAlive;
|
||||
info->_numberDead += d->_numberDead;
|
||||
info->_numberDeletion += d->_numberDeletion;
|
||||
info->_numberShapes += d->_numberShapes;
|
||||
info->_numberAttributes += d->_numberAttributes;
|
||||
info->_numberTransactions += d->_numberTransactions;
|
||||
|
||||
info->_sizeAlive += d->_sizeAlive;
|
||||
info->_sizeDead += d->_sizeDead;
|
||||
info->_sizeShapes += d->_sizeShapes;
|
||||
info->_sizeAttributes += d->_sizeAttributes;
|
||||
info->_sizeTransactions += d->_sizeTransactions;
|
||||
}
|
||||
}
|
||||
|
||||
// add the file sizes for datafiles and journals
|
||||
TRI_collection_t* base = document;
|
||||
|
||||
for (size_t i = 0; i < base->_datafiles._length; ++i) {
|
||||
TRI_datafile_t* df = (TRI_datafile_t*) base->_datafiles._buffer[i];
|
||||
|
||||
info->_datafileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberDatafiles;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < base->_journals._length; ++i) {
|
||||
TRI_datafile_t* df = (TRI_datafile_t*) base->_journals._buffer[i];
|
||||
|
||||
info->_journalfileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberJournalfiles;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < base->_compactors._length; ++i) {
|
||||
TRI_datafile_t* df = (TRI_datafile_t*) base->_compactors._buffer[i];
|
||||
|
||||
info->_compactorfileSize += (int64_t) df->_maximalSize;
|
||||
++info->_numberCompactorfiles;
|
||||
}
|
||||
|
||||
// add index information
|
||||
info->_numberIndexes = 0;
|
||||
info->_sizeIndexes = 0;
|
||||
|
||||
if (document->_headersPtr != nullptr) {
|
||||
info->_sizeIndexes += static_cast<int64_t>(document->_headersPtr->memory());
|
||||
}
|
||||
|
||||
for (auto& idx : document->allIndexes()) {
|
||||
info->_sizeIndexes += idx->memory();
|
||||
info->_numberIndexes++;
|
||||
}
|
||||
|
||||
// get information about shape files (DEPRECATED, thus hard-coded to 0)
|
||||
info->_shapefileSize = 0;
|
||||
info->_numberShapefiles = 0;
|
||||
|
||||
info->_uncollectedLogfileEntries = document->_uncollectedLogfileEntries;
|
||||
info->_tickMax = document->_tickMax;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief initialises a document collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -2053,9 +2048,6 @@ static int InitBaseDocumentCollection (TRI_document_collection_t* document,
|
|||
document->_numberDocuments = 0;
|
||||
document->_lastCompaction = 0.0;
|
||||
|
||||
document->size = Count;
|
||||
|
||||
|
||||
int res = TRI_InitAssociativePointer(&document->_datafileInfo,
|
||||
TRI_UNKNOWN_MEM_ZONE,
|
||||
HashKeyDatafile,
|
||||
|
@ -2179,18 +2171,6 @@ static bool InitDocumentCollection (TRI_document_collection_t* document,
|
|||
|
||||
TRI_InitCondition(&document->_journalsCondition);
|
||||
|
||||
// setup methods
|
||||
document->beginRead = BeginRead;
|
||||
document->endRead = EndRead;
|
||||
|
||||
document->beginWrite = BeginWrite;
|
||||
document->endWrite = EndWrite;
|
||||
|
||||
document->beginReadTimed = BeginReadTimed;
|
||||
document->beginWriteTimed = BeginWriteTimed;
|
||||
|
||||
document->figures = Figures;
|
||||
|
||||
// crud methods
|
||||
document->cleanupIndexes = CleanupIndexes;
|
||||
|
||||
|
|
|
@ -443,8 +443,9 @@ public:
|
|||
int (*beginReadTimed) (struct TRI_document_collection_t*, uint64_t, uint64_t);
|
||||
int (*beginWriteTimed) (struct TRI_document_collection_t*, uint64_t, uint64_t);
|
||||
|
||||
TRI_doc_collection_info_t* (*figures) (struct TRI_document_collection_t* collection);
|
||||
TRI_voc_size_t (*size) (struct TRI_document_collection_t* collection);
|
||||
TRI_doc_collection_info_t* figures ();
|
||||
|
||||
uint64_t size ();
|
||||
|
||||
// function that is called to garbage-collect the collection's indexes
|
||||
int (*cleanupIndexes)(struct TRI_document_collection_t*);
|
||||
|
|
|
@ -400,10 +400,10 @@ static int LockCollection (TRI_transaction_collection_t* trxCollection,
|
|||
"read-locking collection %llu",
|
||||
(unsigned long long) trxCollection->_cid);
|
||||
if (trx->_timeout == 0) {
|
||||
res = document->beginRead(document);
|
||||
res = document->beginRead();
|
||||
}
|
||||
else {
|
||||
res = document->beginReadTimed(document, trx->_timeout, TRI_TRANSACTION_DEFAULT_SLEEP_DURATION);
|
||||
res = document->beginReadTimed(trx->_timeout, TRI_TRANSACTION_DEFAULT_SLEEP_DURATION);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -412,10 +412,10 @@ static int LockCollection (TRI_transaction_collection_t* trxCollection,
|
|||
"write-locking collection %llu",
|
||||
(unsigned long long) trxCollection->_cid);
|
||||
if (trx->_timeout == 0) {
|
||||
res = document->beginWrite(document);
|
||||
res = document->beginWrite();
|
||||
}
|
||||
else {
|
||||
res = document->beginWriteTimed(document, trx->_timeout, TRI_TRANSACTION_DEFAULT_SLEEP_DURATION);
|
||||
res = document->beginWriteTimed(trx->_timeout, TRI_TRANSACTION_DEFAULT_SLEEP_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,14 +482,14 @@ static int UnlockCollection (TRI_transaction_collection_t* trxCollection,
|
|||
nestingLevel,
|
||||
"read-unlocking collection %llu",
|
||||
(unsigned long long) trxCollection->_cid);
|
||||
document->endRead(document);
|
||||
document->endRead();
|
||||
}
|
||||
else {
|
||||
LOG_TRX(trxCollection->_transaction,
|
||||
nestingLevel,
|
||||
"write-unlocking collection %llu",
|
||||
(unsigned long long) trxCollection->_cid);
|
||||
document->endWrite(document);
|
||||
document->endWrite();
|
||||
}
|
||||
|
||||
trxCollection->_lockType = TRI_TRANSACTION_NONE;
|
||||
|
|
|
@ -220,18 +220,6 @@ extern bool IGNORE_DATAFILE_ERRORS;
|
|||
|
||||
#define TRI_INDEX_HANDLE_SEPARATOR_STR "/"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief no limit
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRI_QRY_NO_LIMIT ((TRI_voc_size_t) (4294967295U))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief no skip
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TRI_QRY_NO_SKIP ((TRI_voc_ssize_t) 0)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public types
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue