Skip to content

Commit

Permalink
get rid of unneeded atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Aug 10, 2024
1 parent fecfa93 commit fabd68d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/bitcask/bitcask.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Database {

/// Total size of the file.
/// The size is only updated on writing or set on loading.
std::atomic_uint64_t size{0};
uint64_t size{0};

/// Number of records with a value.
std::atomic_uint64_t records{0};
Expand Down Expand Up @@ -239,9 +239,9 @@ class Database {
std::error_code ReadValue(const ReadOptions& options, const Record& record, std::string& value) const;

/**
* Writes the data to the active data file.
* Writes a record to the active data file.
*
* @returns written record or an error code if the write was unseccessful.
* @returns Descriptor of the written record or an error code if the write was unsuccessful.
*/
std::pair<Record, std::error_code> WriteEntry(const std::string_view key, const std::string_view value,
const uint64_t timestamp, const bool is_tombstone, const bool sync);
Expand Down
12 changes: 6 additions & 6 deletions src/bitcask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::error_code Database::FileInfo::Append(const std::span<const iovec>& parts,
::fsync(fd);
}
// Update total size of the file.
size.fetch_add(length);
size += length;

return {};
}
Expand Down Expand Up @@ -903,7 +903,7 @@ std::error_code Database::ReadValue(
size_t offset = record.offset;
format::Entry e;
std::string key;
return std::get<1>(ReadEntryImpl(record.file->fd, offset, true, e, key, value));
return ReadEntryImpl(record.file->fd, offset, true, e, key, value).second;
} else {
size_t offset = record.offset + (sizeof(uint64_t) + sizeof(format::Entry));
// Allocate memory for the value.
Expand Down Expand Up @@ -961,7 +961,7 @@ std::error_code Database::WriteIndex(const std::shared_ptr<FileInfo>& file) {
uint64_t crc;
const format::Index index{
.timestamp = rec.timestamp,
.entry_pos = uint32_t(rec.offset),
.entry_pos = rec.offset,
.value_size = rec.size,
.key_size = uint16_t(key.size()),
.flags = uint8_t(is_tombstone ? format::kEntryFlagTombstone : 0),
Expand All @@ -978,7 +978,7 @@ std::error_code Database::WriteIndex(const std::shared_ptr<FileInfo>& file) {
return file->Append(parts, false);
};

format::Footer footer{.entries = sizeof(format::Header), .index = file->size.load()};
format::Footer footer{.entries = sizeof(format::Header), .index = file->size};
// Write index entries.
if (auto ec = EnumerateEntries(file, std::make_pair(footer.entries, footer.index), cb)) {
return ec;
Expand Down Expand Up @@ -1010,10 +1010,10 @@ std::error_code Database::LoadFileSections(const std::shared_ptr<FileInfo>& file
sections->header = std::pair{0, sizeof(header)};
sections->entries = std::pair{footer.entries, footer.index};
sections->index = std::pair{footer.index, file->size - sizeof(footer)};
sections->footer = std::pair{file->size - sizeof(footer), file->size.load()};
sections->footer = std::pair{file->size - sizeof(footer), file->size};
} else {
sections->header = std::pair{0, sizeof(header)};
sections->entries = std::pair{sizeof(header), file->size.load()};
sections->entries = std::pair{sizeof(header), file->size};
}

return {};
Expand Down

0 comments on commit fabd68d

Please sign in to comment.