2013-10-16 23:59:46 +02:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2012-08-15 00:20:36 +02:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "db/db_impl.h"
|
|
|
|
#include <string>
|
|
|
|
#include <stdint.h>
|
2012-09-17 04:33:03 +02:00
|
|
|
#include <stdio.h>
|
2012-08-15 00:20:36 +02:00
|
|
|
#include "db/version_set.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2012-08-27 09:50:26 +02:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "util/mutexlock.h"
|
2012-08-15 00:20:36 +02:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2012-08-15 00:20:36 +02:00
|
|
|
|
|
|
|
void DBImpl::MaybeScheduleLogDBDeployStats() {
|
2014-04-15 22:39:26 +02:00
|
|
|
// we did say maybe
|
|
|
|
#ifndef ROCKSDB_LITE
|
2012-08-15 00:20:36 +02:00
|
|
|
// There is a lock in the actual logger.
|
|
|
|
if (!logger_ || options_.db_stats_log_interval < 0
|
|
|
|
|| host_name_.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-27 09:50:26 +02:00
|
|
|
|
|
|
|
if(bg_logstats_scheduled_ || shutting_down_.Acquire_Load()) {
|
2012-08-15 00:20:36 +02:00
|
|
|
// Already scheduled
|
|
|
|
} else {
|
|
|
|
int64_t current_ts = 0;
|
|
|
|
Status st = env_->GetCurrentTime(¤t_ts);
|
|
|
|
if (!st.ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((current_ts - last_log_ts) < options_.db_stats_log_interval) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last_log_ts = current_ts;
|
2012-08-27 09:50:26 +02:00
|
|
|
bg_logstats_scheduled_ = true;
|
|
|
|
env_->Schedule(&DBImpl::BGLogDBDeployStats, this);
|
2012-08-15 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 09:50:26 +02:00
|
|
|
void DBImpl::BGLogDBDeployStats(void* db) {
|
2012-08-15 00:20:36 +02:00
|
|
|
DBImpl* db_inst = reinterpret_cast<DBImpl*>(db);
|
2012-08-27 09:50:26 +02:00
|
|
|
db_inst->LogDBDeployStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBImpl::LogDBDeployStats() {
|
|
|
|
mutex_.Lock();
|
2012-08-15 00:20:36 +02:00
|
|
|
|
2012-08-27 09:50:26 +02:00
|
|
|
if (shutting_down_.Acquire_Load()) {
|
|
|
|
bg_logstats_scheduled_ = false;
|
|
|
|
bg_cv_.SignalAll();
|
|
|
|
mutex_.Unlock();
|
2012-08-15 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-17 04:33:03 +02:00
|
|
|
char tmp_ver[100];
|
|
|
|
sprintf(tmp_ver, "%d.%d", kMajorVersion, kMinorVersion);
|
|
|
|
std::string version_info(tmp_ver);
|
2012-08-15 00:20:36 +02:00
|
|
|
|
|
|
|
uint64_t file_total_size = 0;
|
|
|
|
uint32_t file_total_num = 0;
|
2014-02-11 02:04:44 +01:00
|
|
|
Version* current = default_cf_handle_->cfd()->current();
|
2014-01-16 01:15:43 +01:00
|
|
|
for (int i = 0; i < current->NumberLevels(); i++) {
|
|
|
|
file_total_num += current->NumLevelFiles(i);
|
2014-01-16 01:18:04 +01:00
|
|
|
file_total_size += current->NumLevelBytes(i);
|
2012-08-15 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2014-01-16 01:18:04 +01:00
|
|
|
Version::LevelSummaryStorage scratch;
|
|
|
|
const char* file_num_summary = current->LevelSummary(&scratch);
|
2012-08-15 00:20:36 +02:00
|
|
|
std::string file_num_per_level(file_num_summary);
|
|
|
|
std::string data_size_per_level(file_num_summary);
|
2012-08-28 20:29:30 +02:00
|
|
|
|
|
|
|
mutex_.Unlock();
|
|
|
|
|
2012-08-15 00:20:36 +02:00
|
|
|
int64_t unix_ts;
|
2012-08-27 09:50:26 +02:00
|
|
|
env_->GetCurrentTime(&unix_ts);
|
2012-08-15 00:20:36 +02:00
|
|
|
|
2012-08-27 09:50:26 +02:00
|
|
|
logger_->Log_Deploy_Stats(version_info, host_name_,
|
2012-09-06 02:44:13 +02:00
|
|
|
db_absolute_path_, file_total_size, file_total_num, file_num_per_level,
|
2012-08-15 00:20:36 +02:00
|
|
|
data_size_per_level, unix_ts);
|
2012-08-27 09:50:26 +02:00
|
|
|
|
|
|
|
mutex_.Lock();
|
|
|
|
bg_logstats_scheduled_ = false;
|
|
|
|
bg_cv_.SignalAll();
|
|
|
|
mutex_.Unlock();
|
2014-04-15 22:39:26 +02:00
|
|
|
#endif
|
2012-08-15 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|