private static void waitUntil(long until) { long now = System.currentTimeMillis(); while (now <= until) { try { Thread.sleep(1L); now = System.currentTimeMillis(); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
private void ensureColumnFamilyExists(String tableName, String columnFamily) throws StorageException { HBaseAdmin adm = getAdminInterface(); HTableDescriptor desc = ensureTableExists(tableName); Preconditions.checkNotNull(desc); HColumnDescriptor cf = desc.getFamily(columnFamily.getBytes()); // Create our column family, if necessary if (cf == null) { try { adm.disableTable(tableName); desc.addFamily( new HColumnDescriptor(columnFamily).setCompressionType(Compression.Algorithm.GZ)); adm.modifyTable(tableName.getBytes(), desc); try { logger.debug( "Added HBase ColumnFamily {}, waiting for 1 sec. to propogate.", columnFamily); Thread.sleep(1000L); } catch (InterruptedException ie) { throw new TemporaryStorageException(ie); } adm.enableTable(tableName); } catch (TableNotFoundException ee) { logger.error("TableNotFoundException", ee); throw new PermanentStorageException(ee); } catch (org.apache.hadoop.hbase.TableExistsException ee) { logger.debug("Swallowing exception {}", ee); } catch (IOException ee) { throw new TemporaryStorageException(ee); } } else { // check if compression was enabled, if not - enable it if (cf.getCompressionType() == null || cf.getCompressionType() == Compression.Algorithm.NONE) { try { adm.disableTable(tableName); adm.modifyColumn(tableName, cf.setCompressionType(Compression.Algorithm.GZ)); adm.enableTable(tableName); } catch (IOException e) { throw new TemporaryStorageException(e); } } } }