1
0
Fork 0

Adding Foxx access to agenc

This commit is contained in:
Kaveh Vahedipour 2016-08-26 13:35:39 +02:00
parent 08f1fa3a22
commit b409a1ff25
7 changed files with 176 additions and 4 deletions

View File

@ -253,11 +253,20 @@ bool Agent::recvAppendEntriesRPC(
MUTEX_LOCKER(mutexLocker, _ioLock); MUTEX_LOCKER(mutexLocker, _ioLock);
if (this->term() > term) { if (this->term() > term) { // peer at higher term
LOG_TOPIC(WARN, Logger::AGENCY) << "I have a higher term than RPC caller."; if (leaderCommitIndex >= _lastCommitIndex) { //
_constituent.follow(term);
} else {
LOG_TOPIC(WARN, Logger::AGENCY) << "I have a higher term than RPC caller.";
return false;
}
}
if (!_constituent.vote(term, leaderId, prevIndex, prevTerm, true)) {
LOG_TOPIC(WARN, Logger::AGENCY) << "Not voting for " << leaderId;
return false; return false;
} }
if (!_constituent.vote(term, leaderId, prevIndex, prevTerm, true)) { if (!_constituent.vote(term, leaderId, prevIndex, prevTerm, true)) {
return false; return false;
} }

View File

@ -0,0 +1,118 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Kaveh Vahedipour
////////////////////////////////////////////////////////////////////////////////
#include "v8-agency.h"
#include "Agency/AgencyFeature.h"
#include "Agency/Agent.h"
#include "ApplicationFeatures/ApplicationServer.h"
#include "V8/v8-buffer.h"
#include "V8/v8-conv.h"
#include "V8/v8-globals.h"
#include "V8/v8-utils.h"
#include "V8/v8-vpack.h"
#include "VocBase/server.h"
#include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h>
using namespace arangodb;
using namespace arangodb::application_features;
using namespace arangodb::basics;
using namespace arangodb::consensus;
static void JS_LeadingVulpes(v8::FunctionCallbackInfo<v8::Value> const& args) {
v8::Isolate* isolate = args.GetIsolate();
Agent* agent = nullptr;
try {
AgencyFeature* feature =
ApplicationServer::getEnabledFeature<AgencyFeature>("AgencyFeature");
agent = feature->agent();
} catch (std::exception const& e) {
TRI_V8_THROW_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
std::string("couldn't access agency feature: ") + e.what());
}
v8::Handle<v8::Object> r = v8::Object::New(isolate);
r->Set(TRI_V8_ASCII_STRING("leading"),
v8::Boolean::New(isolate, agent->leading()));
TRI_V8_RETURN(r);
}
static void JS_ReadVulpes(v8::FunctionCallbackInfo<v8::Value> const& args) {
}
static void JS_WriteVulpes(v8::FunctionCallbackInfo<v8::Value> const& args) {
}
void TRI_InitV8Agency(v8::Isolate* isolate, v8::Handle<v8::Context> context) {
TRI_V8_CURRENT_GLOBALS_AND_SCOPE;
TRI_ASSERT(v8g != nullptr);
v8::Handle<v8::ObjectTemplate> rt;
v8::Handle<v8::FunctionTemplate> ft;
// ...........................................................................
// generate the agency template
// ...........................................................................
ft = v8::FunctionTemplate::New(isolate);
ft->SetClassName(TRI_V8_ASCII_STRING("ArangoVulpes"));
rt = ft->InstanceTemplate();
rt->SetInternalFieldCount(2);
TRI_AddMethodVocbase(
isolate, rt, TRI_V8_ASCII_STRING("leading"), JS_LeadingVulpes);
TRI_AddMethodVocbase(
isolate, rt, TRI_V8_ASCII_STRING("read"), JS_ReadVulpes);
TRI_AddMethodVocbase(
isolate, rt, TRI_V8_ASCII_STRING("write"), JS_WriteVulpes);
v8g->VulpesTempl.Reset(isolate, rt);
ft->SetClassName(TRI_V8_ASCII_STRING("ArangoVuplesCtor"));
TRI_AddGlobalFunctionVocbase(
isolate, context, TRI_V8_ASCII_STRING("ArangoVuplesCtor"),
ft->GetFunction(), true);
// register the global object
v8::Handle<v8::Object> aa = rt->NewInstance();
if (!aa.IsEmpty()) {
TRI_AddGlobalVariableVocbase(
isolate, context, TRI_V8_ASCII_STRING("ArangoVuples"), aa);
}
}

View File

@ -0,0 +1,37 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Kaveh Vahedipour
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOD_CLUSTER_V8_AGENCY_H
#define ARANGOD_CLUSTER_V8_AGENCY_H 1
#include "Basics/Common.h"
#include "v8.h"
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a global agency context
////////////////////////////////////////////////////////////////////////////////
void TRI_InitV8Agency(v8::Isolate* isolate, v8::Handle<v8::Context>);
#endif

View File

@ -95,6 +95,7 @@ add_executable(${BIN_ARANGOD}
Agency/State.cpp Agency/State.cpp
Agency/Store.cpp Agency/Store.cpp
Agency/StoreCallback.cpp Agency/StoreCallback.cpp
Agency/v8-agency.cpp
Aql/Aggregator.cpp Aql/Aggregator.cpp
Aql/AqlItemBlock.cpp Aql/AqlItemBlock.cpp
Aql/AqlItemBlockManager.cpp Aql/AqlItemBlockManager.cpp

View File

@ -49,7 +49,7 @@ function agencyTestSuite () {
var whoseTurn = 0; var whoseTurn = 0;
var request = require("@arangodb/request"); var request = require("@arangodb/request");
wait(2); wait(3.0);
function readAgency(list) { function readAgency(list) {
// We simply try all agency servers in turn until one gives us an HTTP // We simply try all agency servers in turn until one gives us an HTTP

View File

@ -35,6 +35,7 @@ TRI_v8_global_s::TRI_v8_global_s(v8::Isolate* isolate)
VPackTempl(), VPackTempl(),
VocbaseColTempl(), VocbaseColTempl(),
VocbaseTempl(), VocbaseTempl(),
VulpesTempl(),
BufferTempl(), BufferTempl(),

View File

@ -517,6 +517,12 @@ typedef struct TRI_v8_global_s {
v8::Persistent<v8::ObjectTemplate> VocbaseTempl; v8::Persistent<v8::ObjectTemplate> VocbaseTempl;
//////////////////////////////////////////////////////////////////////////////
/// @brief vulpes template
//////////////////////////////////////////////////////////////////////////////
v8::Persistent<v8::ObjectTemplate> VulpesTempl;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief TRI_vocbase_t template /// @brief TRI_vocbase_t template
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////