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

Enable backward iterator for keys with user-defined timestamp #8035

Closed
wants to merge 12 commits into from

Conversation

riversand963
Copy link
Contributor

@riversand963 riversand963 commented Mar 5, 2021

This PR does the following:

  • Enable backward iteration for keys with user-defined timestamp. Note that merge, single delete, range delete are not supported yet.
  • Introduces a new helper API Comparator::EqualWithoutTimestamp().
  • Fix a typo in SetTimestamp().
  • Add/update unit tests

Run db_bench (built with DEBUG_LEVEL=0) to demonstrate that no overhead is introduced for CPU-intensive workloads with a lot of Prev(). Also provided results of iterating keys with timestamps.

  1. Disable timestamp, run:
./db_bench -db=/dev/shm/rocksdb -disable_wal=1 -benchmarks=fillseq,seekrandom[-W1-X6] -reverse_iterator=1 -seek_nexts=5

Results:

Baseline

  • seekrandom [AVG 6 runs] : 96115 ops/sec; 53.2 MB/sec
  • seekrandom [MEDIAN 6 runs] : 98075 ops/sec; 54.2 MB/sec

This PR

  • seekrandom [AVG 6 runs] : 95521 ops/sec; 52.8 MB/sec
  • seekrandom [MEDIAN 6 runs] : 96338 ops/sec; 53.3 MB/sec
  1. Enable timestamp, run:
./db_bench -user_timestamp_size=8  -db=/dev/shm/rocksdb -disable_wal=1 -benchmarks=fillseq,seekrandom[-W1-X6] -reverse_iterator=1 -seek_nexts=5

Result:

Baseline: not supported

This PR

  • seekrandom [AVG 6 runs] : 90514 ops/sec; 50.1 MB/sec
  • seekrandom [MEDIAN 6 runs] : 90834 ops/sec; 50.2 MB/sec

Copy link
Contributor

@ltamasi ltamasi left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @riversand963 !

db/compaction/compaction_iterator.cc Outdated Show resolved Hide resolved
db/db_iter.cc Outdated
Comment on lines 491 to 492
const std::string kTsMin(timestamp_size_,
static_cast<unsigned char>(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

std::string is actually std::basic_string<char>, so I actually think the original type was correct. We could consider simply using '\0' though instead of static_casting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try that. Cast to unsigned char due to a warning from VS.

db/db_iter.cc Outdated Show resolved Hide resolved
util/comparator.cc Outdated Show resolved Hide resolved
db/db_iter.cc Show resolved Hide resolved
@riversand963
Copy link
Contributor Author

Thanks @ltamasi for the review.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@ltamasi ltamasi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @riversand963 !

db/db_iter.cc Outdated
kValueTypeForSeek);
if (timestamp_size_ > 0) {
// TODO: pre-create kTsMax.
const std::string kTsMax(timestamp_size_, static_cast<char>(0xffu));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about '\xff'?

Also run db_bench
For seekrandom, warmup 1 run, and test 3 runs.
```
./db_bench -db=/dev/shm/rocksdb -disable_wal=1 -benchmarks=fillseq,seekrandom[-W1-X3] -reverse_iterator=1 -seek_nexts=5
```
…f regression

Rerun tests:
```
./db_bench -db=/dev/shm/rocksdb -disable_wal=1 -benchmarks=fillseq,seekrandom[-W1-X6] -reverse_iterator=1 -seek_nexts=5
```

master:
```
seekrandom [AVG    6 runs] : 96115 ops/sec;   53.2 MB/sec
seekrandom [MEDIAN 6 runs] : 98075 ops/sec;   54.2 MB/sec
```

This PR:
```
seekrandom [AVG    6 runs] : 95521 ops/sec;   52.8 MB/sec
seekrandom [MEDIAN 6 runs] : 96338 ops/sec;   53.3 MB/sec
```

These tests show that newly-added timestamp-related code does not add
overhead to existing backward iteration code without timestamp. The
addition of EqualWithoutTimestamp() to BytewiseComparator is crucial.
Also run db_bench
```
./db_bench -user_timestamp_size=8  -db=/dev/shm/rocksdb -disable_wal=1 -benchmarks=fillseq,seekrandom[-W1-X6] -reverse_iterator=1 -seek_nexts=5
```

Result
```
seekrandom [AVG    6 runs] : 90514 ops/sec;   50.1 MB/sec
seekrandom [MEDIAN 6 runs] : 90834 ops/sec;   50.2 MB/sec
```
@facebook-github-bot
Copy link
Contributor

@riversand963 has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@riversand963 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@riversand963 merged this pull request in 82b3888.

@riversand963 riversand963 deleted the db-iter-ts-rev branch March 10, 2021 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants