Exemplo n.º 1
0
Value::Value(int protocol_version,
             const SharedRefPtr<const DataType>& data_type,
             char* data, int32_t size)
  : protocol_version_(protocol_version)
  , data_type_(data_type) {
  if (size > 0 && data_type->is_collection()) {
    data_ = decode_size(protocol_version, data, count_);
    if (protocol_version_ >= 3) {
      size_ = size - sizeof(int32_t);
    } else {
      size_ = size - sizeof(uint16_t);
    }
  } else {
    if (data_type->is_tuple()) {
      SharedRefPtr<const SubTypesDataType> sub_types(data_type);
      count_ = sub_types->types().size();
    } else if (data_type->is_user_type()) {
      SharedRefPtr<const UserType> user_type(data_type);
      count_ = user_type->fields().size();
    } else {
      count_ = 0;
    }
    data_ = data;
    size_ = size;
  }
}
Exemplo n.º 2
0
SharedRefPtr<Host> LatencyAwarePolicy::LatencyAwareQueryPlan::compute_next() {
    int64_t min = policy_->min_average_.load();
    const Settings& settings = policy_->settings_;
    uint64_t now = uv_hrtime();

    SharedRefPtr<Host> host;
    while ((host = child_plan_->compute_next())) {
        TimestampedAverage latency = host->get_current_average();

        if (min < 0 ||
                latency.average < 0 ||
                latency.num_measured < settings.min_measured ||
                (now - latency.timestamp) > settings.retry_period_ns) {
            return host;
        }

        if (latency.average <= static_cast<int64_t>(settings.exclusion_threshold * min)) {
            return host;
        }

        skipped_.push_back(host);
    }

    if (skipped_index_ < skipped_.size()) {
        return skipped_[skipped_index_++];
    }

    return SharedRefPtr<Host>();
}
Exemplo n.º 3
0
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);
  }
}
Exemplo n.º 4
0
void Session::on_remove(SharedRefPtr<Host> host) {
  load_balancing_policy_->on_remove(host);
  { // Lock hosts
    ScopedMutex l(&hosts_mutex_);
    hosts_.erase(host->address());
  }
  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->remove_pool_async(host->address(), true);
  }
}
Exemplo n.º 5
0
void DCAwarePolicy::init(const SharedRefPtr<Host>& connected_host, const HostMap& hosts) {
  if (local_dc_.empty() && !connected_host->dc().empty()) {
    LOG_INFO("Using '%s' for the local data center "
             "(if this is incorrect, please provide the correct data center)",
             connected_host->dc().c_str());
    local_dc_ = connected_host->dc();
  }

  for (HostMap::const_iterator i = hosts.begin(),
       end = hosts.end(); i != end; ++i) {
    on_add(i->second);
  }
}
Exemplo n.º 6
0
void Session::on_up(SharedRefPtr<Host> host) {
  host->set_up();

  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    return;
  }

  load_balancing_policy_->on_up(host);

  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->add_pool_async(host->address(), false);
  }
}
Exemplo n.º 7
0
void DCAwarePolicy::on_add(const SharedRefPtr<Host>& host) {
  const std::string& dc = host->dc();
  if (local_dc_.empty() && !dc.empty()) {
    LOG_INFO("Using '%s' for local data center "
             "(if this is incorrect, please provide the correct data center)",
             host->dc().c_str());
    local_dc_ = dc;
  }

  if (dc == local_dc_) {
    local_dc_live_hosts_->push_back(host);
  } else {
    per_remote_dc_live_hosts_.add_host_to_dc(dc, host);
  }
}
Exemplo n.º 8
0
CassHostDistance DCAwarePolicy::distance(const SharedRefPtr<Host>& host) const {
  if (local_dc_.empty() || host->dc() == local_dc_) {
    return CASS_HOST_DISTANCE_LOCAL;
  }

  const CopyOnWriteHostVec& hosts = per_remote_dc_live_hosts_.get_hosts(host->dc());
  size_t num_hosts = std::min(hosts->size(), used_hosts_per_remote_dc_);
  for (size_t i = 0; i < num_hosts; ++i) {
    if ((*hosts)[i]->address() == host->address()) {
      return CASS_HOST_DISTANCE_REMOTE;
    }
  }

  return CASS_HOST_DISTANCE_IGNORE;
}
Exemplo n.º 9
0
void Session::on_down(SharedRefPtr<Host> host) {
  host->set_down();
  load_balancing_policy_->on_down(host);

  bool cancel_reconnect = false;
  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    // This permanently removes a host from all IO workers by stopping
    // any attempt to reconnect to that host.
    cancel_reconnect = true;
  }
  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->remove_pool_async(host->address(), cancel_reconnect);
  }
}
Exemplo n.º 10
0
void Session::on_add(SharedRefPtr<Host> host, bool is_initial_connection) {
  host->set_up();

  if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
    return;
  }

  if (is_initial_connection) {
    pending_pool_count_ += io_workers_.size();
  } else {
    load_balancing_policy_->on_add(host);
  }

  for (IOWorkerVec::iterator it = io_workers_.begin(),
       end = io_workers_.end(); it != end; ++it) {
    (*it)->add_pool_async(host->address(), is_initial_connection);
  }
}
Exemplo n.º 11
0
SharedRefPtr<Host> TokenAwarePolicy::TokenAwareQueryPlan::compute_next()  {
  while (remaining_ > 0) {
    --remaining_;
    const SharedRefPtr<Host>& host((*replicas_)[index_++ % replicas_->size()]);
    if (host->is_up() && child_policy_->distance(host) == CASS_HOST_DISTANCE_LOCAL) {
      return host;
    }
  }

  SharedRefPtr<Host> host;
  while ((host = child_plan_->compute_next())) {
    if (!contains(replicas_, host->address()) ||
        child_policy_->distance(host) != CASS_HOST_DISTANCE_LOCAL) {
      return host;
    }
  }
  return SharedRefPtr<Host>();
}
Exemplo n.º 12
0
bool BlacklistDCPolicy::is_valid_host(const SharedRefPtr<Host>& host) const {
    const std::string& host_dc = host->dc();
    for (DcList::const_iterator it = dcs_.begin(),
            end = dcs_.end(); it != end; ++it) {
        if (host_dc.compare(*it) == 0) {
            return false;
        }
    }
    return true;
}
Exemplo n.º 13
0
bool BlacklistPolicy::is_valid_host(const SharedRefPtr<Host>& host) const {
  const std::string& host_address = host->address().to_string(false);
  for (ContactPointList::const_iterator it = hosts_.begin(),
                                                end = hosts_.end();
       it != end; ++it) {
    if (host_address.compare(*it) == 0) {
      return false;
    }
  }
  return true;
}
Exemplo n.º 14
0
void HostTargetingPolicy::on_down(const SharedRefPtr<Host>& host) {
  available_hosts_.erase(host->address());
  ChainedLoadBalancingPolicy::on_down(host);
}
Exemplo n.º 15
0
void HostTargetingPolicy::on_up(const SharedRefPtr<Host>& host) {
  available_hosts_[host->address()] = host;
  ChainedLoadBalancingPolicy::on_up(host);
}
Exemplo n.º 16
0
 UserTypeValue(const SharedRefPtr<const UserType>& data_type)
   : AbstractData(data_type->fields().size())
   , data_type_(data_type) { }
Exemplo n.º 17
0
void LatencyAwarePolicy::on_add(const SharedRefPtr<Host>& host) {
    host->enable_latency_tracking(settings_.scale_ns, settings_.min_measured);
    add_host(hosts_, host);
    ChainedLoadBalancingPolicy::on_add(host);
}