1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.mapreduce;
19
20 import java.io.IOException;
21 import java.util.List;
22
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.client.Delete;
26 import org.apache.hadoop.hbase.client.HTable;
27
28 import com.google.common.annotations.VisibleForTesting;
29
30
31
32
33
34
35 @InterfaceAudience.Private
36 public class BufferedHTable extends HTable {
37
38 private boolean closed = false;
39
40 public BufferedHTable(Configuration conf, String tableName) throws IOException {
41 super(conf, tableName);
42 }
43
44 public BufferedHTable(Configuration conf, byte[] tableName) throws IOException {
45 super(conf, tableName);
46 }
47
48 @Override
49 public void delete(Delete delete) throws IOException {
50 doDelete(delete);
51 }
52
53 @Override
54 public void delete(List<Delete> deletes) throws IOException {
55 for (Delete delete : deletes) {
56 doDelete(delete);
57 }
58 }
59
60 private void doDelete(Delete delete) throws IOException {
61 if (this.closed) {
62 throw new IllegalStateException("BufferedHTable was closed");
63 }
64
65 this.currentWriteBufferSize += delete.heapSize();
66 this.writeAsyncBuffer.add(delete);
67
68
69 if (this.currentWriteBufferSize > getWriteBufferSize()) {
70 flushCommits();
71 }
72 }
73
74 @Override
75 public void close() throws IOException {
76 if (this.closed) {
77 return;
78 }
79 flushCommits();
80 this.closed = true;
81 super.close();
82 }
83
84 @VisibleForTesting
85 long getCurrentWriteBufferSize() {
86 return this.currentWriteBufferSize;
87 }
88 }