Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5CCF8200CCB for ; Thu, 6 Jul 2017 08:17:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5B035165783; Thu, 6 Jul 2017 06:17:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7BB6916577E for ; Thu, 6 Jul 2017 08:17:04 +0200 (CEST) Received: (qmail 80379 invoked by uid 500); 6 Jul 2017 06:17:03 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 80368 invoked by uid 99); 6 Jul 2017 06:17:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Jul 2017 06:17:03 +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 09CCFC13F4 for ; Thu, 6 Jul 2017 06:17:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.011 X-Spam-Level: X-Spam-Status: No, score=-100.011 tagged_above=-999 required=6.31 tests=[SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id nia6lSo7PGGU for ; Thu, 6 Jul 2017 06:17:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id D8C715F2FD for ; Thu, 6 Jul 2017 06:17:00 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 61738E08C3 for ; Thu, 6 Jul 2017 06:17:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1A71E2462A for ; Thu, 6 Jul 2017 06:17:00 +0000 (UTC) Date: Thu, 6 Jul 2017 06:17:00 +0000 (UTC) From: "Hao Zhong (JIRA)" To: commits@cassandra.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (CASSANDRA-13676) Some serializers depend on Stream-specific methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 06 Jul 2017 06:17:05 -0000 Hao Zhong created CASSANDRA-13676: ------------------------------------- Summary: Some serializers depend on Stream-specific methods Key: CASSANDRA-13676 URL: https://issues.apache.org/jira/browse/CASSANDRA-13676 Project: Cassandra Issue Type: Bug Reporter: Hao Zhong When fixing CASSANDRA-2382, Jonathan Ellis complained that some serializers did (do?) depend on Stream-specific methods. The buggy code is as follow: {code} public static class EstimatedHistogramSerializer implements ICompactSerializer { public void serialize(EstimatedHistogram eh, DataOutputStream dos) throws IOException { long[] offsets = eh.getBucketOffsets(); long[] buckets = eh.getBuckets(false); dos.writeInt(buckets.length); for (int i = 0; i < buckets.length; i++) { dos.writeLong(offsets[i == 0 ? 0 : i - 1]); dos.writeLong(buckets[i]); } } public EstimatedHistogram deserialize(DataInputStream dis) throws IOException { int size = dis.readInt(); long[] offsets = new long[size - 1]; long[] buckets = new long[size]; for (int i = 0; i < size; i++) { offsets[i == 0 ? 0 : i - 1] = dis.readLong(); buckets[i] = dis.readLong(); } return new EstimatedHistogram(offsets, buckets); } } {code} The fixed code is: {code} public static class EstimatedHistogramSerializer implements ICompactSerializer2 { public void serialize(EstimatedHistogram eh, DataOutput dos) throws IOException { long[] offsets = eh.getBucketOffsets(); long[] buckets = eh.getBuckets(false); dos.writeInt(buckets.length); for (int i = 0; i < buckets.length; i++) { dos.writeLong(offsets[i == 0 ? 0 : i - 1]); dos.writeLong(buckets[i]); } } public EstimatedHistogram deserialize(DataInput dis) throws IOException { int size = dis.readInt(); long[] offsets = new long[size - 1]; long[] buckets = new long[size]; for (int i = 0; i < size; i++) { offsets[i == 0 ? 0 : i - 1] = dis.readLong(); buckets[i] = dis.readLong(); } return new EstimatedHistogram(offsets, buckets); } } {code} I notice that some serializers still depend on Stream-specific methods. For example, the IndexSummary_deserialize method has the following code: {code} public IndexSummary deserialize(DataInputStream in, IPartitioner partitioner, int expectedMinIndexInterval, int maxIndexInterval) throws IOException { int minIndexInterval = in.readInt(); if (minIndexInterval != expectedMinIndexInterval) { throw new IOException(String.format("Cannot read index summary because min_index_interval changed from %d to %d.", minIndexInterval, expectedMinIndexInterval)); } int offsetCount = in.readInt(); long offheapSize = in.readLong(); int samplingLevel = in.readInt(); int fullSamplingSummarySize = in.readInt(); int effectiveIndexInterval = (int) Math.ceil((BASE_SAMPLING_LEVEL / (double) samplingLevel) * minIndexInterval); if (effectiveIndexInterval > maxIndexInterval) { throw new IOException(String.format("Rebuilding index summary because the effective index interval (%d) is higher than" + " the current max index interval (%d)", effectiveIndexInterval, maxIndexInterval)); } Memory offsets = Memory.allocate(offsetCount * 4); Memory entries = Memory.allocate(offheapSize - offsets.size()); try { FBUtilities.copy(in, new MemoryOutputStream(offsets), offsets.size()); FBUtilities.copy(in, new MemoryOutputStream(entries), entries.size()); } catch (IOException ioe) { offsets.free(); entries.free(); throw ioe; } // our on-disk representation treats the offsets and the summary data as one contiguous structure, // in which the offsets are based from the start of the structure. i.e., if the offsets occupy // X bytes, the value of the first offset will be X. In memory we split the two regions up, so that // the summary values are indexed from zero, so we apply a correction to the offsets when de/serializing. // In this case subtracting X from each of the offsets. for (int i = 0 ; i < offsets.size() ; i += 4) offsets.setInt(i, (int) (offsets.getInt(i) - offsets.size())); return new IndexSummary(partitioner, offsets, offsetCount, entries, entries.size(), fullSamplingSummarySize, minIndexInterval, samplingLevel); } {code} Is it worthy replace the Stream-specific inputs as well? -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org For additional commands, e-mail: commits-help@cassandra.apache.org