accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1397928 - in /accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver: SimpleLRUCache.java SimpleLRUCacheTest.java TabletServer.java
Date Sat, 13 Oct 2012 19:05:15 GMT
Author: ecn
Date: Sat Oct 13 19:05:15 2012
New Revision: 1397928

URL: http://svn.apache.org/viewvc?rev=1397928&view=rev
Log:
ACCUMULO-774 reduce the chances of warnings due to recently unloaded tablets

Added:
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCache.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCacheTest.java
Modified:
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java

Added: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCache.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCache.java?rev=1397928&view=auto
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCache.java
(added)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCache.java
Sat Oct 13 19:05:15 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.accumulo.server.tabletserver;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+
+public class SimpleLRUCache<T> extends HashSet<T> {
+  
+  private static final long serialVersionUID = 1L;
+  
+  final int max;
+  List<T> recent = new LinkedList<T>();
+  
+  public SimpleLRUCache(int max) {
+    this.max = max;
+  }
+  
+  @Override
+  public boolean add(T e) {
+    boolean result = super.add(e);
+    if (result) {
+      recent.add(e);
+      if (recent.size() > max) {
+        T oldest = recent.remove(0);
+        super.remove(oldest);
+      }
+    } else {
+      recent.remove(e);
+      recent.add(e);
+    }
+    return result;
+  }
+  
+  @Override
+  public boolean remove(Object o) {
+    if (super.remove(o)) {
+      recent.remove(o);
+      return true;
+    }
+    return false;
+  }
+  
+  @Override
+  public boolean addAll(Collection<? extends T> c) {
+    throw new UnsupportedOperationException();
+  }
+  
+  @Override
+  public boolean retainAll(Collection<?> c) {
+    throw new UnsupportedOperationException();
+  }
+  
+  @Override
+  public boolean removeAll(Collection<?> c) {
+    throw new UnsupportedOperationException();
+  }
+  
+  @Override
+  public void clear() {
+    super.clear();
+    recent.clear();
+  }
+  
+}

Added: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCacheTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCacheTest.java?rev=1397928&view=auto
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCacheTest.java
(added)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/SimpleLRUCacheTest.java
Sat Oct 13 19:05:15 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.accumulo.server.tabletserver;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class SimpleLRUCacheTest {
+  
+  @Test
+  public void test() {
+    SimpleLRUCache<Integer> test = new SimpleLRUCache<Integer>(4);
+    test.add(0);
+    assertTrue(test.contains(0));
+    test.add(1);
+    assertTrue(test.contains(1));
+    assertFalse(test.contains(2));
+    test.add(2);
+    test.add(3);
+    test.add(4);
+    assertFalse(test.contains(0));
+  }
+}

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java?rev=1397928&r1=1397927&r2=1397928&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServer.java
Sat Oct 13 19:05:15 2012
@@ -2327,8 +2327,10 @@ public class TabletServer extends Abstra
       if (t == null) {
         // Tablet has probably been recently unloaded: repeated master
         // unload request is crossing the successful unloaded message
-        log.info("told to unload tablet that was not being served " + extent);
-        enqueueMasterMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_FAILURE_NOT_SERVING,
extent));
+        if (!recentlyUnloadedCache.contains(extent)) {
+          log.info("told to unload tablet that was not being served " + extent);
+          enqueueMasterMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_FAILURE_NOT_SERVING,
extent));
+        }
         return;
       }
       
@@ -2348,6 +2350,7 @@ public class TabletServer extends Abstra
       
       // stop serving tablet - client will get not serving tablet
       // exceptions
+      recentlyUnloadedCache.add(extent);
       onlineTablets.remove(extent);
       
       try {
@@ -2567,6 +2570,7 @@ public class TabletServer extends Abstra
   private SortedMap<KeyExtent,Tablet> onlineTablets = Collections.synchronizedSortedMap(new
TreeMap<KeyExtent,Tablet>());
   private SortedSet<KeyExtent> unopenedTablets = Collections.synchronizedSortedSet(new
TreeSet<KeyExtent>());
   private SortedSet<KeyExtent> openingTablets = Collections.synchronizedSortedSet(new
TreeSet<KeyExtent>());
+  private Set<KeyExtent> recentlyUnloadedCache = Collections.synchronizedSet(new SimpleLRUCache<KeyExtent>(10));
   
   private Thread majorCompactorThread;
   



Mime
View raw message