1 | /******************************************************************** |
2 | * Copyright (c) 2013 - 2014, Pivotal Inc. |
3 | * All rights reserved. |
4 | * |
5 | * Author: Zhanwei Wang |
6 | ********************************************************************/ |
7 | /******************************************************************** |
8 | * 2014 - |
9 | * open source under Apache License Version 2.0 |
10 | ********************************************************************/ |
11 | /** |
12 | * Licensed to the Apache Software Foundation (ASF) under one |
13 | * or more contributor license agreements. See the NOTICE file |
14 | * distributed with this work for additional information |
15 | * regarding copyright ownership. The ASF licenses this file |
16 | * to you under the Apache License, Version 2.0 (the |
17 | * "License"); you may not use this file except in compliance |
18 | * with the License. You may obtain a copy of the License at |
19 | * |
20 | * http://www.apache.org/licenses/LICENSE-2.0 |
21 | * |
22 | * Unless required by applicable law or agreed to in writing, software |
23 | * distributed under the License is distributed on an "AS IS" BASIS, |
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
25 | * See the License for the specific language governing permissions and |
26 | * limitations under the License. |
27 | */ |
28 | #ifndef _HDFS_LIBHDFS3_SERVER_EXTENDEDBLOCK_H_ |
29 | #define _HDFS_LIBHDFS3_SERVER_EXTENDEDBLOCK_H_ |
30 | |
31 | #include "Hash.h" |
32 | #include <string> |
33 | #include <sstream> |
34 | |
35 | namespace Hdfs { |
36 | namespace Internal { |
37 | |
38 | /** |
39 | * Identifies a Block uniquely across the block pools |
40 | */ |
41 | class ExtendedBlock { |
42 | public: |
43 | ExtendedBlock() : |
44 | blockId(0), generationStamp(0), numBytes(0) { |
45 | } |
46 | |
47 | int64_t getBlockId() const { |
48 | return blockId; |
49 | } |
50 | |
51 | void setBlockId(int64_t blockId) { |
52 | this->blockId = blockId; |
53 | } |
54 | |
55 | int64_t getGenerationStamp() const { |
56 | return generationStamp; |
57 | } |
58 | |
59 | void setGenerationStamp(int64_t generationStamp) { |
60 | this->generationStamp = generationStamp; |
61 | } |
62 | |
63 | int64_t getNumBytes() const { |
64 | return numBytes; |
65 | } |
66 | |
67 | void setNumBytes(int64_t numBytes) { |
68 | this->numBytes = numBytes; |
69 | } |
70 | |
71 | const std::string & getPoolId() const { |
72 | return poolId; |
73 | } |
74 | |
75 | void setPoolId(const std::string & poolId) { |
76 | this->poolId = poolId; |
77 | } |
78 | |
79 | const std::string toString() const { |
80 | std::stringstream ss; |
81 | ss.imbue(std::locale::classic()); |
82 | ss << "[block pool ID: " << poolId << " block ID " << blockId << "_" |
83 | << generationStamp << "]" ; |
84 | return ss.str(); |
85 | } |
86 | |
87 | size_t hash_value() const { |
88 | size_t values[] = { Int64Hasher(blockId), StringHasher(poolId) }; |
89 | return CombineHasher(values, sizeof(values) / sizeof(values[0])); |
90 | } |
91 | |
92 | private: |
93 | int64_t blockId; |
94 | int64_t generationStamp; |
95 | int64_t numBytes; |
96 | std::string poolId; |
97 | }; |
98 | |
99 | } |
100 | } |
101 | |
102 | HDFS_HASH_DEFINE(::Hdfs::Internal::ExtendedBlock); |
103 | |
104 | #endif /* _HDFS_LIBHDFS3_SERVER_EXTENDEDBLOCK_H_ */ |
105 | |