Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2C1F9187FE for ; Tue, 3 Nov 2015 11:26:09 +0000 (UTC) Received: (qmail 67675 invoked by uid 500); 3 Nov 2015 11:26:09 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 67646 invoked by uid 500); 3 Nov 2015 11:26:09 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 67637 invoked by uid 99); 3 Nov 2015 11:26:09 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 11:26:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 95F0AC29AA for ; Tue, 3 Nov 2015 11:26:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id y0pbJsGiWxt7 for ; Tue, 3 Nov 2015 11:26:02 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 1B72D238AF for ; Tue, 3 Nov 2015 11:25:25 +0000 (UTC) Received: (qmail 62056 invoked by uid 99); 3 Nov 2015 11:25:25 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 11:25:25 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F2DCAE00C5; Tue, 3 Nov 2015 11:25:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tushark@apache.org To: commits@geode.incubator.apache.org Date: Tue, 03 Nov 2015 11:26:16 -0000 Message-Id: <30698540def54b539f3b84889a19926a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [54/79] incubator-geode git commit: GEODE-222 Allow redis adapter to handle live entry objects GEODE-222 Allow redis adapter to handle live entry objects Previously encoding a response would not be able to handle the case where an entry was concurrently destroyed. The fix is to catch the EntryDestroyedException gracefully Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/a0b6aae5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/a0b6aae5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/a0b6aae5 Branch: refs/heads/feature/GEODE-17 Commit: a0b6aae5bbdb815fa9bef608a084fb15c20dae6e Parents: 73be563 Author: Vito Gavrilov Authored: Thu Aug 27 10:54:44 2015 -0700 Committer: tushark Committed: Tue Nov 3 16:52:43 2015 +0530 ---------------------------------------------------------------------- .../gemstone/gemfire/internal/redis/Coder.java | 194 +++++++++++-------- 1 file changed, 109 insertions(+), 85 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a0b6aae5/gemfire-core/src/main/java/com/gemstone/gemfire/internal/redis/Coder.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/redis/Coder.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/redis/Coder.java index 9415cd3..0c35c93 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/redis/Coder.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/redis/Coder.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import com.gemstone.gemfire.cache.EntryDestroyedException; import com.gemstone.gemfire.cache.query.Struct; /** @@ -168,29 +169,38 @@ public class Coder { Iterator> it = items.iterator(); ByteBuf response = alloc.buffer(); response.writeByte(ARRAY_ID); - response.writeBytes(intToBytes(items.size() * 2)); - response.writeBytes(CRLFar); - try { - while(it.hasNext()) { - Map.Entry next = it.next(); - byte[] key = next.getKey().toBytes(); - byte[] nextByteArray = next.getValue().toBytes(); - response.writeByte(BULK_STRING_ID); // Add key - response.writeBytes(intToBytes(key.length)); - response.writeBytes(CRLFar); - response.writeBytes(key); - response.writeBytes(CRLFar); - response.writeByte(BULK_STRING_ID); // Add value - response.writeBytes(intToBytes(nextByteArray.length)); - response.writeBytes(CRLFar); - response.writeBytes(nextByteArray); - response.writeBytes(CRLFar); + int size = 0; + ByteBuf tmp = alloc.buffer(); + while(it.hasNext()) { + Map.Entry next = it.next(); + byte[] key; + byte[] nextByteArray; + try { + key = next.getKey().toBytes(); + nextByteArray = next.getValue().toBytes(); + } catch (EntryDestroyedException e) { + continue; } - } catch(Exception e) { - return null; + tmp.writeByte(BULK_STRING_ID); // Add key + tmp.writeBytes(intToBytes(key.length)); + tmp.writeBytes(CRLFar); + tmp.writeBytes(key); + tmp.writeBytes(CRLFar); + tmp.writeByte(BULK_STRING_ID); // Add value + tmp.writeBytes(intToBytes(nextByteArray.length)); + tmp.writeBytes(CRLFar); + tmp.writeBytes(nextByteArray); + tmp.writeBytes(CRLFar); + size++; } + response.writeBytes(intToBytes(size*2)); + response.writeBytes(CRLFar); + response.writeBytes(tmp); + + tmp.release(); + return response; } @@ -211,27 +221,23 @@ public class Coder { response.writeBytes(intToBytes(items.size())); response.writeBytes(CRLFar); - try { - while(it.hasNext()) { - Object nextObject = it.next(); - if (nextObject instanceof String) { - String next = (String) nextObject; - response.writeByte(BULK_STRING_ID); - response.writeBytes(intToBytes(next.length())); - response.writeBytes(CRLFar); - response.writeBytes(stringToBytes(next)); - response.writeBytes(CRLFar); - } else if (nextObject instanceof ByteArrayWrapper) { - byte[] next = ((ByteArrayWrapper) nextObject).toBytes(); - response.writeByte(BULK_STRING_ID); - response.writeBytes(intToBytes(next.length)); - response.writeBytes(CRLFar); - response.writeBytes(next); - response.writeBytes(CRLFar); - } + while(it.hasNext()) { + Object nextObject = it.next(); + if (nextObject instanceof String) { + String next = (String) nextObject; + response.writeByte(BULK_STRING_ID); + response.writeBytes(intToBytes(next.length())); + response.writeBytes(CRLFar); + response.writeBytes(stringToBytes(next)); + response.writeBytes(CRLFar); + } else if (nextObject instanceof ByteArrayWrapper) { + byte[] next = ((ByteArrayWrapper) nextObject).toBytes(); + response.writeByte(BULK_STRING_ID); + response.writeBytes(intToBytes(next.length)); + response.writeBytes(CRLFar); + response.writeBytes(next); + response.writeBytes(CRLFar); } - } catch (Exception e) { - return null; } return response; } @@ -260,7 +266,7 @@ public class Coder { response.writeBytes(CRLFar); return response; } - + public static final ByteBuf getNoAuthResponse(ByteBufAllocator alloc, String error) { byte[] errorAr = stringToBytes(error); ByteBuf response = alloc.buffer(errorAr.length + 25); @@ -306,26 +312,38 @@ public class Coder { Iterator it = items.iterator(); ByteBuf response = alloc.buffer(); response.writeByte(Coder.ARRAY_ID); - response.writeBytes(intToBytes(items.size())); - response.writeBytes(Coder.CRLFar); - + ByteBuf tmp = alloc.buffer(); + int size = 0; while(it.hasNext()) { Object next = it.next(); ByteArrayWrapper nextWrapper = null; - if (next instanceof Entry) - nextWrapper = (ByteArrayWrapper) ((Entry) next).getValue(); - else if (next instanceof Struct) + if (next instanceof Entry) { + try { + nextWrapper = (ByteArrayWrapper) ((Entry) next).getValue(); + } catch (EntryDestroyedException e) { + continue; + } + } else if (next instanceof Struct) { nextWrapper = (ByteArrayWrapper) ((Struct) next).getFieldValues()[1]; + } if (nextWrapper != null) { - response.writeByte(Coder.BULK_STRING_ID); - response.writeBytes(intToBytes(nextWrapper.length())); - response.writeBytes(Coder.CRLFar); - response.writeBytes(nextWrapper.toBytes()); - response.writeBytes(Coder.CRLFar); + tmp.writeByte(Coder.BULK_STRING_ID); + tmp.writeBytes(intToBytes(nextWrapper.length())); + tmp.writeBytes(Coder.CRLFar); + tmp.writeBytes(nextWrapper.toBytes()); + tmp.writeBytes(Coder.CRLFar); } else { - response.writeBytes(Coder.bNIL); + tmp.writeBytes(Coder.bNIL); } + size++; } + + response.writeBytes(intToBytes(size)); + response.writeBytes(Coder.CRLFar); + response.writeBytes(tmp); + + tmp.release(); + return response; } @@ -335,43 +353,49 @@ public class Coder { ByteBuf buffer = alloc.buffer(); buffer.writeByte(Coder.ARRAY_ID); - if (!withScores) - buffer.writeBytes(intToBytes(list.size())); - else - buffer.writeBytes(intToBytes(2 * list.size())); - buffer.writeBytes(Coder.CRLFar); - - try { - for(Object entry: list) { - ByteArrayWrapper key; - DoubleWrapper score; - if (entry instanceof Entry) { + ByteBuf tmp = alloc.buffer(); + int size = 0; + + for(Object entry: list) { + ByteArrayWrapper key; + DoubleWrapper score; + if (entry instanceof Entry) { + try { key = (ByteArrayWrapper) ((Entry) entry).getKey(); - score = (DoubleWrapper) ((Entry) entry).getValue();; - } else { - Object[] fieldVals = ((Struct) entry).getFieldValues(); - key = (ByteArrayWrapper) fieldVals[0]; - score = (DoubleWrapper) fieldVals[1]; - } - byte[] byteAr = key.toBytes(); - buffer.writeByte(Coder.BULK_STRING_ID); - buffer.writeBytes(intToBytes(byteAr.length)); - buffer.writeBytes(Coder.CRLFar); - buffer.writeBytes(byteAr); - buffer.writeBytes(Coder.CRLFar); - if (withScores) { - String scoreString = score.toString(); - byte[] scoreAr = stringToBytes(scoreString); - buffer.writeByte(Coder.BULK_STRING_ID); - buffer.writeBytes(intToBytes(scoreString.length())); - buffer.writeBytes(Coder.CRLFar); - buffer.writeBytes(scoreAr); - buffer.writeBytes(Coder.CRLFar); + score = (DoubleWrapper) ((Entry) entry).getValue(); + } catch (EntryDestroyedException e) { + continue; } + } else { + Object[] fieldVals = ((Struct) entry).getFieldValues(); + key = (ByteArrayWrapper) fieldVals[0]; + score = (DoubleWrapper) fieldVals[1]; + } + byte[] byteAr = key.toBytes(); + tmp.writeByte(Coder.BULK_STRING_ID); + tmp.writeBytes(intToBytes(byteAr.length)); + tmp.writeBytes(Coder.CRLFar); + tmp.writeBytes(byteAr); + tmp.writeBytes(Coder.CRLFar); + size++; + if (withScores) { + String scoreString = score.toString(); + byte[] scoreAr = stringToBytes(scoreString); + tmp.writeByte(Coder.BULK_STRING_ID); + tmp.writeBytes(intToBytes(scoreString.length())); + tmp.writeBytes(Coder.CRLFar); + tmp.writeBytes(scoreAr); + tmp.writeBytes(Coder.CRLFar); + size++; } - } catch(Exception e) { - return null; } + + buffer.writeBytes(intToBytes(size)); + buffer.writeBytes(Coder.CRLFar); + buffer.writeBytes(tmp); + + tmp.release(); + return buffer; }