Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hdfs-fs-cache.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_RUNTIME_HDFS_FS_CACHE_H
17 #define IMPALA_RUNTIME_HDFS_FS_CACHE_H
18 
19 #include <string>
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/unordered_map.hpp>
22 #include <boost/thread/mutex.hpp>
23 #include <hdfs.h>
24 
25 #include "common/status.h"
26 
27 namespace impala {
28 
32 //
39 class HdfsFsCache {
40  public:
41  typedef boost::unordered_map<std::string, hdfsFS> HdfsFsMap;
42 
43  static HdfsFsCache* instance() { return HdfsFsCache::instance_.get(); }
44 
46  static void Init();
47 
49  Status GetLocalConnection(hdfsFS* fs);
50 
55  Status GetConnection(const std::string& path, hdfsFS* fs,
56  HdfsFsMap* local_cache = NULL);
57 
60  static string GetNameNodeFromPath(const string& path, string* err);
61 
62  private:
64  static boost::scoped_ptr<HdfsFsCache> instance_;
65 
66  boost::mutex lock_; // protects fs_map_
68 
69  HdfsFsCache() { };
70  HdfsFsCache(HdfsFsCache const& l); // disable copy ctor
71  HdfsFsCache& operator=(HdfsFsCache const& l); // disable assignment
72 };
73 
74 }
75 
76 #endif
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
boost::unordered_map< std::string, hdfsFS > HdfsFsMap
Definition: hdfs-fs-cache.h:41
HdfsFsCache & operator=(HdfsFsCache const &l)
Status GetConnection(const std::string &path, hdfsFS *fs, HdfsFsMap *local_cache=NULL)
static string GetNameNodeFromPath(const string &path, string *err)
static boost::scoped_ptr< HdfsFsCache > instance_
Singleton instance. Instantiated in Init().
Definition: hdfs-fs-cache.h:64
static HdfsFsCache * instance()
Definition: hdfs-fs-cache.h:43
boost::mutex lock_
Definition: hdfs-fs-cache.h:66
static void Init()
Initializes the cache. Must be called before any other APIs.
Status GetLocalConnection(hdfsFS *fs)
Get connection to the local filesystem.