In logging format, use PRIu64 instead of casting

Summary: Code cleaning up, since we are already using __STDC_FORMAT_MACROS in printing uint64_t, change other places. Only logging is changed.

Test Plan: make all check

Reviewers: ljin

Reviewed By: ljin

Subscribers: dhruba, yhchiang, haobo, leveldb

Differential Revision: https://reviews.facebook.net/D19113
This commit is contained in:
sdong 2014-06-27 16:01:59 -07:00
parent a3594867ba
commit dd337bc0b2
3 changed files with 76 additions and 84 deletions

View file

@ -278,14 +278,12 @@ void CompactionPicker::SetupOtherInputs(Compaction* c) {
if (expanded1.size() == c->inputs_[1].size() && if (expanded1.size() == c->inputs_[1].size() &&
!FilesInCompaction(expanded1)) { !FilesInCompaction(expanded1)) {
Log(options_->info_log, Log(options_->info_log,
"[%s] Expanding@%lu %lu+%lu (%lu+%lu bytes) to %lu+%lu (%lu+%lu " "[%s] Expanding@%d %zu+%zu (%" PRIu64 "+%" PRIu64
"bytes)\n", " bytes) to %zu+%zu (%" PRIu64 "+%" PRIu64 "bytes)\n",
c->column_family_data()->GetName().c_str(), (unsigned long)level, c->column_family_data()->GetName().c_str(), level,
(unsigned long)(c->inputs_[0].size()), c->inputs_[0].size(), c->inputs_[1].size(), inputs0_size,
(unsigned long)(c->inputs_[1].size()), (unsigned long)inputs0_size, inputs1_size, expanded0.size(), expanded1.size(), expanded0_size,
(unsigned long)inputs1_size, (unsigned long)(expanded0.size()), inputs1_size);
(unsigned long)(expanded1.size()), (unsigned long)expanded0_size,
(unsigned long)inputs1_size);
smallest = new_start; smallest = new_start;
largest = new_limit; largest = new_limit;
c->inputs_[0] = expanded0; c->inputs_[0] = expanded0;
@ -656,10 +654,9 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalReadAmp(
candidate_count = 1; candidate_count = 1;
break; break;
} }
LogToBuffer(log_buffer, LogToBuffer(log_buffer, "[%s] Universal: file %" PRIu64
"[%s] Universal: file %lu[%d] being compacted, skipping", "[%d] being compacted, skipping",
version->cfd_->GetName().c_str(), version->cfd_->GetName().c_str(), f->fd.GetNumber(), loop);
(unsigned long)f->fd.GetNumber(), loop);
f = nullptr; f = nullptr;
} }
@ -668,9 +665,8 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalReadAmp(
uint64_t candidate_size = f != nullptr? f->compensated_file_size : 0; uint64_t candidate_size = f != nullptr? f->compensated_file_size : 0;
if (f != nullptr) { if (f != nullptr) {
LogToBuffer(log_buffer, LogToBuffer(log_buffer,
"[%s] Universal: Possible candidate file %lu[%d].", "[%s] Universal: Possible candidate file %" PRIu64 "[%d].",
version->cfd_->GetName().c_str(), version->cfd_->GetName().c_str(), f->fd.GetNumber(), loop);
(unsigned long)f->fd.GetNumber(), loop);
} }
// Check if the suceeding files need compaction. // Check if the suceeding files need compaction.
@ -800,19 +796,19 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalSizeAmp(
start_index = loop; // Consider this as the first candidate. start_index = loop; // Consider this as the first candidate.
break; break;
} }
LogToBuffer( LogToBuffer(log_buffer,
log_buffer, "[%s] Universal: skipping file %lu[%d] compacted %s", "[%s] Universal: skipping file %" PRIu64 "[%d] compacted %s",
version->cfd_->GetName().c_str(), (unsigned long)f->fd.GetNumber(), version->cfd_->GetName().c_str(), f->fd.GetNumber(), loop,
loop, " cannot be a candidate to reduce size amp.\n"); " cannot be a candidate to reduce size amp.\n");
f = nullptr; f = nullptr;
} }
if (f == nullptr) { if (f == nullptr) {
return nullptr; // no candidate files return nullptr; // no candidate files
} }
LogToBuffer(log_buffer, "[%s] Universal: First candidate file %lu[%d] %s", LogToBuffer(log_buffer,
version->cfd_->GetName().c_str(), "[%s] Universal: First candidate file %" PRIu64 "[%d] %s",
(unsigned long)f->fd.GetNumber(), start_index, version->cfd_->GetName().c_str(), f->fd.GetNumber(), start_index,
" to reduce size amp.\n"); " to reduce size amp.\n");
// keep adding up all the remaining files // keep adding up all the remaining files
@ -822,9 +818,9 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalSizeAmp(
f = version->files_[level][index]; f = version->files_[level][index];
if (f->being_compacted) { if (f->being_compacted) {
LogToBuffer( LogToBuffer(
log_buffer, "[%s] Universal: Possible candidate file %lu[%d] %s.", log_buffer,
version->cfd_->GetName().c_str(), (unsigned long)f->fd.GetNumber(), "[%s] Universal: Possible candidate file %" PRIu64 "[%d] %s.",
loop, version->cfd_->GetName().c_str(), f->fd.GetNumber(), loop,
" is already being compacted. No size amp reduction possible.\n"); " is already being compacted. No size amp reduction possible.\n");
return nullptr; return nullptr;
} }
@ -843,17 +839,16 @@ Compaction* UniversalCompactionPicker::PickCompactionUniversalSizeAmp(
if (candidate_size * 100 < ratio * earliest_file_size) { if (candidate_size * 100 < ratio * earliest_file_size) {
LogToBuffer( LogToBuffer(
log_buffer, log_buffer,
"[%s] Universal: size amp not needed. newer-files-total-size %lu " "[%s] Universal: size amp not needed. newer-files-total-size %" PRIu64
"earliest-file-size %lu", "earliest-file-size %" PRIu64,
version->cfd_->GetName().c_str(), (unsigned long)candidate_size, version->cfd_->GetName().c_str(), candidate_size, earliest_file_size);
(unsigned long)earliest_file_size);
return nullptr; return nullptr;
} else { } else {
LogToBuffer(log_buffer, LogToBuffer(
"[%s] Universal: size amp needed. newer-files-total-size %lu " log_buffer,
"earliest-file-size %lu", "[%s] Universal: size amp needed. newer-files-total-size %" PRIu64
version->cfd_->GetName().c_str(), (unsigned long)candidate_size, "earliest-file-size %" PRIu64,
(unsigned long)earliest_file_size); version->cfd_->GetName().c_str(), candidate_size, earliest_file_size);
} }
assert(start_index >= 0 && start_index < file_by_time.size() - 1); assert(start_index >= 0 && start_index < file_by_time.size() - 1);

View file

@ -731,9 +731,8 @@ void DBImpl::PurgeObsoleteFiles(DeletionState& state) {
fname.c_str(), archived_log_name.c_str(), s.ToString().c_str()); fname.c_str(), archived_log_name.c_str(), s.ToString().c_str());
} else { } else {
Status s = env_->DeleteFile(fname); Status s = env_->DeleteFile(fname);
Log(options_.info_log, "Delete %s type=%d #%lu -- %s\n", Log(options_.info_log, "Delete %s type=%d #%" PRIu64 " -- %s\n",
fname.c_str(), type, (unsigned long)number, fname.c_str(), type, number, s.ToString().c_str());
s.ToString().c_str());
} }
} }
@ -1257,8 +1256,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence,
// large sequence numbers). // large sequence numbers).
log::Reader reader(std::move(file), &reporter, true/*checksum*/, log::Reader reader(std::move(file), &reporter, true/*checksum*/,
0/*initial_offset*/); 0/*initial_offset*/);
Log(options_.info_log, "Recovering log #%lu", Log(options_.info_log, "Recovering log #%" PRIu64 "", log_number);
(unsigned long) log_number);
// Read all the records and add to a memtable // Read all the records and add to a memtable
std::string scratch; std::string scratch;
@ -1375,8 +1373,8 @@ Status DBImpl::WriteLevel0TableForRecovery(ColumnFamilyData* cfd, MemTable* mem,
const SequenceNumber newest_snapshot = snapshots_.GetNewest(); const SequenceNumber newest_snapshot = snapshots_.GetNewest();
const SequenceNumber earliest_seqno_in_memtable = const SequenceNumber earliest_seqno_in_memtable =
mem->GetFirstSequenceNumber(); mem->GetFirstSequenceNumber();
Log(options_.info_log, "[%s] Level-0 table #%lu: started", Log(options_.info_log, "[%s] Level-0 table #%" PRIu64 ": started",
cfd->GetName().c_str(), (unsigned long)meta.fd.GetNumber()); cfd->GetName().c_str(), meta.fd.GetNumber());
Status s; Status s;
{ {
@ -1389,9 +1387,10 @@ Status DBImpl::WriteLevel0TableForRecovery(ColumnFamilyData* cfd, MemTable* mem,
mutex_.Lock(); mutex_.Lock();
} }
Log(options_.info_log, "[%s] Level-0 table #%lu: %lu bytes %s", Log(options_.info_log,
cfd->GetName().c_str(), (unsigned long)meta.fd.GetNumber(), "[%s] Level-0 table #%" PRIu64 ": %" PRIu64 " bytes %s",
(unsigned long)meta.fd.GetFileSize(), s.ToString().c_str()); cfd->GetName().c_str(), meta.fd.GetNumber(), meta.fd.GetFileSize(),
s.ToString().c_str());
delete iter; delete iter;
pending_outputs_.erase(meta.fd.GetNumber()); pending_outputs_.erase(meta.fd.GetNumber());
@ -1436,14 +1435,15 @@ Status DBImpl::WriteLevel0Table(ColumnFamilyData* cfd,
log_buffer->FlushBufferToLog(); log_buffer->FlushBufferToLog();
std::vector<Iterator*> memtables; std::vector<Iterator*> memtables;
for (MemTable* m : mems) { for (MemTable* m : mems) {
Log(options_.info_log, "[%s] Flushing memtable with next log file: %lu\n", Log(options_.info_log,
cfd->GetName().c_str(), (unsigned long)m->GetNextLogNumber()); "[%s] Flushing memtable with next log file: %" PRIu64 "\n",
cfd->GetName().c_str(), m->GetNextLogNumber());
memtables.push_back(m->NewIterator(ReadOptions(), true)); memtables.push_back(m->NewIterator(ReadOptions(), true));
} }
Iterator* iter = NewMergingIterator(&cfd->internal_comparator(), Iterator* iter = NewMergingIterator(&cfd->internal_comparator(),
&memtables[0], memtables.size()); &memtables[0], memtables.size());
Log(options_.info_log, "[%s] Level-0 flush table #%lu: started", Log(options_.info_log, "[%s] Level-0 flush table #%" PRIu64 ": started",
cfd->GetName().c_str(), (unsigned long)meta.fd.GetNumber()); cfd->GetName().c_str(), meta.fd.GetNumber());
s = BuildTable(dbname_, env_, *cfd->options(), storage_options_, s = BuildTable(dbname_, env_, *cfd->options(), storage_options_,
cfd->table_cache(), iter, &meta, cfd->internal_comparator(), cfd->table_cache(), iter, &meta, cfd->internal_comparator(),
@ -1451,9 +1451,10 @@ Status DBImpl::WriteLevel0Table(ColumnFamilyData* cfd,
GetCompressionFlush(*cfd->options())); GetCompressionFlush(*cfd->options()));
LogFlush(options_.info_log); LogFlush(options_.info_log);
delete iter; delete iter;
Log(options_.info_log, "[%s] Level-0 flush table #%lu: %lu bytes %s", Log(options_.info_log,
cfd->GetName().c_str(), (unsigned long)meta.fd.GetFileSize(), "[%s] Level-0 flush table #%" PRIu64 ": %" PRIu64 " bytes %s",
(unsigned long)meta.fd.GetFileSize(), s.ToString().c_str()); cfd->GetName().c_str(), meta.fd.GetFileSize(), meta.fd.GetFileSize(),
s.ToString().c_str());
if (!options_.disableDataSync) { if (!options_.disableDataSync) {
db_directory_->Fsync(); db_directory_->Fsync();
@ -2402,9 +2403,10 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
s = iter->status(); s = iter->status();
delete iter; delete iter;
if (s.ok()) { if (s.ok()) {
Log(options_.info_log, "[%s] Generated table #%lu: %lu keys, %lu bytes", Log(options_.info_log, "[%s] Generated table #%" PRIu64 ": %" PRIu64
cfd->GetName().c_str(), (unsigned long)output_number, " keys, %" PRIu64 " bytes",
(unsigned long)current_entries, (unsigned long)current_bytes); cfd->GetName().c_str(), output_number, current_entries,
current_bytes);
} }
} }
return s; return s;
@ -2469,9 +2471,8 @@ inline SequenceNumber DBImpl::findEarliestVisibleSnapshot(
assert(prev); assert(prev);
} }
Log(options_.info_log, Log(options_.info_log,
"Looking for seqid %lu but maxseqid is %lu", "Looking for seqid %" PRIu64 " but maxseqid is %" PRIu64 "", in,
(unsigned long)in, snapshots[snapshots.size() - 1]);
(unsigned long)snapshots[snapshots.size()-1]);
assert(0); assert(0);
return 0; return 0;
} }
@ -4169,8 +4170,9 @@ Status DBImpl::MakeRoomForWrite(
} }
new_mem->Ref(); new_mem->Ref();
cfd->SetMemtable(new_mem); cfd->SetMemtable(new_mem);
Log(options_.info_log, "[%s] New memtable created with log file: #%lu\n", Log(options_.info_log,
cfd->GetName().c_str(), (unsigned long)logfile_number_); "[%s] New memtable created with log file: #%" PRIu64 "\n",
cfd->GetName().c_str(), logfile_number_);
force = false; // Do not force another compaction if have room force = false; // Do not force another compaction if have room
MaybeScheduleFlushOrCompaction(); MaybeScheduleFlushOrCompaction();
superversions_to_free->push_back( superversions_to_free->push_back(

View file

@ -31,6 +31,8 @@
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include "db/builder.h" #include "db/builder.h"
#include "db/db_impl.h" #include "db/db_impl.h"
#include "db/dbformat.h" #include "db/dbformat.h"
@ -82,18 +84,17 @@ class Repairer {
status = WriteDescriptor(); status = WriteDescriptor();
} }
if (status.ok()) { if (status.ok()) {
unsigned long long bytes = 0; uint64_t bytes = 0;
for (size_t i = 0; i < tables_.size(); i++) { for (size_t i = 0; i < tables_.size(); i++) {
bytes += tables_[i].meta.fd.GetFileSize(); bytes += tables_[i].meta.fd.GetFileSize();
} }
Log(options_.info_log, Log(options_.info_log,
"**** Repaired rocksdb %s; " "**** Repaired rocksdb %s; "
"recovered %d files; %llu bytes. " "recovered %zu files; %" PRIu64
"bytes. "
"Some data may have been lost. " "Some data may have been lost. "
"****", "****",
dbname_.c_str(), dbname_.c_str(), tables_.size(), bytes);
static_cast<int>(tables_.size()),
bytes);
} }
return status; return status;
} }
@ -159,8 +160,8 @@ class Repairer {
std::string logname = LogFileName(dbname_, logs_[i]); std::string logname = LogFileName(dbname_, logs_[i]);
Status status = ConvertLogToTable(logs_[i]); Status status = ConvertLogToTable(logs_[i]);
if (!status.ok()) { if (!status.ok()) {
Log(options_.info_log, "Log #%llu: ignoring conversion error: %s", Log(options_.info_log,
(unsigned long long) logs_[i], "Log #%" PRIu64 ": ignoring conversion error: %s", logs_[i],
status.ToString().c_str()); status.ToString().c_str());
} }
ArchiveFile(logname); ArchiveFile(logname);
@ -174,10 +175,8 @@ class Repairer {
uint64_t lognum; uint64_t lognum;
virtual void Corruption(size_t bytes, const Status& s) { virtual void Corruption(size_t bytes, const Status& s) {
// We print error messages for corruption, but continue repairing. // We print error messages for corruption, but continue repairing.
Log(info_log, "Log #%llu: dropping %d bytes; %s", Log(info_log, "Log #%" PRIu64 ": dropping %d bytes; %s", lognum,
(unsigned long long) lognum, static_cast<int>(bytes), s.ToString().c_str());
static_cast<int>(bytes),
s.ToString().c_str());
} }
}; };
@ -220,8 +219,7 @@ class Repairer {
if (status.ok()) { if (status.ok()) {
counter += WriteBatchInternal::Count(&batch); counter += WriteBatchInternal::Count(&batch);
} else { } else {
Log(options_.info_log, "Log #%llu: ignoring %s", Log(options_.info_log, "Log #%" PRIu64 ": ignoring %s", log,
(unsigned long long) log,
status.ToString().c_str()); status.ToString().c_str());
status = Status::OK(); // Keep going with rest of file status = Status::OK(); // Keep going with rest of file
} }
@ -244,9 +242,9 @@ class Repairer {
table_numbers_.push_back(meta.fd.GetNumber()); table_numbers_.push_back(meta.fd.GetNumber());
} }
} }
Log(options_.info_log, "Log #%llu: %d ops saved to Table #%llu %s", Log(options_.info_log,
(unsigned long long)log, counter, "Log #%" PRIu64 ": %d ops saved to Table #%" PRIu64 " %s", log, counter,
(unsigned long long)meta.fd.GetNumber(), status.ToString().c_str()); meta.fd.GetNumber(), status.ToString().c_str());
return status; return status;
} }
@ -257,9 +255,8 @@ class Repairer {
Status status = ScanTable(&t); Status status = ScanTable(&t);
if (!status.ok()) { if (!status.ok()) {
std::string fname = TableFileName(dbname_, table_numbers_[i]); std::string fname = TableFileName(dbname_, table_numbers_[i]);
Log(options_.info_log, "Table #%llu: ignoring %s", Log(options_.info_log, "Table #%" PRIu64 ": ignoring %s",
(unsigned long long) table_numbers_[i], table_numbers_[i], status.ToString().c_str());
status.ToString().c_str());
ArchiveFile(fname); ArchiveFile(fname);
} else { } else {
tables_.push_back(t); tables_.push_back(t);
@ -281,9 +278,8 @@ class Repairer {
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
Slice key = iter->key(); Slice key = iter->key();
if (!ParseInternalKey(key, &parsed)) { if (!ParseInternalKey(key, &parsed)) {
Log(options_.info_log, "Table #%llu: unparsable key %s", Log(options_.info_log, "Table #%" PRIu64 ": unparsable key %s",
(unsigned long long)t->meta.fd.GetNumber(), t->meta.fd.GetNumber(), EscapeString(key).c_str());
EscapeString(key).c_str());
continue; continue;
} }
@ -305,9 +301,8 @@ class Repairer {
} }
delete iter; delete iter;
} }
Log(options_.info_log, "Table #%llu: %d entries %s", Log(options_.info_log, "Table #%" PRIu64 ": %d entries %s",
(unsigned long long)t->meta.fd.GetNumber(), counter, t->meta.fd.GetNumber(), counter, status.ToString().c_str());
status.ToString().c_str());
return status; return status;
} }