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

libroach: avoid recycling encrypted WALs #38868

Merged
merged 1 commit into from
Jul 24, 2019

Conversation

ajkr
Copy link
Contributor

@ajkr ajkr commented Jul 14, 2019

RocksDB fails recovery if there are any non-empty WALs that have zero
readable entries. So we need to make sure
EncryptedEnv::ReuseWritableFile() cannot produce such files, even if
an inopportune crash happens. We do not know how to achieve this while
still changing the encryption key for the recycled WAL, so for now this
PR works around the problem in EncryptedEnv::ReuseWritableFile() by
faking recycling.

Release note: None

@ajkr ajkr requested review from a team July 14, 2019 21:34
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ajkr
Copy link
Contributor Author

ajkr commented Jul 14, 2019

Hm, seems this violates the goal of not reusing keys. I should've read the docs earlier.

@ajkr ajkr changed the title libroach: crash-recoverable encrypted WAL recycling [dnm] libroach: crash-recoverable encrypted WAL recycling Jul 14, 2019
Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, seems this violates the goal of not reusing keys. I should've read the docs earlier.

I was thinking this weekend that perhaps we should just disable WAL reuse if encryption is enabled. There is a performance hit to doing that, though.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mberhault and @petermattis)

@ajkr
Copy link
Contributor Author

ajkr commented Jul 17, 2019

Thought through it again. I don't really like how RocksDB overwrites our recovery_mode, which permits garbage WALs, with a stricter one that rejects garbage WALs. It is doing that under the assumption that the overwrite does not change behavior, but in fact it does change. Made a post about it: https://www.facebook.com/groups/rocksdb.dev/permalink/2405909486174218/

@ajkr
Copy link
Contributor Author

ajkr commented Jul 17, 2019

Also I did look into writing a zero entry using the new encryption key as we discussed. It worked if the whole WAL were zeroed, but not if there were a portion zeroed followed by some unzeroed bytes.

Works:

$ dd of=./tmp/111111.log if=/dev/zero bs=1024 count=1024
$ ./db_bench_tolerate_corrupt_tail -benchmarks=readrandom -use_existing_db=true -db=./tmp

Doesn't work:

$ dd of=./tmp/222222.log if=/dev/zero bs=1024 count=1024
$ dd conv=notrunc oflag=append of=./tmp/222222.log if=/dev/urandom bs=1024 count=1024
$ ./db_bench_tolerate_corrupt_tail -benchmarks=readrandom -use_existing_db=true -db=./tmp
...
open error: Corruption: checksum mismatch

@petermattis
Copy link
Collaborator

Thought through it again. I don't really like how RocksDB overwrites our recovery_mode, which permits garbage WALs, with a stricter one that rejects garbage WALs. It is doing that under the assumption that the overwrite does not change behavior, but in fact it does change. Made a post about it: https://www.facebook.com/groups/rocksdb.dev/permalink/2405909486174218/

That sounds like a good path forward to me. I think you should apply a short-term bandaid here, and disable WAL recycling when encryption is enabled.

@ajkr ajkr changed the title [dnm] libroach: crash-recoverable encrypted WAL recycling libroach: avoid recycling encrypted WALs Jul 21, 2019
@ajkr
Copy link
Contributor Author

ajkr commented Jul 21, 2019

That sounds like a good path forward to me. I think you should apply a short-term bandaid here, and disable WAL recycling when encryption is enabled.

OK, I updated this PR to do that.

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajkr and @mberhault)


c-deps/libroach/ccl/encrypted_env_test.cc, line 293 at r1 (raw file):

    {
      std::unique_ptr<rocksdb::WritableFile> res;
      if (i == static_cast<int>(ReuseWritableFileInjectionEnv::Mode::kNone)) {

I think you can use mode instead of i here, to avoid the cast on the right hand side of the expression.

Copy link
Contributor Author

@ajkr ajkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mberhault and @petermattis)


c-deps/libroach/ccl/encrypted_env_test.cc, line 293 at r1 (raw file):

Previously, petermattis (Peter Mattis) wrote…

I think you can use mode instead of i here, to avoid the cast on the right hand side of the expression.

Oh right, done.

RocksDB fails recovery if there are any non-empty WALs that have zero
readable entries. So we need to make sure
`EncryptedEnv::ReuseWritableFile()` cannot produce such files, even if
an inopportune crash happens. We do not know how to achieve this while
still changing the encryption key for the recycled WAL, so for now this
PR works around the problem in `EncryptedEnv::ReuseWritableFile()` by
faking recycling.

Release note: None
@ajkr
Copy link
Contributor Author

ajkr commented Jul 24, 2019

bors r+

craig bot pushed a commit that referenced this pull request Jul 24, 2019
38868: libroach: avoid recycling encrypted WALs r=ajkr a=ajkr

RocksDB fails recovery if there are any non-empty WALs that have zero
readable entries. So we need to make sure
`EncryptedEnv::ReuseWritableFile()` cannot produce such files, even if
an inopportune crash happens. We do not know how to achieve this while
still changing the encryption key for the recycled WAL, so for now this
PR works around the problem in `EncryptedEnv::ReuseWritableFile()` by
faking recycling.

Release note: None

Co-authored-by: Andrew Kryczka <andrew.kryczka2@gmail.com>
@craig
Copy link
Contributor

craig bot commented Jul 24, 2019

Build succeeded

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.

3 participants