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 DA4CB200C01 for ; Thu, 19 Jan 2017 13:21:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D903A160B57; Thu, 19 Jan 2017 12:21:31 +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 2BBD6160B42 for ; Thu, 19 Jan 2017 13:21:31 +0100 (CET) Received: (qmail 70878 invoked by uid 500); 19 Jan 2017 12:21:30 -0000 Mailing-List: contact issues-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@hbase.apache.org Received: (qmail 70867 invoked by uid 99); 19 Jan 2017 12:21:30 -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, 19 Jan 2017 12:21:30 +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 A68F6C0C88 for ; Thu, 19 Jan 2017 12:21:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] 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 Je_VNonlrnp1 for ; Thu, 19 Jan 2017 12:21:29 +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 36C205FDC3 for ; Thu, 19 Jan 2017 12:21:28 +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 A9B68E015D for ; Thu, 19 Jan 2017 12:21:27 +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 992762528F for ; Thu, 19 Jan 2017 12:21:26 +0000 (UTC) Date: Thu, 19 Jan 2017 12:21:26 +0000 (UTC) From: "Yu Li (JIRA)" To: issues@hbase.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HBASE-17361) Make HTable thread safe MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 19 Jan 2017 12:21:32 -0000 [ https://issues.apache.org/jira/browse/HBASE-17361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15829816#comment-15829816 ] Yu Li commented on HBASE-17361: ------------------------------- Attached the TableBuilder implementation in HBASE-17491. [~stack], [~Apache9] and [~enis], could you take a look there? Thanks. > Make HTable thread safe > ----------------------- > > Key: HBASE-17361 > URL: https://issues.apache.org/jira/browse/HBASE-17361 > Project: HBase > Issue Type: Improvement > Reporter: Yu Li > Assignee: Yu Li > Priority: Critical > Attachments: HBASE-17361.patch, HBASE-17361.patch > > > Currently HTable is marked as NOT thread safe, and this JIRA target at improving this to take better usage of the thread-safe BufferedMutator. > Some findings/work done: > If we try to do put to the same HTable instance in parallel, there'll be problem, since now we have {{HTable#getBufferedMutator}} like > {code} > BufferedMutator getBufferedMutator() throws IOException { > if (mutator == null) { > this.mutator = (BufferedMutatorImpl) connection.getBufferedMutator( > new BufferedMutatorParams(tableName) > .pool(pool) > .writeBufferSize(connConfiguration.getWriteBufferSize()) > .maxKeyValueSize(connConfiguration.getMaxKeyValueSize()) > ); > } > mutator.setRpcTimeout(writeRpcTimeout); > mutator.setOperationTimeout(operationTimeout); > return mutator; > } > {code} > And {{HTable#flushCommits}}: > {code} > void flushCommits() throws IOException { > if (mutator == null) { > // nothing to flush if there's no mutator; don't bother creating one. > return; > } > getBufferedMutator().flush(); > } > {code} > For {{HTable#put}} > {code} > public void put(final Put put) throws IOException { > getBufferedMutator().mutate(put); > flushCommits(); > } > {code} > If we launch multiple threads to put in parallel, below sequence might happen because {{HTable#getBufferedMutator}} is not thread safe: > {noformat} > 1. ThreadA runs to getBufferedMutator and finds mutator==null > 2. ThreadB runs to getBufferedMutator and finds mutator==null > 3. ThreadA initialize mutator to instanceA, then calls mutator#mutate, > adding one put (putA) into {{writeAsyncBuffer}} > 4. ThreadB initialize mutator to instanceB > 5. ThreadA runs to flushCommits, now mutator is instanceB, it calls > instanceB's flush method, putA is lost > {noformat} > After fixing this, we will find quite some contention on {{BufferedMutatorImpl#flush}}, so more efforts required to make HTable thread safe but with good performance meanwhile. -- This message was sent by Atlassian JIRA (v6.3.4#6332)