Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
disk-info.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_DISK_INFO_H
17 #define IMPALA_UTIL_DISK_INFO_H
18 
19 #include <map>
20 #include <string>
21 
22 #include <boost/cstdint.hpp>
23 #include "common/logging.h"
24 
25 namespace impala {
26 
32 class DiskInfo {
33  public:
35  static void Init();
36 
38  static int num_disks() {
39  DCHECK(initialized_);
40  return disks_.size();
41  }
42 
43 #if 0
44  static int num_datanode_dirs() {
49  DCHECK(initialized_);
50  return num_datanode_dirs_;
51  }
52 
54  static int disk_id(int datanode_dir_idx) {
55  return 0;
56  }
57 #endif
58 
61  static int disk_id(const char* path);
62 
64  static const std::string& device_name(int disk_id) {
65  DCHECK_GE(disk_id, 0);
66  DCHECK_LT(disk_id, disks_.size());
67  return disks_[disk_id].name;
68  }
69 
70  static bool is_rotational(int disk_id) {
71  DCHECK_GE(disk_id, 0);
72  DCHECK_LT(disk_id, disks_.size());
73  return disks_[disk_id].is_rotational;
74  }
75 
76  static std::string DebugString();
77 
78  private:
79  static bool initialized_;
80 
81  struct Disk {
83  std::string name;
84 
87  int id;
88 
90 
91  Disk(const std::string& name = "", int id = -1, bool is_rotational = true)
93  };
94 
96  static std::vector<Disk> disks_;
97 
99  static std::map<dev_t, int> device_id_to_disk_id_;
100 
102  static std::map<std::string, int> disk_name_to_disk_id_;
103 
104  static int num_datanode_dirs_;
105 
106  static void GetDeviceNames();
107 };
108 
109 
110 }
111 #endif
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
static const std::string & device_name(int disk_id)
Returns the device name (e.g. sda) for disk_id.
Definition: disk-info.h:64
static bool initialized_
Definition: disk-info.h:79
static int num_disks()
Returns the number of (logical) disks on the system.
Definition: disk-info.h:38
static void Init()
Initialize DiskInfo. Just be called before any other functions.
Definition: disk-info.cc:114
Disk(const std::string &name="", int id=-1, bool is_rotational=true)
Definition: disk-info.h:91
static bool is_rotational(int disk_id)
Definition: disk-info.h:70
static std::vector< Disk > disks_
All disks.
Definition: disk-info.h:96
std::string name
Name of the disk (e.g. sda)
Definition: disk-info.h:83
static std::string DebugString()
Definition: disk-info.cc:127
static int num_datanode_dirs_
Definition: disk-info.h:104
static std::map< dev_t, int > device_id_to_disk_id_
mapping of dev_ts to disk ids
Definition: disk-info.h:99
static void GetDeviceNames()
Definition: disk-info.cc:49
static int disk_id(const char *path)
Definition: disk-info.cc:119
static std::map< std::string, int > disk_name_to_disk_id_
mapping of devices names to disk ids
Definition: disk-info.h:102