Skip to content

Commit

Permalink
Remove ssize_t from code that is not POSIX-specific.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pwnall committed Sep 4, 2018
1 parent 03064cb commit 89af27b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions db/db_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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&);
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions db/fault_injection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 89af27b

Please sign in to comment.