Skip to content

Commit

Permalink
fix: assign threadlocal data structures during connection migration
Browse files Browse the repository at this point in the history
Co-authored-by: Shahar Mike <[email protected]>
Signed-off-by: Roman Gershman <[email protected]>
  • Loading branch information
romange and chakaz committed Dec 1, 2023
1 parent 1dd6a60 commit 97c95b5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/facade/dragonfly_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,13 @@ void Connection::HandleMigrateRequest() {

DecreaseStatsOnClose();

auto update_tl_vars = [this] __attribute__((noinline)) {
this->Migrate(dest);

auto update_tl_vars = [this] [[gnu::noinline]] {
// The compiler barrier that does not allow reordering memory accesses
// to before this function starts. See https://stackoverflow.com/a/75622732
asm volatile("");

queue_backpressure_ = &tl_queue_backpressure_;

stats_ = service_->GetThreadLocalConnectionStats();
Expand All @@ -832,10 +837,9 @@ void Connection::HandleMigrateRequest() {
++stats_->num_replicas;
}
};
this->Migrate(dest);

// We're now running in `dest` thread. We use non-inline lambda to make sure that
// thread local variables have not been loaded into a register before we migrated.
// We're now running in `dest` thread. We use non-inline lambda to force reading new thread's
// thread local vars.
update_tl_vars();
}

Expand Down

0 comments on commit 97c95b5

Please sign in to comment.