HBASE-576 Investigate IPC performance
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@702336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b99382cd1a
commit
e45a93170d
@ -63,18 +63,43 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
private String nameAsString = "";
|
private String nameAsString = "";
|
||||||
|
|
||||||
// Table metadata
|
// Table metadata
|
||||||
protected Map<ImmutableBytesWritable,ImmutableBytesWritable> values =
|
protected Map<ImmutableBytesWritable, ImmutableBytesWritable> values =
|
||||||
new HashMap<ImmutableBytesWritable,ImmutableBytesWritable>();
|
new HashMap<ImmutableBytesWritable, ImmutableBytesWritable>();
|
||||||
|
|
||||||
//TODO: Why can't the following be private? They are only used within this class.
|
|
||||||
|
|
||||||
public static final String FAMILIES = "FAMILIES";
|
public static final String FAMILIES = "FAMILIES";
|
||||||
|
public static final ImmutableBytesWritable FAMILIES_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes(FAMILIES));
|
||||||
|
|
||||||
public static final String MAX_FILESIZE = "MAX_FILESIZE";
|
public static final String MAX_FILESIZE = "MAX_FILESIZE";
|
||||||
|
public static final ImmutableBytesWritable MAX_FILESIZE_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes("MAX_FILESIZE"));
|
||||||
|
|
||||||
public static final String READONLY = "READONLY";
|
public static final String READONLY = "READONLY";
|
||||||
|
public static final ImmutableBytesWritable READONLY_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes("READONLY"));
|
||||||
|
|
||||||
public static final String MEMCACHE_FLUSHSIZE = "MEMCACHE_FLUSHSIZE";
|
public static final String MEMCACHE_FLUSHSIZE = "MEMCACHE_FLUSHSIZE";
|
||||||
|
public static final ImmutableBytesWritable MEMCACHE_FLUSHSIZE_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes("MEMCACHE_FLUSHSIZE"));
|
||||||
|
|
||||||
public static final String IS_ROOT = "IS_ROOT";
|
public static final String IS_ROOT = "IS_ROOT";
|
||||||
|
public static final ImmutableBytesWritable IS_ROOT_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes("IS_ROOT"));
|
||||||
|
|
||||||
public static final String IS_META = "IS_META";
|
public static final String IS_META = "IS_META";
|
||||||
|
public static final ImmutableBytesWritable IS_META_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes("IS_META"));
|
||||||
|
|
||||||
|
public static final ImmutableBytesWritable IN_MEMORY_KEY =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes(HConstants.IN_MEMORY));
|
||||||
|
|
||||||
|
// The below are ugly but better than creating them each time till we
|
||||||
|
// replace booleans being saved as Strings with plain booleans. Need a
|
||||||
|
// migration script to do this. TODO.
|
||||||
|
private static final ImmutableBytesWritable FALSE =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes(Boolean.FALSE.toString()));
|
||||||
|
private static final ImmutableBytesWritable TRUE =
|
||||||
|
new ImmutableBytesWritable(Bytes.toBytes(Boolean.TRUE.toString()));
|
||||||
|
|
||||||
public static final boolean DEFAULT_IN_MEMORY = false;
|
public static final boolean DEFAULT_IN_MEMORY = false;
|
||||||
|
|
||||||
@ -84,8 +109,6 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
|
|
||||||
private transient Boolean meta = null;
|
private transient Boolean meta = null;
|
||||||
|
|
||||||
// End TODO:
|
|
||||||
|
|
||||||
// Key is hash of the family name.
|
// Key is hash of the family name.
|
||||||
private final Map<Integer, HColumnDescriptor> families =
|
private final Map<Integer, HColumnDescriptor> families =
|
||||||
new HashMap<Integer, HColumnDescriptor>();
|
new HashMap<Integer, HColumnDescriptor>();
|
||||||
@ -162,8 +185,7 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* Can make a modifiable descriptor from an UnmodifyableHTableDescriptor.
|
* Can make a modifiable descriptor from an UnmodifyableHTableDescriptor.
|
||||||
* @param desc The descriptor.
|
* @param desc The descriptor.
|
||||||
*/
|
*/
|
||||||
public HTableDescriptor(final HTableDescriptor desc)
|
public HTableDescriptor(final HTableDescriptor desc) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.name = desc.name.clone();
|
this.name = desc.name.clone();
|
||||||
this.nameAsString = Bytes.toString(this.name);
|
this.nameAsString = Bytes.toString(this.name);
|
||||||
@ -190,16 +212,13 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
|
|
||||||
/** @return true if this is the root region */
|
/** @return true if this is the root region */
|
||||||
public boolean isRootRegion() {
|
public boolean isRootRegion() {
|
||||||
String value = getValue(IS_ROOT);
|
return isSomething(IS_ROOT_KEY, false);
|
||||||
if (value != null)
|
|
||||||
return Boolean.valueOf(value);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param isRoot true if this is the root region */
|
/** @param isRoot true if this is the root region */
|
||||||
protected void setRootRegion(boolean isRoot) {
|
protected void setRootRegion(boolean isRoot) {
|
||||||
values.put(new ImmutableBytesWritable(Bytes.toBytes(IS_ROOT)),
|
// TODO: Make the value a boolean rather than String of boolean.
|
||||||
new ImmutableBytesWritable(Bytes.toBytes(Boolean.toString(isRoot))));
|
values.put(IS_ROOT_KEY, isRoot? TRUE: FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true if this is a meta region (part of the root or meta tables) */
|
/** @return true if this is a meta region (part of the root or meta tables) */
|
||||||
@ -211,16 +230,24 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized Boolean calculateIsMetaRegion() {
|
private synchronized Boolean calculateIsMetaRegion() {
|
||||||
String value = getValue(IS_META);
|
return isSomething(IS_META_KEY, false)? Boolean.TRUE: Boolean.FALSE;
|
||||||
return (value != null)? new Boolean(value): Boolean.FALSE;
|
}
|
||||||
|
|
||||||
|
private boolean isSomething(final ImmutableBytesWritable key,
|
||||||
|
final boolean valueIfNull) {
|
||||||
|
byte [] value = getValue(key);
|
||||||
|
if (value != null) {
|
||||||
|
// TODO: Make value be a boolean rather than String of boolean.
|
||||||
|
return Boolean.valueOf(Bytes.toString(value)).booleanValue();
|
||||||
|
}
|
||||||
|
return valueIfNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isMeta true if this is a meta region (part of the root or meta
|
* @param isMeta true if this is a meta region (part of the root or meta
|
||||||
* tables) */
|
* tables) */
|
||||||
protected void setMetaRegion(boolean isMeta) {
|
protected void setMetaRegion(boolean isMeta) {
|
||||||
values.put(new ImmutableBytesWritable(Bytes.toBytes(IS_META)),
|
values.put(IS_META_KEY, isMeta? TRUE: FALSE);
|
||||||
new ImmutableBytesWritable(Bytes.toBytes(Boolean.toString(isMeta))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true if table is the meta table */
|
/** @return true if table is the meta table */
|
||||||
@ -263,7 +290,11 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public byte[] getValue(byte[] key) {
|
public byte[] getValue(byte[] key) {
|
||||||
ImmutableBytesWritable ibw = values.get(new ImmutableBytesWritable(key));
|
return getValue(new ImmutableBytesWritable(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getValue(final ImmutableBytesWritable key) {
|
||||||
|
ImmutableBytesWritable ibw = values.get(key);
|
||||||
if (ibw == null)
|
if (ibw == null)
|
||||||
return null;
|
return null;
|
||||||
return ibw.get();
|
return ibw.get();
|
||||||
@ -292,8 +323,25 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* @param value The value.
|
* @param value The value.
|
||||||
*/
|
*/
|
||||||
public void setValue(byte[] key, byte[] value) {
|
public void setValue(byte[] key, byte[] value) {
|
||||||
values.put(new ImmutableBytesWritable(key),
|
setValue(new ImmutableBytesWritable(key), value);
|
||||||
new ImmutableBytesWritable(value));
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
|
private void setValue(final ImmutableBytesWritable key,
|
||||||
|
final byte[] value) {
|
||||||
|
values.put(key, new ImmutableBytesWritable(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param key The key.
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
|
private void setValue(final ImmutableBytesWritable key,
|
||||||
|
final ImmutableBytesWritable value) {
|
||||||
|
values.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,10 +357,7 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* HRegionServer cache only
|
* HRegionServer cache only
|
||||||
*/
|
*/
|
||||||
public boolean isInMemory() {
|
public boolean isInMemory() {
|
||||||
String value = getValue(HConstants.IN_MEMORY);
|
return isSomething(IN_MEMORY_KEY, DEFAULT_IN_MEMORY);
|
||||||
if (value != null)
|
|
||||||
return Boolean.valueOf(value);
|
|
||||||
return DEFAULT_IN_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,25 +365,22 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* the HRegionServer cache only.
|
* the HRegionServer cache only.
|
||||||
*/
|
*/
|
||||||
public void setInMemory(boolean inMemory) {
|
public void setInMemory(boolean inMemory) {
|
||||||
setValue(HConstants.IN_MEMORY, Boolean.toString(inMemory));
|
setValue(IN_MEMORY_KEY, inMemory? TRUE: FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if all columns in the table should be read only
|
* @return true if all columns in the table should be read only
|
||||||
*/
|
*/
|
||||||
public boolean isReadOnly() {
|
public boolean isReadOnly() {
|
||||||
String value = getValue(READONLY);
|
return isSomething(READONLY_KEY, DEFAULT_READONLY);
|
||||||
if (value != null)
|
|
||||||
return Boolean.valueOf(value);
|
|
||||||
return DEFAULT_READONLY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param readOnly True if all of the columns in the table should be read
|
* @param readOnly True if all of the columns in the table should be read
|
||||||
* only.
|
* only.
|
||||||
*/
|
*/
|
||||||
public void setReadOnly(boolean readOnly) {
|
public void setReadOnly(final boolean readOnly) {
|
||||||
setValue(READONLY, Boolean.toString(readOnly));
|
setValue(READONLY_KEY, readOnly? TRUE: FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return name of table */
|
/** @return name of table */
|
||||||
@ -353,9 +395,9 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
|
|
||||||
/** @return max hregion size for table */
|
/** @return max hregion size for table */
|
||||||
public long getMaxFileSize() {
|
public long getMaxFileSize() {
|
||||||
String value = getValue(MAX_FILESIZE);
|
byte [] value = getValue(MAX_FILESIZE_KEY);
|
||||||
if (value != null)
|
if (value != null)
|
||||||
return Long.valueOf(value);
|
return Long.valueOf(Bytes.toString(value)).longValue();
|
||||||
return HConstants.DEFAULT_MAX_FILE_SIZE;
|
return HConstants.DEFAULT_MAX_FILE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,16 +406,16 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* before a split is triggered.
|
* before a split is triggered.
|
||||||
*/
|
*/
|
||||||
public void setMaxFileSize(long maxFileSize) {
|
public void setMaxFileSize(long maxFileSize) {
|
||||||
setValue(MAX_FILESIZE, Long.toString(maxFileSize));
|
setValue(MAX_FILESIZE_KEY, Bytes.toBytes(Long.toString(maxFileSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return memory cache flush size for each hregion
|
* @return memory cache flush size for each hregion
|
||||||
*/
|
*/
|
||||||
public int getMemcacheFlushSize() {
|
public int getMemcacheFlushSize() {
|
||||||
String value = getValue(MEMCACHE_FLUSHSIZE);
|
byte [] value = getValue(MEMCACHE_FLUSHSIZE_KEY);
|
||||||
if (value != null)
|
if (value != null)
|
||||||
return Integer.valueOf(value);
|
return Integer.valueOf(Bytes.toString(value)).intValue();
|
||||||
return DEFAULT_MEMCACHE_FLUSH_SIZE;
|
return DEFAULT_MEMCACHE_FLUSH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +423,8 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
* @param memcacheFlushSize memory cache flush size for each hregion
|
* @param memcacheFlushSize memory cache flush size for each hregion
|
||||||
*/
|
*/
|
||||||
public void setMemcacheFlushSize(int memcacheFlushSize) {
|
public void setMemcacheFlushSize(int memcacheFlushSize) {
|
||||||
setValue(MEMCACHE_FLUSHSIZE, Integer.toString(memcacheFlushSize));
|
setValue(MEMCACHE_FLUSHSIZE_KEY,
|
||||||
|
Bytes.toBytes(Integer.toString(memcacheFlushSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -514,18 +557,28 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
// Comparable
|
// Comparable
|
||||||
|
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
HTableDescriptor other = (HTableDescriptor) o;
|
return compareTo(this, (HTableDescriptor)o);
|
||||||
int result = Bytes.compareTo(this.name, other.name);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param left
|
||||||
|
* @param right
|
||||||
|
* @return 0 if equal, etc.
|
||||||
|
*/
|
||||||
|
public static int compareTo(HTableDescriptor left, HTableDescriptor right) {
|
||||||
|
int result = Bytes.compareTo(left.getName(), right.getName());
|
||||||
|
Collection<HColumnDescriptor> leftFamilies = left.getFamilies();
|
||||||
|
Collection<HColumnDescriptor> rightFamilies = right.getFamilies();
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = families.size() - other.families.size();
|
result = leftFamilies.size() - rightFamilies.size();
|
||||||
}
|
}
|
||||||
if (result == 0 && families.size() != other.families.size()) {
|
if (result == 0 && leftFamilies.size() != rightFamilies.size()) {
|
||||||
result = Integer.valueOf(families.size()).compareTo(
|
result = Integer.valueOf(leftFamilies.size()).compareTo(
|
||||||
Integer.valueOf(other.families.size()));
|
Integer.valueOf(rightFamilies.size()));
|
||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
for (Iterator<HColumnDescriptor> it = families.values().iterator(),
|
for (Iterator<HColumnDescriptor> it = leftFamilies.iterator(),
|
||||||
it2 = other.families.values().iterator(); it.hasNext(); ) {
|
it2 = rightFamilies.iterator(); it.hasNext(); ) {
|
||||||
result = it.next().compareTo(it2.next());
|
result = it.next().compareTo(it2.next());
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
break;
|
break;
|
||||||
@ -534,7 +587,7 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
// punt on comparison for ordering, just calculate difference
|
// punt on comparison for ordering, just calculate difference
|
||||||
result = this.values.hashCode() - other.values.hashCode();
|
result = leftFamilies.hashCode() - rightFamilies.hashCode();
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
result = -1;
|
result = -1;
|
||||||
else if (result > 0)
|
else if (result > 0)
|
||||||
@ -543,6 +596,16 @@ public class HTableDescriptor implements WritableComparable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comparator used in UI jsp.
|
||||||
|
*/
|
||||||
|
public static class HTableDescriptorComparator
|
||||||
|
implements java.util.Comparator<HTableDescriptor> {
|
||||||
|
public int compare(HTableDescriptor o1, HTableDescriptor o2) {
|
||||||
|
return compareTo(o1, o2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Immutable sorted map of families.
|
* @return Immutable sorted map of families.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user