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 6937E200BEF for ; Wed, 4 Jan 2017 22:09:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 68A80160B21; Wed, 4 Jan 2017 21:09:01 +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 B198E160B3A for ; Wed, 4 Jan 2017 22:09:00 +0100 (CET) Received: (qmail 80614 invoked by uid 500); 4 Jan 2017 21:08:59 -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 80279 invoked by uid 99); 4 Jan 2017 21:08:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2017 21:08:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id A22782C2AB7 for ; Wed, 4 Jan 2017 21:08:58 +0000 (UTC) Date: Wed, 4 Jan 2017 21:08:58 +0000 (UTC) From: "Enis Soztutar (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: Wed, 04 Jan 2017 21:09:01 -0000 [ https://issues.apache.org/jira/browse/HBASE-17361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15799345#comment-15799345 ] Enis Soztutar commented on HBASE-17361: --------------------------------------- I like the idea of having the configuration parameters (timeout, etc) to be set-once at construction time. Then we don't have to deal with the user changing configs on the fly. Our Connection / Table / BM already is a nice abstraction allowing that. If you want different timeout settings, you should instantiate a different Table object from Connection. The {{ConnectionConfiguration}} class used to be called {{TableConfiguration}}, but it was always {{InteraceAudience.Private}}. Maybe we can make a TableConfiguration, deprecate / remove all setXXX and have an API like this: {code} TableConfiguration tableConf = connection.getTableConfigs(); tableConf.setRpcTimeout(42); Table table = connection.getTable(tableName, tableConfigs); {code} HBASE-15645 introduced the setXXXTimeout() methods to Table it seems. > 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 > 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)