mirror of https://gitee.com/bigwinds/arangodb
Remove singletransaction and fetch collection from vocbase directly
This commit is contained in:
parent
d3642f1487
commit
d91a6af1a7
|
@ -956,32 +956,29 @@ static void JS_LeaderResign(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerState::instance()->isDBServer()) {
|
if (ServerState::instance()->isDBServer()) {
|
||||||
arangodb::LogicalCollection const* collection =
|
arangodb::LogicalCollection const* v8Collection =
|
||||||
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
||||||
WRP_VOCBASE_COL_TYPE);
|
WRP_VOCBASE_COL_TYPE);
|
||||||
|
|
||||||
if (collection == nullptr) {
|
if (v8Collection == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_vocbase_t* vocbase = collection->vocbase();
|
TRI_vocbase_t* vocbase = v8Collection->vocbase();
|
||||||
std::string collectionName = collection->name();
|
|
||||||
if (vocbase == nullptr) {
|
if (vocbase == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto transactionContext = std::make_shared<V8TransactionContext>(vocbase, true);
|
std::string collectionName = v8Collection->name();
|
||||||
|
auto collection = vocbase->lookupCollection(collectionName);
|
||||||
SingleCollectionTransaction trx(transactionContext, collectionName,
|
if (collection == nullptr) {
|
||||||
TRI_TRANSACTION_READ);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||||
int res = trx.begin();
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
|
||||||
TRI_V8_THROW_EXCEPTION(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not reset followers at this time...we are still the only source of truth
|
// do not reset followers at this time...we are still the only source of truth
|
||||||
// to trust...
|
// to trust...
|
||||||
//trx.documentCollection()->followers()->clear();
|
//trx.documentCollection()->followers()->clear();
|
||||||
trx.documentCollection()->followers()->setLeader(false);
|
collection->followers()->setLeader(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_V8_RETURN_UNDEFINED();
|
TRI_V8_RETURN_UNDEFINED();
|
||||||
|
@ -1003,30 +1000,26 @@ static void JS_AssumeLeadership(v8::FunctionCallbackInfo<v8::Value> const& args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerState::instance()->isDBServer()) {
|
if (ServerState::instance()->isDBServer()) {
|
||||||
arangodb::LogicalCollection const* collection =
|
arangodb::LogicalCollection const* v8Collection =
|
||||||
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
||||||
WRP_VOCBASE_COL_TYPE);
|
WRP_VOCBASE_COL_TYPE);
|
||||||
|
|
||||||
if (collection == nullptr) {
|
if (v8Collection == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_vocbase_t* vocbase = collection->vocbase();
|
TRI_vocbase_t* vocbase = v8Collection->vocbase();
|
||||||
std::string collectionName = collection->name();
|
|
||||||
if (vocbase == nullptr) {
|
if (vocbase == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto transactionContext = std::make_shared<V8TransactionContext>(vocbase, true);
|
std::string collectionName = v8Collection->name();
|
||||||
|
auto collection = vocbase->lookupCollection(collectionName);
|
||||||
SingleCollectionTransaction trx(transactionContext, collectionName,
|
if (collection == nullptr) {
|
||||||
TRI_TRANSACTION_READ);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||||
int res = trx.begin();
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
|
||||||
TRI_V8_THROW_EXCEPTION(res);
|
|
||||||
}
|
}
|
||||||
trx.documentCollection()->followers()->clear();
|
collection->followers()->clear();
|
||||||
trx.documentCollection()->followers()->setLeader(true);
|
collection->followers()->setLeader(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_V8_RETURN_UNDEFINED();
|
TRI_V8_RETURN_UNDEFINED();
|
||||||
|
@ -1094,29 +1087,25 @@ static void JS_GetFollowers(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
||||||
|
|
||||||
v8::Handle<v8::Array> list = v8::Array::New(isolate);
|
v8::Handle<v8::Array> list = v8::Array::New(isolate);
|
||||||
if (ServerState::instance()->isDBServer()) {
|
if (ServerState::instance()->isDBServer()) {
|
||||||
arangodb::LogicalCollection const* collection =
|
arangodb::LogicalCollection const* v8Collection =
|
||||||
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
TRI_UnwrapClass<arangodb::LogicalCollection>(args.Holder(),
|
||||||
WRP_VOCBASE_COL_TYPE);
|
WRP_VOCBASE_COL_TYPE);
|
||||||
|
|
||||||
if (collection == nullptr) {
|
if (v8Collection == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_vocbase_t* vocbase = collection->vocbase();
|
TRI_vocbase_t* vocbase = v8Collection->vocbase();
|
||||||
std::string collectionName = collection->name();
|
|
||||||
if (vocbase == nullptr) {
|
if (vocbase == nullptr) {
|
||||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto transactionContext = std::make_shared<V8TransactionContext>(vocbase, true);
|
std::string collectionName = v8Collection->name();
|
||||||
|
auto collection = vocbase->lookupCollection(collectionName);
|
||||||
SingleCollectionTransaction trx(transactionContext, collectionName,
|
if (collection == nullptr) {
|
||||||
TRI_TRANSACTION_READ);
|
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
|
||||||
int res = trx.begin();
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
|
||||||
TRI_V8_THROW_EXCEPTION(res);
|
|
||||||
}
|
}
|
||||||
std::unique_ptr<arangodb::FollowerInfo> const& followerInfo = trx.documentCollection()->followers();
|
std::unique_ptr<arangodb::FollowerInfo> const& followerInfo = collection->followers();
|
||||||
std::shared_ptr<std::vector<ServerID> const> followers = followerInfo->get();
|
std::shared_ptr<std::vector<ServerID> const> followers = followerInfo->get();
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (auto const& n : *followers) {
|
for (auto const& n : *followers) {
|
||||||
|
|
|
@ -1244,7 +1244,7 @@ function updateCurrentForDatabases(localErrors, currentDatabases) {
|
||||||
if (localDatabases.hasOwnProperty(name)) {
|
if (localDatabases.hasOwnProperty(name)) {
|
||||||
if (!currentDatabases.hasOwnProperty(name) ||
|
if (!currentDatabases.hasOwnProperty(name) ||
|
||||||
!currentDatabases[name].hasOwnProperty(ourselves) ||
|
!currentDatabases[name].hasOwnProperty(ourselves) ||
|
||||||
currentDatabases[name][ourselves].error == true) {
|
currentDatabases[name][ourselves].error) {
|
||||||
console.debug("adding entry in Current for database '%s'", name);
|
console.debug("adding entry in Current for database '%s'", name);
|
||||||
trx = Object.assign(trx, makeAddDatabaseAgencyOperation({error: false, errorNum: 0, name: name,
|
trx = Object.assign(trx, makeAddDatabaseAgencyOperation({error: false, errorNum: 0, name: name,
|
||||||
id: localDatabases[name].id,
|
id: localDatabases[name].id,
|
||||||
|
|
Loading…
Reference in New Issue