#include <iostream>
|
#include <unistd.h>
|
#include <sys/time.h>
|
#include <vector>
|
#include <boost/interprocess/shared_memory_object.hpp>
|
#include <boost/interprocess/mapped_region.hpp>
|
|
#include <jsoncpp/json/json.h>
|
#include <SemTool.h>
|
#include <basic/util/app/AppConfig.h>
|
#include <basic/debug/Debug.h>
|
|
#include "ErlangDbTool.h"
|
#include "ShareMemoryTool.hpp"
|
|
using namespace std;
|
|
//#erl -name b@192.168.1.164 -setcookie abc -mnesia dir '"/home/firefly/erlang"' -detached -noshell
|
int main(int argc, char **argv) {
|
std::cout << "Hello, World!" << std::endl;
|
ENABLEGLOG(GET_STR_CONFIG("logPath").c_str());
|
|
if (argc <= 1) {
|
ERR("argc size is err");
|
exit(-1);
|
}
|
|
string str_json(argv[1]);
|
// cout << str_json << endl;
|
// string str_json = "{\"path\":\"/opt/erlang/sub1/\",\"nodeName\":\"sub1@192.168.1.186\",\"cookie\":\"abc\",\"tableName\":\"test\"}";
|
|
Json::Value t_json;
|
Json::Reader reader;
|
|
if (!reader.parse(str_json, t_json)) {
|
ERR("json format error :: " << str_json);
|
return -1;
|
}
|
|
int loop = 0;
|
|
std::string path = t_json["path"].asString();//"/opt/erlang/za/";
|
std::string nodeName = t_json["nodeName"].asString();//"za@192.168.188.128";
|
std::string cookie = t_json["cookie"].asString();//"abc";
|
std::string tableName = t_json["tableName"].asString();
|
|
// SemTool semTool(t_json["key"].asInt());
|
//
|
// semTool.semaphore_p();
|
|
|
/***
|
* jiazai renlian
|
*/
|
// struct timeval t1, t2;
|
// gettimeofday(&t1, NULL);
|
|
|
std::string str_node("testNode");
|
str_node.append(to_string((int) getpid()));
|
ErlangTool::ErlangDbTool erlangDbTool(nodeName, cookie, str_node);
|
while (1) {
|
/***
|
* load fea
|
*/
|
|
auto cache = erlangDbTool.loadFaceFeaData(tableName);
|
|
// gettimeofday(&t2, NULL);
|
//那么函数f运行所花的时间为
|
// auto deltaT = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;
|
// DBG(" loadData " << deltaT << "us")
|
// DBG(tableName << "size is " << cache.size() << " " << loop);
|
if (cache.size() <= 0 && loop++ <= 10) {
|
usleep(100);
|
continue;
|
}
|
auto size = sizeof(cache[0]) * cache.size();
|
try {
|
BISTL::shared_memory_object::remove(tableName.c_str());
|
BISTL::BiMapFeaData biMapFeaData(tableName, size);
|
for (auto &item :cache) {
|
biMapFeaData.saveKeyOrValue(item.second.id, item.second.feature, item.second.img, item.second.idcard,
|
item.second.create_by, item.second.create_time, item.second.update_time);
|
}
|
auto mymap = biMapFeaData.getMap();
|
// for (auto it = mymap->begin(); it != mymap->end(); it++) {
|
// std::cout << "feature " << it->second.m_feature << std::endl;
|
// }
|
DBG("load ok " << tableName << "mymap size is " << mymap->size());
|
}
|
catch (const std::exception &e) {
|
printf("Exception:%s\n", e.what());
|
BISTL::shared_memory_object::remove(tableName.c_str());
|
}
|
break;
|
}
|
|
return 0;
|
}
|