void tcp_manager::doRPC_tcp_connect_cb (RPC_delay_args *args, int fd) { hostinfo *hi = lookup_host (args->l->address ()); if (fd < 0) { warn << "locationtable: connect failed: " << strerror (errno) << "\n"; (args->cb) (RPC_CANTSEND); args->l->set_alive (false); remove_host (hi); delete args; } else { struct linger li; li.l_onoff = 1; li.l_linger = 0; setsockopt (fd, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (li)); tcp_nodelay (fd); make_async(fd); hi->fd = fd; hi->xp = axprt_stream::alloc (fd); assert (hi->xp); send_RPC (args); while (hi->connect_waiters.size ()) send_RPC (hi->connect_waiters.pop_front ()); } }
hostinfo * rpc_manager::lookup_host (const net_address &r) { str key = strbuf () << r.hostname << ":" << r.port << "\n"; hostinfo *h = hosts[key]; if (!h) { if (hosts.size () > max_host_cache) { hostinfo *o = hostlru.first; hostlru.remove (o); hosts.remove (o); remove_host (o); delete (o); } h = New hostinfo (r); h->key = key; hostlru.insert_tail (h); hosts.insert (h); } else { // record recent access hostlru.remove (h); hostlru.insert_tail (h); } assert (h); return h; }
void DCAwarePolicy::PerDCHostMap::remove_host_from_dc(const std::string& dc, const SharedRefPtr<Host>& host) { ScopedWriteLock wl(&rwlock_); Map::iterator i = map_.find(dc); if (i != map_.end()) { remove_host(i->second, host); } }
void DCAwarePolicy::on_remove(const SharedRefPtr<Host>& host) { const std::string& dc = host->dc(); if (dc == local_dc_) { remove_host(local_dc_live_hosts_, host); } else { per_remote_dc_live_hosts_.remove_host_from_dc(host->dc(), host); } }
JNIEXPORT void JNICALL Java_com_sun_netstorage_samqfs_mgmt_fs_Host_removeFromConfig(JNIEnv *env, jclass cls /*ARGSUSED*/, jobject ctx, jstring fsName, jstring hostName) { jboolean isCopy; /* used by string macros */ char *fstr = GET_STR(fsName, isCopy); char *hstr = GET_STR(hostName, isCopy); PTRACE(1, "jni:Host_removeFromConfig entry"); PTRACE(1, "jni:Removing host[%s] from fs[%s]", Str(hstr), Str(fstr)); if (-1 == remove_host(CTX, fstr, hstr)) { REL_STR(fsName, fstr, isCopy); REL_STR(hostName, hstr, isCopy); ThrowEx(env); return; } REL_STR(fsName, fstr, isCopy); REL_STR(hostName, hstr, isCopy); PTRACE(1, "jni:Host_removeFromConfig() done"); }
void tcp_manager::send_RPC (RPC_delay_args *args) { hostinfo *hi = lookup_host (args->l->address ()); if (!hi->xp) { delaycb (0, 0, wrap (this, &tcp_manager::send_RPC_ateofcb, args)); } else if (hi->xp->ateof()) { hostlru.remove (hi); hostlru.insert_tail (hi); args->l->set_alive (false); remove_host (hi); delaycb (0, 0, wrap (this, &tcp_manager::send_RPC_ateofcb, args)); } else { hi->orpc++; args->now = getusec (); ptr<aclnt> c = aclnt::alloc (hi->xp, args->prog); c->call (args->procno, args->in, args->out, wrap (this, &tcp_manager::doRPC_tcp_cleanup, c, args)); } }
void LatencyAwarePolicy::on_down(const Host::Ptr& host) { remove_host(hosts_, host); ChainedLoadBalancingPolicy::on_down(host); }
void Dispatcher::dispatch_requests(int id) { debug("Thread %i started", id); while (1) { // Get an request out of the request queue int socket; debug("Try to lock %d", id); { std::unique_lock<std::mutex> lck(request_queue_mutex); while (request_queue.empty()) { debug("Wait %d", id); request_queue_empty.wait(lck); }; socket = request_queue.front(); request_queue.pop(); debug("Unlock %d", id); } debug("New request: Handled by thread %i", id); // Allocates memory for the request struct HttpRequest *request; int http_error = http_receive_request(socket, &request); if (http_error != HTTP_SUCCESS) { debug("Invalid Http request."); assert(request == NULL); // TODO send error msg to client close(socket); continue; } debug("Request payload: %s", request->payload); if (strncmp(request->resource, "/add_node/", 10) == 0) { struct sockaddr addr; socklen_t addrlen = sizeof(struct sockaddr); if (getpeername(socket, &addr, &addrlen) == 0) { if (addr.sa_family == AF_INET || addr.sa_family == AF_UNSPEC) { struct sockaddr_in *sa = (struct sockaddr_in *)&addr; char ip[INET_ADDRSTRLEN]; if (inet_ntop(AF_INET, &(sa->sin_addr), ip, INET_ADDRSTRLEN) == NULL) { log_err("/add_node/ - Converting network address to string"); } int port = (int)strtol(request->resource+10, (char **)NULL, 10); if (port == 0) { log_err("/add_node/ - Detecting port"); } debug("Add host: %s:%i", ip, port); add_host(ip, port); } else { debug("Cannot add host: Unsupported Address family %d", addr.sa_family); } } else { log_err("/add_node/ - getpeername()"); } HttpRequest_free(request); close(socket); } else if (strncmp(request->resource, "/remove_node/", 13) == 0) { char *delimiter = strchr(request->resource, ':'); if (delimiter != NULL) { char *ip = strndup(request->resource + 13, delimiter - (request->resource + 13)); int port = 0; remove_host(ip, port); free(ip); } HttpRequest_free(request); close(socket); } else if (strcmp(request->resource, "/node_info") == 0) { sendNodeInfo(request, socket); HttpRequest_free(request); close(socket); } else if (strcmp(request->resource, "/query") == 0) { int query_t = queryType(request->payload); switch(query_t) { case READ: distributor->distribute(request, socket); break; case LOAD: sendToAll(request, socket); break; case WRITE: distributor->sendToMaster(request, socket); break; default: log_err("Invalid query: %s", request->payload); throw "Invalid query."; } } else if (strcmp(request->resource, "/procedure") == 0) { distributor->sendToMaster(request, socket); } else { log_err("Invalid HTTP resource: %s", request->resource); exit(1); } } }
void LatencyAwarePolicy::on_down(const SharedRefPtr<Host>& host) { remove_host(hosts_, host); ChainedLoadBalancingPolicy::on_down(host); }