Skip to content

Commit

Permalink
remove macro check in CACHE_LINE_SIZE, adjust DBstats, and changing D…
Browse files Browse the repository at this point in the history
…BStats to unique_ptr
  • Loading branch information
mapleFU committed Mar 10, 2024
1 parent ca9bef1 commit c1fad20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/common/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#define USE_ALIGNED_ACCESS
#endif

#ifndef CACHE_LINE_SIZE
#if defined(__s390__)
#if defined(__GNUC__) && __GNUC__ < 7
constexpr size_t CACHE_LINE_SIZE = 64U;
Expand All @@ -36,4 +35,3 @@ constexpr size_t CACHE_LINE_SIZE = 128U;
#else
constexpr size_t CACHE_LINE_SIZE = 64U;
#endif
#endif
14 changes: 9 additions & 5 deletions src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ const int64_t kIORateLimitMaxMb = 1024000;
using rocksdb::Slice;

Storage::Storage(Config *config)
: backup_creating_time_(util::GetTimeStamp()), env_(rocksdb::Env::Default()), config_(config), lock_mgr_(16) {
: backup_creating_time_(util::GetTimeStamp()),
env_(rocksdb::Env::Default()),
config_(config),
lock_mgr_(16),
db_stats_(std::make_unique<DBStats>()) {
Metadata::InitVersionCounter();
SetWriteOptions(config->rocks_db.write_options);
}
Expand Down Expand Up @@ -707,16 +711,16 @@ Status Storage::ApplyWriteBatch(const rocksdb::WriteOptions &options, std::strin
void Storage::RecordStat(StatType type, uint64_t v) {
switch (type) {
case StatType::FlushCount:
db_stats_.flush_count.fetch_add(v, std::memory_order_relaxed);
db_stats_->flush_count.fetch_add(v, std::memory_order_relaxed);
break;
case StatType::CompactionCount:
db_stats_.compaction_count.fetch_add(v, std::memory_order_relaxed);
db_stats_->compaction_count.fetch_add(v, std::memory_order_relaxed);
break;
case StatType::KeyspaceHits:
db_stats_.keyspace_hits.fetch_add(v, std::memory_order_relaxed);
db_stats_->keyspace_hits.fetch_add(v, std::memory_order_relaxed);
break;
case StatType::KeyspaceMisses:
db_stats_.keyspace_misses.fetch_add(v, std::memory_order_relaxed);
db_stats_->keyspace_misses.fetch_add(v, std::memory_order_relaxed);
break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ enum class StatType : uint_fast8_t {
KeyspaceMisses,
};

struct alignas(CACHE_LINE_SIZE) DBStats {
std::atomic<uint_fast64_t> compaction_count = 0;
std::atomic<uint_fast64_t> flush_count = 0;
std::atomic<uint_fast64_t> keyspace_hits = 0;
std::atomic<uint_fast64_t> keyspace_misses = 0;
struct DBStats {
alignas(CACHE_LINE_SIZE) std::atomic<uint_fast64_t> compaction_count = 0;
alignas(CACHE_LINE_SIZE) std::atomic<uint_fast64_t> flush_count = 0;
alignas(CACHE_LINE_SIZE) std::atomic<uint_fast64_t> keyspace_hits = 0;
alignas(CACHE_LINE_SIZE) std::atomic<uint_fast64_t> keyspace_misses = 0;
};

class Storage {
Expand Down Expand Up @@ -196,7 +196,7 @@ class Storage {
bool IsSlotIdEncoded() const { return config_->slot_id_encoded; }
Config *GetConfig() const { return config_; }

const DBStats *GetDBStats() const { return &db_stats_; }
const DBStats *GetDBStats() const { return db_stats_.get(); }
void RecordStat(StatType type, uint64_t v);

Status BeginTxn();
Expand Down Expand Up @@ -262,7 +262,7 @@ class Storage {
LockManager lock_mgr_;
std::atomic<bool> db_size_limit_reached_{false};

DBStats db_stats_;
std::unique_ptr<DBStats> db_stats_;

std::shared_mutex db_rw_lock_;
bool db_closing_ = true;
Expand Down

0 comments on commit c1fad20

Please sign in to comment.