1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver;
21
22 import org.apache.hadoop.hbase.*;
23 import org.apache.hadoop.hbase.client.Get;
24 import org.apache.hadoop.hbase.client.Put;
25 import org.apache.hadoop.hbase.testclassification.MediumTests;
26 import org.apache.hadoop.hbase.util.Bytes;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 import java.io.IOException;
33
34
35
36
37
38 @Category(MediumTests.class)
39 public class TestRowTooBig {
40 private final static HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU();
41 private static final HTableDescriptor TEST_HTD =
42 new HTableDescriptor(TableName.valueOf(TestRowTooBig.class.getSimpleName()));
43
44 @BeforeClass
45 public static void before() throws Exception {
46 HTU.startMiniCluster();
47 HTU.getConfiguration().setLong(HConstants.TABLE_MAX_ROWSIZE_KEY,
48 10 * 1024 * 1024L);
49 }
50
51 @AfterClass
52 public static void after() throws Exception {
53 HTU.shutdownMiniCluster();
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67 @Test(expected = RowTooBigException.class)
68 public void testScannersSeekOnFewLargeCells() throws IOException {
69 byte[] row1 = Bytes.toBytes("row1");
70 byte[] fam1 = Bytes.toBytes("fam1");
71
72 HTableDescriptor htd = TEST_HTD;
73 HColumnDescriptor hcd = new HColumnDescriptor(fam1);
74 if (htd.hasFamily(hcd.getName())) {
75 htd.modifyFamily(hcd);
76 } else {
77 htd.addFamily(hcd);
78 }
79
80 final HRegionInfo hri =
81 new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,
82 HConstants.EMPTY_END_ROW);
83 HRegion region = HTU.createLocalHRegion(hri, htd);
84
85
86 for (int i = 0; i < 5 ; i++) {
87 Put put = new Put(row1);
88
89 put.add(fam1, Bytes.toBytes("col_" + i ), new byte[5 * 1024 * 1024]);
90 region.put(put);
91 region.flushcache();
92 }
93
94 Get get = new Get(row1);
95 region.get(get);
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109 @Test(expected = RowTooBigException.class)
110 public void testScanAcrossManySmallColumns() throws IOException {
111 byte[] row1 = Bytes.toBytes("row1");
112 byte[] fam1 = Bytes.toBytes("fam1");
113
114 HTableDescriptor htd = TEST_HTD;
115 HColumnDescriptor hcd = new HColumnDescriptor(fam1);
116 if (htd.hasFamily(hcd.getName())) {
117 htd.modifyFamily(hcd);
118 } else {
119 htd.addFamily(hcd);
120 }
121
122 final HRegionInfo hri =
123 new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW,
124 HConstants.EMPTY_END_ROW);
125 HRegion region = HTU.createLocalHRegion(hri, htd);
126
127
128 for (int i = 0; i < 10; i++) {
129 Put put = new Put(row1);
130 for (int j = 0; j < 10 * 10000; j++) {
131 put.add(fam1, Bytes.toBytes("col_" + i + "_" + j), new byte[10]);
132 }
133 region.put(put);
134 region.flushcache();
135 }
136 region.compactStores(true);
137
138 Get get = new Get(row1);
139 region.get(get);
140 }
141 }