Skip to content

Commit

Permalink
Review update
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgamez committed Jun 8, 2023
1 parent baac718 commit 0e772dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
21 changes: 2 additions & 19 deletions extensions/rocksdb-repos/DatabaseContentRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,29 +287,12 @@ uint64_t DatabaseContentRepository::getRepositoryEntryCount() const {
}

std::optional<RepositoryMetricsSource::RocksDbStats> DatabaseContentRepository::getRocksDbStats() const {
RocksDbStats stats;
auto opendb = db_->open();
if (!opendb) {
return stats;
return RocksDbStats{};
}

std::string table_readers;
opendb->GetProperty("rocksdb.estimate-table-readers-mem", &table_readers);
try {
stats.table_readers_size = std::stoull(table_readers);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.estimate-table-readers-mem' property value from rocksdb content repository!");
}

std::string all_memtables;
opendb->GetProperty("rocksdb.cur-size-all-mem-tables", &all_memtables);
try {
stats.all_memory_tables_size = std::stoull(all_memtables);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.cur-size-all-mem-tables' property value from rocksdb content repository!");
}

return stats;
return opendb->getStats();
}

REGISTER_RESOURCE_AS(DatabaseContentRepository, InternalResource, ("DatabaseContentRepository", "databasecontentrepository"));
Expand Down
21 changes: 2 additions & 19 deletions extensions/rocksdb-repos/RocksDbRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,12 @@ using namespace std::literals::chrono_literals;
namespace org::apache::nifi::minifi::core::repository {

std::optional<RepositoryMetricsSource::RocksDbStats> RocksDbRepository::getRocksDbStats() const {
RocksDbStats stats;
auto opendb = db_->open();
if (!opendb) {
return stats;
return RocksDbStats{};
}

std::string table_readers;
opendb->GetProperty("rocksdb.estimate-table-readers-mem", &table_readers);
try {
stats.table_readers_size = std::stoull(table_readers);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.estimate-table-readers-mem' property value from rocksdb content repository!");
}

std::string all_memtables;
opendb->GetProperty("rocksdb.cur-size-all-mem-tables", &all_memtables);
try {
stats.all_memory_tables_size = std::stoull(all_memtables);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.cur-size-all-mem-tables' property value from rocksdb content repository!");
}

return stats;
return opendb->getStats();
}

bool RocksDbRepository::ExecuteWithRetry(const std::function<rocksdb::Status()>& operation) {
Expand Down
21 changes: 21 additions & 0 deletions extensions/rocksdb-repos/database/OpenRocksDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,25 @@ std::optional<uint64_t> OpenRocksDb::getApproximateSizes() const {
return std::nullopt;
}

minifi::core::RepositoryMetricsSource::RocksDbStats OpenRocksDb::getStats() {
minifi::core::RepositoryMetricsSource::RocksDbStats stats;
std::string table_readers;
GetProperty("rocksdb.estimate-table-readers-mem", &table_readers);
try {
stats.table_readers_size = std::stoull(table_readers);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.estimate-table-readers-mem' property value from rocksdb content repository!");
}

std::string all_memtables;
GetProperty("rocksdb.cur-size-all-mem-tables", &all_memtables);
try {
stats.all_memory_tables_size = std::stoull(all_memtables);
} catch (const std::exception&) {
logger_->log_error("Could not retrieve valid 'rocksdb.cur-size-all-mem-tables' property value from rocksdb content repository!");
}

return stats;
}

} // namespace org::apache::nifi::minifi::internal
4 changes: 4 additions & 0 deletions extensions/rocksdb-repos/database/OpenRocksDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "rocksdb/db.h"
#include "rocksdb/utilities/checkpoint.h"
#include "WriteBatch.h"
#include "core/RepositoryMetricsSource.h"
#include "core/logging/LoggerConfiguration.h"

namespace org::apache::nifi::minifi::internal {

Expand Down Expand Up @@ -73,6 +75,7 @@ class OpenRocksDb {
rocksdb::DB* get();

std::optional<uint64_t> getApproximateSizes() const;
minifi::core::RepositoryMetricsSource::RocksDbStats getStats();

private:
void handleResult(const rocksdb::Status& result);
Expand All @@ -81,6 +84,7 @@ class OpenRocksDb {
gsl::not_null<RocksDbInstance*> db_;
gsl::not_null<std::shared_ptr<rocksdb::DB>> impl_;
gsl::not_null<std::shared_ptr<ColumnHandle>> column_;
std::shared_ptr<minifi::core::logging::Logger> logger_{minifi::core::logging::LoggerFactory<OpenRocksDb>::getLogger()};
};

} // namespace org::apache::nifi::minifi::internal

0 comments on commit 0e772dd

Please sign in to comment.