1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mob.compactions;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.fs.FileStatus;
28 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
29
30
31
32
33
34
35
36 @InterfaceAudience.Private
37 public class PartitionedMobCompactionRequest extends MobCompactionRequest {
38
39 protected Collection<FileStatus> delFiles;
40 protected Collection<CompactionPartition> compactionPartitions;
41
42 public PartitionedMobCompactionRequest(Collection<CompactionPartition> compactionPartitions,
43 Collection<FileStatus> delFiles) {
44 this.selectionTime = EnvironmentEdgeManager.currentTime();
45 this.compactionPartitions = compactionPartitions;
46 this.delFiles = delFiles;
47 }
48
49
50
51
52
53 public Collection<CompactionPartition> getCompactionPartitions() {
54 return this.compactionPartitions;
55 }
56
57
58
59
60
61 public Collection<FileStatus> getDelFiles() {
62 return this.delFiles;
63 }
64
65
66
67
68
69
70 protected static class CompactionPartition {
71 private List<FileStatus> files = new ArrayList<FileStatus>();
72 private CompactionPartitionId partitionId;
73
74 public CompactionPartition(CompactionPartitionId partitionId) {
75 this.partitionId = partitionId;
76 }
77
78 public CompactionPartitionId getPartitionId() {
79 return this.partitionId;
80 }
81
82 public void addFile(FileStatus file) {
83 files.add(file);
84 }
85
86 public List<FileStatus> listFiles() {
87 return Collections.unmodifiableList(files);
88 }
89 public int getFileCount () {
90 return files.size();
91 }
92 }
93
94
95
96
97 public static class CompactionPartitionId {
98 private String startKey;
99 private String date;
100
101 public CompactionPartitionId() {
102
103 this.startKey = "";
104 this.date = "";
105 }
106
107 public CompactionPartitionId(String startKey, String date) {
108 if (startKey == null || date == null) {
109 throw new IllegalArgumentException("Neither of start key and date could be null");
110 }
111 this.startKey = startKey;
112 this.date = date;
113 }
114
115 public String getStartKey() {
116 return this.startKey;
117 }
118
119 public void setStartKey(final String startKey) {
120 this.startKey = startKey;
121 }
122
123 public String getDate() {
124 return this.date;
125 }
126
127 public void setDate(final String date) {
128 this.date = date;
129 }
130
131 @Override
132 public int hashCode() {
133 int result = 17;
134 result = 31 * result + startKey.hashCode();
135 result = 31 * result + date.hashCode();
136 return result;
137 }
138
139 @Override
140 public boolean equals(Object obj) {
141 if (this == obj) {
142 return true;
143 }
144 if (!(obj instanceof CompactionPartitionId)) {
145 return false;
146 }
147 CompactionPartitionId another = (CompactionPartitionId) obj;
148 if (!this.startKey.equals(another.startKey)) {
149 return false;
150 }
151 if (!this.date.equals(another.date)) {
152 return false;
153 }
154 return true;
155 }
156
157 @Override
158 public String toString() {
159 return new StringBuilder(startKey).append(date).toString();
160 }
161 }
162 }