int RemoteFileCopier::init(const std::string& uri, FileSystemAdaptor* fs, 
        SnapshotThrottle* throttle) {
    // Parse uri format: remote://ip:port/reader_id
    static const size_t prefix_size = strlen("remote://");
    butil::StringPiece uri_str(uri);
    if (!uri_str.starts_with("remote://")) {
        LOG(ERROR) << "Invalid uri=" << uri;
        return -1;
    }
    uri_str.remove_prefix(prefix_size);
    size_t slash_pos = uri_str.find('/');
    butil::StringPiece ip_and_port = uri_str.substr(0, slash_pos);
    uri_str.remove_prefix(slash_pos + 1);
    if (!butil::StringToInt64(uri_str, &_reader_id)) {
        LOG(ERROR) << "Invalid reader_id_format=" << uri_str
                   << " in " << uri;
        return -1;
    }
    if (_channel.Init(ip_and_port.as_string().c_str(), NULL) != 0) {
        LOG(ERROR) << "Fail to init Channel to " << ip_and_port;
        return -1;
    }
    _fs = fs;
    _throttle = throttle;
    return 0;
}
Example #2
0
static char *
get_uri(URI *uri) {
  size_t len;
  char *buffer;

  len = uri_str(uri, NULL, 0);
  if(len == (size_t) -1) return NULL;

  buffer = (char *) malloc(len);
  if(!buffer) return NULL;

  len = uri_str(uri, buffer, len);
  if(len == (size_t) -1) return NULL;

  return buffer;
}