Skip to content

Commit

Permalink
monotime: remove granularity argument
Browse files Browse the repository at this point in the history
In practice, we almost never used the 'COARSE' granularity.
Instead, it just added an extra crufty argument to hundreds of call
sites.

Let's remove it for now so that the API is a little simpler. If we ever
have a perf-sensitive use case where COARSE makes sense, we can revive
this.

monotime.h is part of the public-facing client API, but MonoTime isn't
used in any public-facing methods. So, I think it's safe to remove the
argument without considering this a breaking change.

Change-Id: If1d375d54e8598105f3ec833c37d96a382c1a8f7
Reviewed-on: http://gerrit.cloudera.org:8080/3966
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Adar Dembo <[email protected]>
  • Loading branch information
toddlipcon committed Aug 14, 2016
1 parent 9d897e6 commit ea81e05
Show file tree
Hide file tree
Showing 88 changed files with 293 additions and 320 deletions.
2 changes: 1 addition & 1 deletion src/kudu/client/batcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ MonoTime Batcher::ComputeDeadlineUnlocked() const {
<< GetStackTrace();
timeout = MonoDelta::FromSeconds(60);
}
MonoTime ret = MonoTime::Now(MonoTime::FINE);
MonoTime ret = MonoTime::Now();
ret.AddDelta(timeout);
return ret;
}
Expand Down
10 changes: 5 additions & 5 deletions src/kudu/client/client-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Status RetryFunc(const MonoTime& deadline,
const boost::function<Status(const MonoTime&, bool*)>& func) {
DCHECK(deadline.Initialized());

MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
if (deadline.ComesBefore(now)) {
return Status::TimedOut(timeout_msg);
}
Expand All @@ -104,7 +104,7 @@ Status RetryFunc(const MonoTime& deadline,
if (!retry) {
return s;
}
now = MonoTime::Now(MonoTime::FINE);
now = MonoTime::Now();
MonoDelta func_time = now.GetDeltaSince(func_stime);

VLOG(1) << retry_msg << " status=" << s.ToString();
Expand All @@ -124,7 +124,7 @@ Status RetryFunc(const MonoTime& deadline,
VLOG(1) << "Waiting for " << HumanReadableElapsedTime::ToShortString(wait_secs)
<< " before retrying...";
SleepFor(MonoDelta::FromSeconds(wait_secs));
now = MonoTime::Now(MonoTime::FINE);
now = MonoTime::Now();

}

Expand Down Expand Up @@ -154,7 +154,7 @@ Status KuduClient::Data::SyncLeaderMasterRpc(
}

// Have we already exceeded our deadline?
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
if (deadline.ComesBefore(now)) {
return Status::TimedOut(Substitute("$0 timed out after deadline expired",
func_name));
Expand Down Expand Up @@ -199,7 +199,7 @@ Status KuduClient::Data::SyncLeaderMasterRpc(
}

if (s.IsTimedOut()) {
if (MonoTime::Now(MonoTime::FINE).ComesBefore(deadline)) {
if (MonoTime::Now().ComesBefore(deadline)) {
LOG(WARNING) << "Unable to send the request (" << req.ShortDebugString()
<< ") to leader Master (" << leader_master_hostport().ToString()
<< "): " << s.ToString();
Expand Down
2 changes: 1 addition & 1 deletion src/kudu/client/client-unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Status TestFunc(const MonoTime& deadline, bool* retry, int* counter) {
} // anonymous namespace

TEST(ClientUnitTest, TestRetryFunc) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(MonoDelta::FromMilliseconds(100));
int counter = 0;
Status s = RetryFunc(deadline, "retrying test func", "timed out",
Expand Down
26 changes: 13 additions & 13 deletions src/kudu/client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Status KuduClientBuilder::Build(shared_ptr<KuduClient>* client) {

// Let's allow for plenty of time for discovering the master the first
// time around.
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(c->default_admin_operation_timeout());
RETURN_NOT_OK_PREPEND(c->data_->SetMasterServerProxy(c.get(), deadline),
"Could not locate the leader master");
Expand Down Expand Up @@ -263,13 +263,13 @@ KuduTableCreator* KuduClient::NewTableCreator() {

Status KuduClient::IsCreateTableInProgress(const string& table_name,
bool *create_in_progress) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
return data_->IsCreateTableInProgress(this, table_name, deadline, create_in_progress);
}

Status KuduClient::DeleteTable(const string& table_name) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
return data_->DeleteTable(this, table_name, deadline);
}
Expand All @@ -280,14 +280,14 @@ KuduTableAlterer* KuduClient::NewTableAlterer(const string& name) {

Status KuduClient::IsAlterTableInProgress(const string& table_name,
bool *alter_in_progress) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
return data_->IsAlterTableInProgress(this, table_name, deadline, alter_in_progress);
}

Status KuduClient::GetTableSchema(const string& table_name,
KuduSchema* schema) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
string table_id_ignored;
PartitionSchema partition_schema;
Expand All @@ -303,7 +303,7 @@ Status KuduClient::ListTabletServers(vector<KuduTabletServer*>* tablet_servers)
ListTabletServersRequestPB req;
ListTabletServersResponsePB resp;

MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
Status s =
data_->SyncLeaderMasterRpc<ListTabletServersRequestPB, ListTabletServersResponsePB>(
Expand Down Expand Up @@ -336,7 +336,7 @@ Status KuduClient::ListTables(vector<string>* tables,
if (!filter.empty()) {
req.set_name_filter(filter);
}
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
Status s =
data_->SyncLeaderMasterRpc<ListTablesRequestPB, ListTablesResponsePB>(
Expand Down Expand Up @@ -375,7 +375,7 @@ Status KuduClient::OpenTable(const string& table_name,
KuduSchema schema;
string table_id;
PartitionSchema partition_schema;
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(default_admin_operation_timeout());
RETURN_NOT_OK(data_->GetTableSchema(this,
table_name,
Expand Down Expand Up @@ -546,7 +546,7 @@ Status KuduTableCreator::Create() {

req.mutable_partition_schema()->CopyFrom(data_->partition_schema_);

MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
if (data_->timeout_.Initialized()) {
deadline.AddDelta(data_->timeout_);
} else {
Expand Down Expand Up @@ -910,7 +910,7 @@ Status KuduTableAlterer::Alter() {
MonoDelta timeout = data_->timeout_.Initialized() ?
data_->timeout_ :
data_->client_->default_admin_operation_timeout();
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(timeout);
RETURN_NOT_OK(data_->client_->data_->AlterTable(data_->client_, req, deadline,
data_->has_alter_partitioning_steps));
Expand Down Expand Up @@ -1130,7 +1130,7 @@ Status KuduScanner::Open() {

VLOG(1) << "Beginning scan " << ToString();

MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(data_->configuration().timeout());
set<string> blacklist;

Expand Down Expand Up @@ -1210,7 +1210,7 @@ Status KuduScanner::NextBatch(KuduScanBatch* batch) {
// More data is available in this tablet.
VLOG(1) << "Continuing scan " << ToString();

MonoTime batch_deadline = MonoTime::Now(MonoTime::FINE);
MonoTime batch_deadline = MonoTime::Now();
batch_deadline.AddDelta(data_->configuration().timeout());
data_->PrepareRequest(KuduScanner::Data::CONTINUE);

Expand Down Expand Up @@ -1258,7 +1258,7 @@ Status KuduScanner::NextBatch(KuduScanBatch* batch) {
// server closed it for us.
VLOG(1) << "Scanning next tablet " << ToString();
data_->last_primary_key_.clear();
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(data_->configuration().timeout());
set<string> blacklist;

Expand Down
10 changes: 5 additions & 5 deletions src/kudu/client/meta_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ bool MetaCacheEntry::Contains(const string& partition_key) const {

bool MetaCacheEntry::stale() const {
DCHECK(Initialized());
return expiration_time_.ComesBefore(MonoTime::Now(MonoTime::FINE)) ||
return expiration_time_.ComesBefore(MonoTime::Now()) ||
(!is_non_covered_range() && tablet_->stale());
}

Expand All @@ -311,7 +311,7 @@ string MetaCacheEntry::DebugString(const KuduTable* table) const {
string upper_bound_string = upper_bound.empty() ? "<end>" :
table->partition_schema().PartitionKeyDebugString(upper_bound, *table->schema().schema_);

MonoDelta ttl = expiration_time_.GetDeltaSince(MonoTime::Now(MonoTime::FINE));
MonoDelta ttl = expiration_time_.GetDeltaSince(MonoTime::Now());

if (is_non_covered_range()) {
return strings::Substitute(
Expand Down Expand Up @@ -645,7 +645,7 @@ void LookupRpc::SendRpc() {
// some additional tablets.

// See KuduClient::Data::SyncLeaderMasterRpc().
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
if (retrier().deadline().ComesBefore(now)) {
SendRpcCb(Status::TimedOut("timed out after deadline expired"));
return;
Expand Down Expand Up @@ -718,7 +718,7 @@ void LookupRpc::SendRpcCb(const Status& status) {

// Check for more generic errors (TimedOut can come from multiple places).
if (new_status.IsTimedOut()) {
if (MonoTime::Now(MonoTime::FINE).ComesBefore(retrier().deadline())) {
if (MonoTime::Now().ComesBefore(retrier().deadline())) {
if (meta_cache_->client_->IsMultiMaster()) {
LOG(WARNING) << "Leader Master timed out, re-trying...";
ResetMasterLeaderAndRetry();
Expand Down Expand Up @@ -770,7 +770,7 @@ Status MetaCache::ProcessLookupResponse(const LookupRpc& rpc,
VLOG(2) << "Processing master response for " << rpc.ToString()
<< ". Response: " << rpc.resp().ShortDebugString();

MonoTime expiration_time = MonoTime::Now(MonoTime::FINE);
MonoTime expiration_time = MonoTime::Now();
expiration_time.AddDelta(MonoDelta::FromMilliseconds(rpc.resp().ttl_millis()));

std::lock_guard<rw_spinlock> l(lock_);
Expand Down
2 changes: 1 addition & 1 deletion src/kudu/client/scan_token-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Status KuduScanTokenBuilder::Data::Build(vector<KuduScanToken*>* tokens) {
pb.set_cache_blocks(configuration_.spec().cache_blocks());
pb.set_fault_tolerant(configuration_.is_fault_tolerant());

MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(client->default_admin_operation_timeout());

PartitionPruner pruner;
Expand Down
6 changes: 3 additions & 3 deletions src/kudu/client/scanner-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Status KuduScanner::Data::HandleError(const ScanRpcStatus& err,
if (backoff) {
MonoDelta sleep =
KuduClient::Data::ComputeExponentialBackoff(scan_attempts_);
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
now.AddDelta(sleep);
if (deadline.ComesBefore(now)) {
Status ret = Status::TimedOut("unable to retry before timeout",
Expand Down Expand Up @@ -231,7 +231,7 @@ ScanRpcStatus KuduScanner::Data::SendScanRpc(const MonoTime& overall_deadline,
// if the first server we try happens to be hung.
MonoTime rpc_deadline;
if (allow_time_for_failover) {
rpc_deadline = MonoTime::Now(MonoTime::FINE);
rpc_deadline = MonoTime::Now();
rpc_deadline.AddDelta(table_->client()->default_rpc_timeout());
rpc_deadline = MonoTime::Earliest(overall_deadline, rpc_deadline);
} else {
Expand Down Expand Up @@ -354,7 +354,7 @@ Status KuduScanner::Data::OpenTablet(const string& partition_key,
// it's likely that the tablet is undergoing a leader election and will
// soon have one.
if (lookup_status.IsServiceUnavailable() &&
MonoTime::Now(MonoTime::FINE).ComesBefore(deadline)) {
MonoTime::Now().ComesBefore(deadline)) {

// ServiceUnavailable means that we have already blacklisted all of the candidate
// tablet servers. So, we clear the list so that we will cycle through them all
Expand Down
4 changes: 2 additions & 2 deletions src/kudu/consensus/consensus_peers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Status SetPermanentUuidForRemotePeer(const shared_ptr<Messenger>& messenger,
// TODO generalize this exponential backoff algorithm, as we do the
// same thing in catalog_manager.cc
// (AsyncTabletRequestTask::RpcCallBack).
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(MonoDelta::FromMilliseconds(FLAGS_raft_get_node_instance_timeout_ms));
int attempt = 1;
while (true) {
Expand All @@ -465,7 +465,7 @@ Status SetPermanentUuidForRemotePeer(const shared_ptr<Messenger>& messenger,

LOG(WARNING) << "Error getting permanent uuid from config peer " << hostport.ToString() << ": "
<< s.ToString();
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
if (now.ComesBefore(deadline)) {
int64_t remaining_ms = deadline.GetDeltaSince(now).ToMilliseconds();
int64_t base_delay_ms = 1 << (attempt + 3); // 1st retry delayed 2^4 ms, 2nd 2^5, etc..
Expand Down
8 changes: 4 additions & 4 deletions src/kudu/consensus/consensus_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void PeerMessageQueue::SetLeaderMode(const OpId& committed_index,

// Reset last communication time with all peers to reset the clock on the
// failure timeout.
MonoTime now(MonoTime::Now(MonoTime::FINE));
MonoTime now(MonoTime::Now());
for (const PeersMap::value_type& entry : peers_map_) {
entry.second->last_successful_communication_time = now;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ Status PeerMessageQueue::RequestForPeer(const string& uuid,
}

MonoDelta unreachable_time =
MonoTime::Now(MonoTime::FINE).GetDeltaSince(peer->last_successful_communication_time);
MonoTime::Now().GetDeltaSince(peer->last_successful_communication_time);
if (unreachable_time.ToSeconds() > FLAGS_follower_unavailable_considered_failed_sec) {
if (CountVoters(*queue_state_.active_config) > 2) {
// We never drop from 2 to 1 automatically, at least for now. We may want
Expand Down Expand Up @@ -470,7 +470,7 @@ void PeerMessageQueue::NotifyPeerIsResponsiveDespiteError(const std::string& pee
std::lock_guard<simple_spinlock> l(queue_lock_);
TrackedPeer* peer = FindPtrOrNull(peers_map_, peer_uuid);
if (!peer) return;
peer->last_successful_communication_time = MonoTime::Now(MonoTime::FINE);
peer->last_successful_communication_time = MonoTime::Now();
}

void PeerMessageQueue::ResponseFromPeer(const std::string& peer_uuid,
Expand Down Expand Up @@ -531,7 +531,7 @@ void PeerMessageQueue::ResponseFromPeer(const std::string& peer_uuid,
// Update the peer status based on the response.
peer->is_new = false;
peer->last_known_committed_idx = status.last_committed_idx();
peer->last_successful_communication_time = MonoTime::Now(MonoTime::FINE);
peer->last_successful_communication_time = MonoTime::Now();

// If the reported last-received op for the replica is in our local log,
// then resume sending entries from that point onward. Otherwise, resume
Expand Down
2 changes: 1 addition & 1 deletion src/kudu/consensus/consensus_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PeerMessageQueue {
last_received(MinimumOpId()),
last_known_committed_idx(MinimumOpId().index()),
is_last_exchange_successful(false),
last_successful_communication_time(MonoTime::Now(MonoTime::FINE)),
last_successful_communication_time(MonoTime::Now()),
needs_tablet_copy(false),
last_seen_term_(0) {}

Expand Down
4 changes: 2 additions & 2 deletions src/kudu/consensus/log_anchor_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ size_t LogAnchorRegistry::GetAnchorCountForTests() const {
std::string LogAnchorRegistry::DumpAnchorInfo() const {
string buf;
std::lock_guard<simple_spinlock> l(lock_);
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
for (const AnchorMultiMap::value_type& entry : anchors_) {
const LogAnchor* anchor = entry.second;
DCHECK(anchor->is_registered);
Expand All @@ -109,7 +109,7 @@ void LogAnchorRegistry::RegisterUnlocked(int64_t log_index,
anchor->log_index = log_index;
anchor->owner.assign(owner);
anchor->is_registered = true;
anchor->when_registered = MonoTime::Now(MonoTime::FINE);
anchor->when_registered = MonoTime::Now();
AnchorMultiMap::value_type value(log_index, anchor);
anchors_.insert(value);
}
Expand Down
12 changes: 6 additions & 6 deletions src/kudu/consensus/raft_consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ Status RaftConsensus::StartElection(ElectionMode mode) {
}

Status RaftConsensus::WaitUntilLeaderForTests(const MonoDelta& timeout) {
MonoTime deadline = MonoTime::Now(MonoTime::FINE);
MonoTime deadline = MonoTime::Now();
deadline.AddDelta(timeout);
while (role() != consensus::RaftPeerPB::LEADER) {
MonoTime now = MonoTime::Now(MonoTime::FINE);
MonoTime now = MonoTime::Now();
if (!now.ComesBefore(deadline)) {
return Status::TimedOut(Substitute("Peer $0 is not leader of tablet $1 after $2. Role: $3",
peer_uuid(), tablet_id(), timeout.ToString(), role()));
Expand Down Expand Up @@ -1087,7 +1087,7 @@ Status RaftConsensus::UpdateReplica(const ConsensusRequestPB* request,
RETURN_NOT_OK(SnoozeFailureDetectorUnlocked());

// Also prohibit voting for anyone for the minimum election timeout.
withhold_votes_until_ = MonoTime::Now(MonoTime::FINE);
withhold_votes_until_ = MonoTime::Now();
withhold_votes_until_.AddDelta(MinimumElectionTimeout());


Expand Down Expand Up @@ -1341,7 +1341,7 @@ Status RaftConsensus::RequestVote(const VoteRequestPB* request, VoteResponsePB*
//
// See also https://ramcloud.stanford.edu/~ongaro/thesis.pdf
// section 4.2.3.
MonoTime now = MonoTime::Now(MonoTime::COARSE);
MonoTime now = MonoTime::Now();
if (!request->ignore_live_leader() &&
now.ComesBefore(withhold_votes_until_)) {
return RequestVoteRespondLeaderIsAlive(request, response);
Expand Down Expand Up @@ -1929,7 +1929,7 @@ Status RaftConsensus::EnsureFailureDetectorEnabledUnlocked() {
return Status::OK();
}
return failure_detector_->Track(kTimerId,
MonoTime::Now(MonoTime::FINE),
MonoTime::Now(),
// Unretained to avoid a circular ref.
Bind(&RaftConsensus::ReportFailureDetected, Unretained(this)));
}
Expand Down Expand Up @@ -1963,7 +1963,7 @@ Status RaftConsensus::SnoozeFailureDetectorUnlocked(const MonoDelta& additional_
return Status::OK();
}

MonoTime time = MonoTime::Now(MonoTime::FINE);
MonoTime time = MonoTime::Now();
time.AddDelta(additional_delta);

if (allow_logging == ALLOW_LOGGING) {
Expand Down
Loading

0 comments on commit ea81e05

Please sign in to comment.