示例#1
0
/** Send a Fetch task to a target worker.
 * @param to a worker that will receive a split
 * @param from a worker that will send a split
 * @param name a name of a split that will be sent
 * @param size the size of a split that will be sent
 * @param id id of this task (generally 0)
 * @param uid id of this fetch task.
 * @param parentid parent id of this task
 * @return NULL
 */
static void dispatch_fetch(WorkerInfo *to, const ServerInfo &from,
                           const string &name, size_t size, 
                           ::uint64_t id, ::uint64_t uid) {
  FetchRequest req;
  req.set_name(name);
  req.mutable_location()->CopyFrom(from);
  req.set_size(size);
  req.set_id(id);
  req.set_uid(uid);

  to->Fetch(req);
  LOG_DEBUG("FETCH TaskID %16d - Sent to Worker %s", static_cast<int>(uid), to->hostname().c_str());
}
示例#2
0
/** Fetch a split from remote worker and keep it in the shared memory region
 * @param dest a memory pointer where the split will be written (usually shared mem)
 * @param name a name of split to fetch
 * @param size the size of split to fetch
 * @param client a worker information from where we will fetch the split
 * @param myhostname a name of worker who initiate the transfer request
 * @param store a location other than dram where the split will be written. It can be zero-length
 * @return return code from server
 */
int32_t TransferServer::transfer_blob(void *dest, const string &name,
                                      size_t size, WorkerInfo* client,
                                      const string& myhostname,
                                      const string &store) {
  // Setup the transfer
  this->dest_ = dest;
  this->size_ = size;
  bytes_fetched_ = 0;

  // Initialize semaphore to zero. Server thread will increment
  // when it is ready
  sem_init(&server_ready, 0, 0);

  // Setup a receicing thread.
  // Later, we will send a Fetch request,
  // and the data will arrive to this thread
  pthread_t server_thread;
  pthread_create(&server_thread, 0, transfer_pthread, this);

  // fprintf(stderr,
  //   "Waiting for server to be ready for transfer array %s from %s\n",
  //   a.name.c_str(), a.location.name.c_str());
  // Wait till server is ready
  sem_wait(&server_ready);

  // FIXME(shivaram): This doesn't work on bfc machines
  // char hostname[64]; // HOST_NAME_MAX is 64 in Linux
  // int ret = gethostname(hostname, 64);
  // if (ret < 0) {
  //   return ret;
  // }

  // Information of the requester
  ServerInfo location;
  location.set_name(myhostname);
  location.set_presto_port(server_socket_port);
  // Create a fetch request
  FetchRequest req;
  req.mutable_location()->CopyFrom(location);
  req.set_size(size);
  req.set_name(name);
  if (!store.empty()) {
    req.set_store(store);
  }

  client->NewTransfer(req);  // request transfer to remote workers

  void* server_ret;
  pthread_join(server_thread, &server_ret);
  sem_destroy(&server_ready);
  return *reinterpret_cast<int32_t*>(server_ret);

  // TODO(erik): error handling

// } else {
//     // Cancel the server thread if transfer failed.
//     // TODO(shivaram): Check if this behaves correctly or use signals.
//     fprintf(stderr, "Transfer failed, cancelling server\n");
//     sem_destroy(&server_ready);
//     pthread_cancel(server_thread);
//     shutdown(serverfd, SHUT_RDWR);
//     close(serverfd);
//     return -1;
//   }
}