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

[don't merge me] - designed to show write lock in merged() is no longer needed after #5701 #5825

Closed
wants to merge 2 commits into from

Conversation

jonseymour
Copy link
Contributor

This contains two changes that are in #5701 but does not include the other the changes.

The purpose is to demonstrate that without the other changes in #5701, taking a write lock is necessary to ensure thread safety.

The fact that the test case executes successfully after #5701, shows that the protection offered by taking the cache write lock is no longer necessary because #5701 introduces entry locks that offer the required protection.

Signed-off-by: Jon Seymour <jon@wildducktheories.com>
Previously, we needed a write lock on the cache because it was the
only lock we had available to guard updates to entry.values and
entry.needSort.

However, now we have a entry-scoped lock for this purpose, we don't
need the cache write lock for this purpose. Since merged() doesn't
modify the .store or the c.snapshot.sort, there is no need for
a write lock on the cache to protect the cache.

So, we don't need to escalate here - we simply rely on the entry lock
to protect the entries we are iterating over.

Signed-off-by: Jon Seymour <jon@wildducktheories.com>
@jonseymour jonseymour changed the title [don' [don't merge me] - designed to show write lock in merged() is no longer needed after #5701 Feb 25, 2016
@jonseymour
Copy link
Contributor Author

Mmmm. I was expecting the automated CI tests to detect the race. Not sure why they didn't. Here is the evidence from manually invoking it.

==================
WARNING: DATA RACE
Read by goroutine 32:
  runtime.slicecopy()
      /usr/local/Cellar/go/1.5.3/libexec/src/runtime/slice.go:110 +0x0
  github.com/influxdata/influxdb/tsdb/engine/tsm1.(*Cache).merged()
      /Users/jonseymour/ninja/go/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/cache.go:317 +0x7f4
  github.com/influxdata/influxdb/tsdb/engine/tsm1.(*Cache).Values()
      /Users/jonseymour/ninja/go/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/cache.go:256 +0xa3
  command-line-arguments_test.TestCheckConcurrentReadsAreSafe.func2()
      /Users/jonseymour/ninja/go/src/github.com/influxdb/influxdb/tsdb/engine/tsm1/cache_race_test.go:47 +0x90

Previous write by goroutine 31:
  [failed to restore the stack]

Goroutine 32 (running) created at:
  command-line-arguments_test.TestCheckConcurrentReadsAreSafe()
      /Users/jonseymour/ninja/go/src/github.com/influxdb/influxdb/tsdb/engine/tsm1/cache_race_test.go:48 +0xa70
  testing.tRunner()
      /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:456 +0xdc

Goroutine 31 (running) created at:
  command-line-arguments_test.TestCheckConcurrentReadsAreSafe()
      /Users/jonseymour/ninja/go/src/github.com/influxdb/influxdb/tsdb/engine/tsm1/cache_race_test.go:43 +0xa17
  testing.tRunner()
      /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:456 +0xdc
==================
PASS
Found 17 data race(s)
FAIL    command-line-arguments  1.514s

@jwilder
Copy link
Contributor

jwilder commented Feb 25, 2016

Closing since #5701 has been merged w/ the write-lock removed.

@jwilder jwilder closed this Feb 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants