@@ -60,6 +60,13 @@ public final class TableDescriptorChecker {
60
60
private TableDescriptorChecker () {
61
61
}
62
62
63
+ private static boolean shouldSanityCheck (final Configuration conf ) {
64
+ if (conf .getBoolean (TABLE_SANITY_CHECKS , DEFAULT_TABLE_SANITY_CHECKS )) {
65
+ return true ;
66
+ }
67
+ return false ;
68
+ }
69
+
63
70
/**
64
71
* Checks whether the table conforms to some sane limits, and configured values (compression, etc)
65
72
* work. Throws an exception if something is wrong.
@@ -68,15 +75,8 @@ public static void sanityCheck(final Configuration c, final TableDescriptor td)
68
75
throws IOException {
69
76
CompoundConfiguration conf = new CompoundConfiguration ().add (c ).addBytesMap (td .getValues ());
70
77
71
- // Setting this to true logs the warning instead of throwing exception
72
- boolean logWarn = false ;
73
- if (!conf .getBoolean (TABLE_SANITY_CHECKS , DEFAULT_TABLE_SANITY_CHECKS )) {
74
- logWarn = true ;
75
- }
76
- String tableVal = td .getValue (TABLE_SANITY_CHECKS );
77
- if (tableVal != null && !Boolean .valueOf (tableVal )) {
78
- logWarn = true ;
79
- }
78
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
79
+ boolean logWarn = !shouldSanityCheck (conf );
80
80
81
81
// check max file size
82
82
long maxFileSizeLowerLimit = 2 * 1024 * 1024L ; // 2M is the default lower limit
@@ -107,36 +107,20 @@ public static void sanityCheck(final Configuration c, final TableDescriptor td)
107
107
}
108
108
109
109
// check that coprocessors and other specified plugin classes can be loaded
110
- try {
111
- checkClassLoading (conf , td );
112
- } catch (Exception ex ) {
113
- warnOrThrowExceptionForFailure (logWarn , ex .getMessage (), null );
114
- }
110
+ checkClassLoading (conf , td );
115
111
116
112
if (conf .getBoolean (MASTER_CHECK_COMPRESSION , DEFAULT_MASTER_CHECK_COMPRESSION )) {
117
113
// check compression can be loaded
118
- try {
119
- checkCompression (td );
120
- } catch (IOException e ) {
121
- warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
122
- }
114
+ checkCompression (conf , td );
123
115
}
124
116
125
117
if (conf .getBoolean (MASTER_CHECK_ENCRYPTION , DEFAULT_MASTER_CHECK_ENCRYPTION )) {
126
118
// check encryption can be loaded
127
- try {
128
- checkEncryption (conf , td );
129
- } catch (IOException e ) {
130
- warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
131
- }
119
+ checkEncryption (conf , td );
132
120
}
133
121
134
122
// Verify compaction policy
135
- try {
136
- checkCompactionPolicy (conf , td );
137
- } catch (IOException e ) {
138
- warnOrThrowExceptionForFailure (false , e .getMessage (), e );
139
- }
123
+ checkCompactionPolicy (conf , td );
140
124
// check that we have at least 1 CF
141
125
if (td .getColumnFamilyCount () == 0 ) {
142
126
String message = "Table should have at least one column family." ;
@@ -155,6 +139,12 @@ public static void sanityCheck(final Configuration c, final TableDescriptor td)
155
139
warnOrThrowExceptionForFailure (false , "Meta table can't be set as read only." , null );
156
140
}
157
141
142
+ // check replication scope
143
+ checkReplicationScope (conf , td );
144
+
145
+ // check bloom filter type
146
+ checkBloomFilterType (conf , td );
147
+
158
148
for (ColumnFamilyDescriptor hcd : td .getColumnFamilies ()) {
159
149
if (hcd .getTimeToLive () <= 0 ) {
160
150
String message = "TTL for column family " + hcd .getNameAsString () + " must be positive." ;
@@ -185,11 +175,6 @@ public static void sanityCheck(final Configuration c, final TableDescriptor td)
185
175
warnOrThrowExceptionForFailure (logWarn , message , null );
186
176
}
187
177
188
- // check replication scope
189
- checkReplicationScope (hcd );
190
- // check bloom filter type
191
- checkBloomFilterType (hcd );
192
-
193
178
// check data replication factor, it can be 0(default value) when user has not explicitly
194
179
// set the value, in this case we use default replication factor set in the file system.
195
180
if (hcd .getDFSReplication () < 0 ) {
@@ -207,103 +192,144 @@ public static void sanityCheck(final Configuration c, final TableDescriptor td)
207
192
}
208
193
}
209
194
210
- private static void checkReplicationScope (final ColumnFamilyDescriptor cfd ) throws IOException {
211
- // check replication scope
212
- WALProtos .ScopeType scop = WALProtos .ScopeType .valueOf (cfd .getScope ());
213
- if (scop == null ) {
214
- String message = "Replication scope for column family " + cfd .getNameAsString () + " is "
215
- + cfd .getScope () + " which is invalid." ;
216
-
217
- LOG .error (message );
218
- throw new DoNotRetryIOException (message );
219
- }
220
- }
221
-
222
- private static void checkCompactionPolicy (Configuration conf , TableDescriptor td )
195
+ private static void checkReplicationScope (final Configuration conf , final TableDescriptor td )
223
196
throws IOException {
224
- // FIFO compaction has some requirements
225
- // Actually FCP ignores periodic major compactions
226
- String className = td .getValue (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY );
227
- if (className == null ) {
228
- className = conf .get (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY ,
229
- ExploringCompactionPolicy .class .getName ());
230
- }
231
-
232
- int blockingFileCount = HStore .DEFAULT_BLOCKING_STOREFILE_COUNT ;
233
- String sv = td .getValue (HStore .BLOCKING_STOREFILES_KEY );
234
- if (sv != null ) {
235
- blockingFileCount = Integer .parseInt (sv );
236
- } else {
237
- blockingFileCount = conf .getInt (HStore .BLOCKING_STOREFILES_KEY , blockingFileCount );
238
- }
239
-
240
- for (ColumnFamilyDescriptor hcd : td .getColumnFamilies ()) {
241
- String compactionPolicy =
242
- hcd .getConfigurationValue (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY );
243
- if (compactionPolicy == null ) {
244
- compactionPolicy = className ;
245
- }
246
- if (!compactionPolicy .equals (FIFOCompactionPolicy .class .getName ())) {
247
- continue ;
197
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
198
+ boolean logWarn = !shouldSanityCheck (conf );
199
+ try {
200
+ for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
201
+ // check replication scope
202
+ WALProtos .ScopeType scop = WALProtos .ScopeType .valueOf (cfd .getScope ());
203
+ if (scop == null ) {
204
+ String message = "Replication scope for column family " + cfd .getNameAsString () + " is "
205
+ + cfd .getScope () + " which is invalid." ;
206
+
207
+ throw new DoNotRetryIOException (message );
208
+ }
248
209
}
249
- // FIFOCompaction
250
- String message = null ;
210
+ } catch (IOException e ) {
211
+ warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
212
+ }
251
213
252
- // 1. Check TTL
253
- if (hcd .getTimeToLive () == ColumnFamilyDescriptorBuilder .DEFAULT_TTL ) {
254
- message = "Default TTL is not supported for FIFO compaction" ;
255
- throw new IOException (message );
256
- }
214
+ }
257
215
258
- // 2. Check min versions
259
- if (hcd .getMinVersions () > 0 ) {
260
- message = "MIN_VERSION > 0 is not supported for FIFO compaction" ;
261
- throw new IOException (message );
216
+ private static void checkCompactionPolicy (final Configuration conf , final TableDescriptor td )
217
+ throws IOException {
218
+ try {
219
+ // FIFO compaction has some requirements
220
+ // Actually FCP ignores periodic major compactions
221
+ String className = td .getValue (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY );
222
+ if (className == null ) {
223
+ className = conf .get (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY ,
224
+ ExploringCompactionPolicy .class .getName ());
262
225
}
263
226
264
- // 3. blocking file count
265
- sv = hcd . getConfigurationValue (HStore .BLOCKING_STOREFILES_KEY );
227
+ int blockingFileCount = HStore . DEFAULT_BLOCKING_STOREFILE_COUNT ;
228
+ String sv = td . getValue (HStore .BLOCKING_STOREFILES_KEY );
266
229
if (sv != null ) {
267
230
blockingFileCount = Integer .parseInt (sv );
231
+ } else {
232
+ blockingFileCount = conf .getInt (HStore .BLOCKING_STOREFILES_KEY , blockingFileCount );
268
233
}
269
- if (blockingFileCount < 1000 ) {
270
- message =
271
- "Blocking file count '" + HStore .BLOCKING_STOREFILES_KEY + "' " + blockingFileCount
272
- + " is below recommended minimum of 1000 for column family " + hcd .getNameAsString ();
273
- throw new IOException (message );
234
+
235
+ for (ColumnFamilyDescriptor hcd : td .getColumnFamilies ()) {
236
+ String compactionPolicy =
237
+ hcd .getConfigurationValue (DefaultStoreEngine .DEFAULT_COMPACTION_POLICY_CLASS_KEY );
238
+ if (compactionPolicy == null ) {
239
+ compactionPolicy = className ;
240
+ }
241
+ if (!compactionPolicy .equals (FIFOCompactionPolicy .class .getName ())) {
242
+ continue ;
243
+ }
244
+ // FIFOCompaction
245
+ String message = null ;
246
+
247
+ // 1. Check TTL
248
+ if (hcd .getTimeToLive () == ColumnFamilyDescriptorBuilder .DEFAULT_TTL ) {
249
+ message = "Default TTL is not supported for FIFO compaction" ;
250
+ throw new IOException (message );
251
+ }
252
+
253
+ // 2. Check min versions
254
+ if (hcd .getMinVersions () > 0 ) {
255
+ message = "MIN_VERSION > 0 is not supported for FIFO compaction" ;
256
+ throw new IOException (message );
257
+ }
258
+
259
+ // 3. blocking file count
260
+ sv = hcd .getConfigurationValue (HStore .BLOCKING_STOREFILES_KEY );
261
+ if (sv != null ) {
262
+ blockingFileCount = Integer .parseInt (sv );
263
+ }
264
+ if (blockingFileCount < 1000 ) {
265
+ message =
266
+ "Blocking file count '" + HStore .BLOCKING_STOREFILES_KEY + "' " + blockingFileCount
267
+ + " is below recommended minimum of 1000 for column family " + hcd .getNameAsString ();
268
+ throw new IOException (message );
269
+ }
274
270
}
271
+ } catch (IOException e ) {
272
+ warnOrThrowExceptionForFailure (false , e .getMessage (), e );
275
273
}
276
274
}
277
275
278
- private static void checkBloomFilterType (ColumnFamilyDescriptor cfd ) throws IOException {
279
- Configuration conf = new CompoundConfiguration ().addStringMap (cfd .getConfiguration ());
276
+ private static void checkBloomFilterType (final Configuration conf , final TableDescriptor td )
277
+ throws IOException {
278
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
279
+ boolean logWarn = !shouldSanityCheck (conf );
280
280
try {
281
- BloomFilterUtil .getBloomFilterParam (cfd .getBloomFilterType (), conf );
282
- } catch (IllegalArgumentException e ) {
283
- throw new DoNotRetryIOException ("Failed to get bloom filter param" , e );
281
+ for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
282
+ Configuration cfdConf = new CompoundConfiguration ().addStringMap (cfd .getConfiguration ());
283
+ try {
284
+ BloomFilterUtil .getBloomFilterParam (cfd .getBloomFilterType (), cfdConf );
285
+ } catch (IllegalArgumentException e ) {
286
+ throw new DoNotRetryIOException ("Failed to get bloom filter param" , e );
287
+ }
288
+ }
289
+ } catch (IOException e ) {
290
+ warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
284
291
}
285
292
}
286
293
287
- public static void checkCompression (final TableDescriptor td ) throws IOException {
288
- for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
289
- CompressionTest .testCompression (cfd .getCompressionType ());
290
- CompressionTest .testCompression (cfd .getCompactionCompressionType ());
291
- CompressionTest .testCompression (cfd .getMajorCompactionCompressionType ());
292
- CompressionTest .testCompression (cfd .getMinorCompactionCompressionType ());
294
+ public static void checkCompression (final Configuration conf , final TableDescriptor td )
295
+ throws IOException {
296
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
297
+ boolean logWarn = !shouldSanityCheck (conf );
298
+ try {
299
+ for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
300
+ CompressionTest .testCompression (cfd .getCompressionType ());
301
+ CompressionTest .testCompression (cfd .getCompactionCompressionType ());
302
+ CompressionTest .testCompression (cfd .getMajorCompactionCompressionType ());
303
+ CompressionTest .testCompression (cfd .getMinorCompactionCompressionType ());
304
+ }
305
+ } catch (IOException e ) {
306
+ warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
293
307
}
294
308
}
295
309
296
310
public static void checkEncryption (final Configuration conf , final TableDescriptor td )
297
311
throws IOException {
298
- for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
299
- EncryptionTest .testEncryption (conf , cfd .getEncryptionType (), cfd .getEncryptionKey ());
312
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
313
+ boolean logWarn = !shouldSanityCheck (conf );
314
+ try {
315
+ for (ColumnFamilyDescriptor cfd : td .getColumnFamilies ()) {
316
+ EncryptionTest .testEncryption (conf , cfd .getEncryptionType (), cfd .getEncryptionKey ());
317
+ }
318
+ } catch (IOException e ) {
319
+ warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
300
320
}
301
321
}
302
322
303
323
public static void checkClassLoading (final Configuration conf , final TableDescriptor td )
304
324
throws IOException {
305
- RegionSplitPolicy .getSplitPolicyClass (td , conf );
306
- RegionCoprocessorHost .testTableCoprocessorAttrs (conf , td );
325
+ // Setting logs to warning instead of throwing exception if sanityChecks are disabled
326
+ boolean logWarn = !shouldSanityCheck (conf );
327
+ try {
328
+ RegionSplitPolicy .getSplitPolicyClass (td , conf );
329
+ RegionCoprocessorHost .testTableCoprocessorAttrs (conf , td );
330
+ } catch (Exception e ) {
331
+ warnOrThrowExceptionForFailure (logWarn , e .getMessage (), e );
332
+ }
307
333
}
308
334
309
335
// HBASE-13350 - Helper method to log warning on sanity check failures if checks disabled.
0 commit comments