Skip to content

Commit

Permalink
Fix for ES7
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Sep 20, 2019
1 parent eaae959 commit d623471
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion libraries/plugins/elasticsearch/elasticsearch_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class elasticsearch_plugin_impl
std::string bulk_line;
std::string index_name;
bool is_sync = false;
bool esge7 = false;
private:
bool add_elasticsearch( const account_id_type account_id, const optional<operation_history_object>& oho, const uint32_t block_number );
const account_transaction_history_object& addNewEntry(const account_statistics_object& stats_obj,
Expand Down Expand Up @@ -286,6 +287,7 @@ bool elasticsearch_plugin_impl::add_elasticsearch( const account_id_type account
const auto &stats_obj = getStatsObject(account_id);
const auto &ath = addNewEntry(stats_obj, account_id, oho);
growStats(stats_obj, ath);

if(block_number > _elasticsearch_start_es_after_block) {
createBulkLine(ath);
prepareBulk(ath.id);
Expand Down Expand Up @@ -354,7 +356,8 @@ void elasticsearch_plugin_impl::prepareBulk(const account_transaction_history_id
const std::string _id = fc::json::to_string(ath_id);
fc::mutable_variant_object bulk_header;
bulk_header["_index"] = index_name;
bulk_header["_type"] = "data";
if(!esge7)
bulk_header["_type"] = "data";
bulk_header["_id"] = fc::to_string(ath_id.space_id) + "." + fc::to_string(ath_id.type_id) + "."
+ fc::to_string(ath_id.instance.value);
prepare = graphene::utilities::createBulk(bulk_header, std::move(bulk_line));
Expand Down Expand Up @@ -513,6 +516,11 @@ void elasticsearch_plugin::plugin_startup()

if(!graphene::utilities::checkES(es))
FC_THROW_EXCEPTION(fc::exception, "ES database is not up in url ${url}", ("url", my->_elasticsearch_node_url));

const auto es_version = graphene::utilities::getVersion(es);
if(std::stoi(es_version.substr(0,1)) >= 7)
my->esge7 = true;

ilog("elasticsearch ACCOUNT HISTORY: plugin_startup() begin");
}

Expand Down
11 changes: 9 additions & 2 deletions libraries/plugins/es_objects/es_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class es_objects_plugin_impl

uint32_t block_number;
fc::time_point_sec block_time;
bool esge7 = false;

private:
template<typename T>
Expand Down Expand Up @@ -224,7 +225,8 @@ void es_objects_plugin_impl::remove_from_database( object_id_type id, std::strin
fc::mutable_variant_object delete_line;
delete_line["_id"] = string(id);
delete_line["_index"] = _es_objects_index_prefix + index;
delete_line["_type"] = "data";
if(!esge7)
delete_line["_type"] = "data";
fc::mutable_variant_object final_delete_line;
final_delete_line["delete"] = delete_line;
prepare.push_back(fc::json::to_string(final_delete_line));
Expand All @@ -238,7 +240,8 @@ void es_objects_plugin_impl::prepareTemplate(T blockchain_object, string index_n
{
fc::mutable_variant_object bulk_header;
bulk_header["_index"] = _es_objects_index_prefix + index_name;
bulk_header["_type"] = "data";
if(!esge7)
bulk_header["_type"] = "data";
if(_es_objects_keep_only_current)
{
bulk_header["_id"] = string(blockchain_object.id);
Expand Down Expand Up @@ -403,6 +406,10 @@ void es_objects_plugin::plugin_startup()
if(!graphene::utilities::checkES(es))
FC_THROW_EXCEPTION(fc::exception, "ES database is not up in url ${url}", ("url", my->_es_objects_elasticsearch_url));
ilog("elasticsearch OBJECTS: plugin_startup() begin");

const auto es_version = graphene::utilities::getVersion(es);
if(std::stoi(es_version.substr(0,1)) >= 7)
my->esge7 = true;
}

} }
14 changes: 14 additions & 0 deletions libraries/utilities/elasticsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ bool checkES(ES& es)
return true;

}

const std::string getVersion(ES& es)
{
graphene::utilities::CurlRequest curl_request;
curl_request.handler = es.curl;
curl_request.url = es.elasticsearch_url;
curl_request.auth = es.auth;
curl_request.type = "GET";

fc::variant response = fc::json::from_string(doCurl(curl_request));

return response["version"]["number"].as_string();
}

const std::string simpleQuery(ES& es)
{
graphene::utilities::CurlRequest curl_request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace graphene { namespace utilities {
bool SendBulk(ES&& es);
const std::vector<std::string> createBulk(const fc::mutable_variant_object& bulk_header, std::string&& data);
bool checkES(ES& es);
const std::string getVersion(ES& es);
const std::string simpleQuery(ES& es);
bool deleteAll(ES& es);
bool handleBulkResponse(long http_code, const std::string& CurlReadBuffer);
Expand Down

0 comments on commit d623471

Please sign in to comment.