Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 80252 invoked from network); 25 Jan 2010 16:45:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Jan 2010 16:45:09 -0000 Received: (qmail 81677 invoked by uid 500); 25 Jan 2010 16:45:09 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 81661 invoked by uid 500); 25 Jan 2010 16:45:09 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Received: (qmail 81651 invoked by uid 99); 25 Jan 2010 16:45:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jan 2010 16:45:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jan 2010 16:45:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CCE4C23889B1; Mon, 25 Jan 2010 16:44:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r902868 - /incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java Date: Mon, 25 Jan 2010 16:44:45 -0000 To: cassandra-commits@incubator.apache.org From: jbellis@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100125164445.CCE4C23889B1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jbellis Date: Mon Jan 25 16:44:45 2010 New Revision: 902868 URL: http://svn.apache.org/viewvc?rev=902868&view=rev Log: fix potential race in Table.open. patch by jbellis; reviewed by Jeff Hodges for CASSANDRA-734 Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java?rev=902868&r1=902867&r2=902868&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java (original) +++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/db/Table.java Mon Jan 25 16:44:45 2010 @@ -33,6 +33,7 @@ import java.net.InetAddress; import org.apache.cassandra.utils.*; import org.apache.cassandra.db.filter.*; +import org.cliffc.high_scale_lib.NonBlockingHashMap; import org.apache.log4j.Logger; @@ -163,9 +164,8 @@ } } - /* Used to lock the factory for creation of Table instance */ - private static final Lock createLock_ = new ReentrantLock(); - private static final Map instances_ = new HashMap(); + /** Table objects, one per keyspace. only one instance should ever exist for any given keyspace. */ + private static final Map instances_ = new NonBlockingHashMap(); /* Table name. */ private final String table_; /* Handle to the Table Metadata */ @@ -178,26 +178,19 @@ public static Table open(String table) throws IOException { Table tableInstance = instances_.get(table); - /* - * Read the config and figure the column families for this table. - * Set the isConfigured flag so that we do not read config all the - * time. - */ if (tableInstance == null) { - Table.createLock_.lock(); - try + // instantiate the Table. we could use putIfAbsent but it's important to making sure it is only done once + // per keyspace, so we synchronize and re-check before doing it. + synchronized (Table.class) { + tableInstance = instances_.get(table); if (tableInstance == null) { tableInstance = new Table(table); instances_.put(table, tableInstance); } } - finally - { - createLock_.unlock(); - } } return tableInstance; }