mirror of
https://github.com/google/leveldb.git
synced 2024-12-14 06:08:58 +08:00
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
This commit is contained in:
parent
03064cbbb2
commit
89af27bde5
@ -57,7 +57,7 @@ class DBIter: public Iterator {
|
|||||||
direction_(kForward),
|
direction_(kForward),
|
||||||
valid_(false),
|
valid_(false),
|
||||||
rnd_(seed),
|
rnd_(seed),
|
||||||
bytes_counter_(RandomPeriod()) {
|
bytes_until_read_sampling_(RandomCompactionPeriod()) {
|
||||||
}
|
}
|
||||||
virtual ~DBIter() {
|
virtual ~DBIter() {
|
||||||
delete iter_;
|
delete iter_;
|
||||||
@ -103,8 +103,8 @@ class DBIter: public Iterator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick next gap with average value of config::kReadBytesPeriod.
|
// Picks the number of bytes that can be read until a compaction is scheduled.
|
||||||
ssize_t RandomPeriod() {
|
size_t RandomCompactionPeriod() {
|
||||||
return rnd_.Uniform(2*config::kReadBytesPeriod);
|
return rnd_.Uniform(2*config::kReadBytesPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class DBIter: public Iterator {
|
|||||||
bool valid_;
|
bool valid_;
|
||||||
|
|
||||||
Random rnd_;
|
Random rnd_;
|
||||||
ssize_t bytes_counter_;
|
size_t bytes_until_read_sampling_;
|
||||||
|
|
||||||
// No copying allowed
|
// No copying allowed
|
||||||
DBIter(const DBIter&);
|
DBIter(const DBIter&);
|
||||||
@ -129,12 +129,15 @@ class DBIter: public Iterator {
|
|||||||
|
|
||||||
inline bool DBIter::ParseKey(ParsedInternalKey* ikey) {
|
inline bool DBIter::ParseKey(ParsedInternalKey* ikey) {
|
||||||
Slice k = iter_->key();
|
Slice k = iter_->key();
|
||||||
ssize_t n = k.size() + iter_->value().size();
|
|
||||||
bytes_counter_ -= n;
|
size_t bytes_read = k.size() + iter_->value().size();
|
||||||
while (bytes_counter_ < 0) {
|
while (bytes_until_read_sampling_ < bytes_read) {
|
||||||
bytes_counter_ += RandomPeriod();
|
bytes_until_read_sampling_ += RandomCompactionPeriod();
|
||||||
db_->RecordReadSample(k);
|
db_->RecordReadSample(k);
|
||||||
}
|
}
|
||||||
|
assert(bytes_until_read_sampling_ >= bytes_read);
|
||||||
|
bytes_until_read_sampling_ -= bytes_read;
|
||||||
|
|
||||||
if (!ParseInternalKey(k, ikey)) {
|
if (!ParseInternalKey(k, ikey)) {
|
||||||
status_ = Status::Corruption("corrupted internal key in DBIter");
|
status_ = Status::Corruption("corrupted internal key in DBIter");
|
||||||
return false;
|
return false;
|
||||||
|
@ -85,9 +85,9 @@ Status Truncate(const std::string& filename, uint64_t length) {
|
|||||||
|
|
||||||
struct FileState {
|
struct FileState {
|
||||||
std::string filename_;
|
std::string filename_;
|
||||||
ssize_t pos_;
|
int64_t pos_;
|
||||||
ssize_t pos_at_last_sync_;
|
int64_t pos_at_last_sync_;
|
||||||
ssize_t pos_at_last_flush_;
|
int64_t pos_at_last_flush_;
|
||||||
|
|
||||||
FileState(const std::string& filename)
|
FileState(const std::string& filename)
|
||||||
: filename_(filename),
|
: filename_(filename),
|
||||||
@ -360,7 +360,7 @@ void FaultInjectionTestEnv::WritableFileClosed(const FileState& state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status FileState::DropUnsyncedData() const {
|
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);
|
return Truncate(filename_, sync_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user