| 301 |
ashish |
1 |
// Copyright (c) 2009- Facebook
|
|
|
2 |
// Distributed under the Scribe Software License
|
|
|
3 |
//
|
|
|
4 |
// See accompanying file LICENSE or visit the Scribe site at:
|
|
|
5 |
// http://developers.facebook.com/scribe/
|
|
|
6 |
//
|
|
|
7 |
#ifndef HDFS_FILE_H
|
|
|
8 |
#define HDFS_FILE_H
|
|
|
9 |
|
|
|
10 |
#ifdef USE_SCRIBE_HDFS
|
|
|
11 |
#include "hdfs.h"
|
|
|
12 |
|
|
|
13 |
class HdfsFile : public FileInterface {
|
|
|
14 |
public:
|
|
|
15 |
HdfsFile(const std::string& name);
|
|
|
16 |
virtual ~HdfsFile();
|
|
|
17 |
|
|
|
18 |
static void init(); // initialize hdfs subsystem
|
|
|
19 |
bool openRead(); // open for reading file
|
|
|
20 |
bool openWrite(); // open for appending to file
|
|
|
21 |
bool openTruncate(); // truncate and open for write
|
|
|
22 |
bool isOpen(); // is file open?
|
|
|
23 |
void close();
|
|
|
24 |
bool write(const std::string& data);
|
|
|
25 |
void flush();
|
|
|
26 |
unsigned long fileSize();
|
|
|
27 |
bool readNext(std::string& _return);
|
|
|
28 |
void deleteFile();
|
|
|
29 |
void listImpl(const std::string& path, std::vector<std::string>& _return);
|
|
|
30 |
std::string getFrame(unsigned data_size);
|
|
|
31 |
bool createDirectory(std::string path);
|
|
|
32 |
bool createSymlink(std::string newpath, std::string oldpath);
|
|
|
33 |
|
|
|
34 |
private:
|
|
|
35 |
char* inputBuffer_;
|
|
|
36 |
unsigned bufferSize_;
|
|
|
37 |
hdfsFS fileSys;
|
|
|
38 |
hdfsFile hfile;
|
|
|
39 |
hdfsFS connectToPath(const char* uri);
|
|
|
40 |
|
|
|
41 |
// disallow copy, assignment, and empty construction
|
|
|
42 |
HdfsFile();
|
|
|
43 |
HdfsFile(HdfsFile& rhs);
|
|
|
44 |
HdfsFile& operator=(HdfsFile& rhs);
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* A static lock
|
|
|
49 |
*/
|
|
|
50 |
class HdfsLock {
|
|
|
51 |
private:
|
|
|
52 |
static bool lockInitialized;
|
|
|
53 |
|
|
|
54 |
public:
|
|
|
55 |
static pthread_mutex_t lock;
|
|
|
56 |
static bool initLock() {
|
|
|
57 |
pthread_mutex_init(&lock, NULL);
|
|
|
58 |
return true;
|
|
|
59 |
}
|
|
|
60 |
};
|
|
|
61 |
|
|
|
62 |
#else
|
|
|
63 |
|
|
|
64 |
class HdfsFile : public FileInterface {
|
|
|
65 |
public:
|
|
|
66 |
HdfsFile(const std::string& name) : FileInterface(name, false) {
|
|
|
67 |
LOG_OPER("[hdfs] ERROR: HDFS is not supported. file: %s", name.c_str());
|
|
|
68 |
LOG_OPER("[hdfs] If you want HDFS Support, please recompile scribe with HDFS support");
|
|
|
69 |
}
|
|
|
70 |
static void init() {};
|
|
|
71 |
bool openRead() { return false; }; // open for reading file
|
|
|
72 |
bool openWrite(){ return false; }; // open for appending to file
|
|
|
73 |
bool openTruncate() { return false; } // open for write and truncate
|
|
|
74 |
bool isOpen() { return false; }; // is file open?
|
|
|
75 |
void close() {};
|
|
|
76 |
bool write(const std::string& data) { return false; };
|
|
|
77 |
void flush() {};
|
|
|
78 |
unsigned long fileSize() { return 0; };
|
|
|
79 |
bool readNext(std::string& _return) { return false; };
|
|
|
80 |
void deleteFile() {};
|
|
|
81 |
void listImpl(const std::string& path, std::vector<std::string>& _return) {};
|
|
|
82 |
std::string getFrame(unsigned data_size) { return 0; };
|
|
|
83 |
bool createDirectory(std::string path) { return false; };
|
|
|
84 |
bool createSymlink(std::string newpath, std::string oldpath) { return false; };
|
|
|
85 |
};
|
|
|
86 |
#endif // USE_SCRIBE_HDFS
|
|
|
87 |
|
|
|
88 |
#endif // HDFS_FILE_H
|