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 }
90
91
92
93
94 public static class CompactionPartitionId {
95
96 private String startKey;
97 private String date;
98
99 public CompactionPartitionId(String startKey, String date) {
100 if (startKey == null || date == null) {
101 throw new IllegalArgumentException("Neither of start key and date could be null");
102 }
103 this.startKey = startKey;
104 this.date = date;
105 }
106
107 public String getStartKey() {
108 return this.startKey;
109 }
110
111 public String getDate() {
112 return this.date;
113 }
114
115 @Override
116 public int hashCode() {
117 int result = 17;
118 result = 31 * result + startKey.hashCode();
119 result = 31 * result + date.hashCode();
120 return result;
121 }
122
123 @Override
124 public boolean equals(Object obj) {
125 if (this == obj) {
126 return true;
127 }
128 if (!(obj instanceof CompactionPartitionId)) {
129 return false;
130 }
131 CompactionPartitionId another = (CompactionPartitionId) obj;
132 if (!this.startKey.equals(another.startKey)) {
133 return false;
134 }
135 if (!this.date.equals(another.date)) {
136 return false;
137 }
138 return true;
139 }
140
141 @Override
142 public String toString() {
143 return new StringBuilder(startKey).append(date).toString();
144 }
145 }
146 }