You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2009/01/03 00:17:25 UTC
svn commit: r730865 - in /hadoop/hbase/branches/0.19_on_hadoop_0.18:
CHANGES.txt bin/HBase.rb
src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
src/java/org/apache/hadoop/hbase/master/RegionManager.java
Author: apurtell
Date: Fri Jan 2 15:17:24 2009
New Revision: 730865
URL: http://svn.apache.org/viewvc?rev=730865&view=rev
Log:
merge up to latest trunk (rev 730494)
Modified:
hadoop/hbase/branches/0.19_on_hadoop_0.18/CHANGES.txt
hadoop/hbase/branches/0.19_on_hadoop_0.18/bin/HBase.rb
hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/master/RegionManager.java
Modified: hadoop/hbase/branches/0.19_on_hadoop_0.18/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.19_on_hadoop_0.18/CHANGES.txt?rev=730865&r1=730864&r2=730865&view=diff
==============================================================================
--- hadoop/hbase/branches/0.19_on_hadoop_0.18/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.19_on_hadoop_0.18/CHANGES.txt Fri Jan 2 15:17:24 2009
@@ -201,6 +201,7 @@
operations on individual regions
HBASE-1062 Compactions at (re)start on a large table can overwhelm DFS
HBASE-1102 boolean HTable.exists()
+ HBASE-1105 Remove duplicated code in HCM, add javadoc to RegionState, etc.
NEW FEATURES
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]
Modified: hadoop/hbase/branches/0.19_on_hadoop_0.18/bin/HBase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.19_on_hadoop_0.18/bin/HBase.rb?rev=730865&r1=730864&r2=730865&view=diff
==============================================================================
--- hadoop/hbase/branches/0.19_on_hadoop_0.18/bin/HBase.rb (original)
+++ hadoop/hbase/branches/0.19_on_hadoop_0.18/bin/HBase.rb Fri Jan 2 15:17:24 2009
@@ -418,7 +418,7 @@
s = @table.getScanner(cs)
count = 0
i = s.iterator()
- @formatter.header("Count may take a long time to complete!")
+ @formatter.header()
while i.hasNext()
r = i.next()
count += 1
Modified: hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=730865&r1=730864&r2=730865&view=diff
==============================================================================
--- hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java Fri Jan 2 15:17:24 2009
@@ -137,8 +137,8 @@
private volatile HRegionLocation rootRegionLocation;
private final Map<Integer, SoftValueSortedMap<byte [], HRegionLocation>>
- cachedRegionLocations = Collections.synchronizedMap(
- new HashMap<Integer, SoftValueSortedMap<byte [], HRegionLocation>>());
+ cachedRegionLocations =
+ new HashMap<Integer, SoftValueSortedMap<byte [], HRegionLocation>>();
/**
* constructor
@@ -431,7 +431,7 @@
}
private HRegionLocation locateRegion(final byte [] tableName,
- final byte [] row, boolean useCache)
+ final byte [] row, boolean useCache)
throws IOException{
if (tableName == null || tableName.length == 0) {
throw new IllegalArgumentException(
@@ -454,7 +454,6 @@
// This block guards against two threads trying to load the meta
// region at the same time. The first will load the meta region and
// the second will use the value that the first one found.
-
return locateRegionInMeta(ROOT_TABLE_NAME, tableName, row, useCache);
}
} else {
@@ -464,7 +463,7 @@
}
}
- /**
+ /*
* Search one of the meta tables (-ROOT- or .META.) for the HRegionLocation
* info that contains the table and row we're seeking.
*/
@@ -472,9 +471,8 @@
final byte [] tableName, final byte [] row, boolean useCache)
throws IOException{
HRegionLocation location = null;
- // if we're supposed to be using the cache, then check it for a possible
- // hit. otherwise, delete any existing cached location so it won't
- // interfere.
+ // If supposed to be using the cache, then check it for a possible hit.
+ // Otherwise, delete any existing cached location so it won't interfere.
if (useCache) {
location = getCachedLocation(tableName, row);
if (location != null) {
@@ -495,38 +493,33 @@
+ Bytes.toString(row) + " after " + numRetries + " tries.");
}
- try{
+ try {
// locate the root region
HRegionLocation metaLocation = locateRegion(parentTable, metaKey);
- HRegionInterface server =
+ HRegionInterface server =
getHRegionConnection(metaLocation.getServerAddress());
// Query the root region for the location of the meta region
RowResult regionInfoRow = server.getClosestRowBefore(
metaLocation.getRegionInfo().getRegionName(), metaKey,
HConstants.COLUMN_FAMILY);
-
if (regionInfoRow == null) {
throw new TableNotFoundException(Bytes.toString(tableName));
}
Cell value = regionInfoRow.get(COL_REGIONINFO);
-
if (value == null || value.getValue().length == 0) {
throw new IOException("HRegionInfo was null or empty in " +
Bytes.toString(parentTable));
}
-
// convert the row result into the HRegionLocation we need!
HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable(
value.getValue(), new HRegionInfo());
-
// possible we got a region of a different table...
if (!Bytes.equals(regionInfo.getTableDesc().getName(), tableName)) {
throw new TableNotFoundException(
"Table '" + Bytes.toString(tableName) + "' was not found.");
}
-
if (regionInfo.isOffline()) {
throw new RegionOfflineException("region offline: " +
regionInfo.getRegionNameAsString());
@@ -534,7 +527,6 @@
String serverAddress =
Writables.cellToString(regionInfoRow.get(COL_SERVER));
-
if (serverAddress.equals("")) {
throw new NoServerForRegionException("No server address listed " +
"in " + Bytes.toString(parentTable) + " for region " +
@@ -542,11 +534,9 @@
}
// instantiate the location
- location = new HRegionLocation(regionInfo,
- new HServerAddress(serverAddress));
-
+ location = new HRegionLocation(regionInfo,
+ new HServerAddress(serverAddress));
cacheLocation(tableName, location);
-
return location;
} catch (TableNotFoundException e) {
// if we got this error, probably means the table just plain doesn't
@@ -591,17 +581,8 @@
*/
private HRegionLocation getCachedLocation(final byte [] tableName,
final byte [] row) {
- // find the map of cached locations for this table
- Integer key = Bytes.mapKey(tableName);
SoftValueSortedMap<byte [], HRegionLocation> tableLocations =
- cachedRegionLocations.get(key);
-
- // if tableLocations for this table isn't built yet, make one
- if (tableLocations == null) {
- tableLocations = new SoftValueSortedMap<byte [],
- HRegionLocation>(Bytes.BYTES_COMPARATOR);
- cachedRegionLocations.put(key, tableLocations);
- }
+ getTableLocations(tableName);
// start to examine the cache. we can only do cache actions
// if there's something in the cache for this table.
@@ -612,9 +593,9 @@
HRegionLocation rl = tableLocations.get(row);
if (rl != null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Cache hit in table locations for row <" +
+ LOG.debug("Cache hit for row <" +
Bytes.toString(row) +
- "> and tableName " + Bytes.toString(tableName) +
+ "> in tableName " + Bytes.toString(tableName) +
": location server " + rl.getServerAddress() +
", location region name " +
rl.getRegionInfo().getRegionNameAsString());
@@ -657,23 +638,14 @@
return null;
}
- /**
+ /*
* Delete a cached location, if it satisfies the table name and row
* requirements.
*/
private void deleteCachedLocation(final byte [] tableName,
final byte [] row) {
- // find the map of cached locations for this table
- Integer key = Bytes.mapKey(tableName);
- SoftValueSortedMap<byte [], HRegionLocation> tableLocations =
- cachedRegionLocations.get(key);
-
- // if tableLocations for this table isn't built yet, make one
- if (tableLocations == null) {
- tableLocations = new SoftValueSortedMap<byte [],
- HRegionLocation>(Bytes.BYTES_COMPARATOR);
- cachedRegionLocations.put(key, tableLocations);
- }
+ SoftValueSortedMap<byte [], HRegionLocation> tableLocations =
+ getTableLocations(tableName);
// start to examine the cache. we can only do cache actions
// if there's something in the cache for this table.
@@ -687,47 +659,56 @@
// we need to examine the cached location to verify that it is
// a match by end key as well.
if (!matchingRegions.isEmpty()) {
- HRegionLocation possibleRegion =
+ HRegionLocation possibleRegion =
matchingRegions.get(matchingRegions.lastKey());
-
byte [] endKey = possibleRegion.getRegionInfo().getEndKey();
-
+
// by nature of the map, we know that the start key has to be <
// otherwise it wouldn't be in the headMap.
if (HStoreKey.compareTwoRowKeys(possibleRegion.getRegionInfo(),
endKey, row) <= 0) {
// delete any matching entry
- HRegionLocation rl =
+ HRegionLocation rl =
tableLocations.remove(matchingRegions.lastKey());
if (rl != null && LOG.isDebugEnabled()) {
LOG.debug("Removed " + rl.getRegionInfo().getRegionNameAsString() +
- " from cache because of " + Bytes.toString(row));
+ " for tableName=" + Bytes.toString(tableName) + " from cache " +
+ "because of " + Bytes.toString(row));
}
}
}
}
}
-
- /**
- * Put a newly discovered HRegionLocation into the cache.
- */
- private void cacheLocation(final byte [] tableName,
- final HRegionLocation location){
- byte [] startKey = location.getRegionInfo().getStartKey();
-
+
+ /*
+ * @param tableName
+ * @return Map of cached locations for passed <code>tableName</code>
+ */
+ private SoftValueSortedMap<byte [], HRegionLocation> getTableLocations(
+ final byte [] tableName) {
// find the map of cached locations for this table
Integer key = Bytes.mapKey(tableName);
- SoftValueSortedMap<byte [], HRegionLocation> tableLocations =
- cachedRegionLocations.get(key);
-
- // if tableLocations for this table isn't built yet, make one
- if (tableLocations == null) {
- tableLocations = new SoftValueSortedMap<byte [],
- HRegionLocation>(Bytes.BYTES_COMPARATOR);
- cachedRegionLocations.put(key, tableLocations);
+ SoftValueSortedMap<byte [], HRegionLocation> result = null;
+ synchronized (this.cachedRegionLocations) {
+ result = this.cachedRegionLocations.get(key);
+ // if tableLocations for this table isn't built yet, make one
+ if (result == null) {
+ result = new SoftValueSortedMap<byte [], HRegionLocation>(
+ Bytes.BYTES_COMPARATOR);
+ this.cachedRegionLocations.put(key, result);
+ }
}
-
- // save the HRegionLocation under the startKey
+ return result;
+ }
+
+ /*
+ * Put a newly discovered HRegionLocation into the cache.
+ */
+ private void cacheLocation(final byte [] tableName,
+ final HRegionLocation location) {
+ byte [] startKey = location.getRegionInfo().getStartKey();
+ SoftValueSortedMap<byte [], HRegionLocation> tableLocations =
+ getTableLocations(tableName);
tableLocations.put(startKey, location);
}
@@ -901,9 +882,9 @@
boolean retryOnlyOne = false;
Collections.sort(list);
List<BatchUpdate> tempUpdates = new ArrayList<BatchUpdate>();
- byte[] currentRegion = getRegionLocation(tableName, list.get(0).getRow(),
- false).getRegionInfo().getRegionName();
- byte[] region = currentRegion;
+ byte [] currentRegion = getRegionLocation(tableName, list.get(0).getRow(),
+ false).getRegionInfo().getRegionName();
+ byte [] region = currentRegion;
boolean isLastRow = false;
int tries = 0;
for (int i = 0; i < list.size() && tries < numRetries; i++) {
@@ -932,8 +913,9 @@
}
long sleepTime = getPauseTime(tries);
if (LOG.isDebugEnabled()) {
- LOG.debug("Reloading table servers because region " +
- "server didn't accept updates; tries=" + tries +
+ LOG.debug("Reloading region " + Bytes.toString(currentRegion) +
+ " location because regionserver didn't accept updates; " +
+ "tries=" + tries +
" of max=" + this.numRetries + ", waiting=" + sleepTime + "ms");
}
try {
@@ -946,7 +928,6 @@
retryOnlyOne = true;
region = getRegionLocation(tableName, list.get(i + 1).getRow(),
true).getRegionInfo().getRegionName();
-
}
else {
retryOnlyOne = false;
Modified: hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/master/RegionManager.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/master/RegionManager.java?rev=730865&r1=730864&r2=730865&view=diff
==============================================================================
--- hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/master/RegionManager.java (original)
+++ hadoop/hbase/branches/0.19_on_hadoop_0.18/src/java/org/apache/hadoop/hbase/master/RegionManager.java Fri Jan 2 15:17:24 2009
@@ -90,6 +90,7 @@
*
* Note: Needs to be SortedMap so we can specify a comparator
*
+ * @see RegionState inner-class below
*/
private final SortedMap<byte[], RegionState> regionsInTransition =
Collections.synchronizedSortedMap(
@@ -427,7 +428,7 @@
continue;
}
LOG.debug("Going to close region " +
- currentRegion.getRegionNameAsString());
+ currentRegion.getRegionNameAsString());
// make a message to close the region
returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_CLOSE, currentRegion,
OVERLOADED));
@@ -1013,38 +1014,38 @@
}
/*
- * State of a Region.
- * Used while regions are making transitions from unassigned to assigned to
- * opened, etc.
+ * State of a Region as it transitions from closed to open, etc. See
+ * note on regionsInTransition data member above for listing of state
+ * transitions.
*/
private static class RegionState implements Comparable<RegionState> {
- private final byte [] regionName;
- private HRegionInfo regionInfo = null;
+ private final HRegionInfo regionInfo;
private volatile boolean unassigned = false;
private volatile boolean assigned = false;
private volatile boolean pending = false;
private volatile boolean closing = false;
private volatile boolean closed = false;
private volatile boolean offlined = false;
- private String serverName = null;
-
- RegionState(byte [] regionName) {
- this.regionName = regionName;
- }
+ /* Set when region is assigned.
+ */
+ private String serverName = null;
+
RegionState(HRegionInfo info) {
- this.regionName = info.getRegionName();
this.regionInfo = info;
}
- byte[] getRegionName() {
- return regionName;
+ byte [] getRegionName() {
+ return this.regionInfo.getRegionName();
}
synchronized HRegionInfo getRegionInfo() {
return this.regionInfo;
}
-
+
+ /*
+ * @return Server this region was assigned to
+ */
synchronized String getServerName() {
return this.serverName;
}
@@ -1070,7 +1071,10 @@
return assigned;
}
- synchronized void setAssigned(String serverName) {
+ /*
+ * @param serverName Server region was assigned to.
+ */
+ synchronized void setAssigned(final String serverName) {
if (!this.unassigned) {
throw new IllegalStateException(
"Cannot assign a region that is not currently unassigned. " +
@@ -1132,7 +1136,7 @@
@Override
public synchronized String toString() {
- return "name=" + Bytes.toString(this.regionName) +
+ return "name=" + Bytes.toString(getRegionName()) +
", isUnassigned=" + this.unassigned + ", isAssigned=" +
this.assigned + ", isPending=" + this.pending + ", isClosing=" +
this.closing + ", isClosed=" + this.closed + ", isOfflined=" +
@@ -1146,7 +1150,7 @@
@Override
public int hashCode() {
- return Bytes.toString(regionName).hashCode();
+ return Bytes.toString(getRegionName()).hashCode();
}
@Override
@@ -1154,7 +1158,7 @@
if (o == null) {
return 1;
}
- return Bytes.compareTo(this.regionName, o.getRegionName());
+ return Bytes.compareTo(getRegionName(), o.getRegionName());
}
}
}
\ No newline at end of file