-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdfslistblocks.cpp
More file actions
65 lines (50 loc) · 1.65 KB
/
hdfslistblocks.cpp
File metadata and controls
65 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "hdfscpp.h"
#include <iostream>
#include <vector>
#include <string>
/**********************************************************************/
void ShowUsage()
{
std::cerr << "Usage: hdfslistblocks <path> " << std::endl;
}
int main(int argc, char* argv[])
{
using namespace tmacam;
// Check command line arguments
if ( argc != 2) {
std::cerr << "Wrong number of arguments" << std::endl;
ShowUsage();
exit(EXIT_FAILURE);
}
const char* path = argv[1];
// Connect to HDFS / get filesystem handle
hdfs::FileSystem fs;
// Path is a file, right?
if (!fs.Exists(path)) {
std::cerr << "Path '" << path << "' does not exist." << std::endl;
exit(EXIT_FAILURE);
}
hdfs::FileInfoList path_info;
fs.GetPathInfo(path, &path_info);
if (path_info->mKind != kObjectKindFile ) {
std::cerr << "Path '" << path << "' is not a regular file."
<< std::endl;
exit(EXIT_FAILURE);
}
// Get block distributions for ALL blocks
std::cout << path << " has a block size of "
<< (path_info->mBlockSize >> 20) << " MB" << std::endl;
hdfs::BlockLocationList blocks_location;
hdfs::GetFileBlockLocations(fs, path, 0, path_info->mSize,
&blocks_location);
for(int i = 0; i < blocks_location.size(); ++i) {
std::cout << "In block " << i << std::endl;
for(int j = 0; j < blocks_location[i].size(); ++j) {
std::cout << "\tavailable @ host " << blocks_location[i][j]
<< std::endl;
}
}
std::cout << "Foi" << std::endl;
return 0;
}
// vim: et ai sts=4 ts=4 sw=4