Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkTServerAsLeader could crash due to race in case of network partition in debug build #972

Closed
ttyusupov opened this issue Mar 12, 2019 · 0 comments
Assignees
Labels
kind/bug This issue is a bug

Comments

@ttyusupov
Copy link
Contributor

Tablet replicas set could be changed in concurrent thread between GetRemoteTabletServers and MarkTServerAsLeader calls in TabletInvoker::SelectTabletServer:

  if (!current_ts_) {
    // Try to "guess" the next leader.
    vector<RemoteTabletServer*> replicas;
    tablet_->GetRemoteTabletServers(&replicas);
    for (RemoteTabletServer* ts : replicas) {
      if (!ContainsKey(followers_, ts)) {
        current_ts_ = ts;
        break;
      }
    }
    if (current_ts_) {
      // Mark this next replica "preemptively" as the leader in the meta cache,
      // so we go to it first on the next write if writing was successful.
      VLOG(1) << "Tablet " << tablet_id_ << ": Previous leader failed. "
              << "Preemptively marking tserver " << current_ts_->ToString()
              << " as leader in the meta cache.";
      tablet_->MarkTServerAsLeader(current_ts_);
    }
  }

This will cause DCHECK in MarkTServerAsLeader to crash with FATAL in debug build:

void RemoteTablet::MarkTServerAsLeader(const RemoteTabletServer* server) {
  bool found = false;
  std::lock_guard<simple_spinlock> l(lock_);
  for (RemoteReplica& replica : replicas_) {
    if (replica.ts == server) {
      replica.role = RaftPeerPB::LEADER;
      found = true;
    } else if (replica.role == RaftPeerPB::LEADER) {
      replica.role = RaftPeerPB::FOLLOWER;
    }
  }
  VLOG(3) << "Latest replicas: " << ReplicasAsStringUnlocked();
  DCHECK(found) << "Tablet " << tablet_id_ << ": Specified server not found: "
                << server->ToString() << ". Replicas: " << ReplicasAsStringUnlocked();
}
@ttyusupov ttyusupov added the kind/bug This issue is a bug label Mar 12, 2019
@ttyusupov ttyusupov self-assigned this Mar 12, 2019
yugabyte-ci pushed a commit that referenced this issue Mar 12, 2019
Summary:
Tablet replicas set could be changed in a concurrent thread between `GetRemoteTabletServers`
and `MarkTServerAsLeader` calls in `TabletInvoker::SelectTabletServer`. This will cause `DCHECK` in
`MarkTServerAsLeader` to crash with FATAL in debug build.

Test Plan: Added `TabletRpcTest` to catch the fixed bug.

Reviewers: mikhail, sergei

Reviewed By: sergei

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D6304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This issue is a bug
Projects
None yet
Development

No branches or pull requests

1 participant