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 2010/08/09 17:55:20 UTC

svn commit: r983699 - in /hbase/trunk: CHANGES.txt src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java

Author: apurtell
Date: Mon Aug  9 15:55:19 2010
New Revision: 983699

URL: http://svn.apache.org/viewvc?rev=983699&view=rev
Log:
HBASE-2905 NPE when inserting mass data via REST interface

Modified:
    hbase/trunk/CHANGES.txt
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java

Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=983699&r1=983698&r2=983699&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Mon Aug  9 15:55:19 2010
@@ -472,6 +472,8 @@ Release 0.21.0 - Unreleased
    HBASE-2823  Entire Row Deletes not stored in Row+Col Bloom
                (Alexander Georgiev via Stack)
    HBASE-2897  RowResultGenerator should handle NoSuchColumnFamilyException
+   HBASE-2905  NPE when inserting mass data via REST interface (Sandy Yin via
+               Andrew Purtell)
 
   IMPROVEMENTS
    HBASE-1760  Cleanup TODOs in HTable

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java?rev=983699&r1=983698&r2=983699&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/PlainTextMessageBodyProducer.java Mon Aug  9 15:55:19 2010
@@ -24,8 +24,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-import java.util.Map;
-import java.util.WeakHashMap;
 
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
@@ -47,7 +45,7 @@ import org.apache.hadoop.hbase.rest.Cons
 public class PlainTextMessageBodyProducer 
   implements MessageBodyWriter<Object> {
 
-  private Map<Object, byte[]> buffer = new WeakHashMap<Object, byte[]>();
+  private ThreadLocal<byte[]> buffer = new ThreadLocal<byte[]>();
 
   @Override
   public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
@@ -58,9 +56,9 @@ public class PlainTextMessageBodyProduce
 	@Override
 	public long getSize(Object object, Class<?> type, Type genericType,
 			Annotation[] annotations, MediaType mediaType) {
-	  byte[] bytes = object.toString().getBytes(); 
-	  buffer.put(object, bytes);
-		return bytes.length;
+    byte[] bytes = object.toString().getBytes(); 
+	  buffer.set(bytes);
+    return bytes.length;
 	}
 
 	@Override
@@ -68,6 +66,8 @@ public class PlainTextMessageBodyProduce
 			Annotation[] annotations, MediaType mediaType,
 			MultivaluedMap<String, Object> httpHeaders, OutputStream outStream)
 			throws IOException, WebApplicationException {
-		outStream.write(buffer.remove(object));
+    byte[] bytes = buffer.get();
+		outStream.write(bytes);
+    buffer.remove();
 	}	
 }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java?rev=983699&r1=983698&r2=983699&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/rest/provider/producer/ProtobufMessageBodyProducer.java Mon Aug  9 15:55:19 2010
@@ -25,8 +25,6 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-import java.util.Map;
-import java.util.WeakHashMap;
 
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
@@ -49,7 +47,7 @@ import org.apache.hadoop.hbase.rest.Prot
 public class ProtobufMessageBodyProducer
   implements MessageBodyWriter<ProtobufMessageHandler> {
 
-  private Map<Object, byte[]> buffer = new WeakHashMap<Object, byte[]>();
+  private ThreadLocal<byte[]> buffer = new ThreadLocal<byte[]>();
 
 	@Override
 	public boolean isWriteable(Class<?> type, Type genericType, 
@@ -67,7 +65,7 @@ public class ProtobufMessageBodyProducer
 	    return -1;
 	  }
 	  byte[] bytes = baos.toByteArray();
-	  buffer.put(m, bytes);
+	  buffer.set(bytes);
 	  return bytes.length;
 	}
 
@@ -75,6 +73,8 @@ public class ProtobufMessageBodyProducer
 	    Annotation[] annotations, MediaType mediaType, 
 	    MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) 
 	    throws IOException, WebApplicationException {
-	  entityStream.write(buffer.remove(m));
+    byte[] bytes = buffer.get();
+	  entityStream.write(bytes);
+    buffer.remove();
 	}
 }