summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorcostan <costan@google.com>2018-09-04 09:44:56 -0700
committerVictor Costan <pwnall@chromium.org>2018-09-04 10:37:22 -0700
commit89af27bde59fbbb3025653812b45fec10a655cb7 (patch)
tree9b64731099d6fe0b85a4c3cef9a4ff5768e048c3 /db
parent03064cbbb2c00c3e6e41a78e8111d14a020f7d6f (diff)
downloadleveldb-89af27bde59fbbb3025653812b45fec10a655cb7.tar.gz
Remove ssize_t from code that is not POSIX-specific.
ssize_t is not standard C++. It is a POSIX extension. Therefore, it does not belong in generic code. This change tweaks the logic in DBIter to remove the need for signed integers, so ssize_t can be replaced with size_t. The impacted method and private member are renamed to better express their purpose. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211471606
Diffstat (limited to 'db')
-rw-r--r--db/db_iter.cc19
-rw-r--r--db/fault_injection_test.cc8
2 files changed, 15 insertions, 12 deletions
diff --git a/db/db_iter.cc b/db/db_iter.cc
index 3b2035e..4d0f42e 100644
--- a/db/db_iter.cc
+++ b/db/db_iter.cc
@@ -57,7 +57,7 @@ class DBIter: public Iterator {
direction_(kForward),
valid_(false),
rnd_(seed),
- bytes_counter_(RandomPeriod()) {
+ bytes_until_read_sampling_(RandomCompactionPeriod()) {
}
virtual ~DBIter() {
delete iter_;
@@ -103,8 +103,8 @@ class DBIter: public Iterator {
}
}
- // Pick next gap with average value of config::kReadBytesPeriod.
- ssize_t RandomPeriod() {
+ // Picks the number of bytes that can be read until a compaction is scheduled.
+ size_t RandomCompactionPeriod() {
return rnd_.Uniform(2*config::kReadBytesPeriod);
}
@@ -120,7 +120,7 @@ class DBIter: public Iterator {
bool valid_;
Random rnd_;
- ssize_t bytes_counter_;
+ size_t bytes_until_read_sampling_;
// No copying allowed
DBIter(const DBIter&);
@@ -129,12 +129,15 @@ class DBIter: public Iterator {
inline bool DBIter::ParseKey(ParsedInternalKey* ikey) {
Slice k = iter_->key();
- ssize_t n = k.size() + iter_->value().size();
- bytes_counter_ -= n;
- while (bytes_counter_ < 0) {
- bytes_counter_ += RandomPeriod();
+
+ size_t bytes_read = k.size() + iter_->value().size();
+ while (bytes_until_read_sampling_ < bytes_read) {
+ bytes_until_read_sampling_ += RandomCompactionPeriod();
db_->RecordReadSample(k);
}
+ assert(bytes_until_read_sampling_ >= bytes_read);
+ bytes_until_read_sampling_ -= bytes_read;
+
if (!ParseInternalKey(k, ikey)) {
status_ = Status::Corruption("corrupted internal key in DBIter");
return false;
diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc
index 7894999..b3429ac 100644
--- a/db/fault_injection_test.cc
+++ b/db/fault_injection_test.cc
@@ -85,9 +85,9 @@ Status Truncate(const std::string& filename, uint64_t length) {
struct FileState {
std::string filename_;
- ssize_t pos_;
- ssize_t pos_at_last_sync_;
- ssize_t pos_at_last_flush_;
+ int64_t pos_;
+ int64_t pos_at_last_sync_;
+ int64_t pos_at_last_flush_;
FileState(const std::string& filename)
: filename_(filename),
@@ -360,7 +360,7 @@ void FaultInjectionTestEnv::WritableFileClosed(const FileState& state) {
}
Status FileState::DropUnsyncedData() const {
- ssize_t sync_pos = pos_at_last_sync_ == -1 ? 0 : pos_at_last_sync_;
+ int64_t sync_pos = pos_at_last_sync_ == -1 ? 0 : pos_at_last_sync_;
return Truncate(filename_, sync_pos);
}