/** * This utility method creates a new Thrift ColumnDescriptor "struct" based on * an Hbase HColumnDescriptor object. * * @param in * Hbase HColumnDescriptor object * @return Thrift ColumnDescriptor */ static public ColumnDescriptor colDescFromHbase(HColumnDescriptor in) { ColumnDescriptor col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(Bytes.add(in.getName(), KeyValue.COLUMN_FAMILY_DELIM_ARRAY)); col.maxVersions = in.getMaxVersions(); col.compression = in.getCompressionType().toString(); col.inMemory = in.isInMemory(); col.blockCacheEnabled = in.isBlockCacheEnabled(); col.bloomFilterType = in.getBloomFilterType().toString(); col.timeToLive = in.getTimeToLive(); return col; }
hcd.setKeepDeletedCells(KeepDeletedCells.TRUE); hcd.setInMemory(!HColumnDescriptor.DEFAULT_IN_MEMORY); boolean inmemory = hcd.isInMemory(); hcd.setScope(v); hcd.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF); assertEquals(hcd.getMinVersions(), deserializedHcd.getMinVersions()); assertEquals(hcd.getKeepDeletedCells(), deserializedHcd.getKeepDeletedCells()); assertEquals(inmemory, deserializedHcd.isInMemory()); assertEquals(hcd.getScope(), deserializedHcd.getScope()); assertTrue(deserializedHcd.getCompressionType().equals(Compression.Algorithm.SNAPPY));
@Test public void testAlterColumnFamilyProperty() throws Exception { Properties props = new Properties(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); String ddl = "CREATE TABLE test_table " + " (a_string varchar not null, col1 integer" + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; try { conn.createStatement().execute(ddl); conn.createStatement().execute("ALTER TABLE TEST_TABLE ADD col2 integer IN_MEMORY=true"); HTableInterface htable1 = conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes("TEST_TABLE")); HTableDescriptor htableDesciptor1 = htable1.getTableDescriptor(); HColumnDescriptor hcolumnDescriptor1 = htableDesciptor1.getFamily(Bytes.toBytes("_0")); assertTrue(hcolumnDescriptor1.isInMemory()); try { conn.createStatement().execute("ALTER TABLE TEST_TABLE SET IN_MEMORY=false"); fail("Should have caught exception."); } catch (SQLException e) { assertTrue(e.getMessage(), e.getMessage().contains("ERROR 1025 (42Y84): Unsupported property set in ALTER TABLE command.")); } }finally { conn.close(); } }
public FamilyAdmin inMemory() { HColumnDescriptor columnDescriptor = desc.getFamily(familyName); if (!columnDescriptor.isInMemory()) { LOG.info("Setting family [" + Bytes.toString(familyName) + "] to be in memory family."); disableTable(); columnDescriptor.setInMemory(true); desc.addFamily(columnDescriptor); return modifyAndEnable(); } LOG.info("Family [" + Bytes.toString(familyName) + "] is in memory family."); return this; }
/** * Create a cache configuration using the specified configuration object and * family descriptor. * @param conf hbase configuration * @param family column family configuration */ public CacheConfig(Configuration conf, HColumnDescriptor family) { this(CacheConfig.instantiateBlockCache(conf), family.isBlockCacheEnabled(), family.isInMemory(), // For the following flags we enable them regardless of per-schema settings // if they are enabled in the global configuration. conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE) || family.shouldCacheDataOnWrite(), conf.getBoolean(CACHE_INDEX_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_INDEXES_ON_WRITE) || family.shouldCacheIndexesOnWrite(), conf.getBoolean(CACHE_BLOOM_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_BLOOMS_ON_WRITE) || family.shouldCacheBloomsOnWrite(), conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE) || family.shouldEvictBlocksOnClose(), conf.getBoolean(CACHE_DATA_BLOCKS_COMPRESSED_KEY, DEFAULT_COMPRESSED_CACHE) ); }
@Override public int compare(HColumnDescriptor o1, HColumnDescriptor o2) { int nameResult = Bytes.compareTo(o1.getName(), o2.getName()); if (nameResult != 0) { return nameResult; } int maxVersionsResult = Integer.valueOf(o1.getMaxVersions()).compareTo(o2.getMaxVersions()); if (maxVersionsResult != 0) { return maxVersionsResult; } int timeToLiveResult = Integer.valueOf(o1.getTimeToLive()).compareTo(o2.getTimeToLive()); if (timeToLiveResult != 0) { return timeToLiveResult; } int inMemoryResult = Boolean.valueOf(o1.isInMemory()).compareTo(o2.isInMemory()); if (inMemoryResult != 0) { return inMemoryResult; } int blockSizeResult = Integer.valueOf(o1.getBlocksize()).compareTo(o2.getBlocksize()); if (blockSizeResult != 0) { return blockSizeResult; } int bloomTypeResult = SchemaPlatformBridge.get().compareBloom(o1, o2); if (bloomTypeResult != 0) { return bloomTypeResult; } return SchemaPlatformBridge.get().compareCompression(o1, o2); } }
hcd.setKeepDeletedCells(KeepDeletedCells.TRUE); hcd.setInMemory(!HColumnDescriptor.DEFAULT_IN_MEMORY); boolean inmemory = hcd.isInMemory(); hcd.setScope(v); hcd.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF); assertEquals(hcd.getMinVersions(), deserializedHcd.getMinVersions()); assertEquals(hcd.getKeepDeletedCells(), deserializedHcd.getKeepDeletedCells()); assertEquals(inmemory, deserializedHcd.isInMemory()); assertEquals(hcd.getScope(), deserializedHcd.getScope()); assertTrue(deserializedHcd.getCompressionType().equals(Compression.Algorithm.SNAPPY));
/** * Create a cache configuration using the specified configuration object and * family descriptor. * @param conf hbase configuration * @param family column family configuration */ public CacheConfig(Configuration conf, HColumnDescriptor family) { this(CacheConfig.instantiateBlockCache(conf), family.isBlockCacheEnabled(), family.isInMemory(), // For the following flags we enable them regardless of per-schema settings // if they are enabled in the global configuration. conf.getBoolean(CACHE_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_DATA_ON_WRITE) || family.isCacheDataOnWrite(), conf.getBoolean(CACHE_INDEX_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_INDEXES_ON_WRITE) || family.isCacheIndexesOnWrite(), conf.getBoolean(CACHE_BLOOM_BLOCKS_ON_WRITE_KEY, DEFAULT_CACHE_BLOOMS_ON_WRITE) || family.isCacheBloomsOnWrite(), conf.getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE) || family.isEvictBlocksOnClose(), conf.getBoolean(CACHE_DATA_BLOCKS_COMPRESSED_KEY, DEFAULT_CACHE_DATA_COMPRESSED), conf.getBoolean(PREFETCH_BLOCKS_ON_OPEN_KEY, DEFAULT_PREFETCH_ON_OPEN) || family.isPrefetchBlocksOnOpen(), conf.getBoolean(HColumnDescriptor.CACHE_DATA_IN_L1, HColumnDescriptor.DEFAULT_CACHE_DATA_IN_L1) || family.isCacheDataInL1(), conf.getBoolean(DROP_BEHIND_CACHE_COMPACTION_KEY,DROP_BEHIND_CACHE_COMPACTION_DEFAULT) ); }
static public AFamilyDescriptor hcdToAFD(HColumnDescriptor hcd) throws IOException { AFamilyDescriptor afamily = new AFamilyDescriptor(); afamily.name = ByteBuffer.wrap(hcd.getName()); String compressionAlgorithm = hcd.getCompressionType().getName(); if (compressionAlgorithm == "LZO") { afamily.compression = ACompressionAlgorithm.LZO; } else if (compressionAlgorithm == "GZ") { afamily.compression = ACompressionAlgorithm.GZ; } else { afamily.compression = ACompressionAlgorithm.NONE; } afamily.maxVersions = hcd.getMaxVersions(); afamily.blocksize = hcd.getBlocksize(); afamily.inMemory = hcd.isInMemory(); afamily.timeToLive = hcd.getTimeToLive(); afamily.blockCacheEnabled = hcd.isBlockCacheEnabled(); return afamily; }
/** * This utility method creates a new Thrift ColumnDescriptor "struct" based on * an Hbase HColumnDescriptor object. * * @param in * Hbase HColumnDescriptor object * @return Thrift ColumnDescriptor */ static public ColumnDescriptor colDescFromHbase(HColumnDescriptor in) { ColumnDescriptor col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(Bytes.add(in.getName(), KeyValue.COLUMN_FAMILY_DELIM_ARRAY)); col.maxVersions = in.getMaxVersions(); col.compression = in.getCompression().toString(); col.inMemory = in.isInMemory(); col.blockCacheEnabled = in.isBlockCacheEnabled(); col.bloomFilterType = in.getBloomFilterType().toString(); return col; }
if (isInMemory != null && isInMemory != hColumnDescriptor.isInMemory())
/** * This utility method creates a new Thrift ColumnDescriptor "struct" based on * an Hbase HColumnDescriptor object. * * @param in * Hbase HColumnDescriptor object * @return Thrift ColumnDescriptor */ static public ColumnDescriptor colDescFromHbase(HColumnDescriptor in) { ColumnDescriptor col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(Bytes.add(in.getName(), KeyValue.COLUMN_FAMILY_DELIM_ARRAY)); col.maxVersions = in.getMaxVersions(); col.compression = in.getCompressionType().toString(); col.inMemory = in.isInMemory(); col.blockCacheEnabled = in.isBlockCacheEnabled(); col.bloomFilterType = in.getBloomFilterType().toString(); col.timeToLive = in.getTimeToLive(); return col; }
/** * This utility method creates a new Thrift ColumnDescriptor "struct" based on * an Hbase HColumnDescriptor object. * * @param in * Hbase HColumnDescriptor object * @return Thrift ColumnDescriptor */ static public ColumnDescriptor colDescFromHbase(HColumnDescriptor in) { ColumnDescriptor col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(Bytes.add(in.getName(), KeyValue.COLUMN_FAMILY_DELIM_ARRAY)); col.maxVersions = in.getMaxVersions(); col.compression = in.getCompressionType().toString(); col.inMemory = in.isInMemory(); col.blockCacheEnabled = in.isBlockCacheEnabled(); col.bloomFilterType = in.getBloomFilterType().toString(); col.timeToLive = in.getTimeToLive(); return col; }
protected void checkLockFamilyDesc(HColumnDescriptor columnDesc) { Assert.assertArrayEquals(ColumnUtil.LOCK_FAMILY_NAME, columnDesc.getName()); Assert.assertEquals(1, columnDesc.getMaxVersions()); Assert.assertTrue(columnDesc.isInMemory()); Assert.assertEquals(HConstants.FOREVER, columnDesc.getTimeToLive()); }