std::string graph_serv::create_node(){ /* no lock here */ uint64_t nid = idgen_.generate(); std::string nid_str = pfi::lang::lexical_cast<std::string>(nid); if(not a_.is_standalone()){ // we dont need global locking, because getting unique id from zk // guarantees there'll be no data confliction { std::vector<std::pair<std::string, int> > nodes; find_from_cht(nid_str, 2, nodes); if(nodes.empty()){ throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("fatal: no server found in cht: "+nid_str)); } selective_create_node_(nodes[0], nid_str); for(size_t i = 1; i < nodes.size(); ++i){ try{ selective_create_node_(nodes[i], nid_str); }catch(const graph::local_node_exists& e){ // pass through }catch(const graph::global_node_exists& e){// pass through }catch(const std::runtime_error& e){ // error ! LOG(INFO) << i+1 << "th replica: " << nodes[i].first << ":" << nodes[i].second << " " << e.what(); } } } }else{ pfi::concurrent::scoped_lock lk(wlock(m_)); this->create_node_here(nid_str); } DLOG(INFO) << "new node created: " << nid_str; return nid_str; }
id_with_score anomaly_serv::add_zk(const string&id_str, const datum& d) { vector<pair<string, int> > nodes; float score = 0; find_from_cht(id_str, 2, nodes); if (nodes.empty()) { throw JUBATUS_EXCEPTION( core::common::membership_error("no server found in cht: " + argv().name)); } // this sequences MUST success, // in case of failures the whole request should be canceled DLOG(INFO) << "initial add request to " << nodes[0].first << ":" << nodes[0].second; try { score = selective_update(nodes[0].first, nodes[0].second, id_str, d); } catch (const std::runtime_error& e) { throw JUBATUS_EXCEPTION(core::common::exception::runtime_error( "failed to add ID " + id_str + " (" + e.what() + "): " + nodes[0].first + ":" + lexical_cast<string>(nodes[0].second))); } for (size_t i = 1; i < nodes.size(); ++i) { DLOG(INFO) << "replica add request to " << nodes[i].first << ":" << nodes[i].second; try { selective_update(nodes[i].first, nodes[i].second, id_str, d); } catch (const std::runtime_error& e) { LOG(WARNING) << "cannot create " << i << "th replica " << "(" << e.what() << "): " << nodes[i].first << ":" << nodes[i].second; } } DLOG(INFO) << "point added: " << id_str; return id_with_score(id_str, score); }
//@cht int graph_serv::create_edge(const std::string& id, const edge_info& ei) /* no lock here */ { edge_id_t eid = idgen_.generate(); //TODO: assert id==ei.src if(not a_.is_standalone()){ // we dont need global locking, because getting unique id from zk // guarantees there'll be no data confliction std::vector<std::pair<std::string, int> > nodes; find_from_cht(ei.src, 2, nodes); if(nodes.empty()){ throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("fatal: no server found in cht: "+ei.src)); } // TODO: assertion: nodes[0] should be myself { pfi::concurrent::scoped_lock lk(wlock(m_)); this->create_edge_here(eid, ei); } for(size_t i = 1; i < nodes.size(); ++i){ try{ if(nodes[i].first == a_.eth && nodes[i].second == a_.port){ }else{ client::graph c(nodes[i].first, nodes[i].second, 5.0); c.create_edge_here(a_.name, eid, ei); } }catch(const graph::local_node_exists& e){ // pass through }catch(const graph::global_node_exists& e){// pass through }catch(const std::runtime_error& e){ // error ! LOG(WARNING) << nodes[i].first << ":" << nodes[i].second << " " << e.what(); } } }else{ pfi::concurrent::scoped_lock lk(wlock(m_)); this->create_edge_here(eid, ei); } DLOG(INFO) << "edge created (" << eid << ") " << ei.src << " => " << ei.tgt; return eid; }