Ejemplo n.º 1
0
 /** Apply column family options such as Bloom filters, compression, and data block encoding. */
 protected void applyColumnFamilyOptions(byte[] tableName, byte[][] columnFamilies)
     throws IOException {
   HBaseAdmin admin = new HBaseAdmin(conf);
   HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
   LOG.info("Disabling table " + Bytes.toString(tableName));
   admin.disableTable(tableName);
   for (byte[] cf : columnFamilies) {
     HColumnDescriptor columnDesc = tableDesc.getFamily(cf);
     boolean isNewCf = columnDesc == null;
     if (isNewCf) {
       columnDesc = new HColumnDescriptor(cf);
     }
     if (bloomType != null) {
       columnDesc.setBloomFilterType(bloomType);
     }
     if (compressAlgo != null) {
       columnDesc.setCompressionType(compressAlgo);
     }
     if (dataBlockEncodingAlgo != null) {
       columnDesc.setDataBlockEncoding(dataBlockEncodingAlgo);
       columnDesc.setEncodeOnDisk(!encodeInCacheOnly);
     }
     if (inMemoryCF) {
       columnDesc.setInMemory(inMemoryCF);
     }
     if (isNewCf) {
       admin.addColumn(tableName, columnDesc);
     } else {
       admin.modifyColumn(tableName, columnDesc);
     }
   }
   LOG.info("Enabling table " + Bytes.toString(tableName));
   admin.enableTable(tableName);
 }
Ejemplo n.º 2
0
  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);
        }
      }
    }
  }