hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r816956 - in /hadoop/hbase/branches/0.20: CHANGES.txt src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java src/test/org/apache/hadoop/hbase/TestHMsg.java
Date Sat, 19 Sep 2009 21:41:54 GMT
Author: stack
Date: Sat Sep 19 21:41:53 2009
New Revision: 816956

URL: http://svn.apache.org/viewvc?rev=816956&view=rev
Log:
HBASE-1853 Each time around the regionserver core loop, we clear the messages to pass master,
even if we failed to deliver them

Added:
    hadoop/hbase/branches/0.20/src/test/org/apache/hadoop/hbase/TestHMsg.java
Modified:
    hadoop/hbase/branches/0.20/CHANGES.txt
    hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Modified: hadoop/hbase/branches/0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/CHANGES.txt?rev=816956&r1=816955&r2=816956&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.20/CHANGES.txt Sat Sep 19 21:41:53 2009
@@ -19,6 +19,8 @@
                for when Writable is not Configurable (Stack via jgray)
    HBASE-1847  Delete latest of a null qualifier when non-null qualifiers
                exist throws a RuntimeException 
+   HBASE-1853  Each time around the regionserver core loop, we clear the
+               messages to pass master, even if we failed to deliver them
 
   IMPROVEMENTS
    HBASE-1819  Update to 0.20.1 hadoop and zk 3.2.1

Modified: hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=816956&r1=816955&r2=816956&view=diff
==============================================================================
--- hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hadoop/hbase/branches/0.20/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Sat Sep 19 21:41:53 2009
@@ -433,6 +433,7 @@
         LOG.warn("No response from master on reportForDuty. Sleeping and " +
           "then trying again.");
       }
+      HMsg outboundArray[] = null;
       long lastMsg = 0;
       // Now ask master what it wants us to do and tell it what we have done
       for (int tries = 0; !stopRequested.get() && isHealthy();) {
@@ -454,12 +455,6 @@
             " milliseconds - retrying");
         }
         if ((now - lastMsg) >= msgInterval) {
-          HMsg outboundArray[] = null;
-          synchronized(this.outboundMsgs) {
-            outboundArray =
-              this.outboundMsgs.toArray(new HMsg[outboundMsgs.size()]);
-            this.outboundMsgs.clear();
-          }
           try {
             doMetrics();
             MemoryUsage memory =
@@ -472,9 +467,11 @@
             }
             this.serverInfo.setLoad(hsl);
             this.requestCount.set(0);
+            outboundArray = getOutboundMsgs(outboundArray);
             HMsg msgs[] = hbaseMaster.regionServerReport(
               serverInfo, outboundArray, getMostLoadedRegions());
             lastMsg = System.currentTimeMillis();
+            outboundArray = updateOutboundMsgs(outboundArray);
             if (this.quiesced.get() && onlineRegions.size() == 0) {
               // We've just told the master we're exiting because we aren't
               // serving any regions. So set the stop bit and exit.
@@ -685,6 +682,34 @@
     LOG.info(Thread.currentThread().getName() + " exiting");
   }
 
+  /*
+   * @param msgs Current outboundMsgs array
+   * @return Messages to send or returns current outboundMsgs if it already had
+   * content to send.
+   */
+  private HMsg [] getOutboundMsgs(final HMsg [] msgs) {
+    // If passed msgs are not null, means we haven't passed them to master yet.
+    if (msgs != null) return msgs;
+    synchronized(this.outboundMsgs) {
+      return this.outboundMsgs.toArray(new HMsg[outboundMsgs.size()]);
+    }
+  }
+
+  /*
+   * @param msgs Messages we sent the master.
+   * @return Null
+   */
+  private HMsg [] updateOutboundMsgs(final HMsg [] msgs) {
+    if (msgs == null) return null;
+    synchronized(this.outboundMsgs) {
+      for (HMsg m: msgs) {
+        int index = this.outboundMsgs.indexOf(m);
+        if (index != -1) this.outboundMsgs.remove(index);
+      }
+    }
+    return null;
+  }
+
   /**
    * Run and wait on passed thread in HRS context.
    * @param t

Added: hadoop/hbase/branches/0.20/src/test/org/apache/hadoop/hbase/TestHMsg.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.20/src/test/org/apache/hadoop/hbase/TestHMsg.java?rev=816956&view=auto
==============================================================================
--- hadoop/hbase/branches/0.20/src/test/org/apache/hadoop/hbase/TestHMsg.java (added)
+++ hadoop/hbase/branches/0.20/src/test/org/apache/hadoop/hbase/TestHMsg.java Sat Sep 19 21:41:53
2009
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+public class TestHMsg extends TestCase {
+  public void testList() {
+    List<HMsg> msgs = new ArrayList<HMsg>();
+    HMsg hmsg = null;
+    final int size = 10;
+    for (int i = 0; i < size; i++) {
+      byte [] b = Bytes.toBytes(i);
+      hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+        new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
+      msgs.add(hmsg);
+    }
+    assertEquals(size, msgs.size());
+    int index = msgs.indexOf(hmsg);
+    assertNotSame(-1, index);
+    msgs.remove(index);
+    assertEquals(size - 1, msgs.size());
+    byte [] other = Bytes.toBytes("other");
+    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+      new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), other, other));
+    assertEquals(-1, msgs.indexOf(hmsg));
+    // Assert that two HMsgs are same if same content.
+    byte [] b = Bytes.toBytes(1);
+    hmsg = new HMsg(HMsg.Type.MSG_REGION_OPEN,
+     new HRegionInfo(new HTableDescriptor(Bytes.toBytes("test")), b, b));
+    assertNotSame(-1, msgs.indexOf(hmsg));
+  }
+}



Mime
View raw message