]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/db_info_dumper.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 #ifndef __STDC_FORMAT_MACROS
7 #define __STDC_FORMAT_MACROS
10 #include "db/db_info_dumper.h"
18 #include "rocksdb/env.h"
19 #include "util/filename.h"
23 void DumpDBFileSummary(const ImmutableDBOptions
& options
,
24 const std::string
& dbname
) {
25 if (options
.info_log
== nullptr) {
29 auto* env
= options
.env
;
31 FileType type
= kInfoLogFile
;
33 std::vector
<std::string
> files
;
34 uint64_t file_num
= 0;
36 std::string file_info
, wal_info
;
38 Header(options
.info_log
, "DB SUMMARY\n");
39 // Get files in dbname dir
40 if (!env
->GetChildren(dbname
, &files
).ok()) {
41 Error(options
.info_log
,
42 "Error when reading %s dir\n", dbname
.c_str());
44 std::sort(files
.begin(), files
.end());
45 for (const std::string
& file
: files
) {
46 if (!ParseFileName(file
, &number
, &type
)) {
51 Header(options
.info_log
, "CURRENT file: %s\n", file
.c_str());
54 Header(options
.info_log
, "IDENTITY file: %s\n", file
.c_str());
57 env
->GetFileSize(dbname
+ "/" + file
, &file_size
);
58 Header(options
.info_log
, "MANIFEST file: %s size: %" PRIu64
" Bytes\n",
59 file
.c_str(), file_size
);
62 env
->GetFileSize(dbname
+ "/" + file
, &file_size
);
64 snprintf(str
, sizeof(str
), "%" PRIu64
, file_size
);
65 wal_info
.append(file
).append(" size: ").
66 append(str
).append(" ; ");
69 if (++file_num
< 10) {
70 file_info
.append(file
).append(" ");
78 // Get sst files in db_path dir
79 for (auto& db_path
: options
.db_paths
) {
80 if (dbname
.compare(db_path
.path
) != 0) {
81 if (!env
->GetChildren(db_path
.path
, &files
).ok()) {
82 Error(options
.info_log
,
83 "Error when reading %s dir\n",
84 db_path
.path
.c_str());
87 std::sort(files
.begin(), files
.end());
88 for (const std::string
& file
: files
) {
89 if (ParseFileName(file
, &number
, &type
)) {
90 if (type
== kTableFile
&& ++file_num
< 10) {
91 file_info
.append(file
).append(" ");
96 Header(options
.info_log
,
97 "SST files in %s dir, Total Num: %" PRIu64
", files: %s\n",
98 db_path
.path
.c_str(), file_num
, file_info
.c_str());
103 // Get wal file in wal_dir
104 if (dbname
.compare(options
.wal_dir
) != 0) {
105 if (!env
->GetChildren(options
.wal_dir
, &files
).ok()) {
106 Error(options
.info_log
,
107 "Error when reading %s dir\n",
108 options
.wal_dir
.c_str());
112 for (const std::string
& file
: files
) {
113 if (ParseFileName(file
, &number
, &type
)) {
114 if (type
== kLogFile
) {
115 env
->GetFileSize(options
.wal_dir
+ "/" + file
, &file_size
);
117 snprintf(str
, sizeof(str
), "%" PRIu64
, file_size
);
118 wal_info
.append(file
).append(" size: ").
119 append(str
).append(" ; ");
124 Header(options
.info_log
, "Write Ahead Log file in %s: %s\n",
125 options
.wal_dir
.c_str(), wal_info
.c_str());
127 } // namespace rocksdb