Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tmp-file-mgr.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 #ifndef IMPALA_RUNTIME_TMP_FILE_MGR_H
16 #define IMPALA_RUNTIME_TMP_FILE_MGR_H
17 
18 #include <common/status.h>
19 #include "gen-cpp/Types_types.h" // for TUniqueId
20 
21 namespace impala {
22 
25 //
28 class TmpFileMgr {
29  public:
33  class File {
34  public:
38  Status AllocateSpace(int64_t write_size, int64_t* offset);
39 
42  Status Remove();
43 
44  const std::string& path() const { return path_; }
45  int disk_id() const { return disk_id_; }
46 
47  private:
48  friend class TmpFileMgr;
49 
52  const static std::string TMP_SUB_DIR_NAME;
53 
57 
58  File(const std::string& path);
59 
61  std::string path_;
62 
64  int disk_id_;
65 
67  int64_t current_offset_;
68 
71  int64_t current_size_;
72  };
73 
76  static Status Init();
77 
82  static Status GetFile(int tmp_device_id, const TUniqueId& query_id,
83  File** new_file);
84 
87  static int num_tmp_devices() { return tmp_dirs_.size(); }
88 
89  private:
90  static bool initialized_;
91 
93  static std::vector<std::string> tmp_dirs_;
94 };
95 
96 }
97 
98 #endif
static int num_tmp_devices()
Definition: tmp-file-mgr.h:87
static Status GetFile(int tmp_device_id, const TUniqueId &query_id, File **new_file)
Definition: tmp-file-mgr.cc:88
const TUniqueId & query_id() const
Definition: coordinator.h:152
Status AllocateSpace(int64_t write_size, int64_t *offset)
static Status Init()
Definition: tmp-file-mgr.cc:47
const std::string & path() const
Definition: tmp-file-mgr.h:44
std::string path_
Path of the physical file in the filesystem.
Definition: tmp-file-mgr.h:61
int64_t current_offset_
Offset to which the next block will be written.
Definition: tmp-file-mgr.h:67
static std::vector< std::string > tmp_dirs_
The created tmp directories, atmost one per device.
Definition: tmp-file-mgr.h:93
static const uint64_t AVAILABLE_SPACE_THRESHOLD_MB
Definition: tmp-file-mgr.h:56
int disk_id_
The id of the disk on which the physical file lies.
Definition: tmp-file-mgr.h:64
File(const std::string &path)
uint8_t offset[7 *64-sizeof(uint64_t)]
static const std::string TMP_SUB_DIR_NAME
Definition: tmp-file-mgr.h:52
static bool initialized_
Definition: tmp-file-mgr.h:90