mirror of https://gitee.com/bigwinds/arangodb
Feature/small misc optimizations (#4504)
This commit is contained in:
parent
0eae1d225f
commit
b2ceb68205
|
@ -113,7 +113,7 @@ void Constituent::termNoLock(term_t t, std::string const& votedFor) {
|
|||
|
||||
if (tmp != t || tmpVotedFor != votedFor) {
|
||||
LOG_TOPIC(INFO, Logger::AGENCY) << _id << ": changing term or votedFor, "
|
||||
<< "current role:" << roleStr[_role] << " term " << t << " votedFor: "
|
||||
<< "current role: " << roleStr[_role] << " term " << t << " votedFor: "
|
||||
<< votedFor;
|
||||
|
||||
Builder body;
|
||||
|
|
|
@ -270,13 +270,12 @@ struct ClusterCommResult {
|
|||
dynamic_cast<HttpResponse*>(response.get())->body().c_str(),
|
||||
dynamic_cast<HttpResponse*>(response.get())->body().length(), std::unordered_map<std::string,std::string>());
|
||||
|
||||
auto headers = response->headers();
|
||||
auto const& headers = response->headers();
|
||||
auto errorCodes = headers.find(StaticStrings::ErrorCodes);
|
||||
if (errorCodes != headers.end()) {
|
||||
request->setHeader(StaticStrings::ErrorCodes, errorCodes->second);
|
||||
}
|
||||
request->setHeader("x-arango-response-code",
|
||||
GeneralResponse::responseString(answer_code));
|
||||
request->setHeader(StaticStrings::ResponseCode, GeneralResponse::responseString(answer_code));
|
||||
answer.reset(request);
|
||||
TRI_ASSERT(response != nullptr);
|
||||
result = std::make_shared<httpclient::SimpleHttpCommunicatorResult>(
|
||||
|
|
|
@ -285,7 +285,7 @@ static void mergeResultsAllShards(
|
|||
static void extractErrorCodes(ClusterCommResult const& res,
|
||||
std::unordered_map<int, size_t>& errorCounter,
|
||||
bool includeNotFound) {
|
||||
auto resultHeaders = res.answer->headers();
|
||||
auto const& resultHeaders = res.answer->headers();
|
||||
auto codes = resultHeaders.find(StaticStrings::ErrorCodes);
|
||||
if (codes != resultHeaders.end()) {
|
||||
auto parsedCodes = VPackParser::fromJson(codes->second);
|
||||
|
|
|
@ -105,7 +105,7 @@ void RestClusterHandler::handleCommandEndpoints() {
|
|||
// endpoint value, and can tell the following two cases apart:
|
||||
// - endpoint value is not empty: there is a leader, and it is known
|
||||
// - endpoint value is empty: leadership challenge is ongoing, current leader is unknown
|
||||
_response->setHeader(StaticStrings::LeaderEndpoint, "");
|
||||
_response->setHeaderNC(StaticStrings::LeaderEndpoint, "");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class MaintenanceHandler : public RestBaseHandler {
|
|||
}
|
||||
generateError(Result(TRI_ERROR_CLUSTER_NOT_LEADER));
|
||||
// return the endpoint of the actual leader
|
||||
_response->setHeader(StaticStrings::LeaderEndpoint, endpoint);
|
||||
_response->setHeaderNC(StaticStrings::LeaderEndpoint, endpoint);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class MaintenanceHandler : public RestBaseHandler {
|
|||
// intentionally do not set "Location" header, but use a custom header that
|
||||
// clients can inspect. if they find an empty endpoint, it means that there
|
||||
// is an ongoing leadership challenge
|
||||
_response->setHeader(StaticStrings::LeaderEndpoint, "");
|
||||
_response->setHeaderNC(StaticStrings::LeaderEndpoint, "");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ void RestCollectionHandler::handleCommandGet() {
|
|||
}
|
||||
if (found.ok()) {
|
||||
generateOk(rest::ResponseCode::OK, builder);
|
||||
_response->setHeader("location", _request->requestPath());
|
||||
_response->setHeaderNC(StaticStrings::Location, _request->requestPath());
|
||||
} else {
|
||||
generateError(found);
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ void RestCollectionHandler::handleCommandPut() {
|
|||
generateError(found);
|
||||
} else if (res.ok()) {
|
||||
generateOk(rest::ResponseCode::OK, builder);
|
||||
_response->setHeader("location", _request->requestPath());
|
||||
_response->setHeaderNC(StaticStrings::Location, _request->requestPath());
|
||||
} else {
|
||||
generateError(res);
|
||||
}
|
||||
|
|
|
@ -415,7 +415,7 @@ static v8::Handle<v8::Object> RequestCppToV8(v8::Isolate* isolate,
|
|||
|
||||
// copy header fields
|
||||
v8::Handle<v8::Object> headerFields = v8::Object::New(isolate);
|
||||
|
||||
// intentional copy, as we will modify the headers later
|
||||
auto headers = request->headers();
|
||||
|
||||
TRI_GET_GLOBAL_STRING(HeadersKey);
|
||||
|
@ -526,7 +526,7 @@ static v8::Handle<v8::Object> RequestCppToV8(v8::Isolate* isolate,
|
|||
TRI_GET_GLOBAL_STRING(ParametersKey);
|
||||
req->ForceSet(ParametersKey, valuesObject);
|
||||
|
||||
// copy cookie -- only for http protocl
|
||||
// copy cookie -- only for http protocol
|
||||
if (request->transportType() == Endpoint::TransportType::HTTP) { // FIXME
|
||||
v8::Handle<v8::Object> cookiesObject = v8::Object::New(isolate);
|
||||
|
||||
|
@ -591,8 +591,8 @@ static void ResponseV8ToCpp(v8::Isolate* isolate, TRI_v8_global_t const* v8g,
|
|||
break;
|
||||
|
||||
case Endpoint::TransportType::VST:
|
||||
response->setHeader(arangodb::StaticStrings::ContentTypeHeader,
|
||||
contentType);
|
||||
response->setHeaderNC(arangodb::StaticStrings::ContentTypeHeader,
|
||||
contentType);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ARANGOD_VOCBASE_METHODS_TRANSACTIONS_HANDLER_H
|
||||
#define ARANGOD_VOCBASW_METHODS_TRANSACTIONS_HANDLER_H 1
|
||||
#define ARANGOD_VOCBASE_METHODS_TRANSACTIONS_HANDLER_H 1
|
||||
|
||||
#include "Basics/ReadWriteLock.h"
|
||||
#include "Basics/Result.h"
|
||||
|
|
|
@ -117,6 +117,7 @@ std::string const StaticStrings::Location("location");
|
|||
std::string const StaticStrings::MultiPartContentType("multipart/form-data");
|
||||
std::string const StaticStrings::NoSniff("nosniff");
|
||||
std::string const StaticStrings::Origin("origin");
|
||||
std::string const StaticStrings::ResponseCode("x-arango-response-code");
|
||||
std::string const StaticStrings::Queue("x-arango-queue");
|
||||
std::string const StaticStrings::Server("server");
|
||||
std::string const StaticStrings::StartThread("x-arango-start-thread");
|
||||
|
|
|
@ -112,6 +112,7 @@ class StaticStrings {
|
|||
static std::string const MultiPartContentType;
|
||||
static std::string const NoSniff;
|
||||
static std::string const Origin;
|
||||
static std::string const ResponseCode;
|
||||
static std::string const Queue;
|
||||
static std::string const Server;
|
||||
static std::string const StartThread;
|
||||
|
|
|
@ -433,7 +433,6 @@ rest::ResponseCode GeneralResponse::responseCode(int code) {
|
|||
|
||||
GeneralResponse::GeneralResponse(ResponseCode responseCode)
|
||||
: _responseCode(responseCode),
|
||||
_headers(),
|
||||
_contentType(ContentType::UNSET),
|
||||
_connectionType(ConnectionType::C_NONE),
|
||||
_options(velocypack::Options::Defaults),
|
||||
|
|
|
@ -104,7 +104,7 @@ class GeneralResponse {
|
|||
_headers = std::move(headers);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> headers() const {
|
||||
std::unordered_map<std::string, std::string> const& headers() const {
|
||||
return _headers;
|
||||
}
|
||||
|
||||
|
@ -155,10 +155,10 @@ class GeneralResponse {
|
|||
bool resolveExternals = true) = 0;
|
||||
|
||||
virtual int reservePayload(std::size_t size) { return TRI_ERROR_NO_ERROR; }
|
||||
bool generateBody() const { return _generateBody; }; // used for head
|
||||
bool generateBody() const { return _generateBody; } // used for head
|
||||
virtual bool setGenerateBody(bool) {
|
||||
return _generateBody;
|
||||
}; // used for head
|
||||
} // used for head
|
||||
// resonses
|
||||
void setOptions(VPackOptions options) { _options = std::move(options); };
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ class RestBatchHandler;
|
|||
namespace rest {
|
||||
class GeneralCommTask;
|
||||
class HttpCommTask;
|
||||
class HttpsCommTask;
|
||||
}
|
||||
|
||||
namespace velocypack {
|
||||
|
@ -44,7 +43,6 @@ struct Options;
|
|||
|
||||
class HttpRequest final : public GeneralRequest {
|
||||
friend class rest::HttpCommTask;
|
||||
friend class rest::HttpsCommTask;
|
||||
friend class rest::GeneralCommTask;
|
||||
friend class RestBatchHandler; // TODO must be removed
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ void HttpResponse::writeHeader(StringBuffer* output) {
|
|||
|
||||
// add "Server" response header
|
||||
if (!seenServerHeader && !HIDE_PRODUCT_HEADER) {
|
||||
output->appendText("Server: ArangoDB\r\n");
|
||||
output->appendText(TRI_CHAR_LENGTH_PAIR("Server: ArangoDB\r\n"));
|
||||
}
|
||||
|
||||
// add "Connection" response header
|
||||
|
|
|
@ -63,7 +63,6 @@ VstRequest::VstRequest(ConnectionInfo const& connectionInfo,
|
|||
VstInputMessage&& message, uint64_t messageId, bool isFake)
|
||||
: GeneralRequest(connectionInfo),
|
||||
_message(std::move(message)),
|
||||
_headers(nullptr),
|
||||
_messageId(messageId) {
|
||||
_protocol = "vst";
|
||||
_contentType = ContentType::VPACK;
|
||||
|
|
|
@ -72,7 +72,7 @@ class SimpleHttpCommunicatorResult: public SimpleHttpResult {
|
|||
throw std::runtime_error(message);
|
||||
}
|
||||
virtual std::string getHeaderField(std::string const& header, bool& found) const override {
|
||||
auto headers = _response->headers();
|
||||
auto const& headers = _response->headers();
|
||||
auto it = headers.find(header);
|
||||
if (it == headers.end()) {
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue