Return-Path: X-Original-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-connectors-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 162287AD2 for ; Fri, 18 Nov 2011 02:08:50 +0000 (UTC) Received: (qmail 61078 invoked by uid 500); 18 Nov 2011 02:08:49 -0000 Delivered-To: apmail-incubator-connectors-commits-archive@incubator.apache.org Received: (qmail 61037 invoked by uid 500); 18 Nov 2011 02:08:49 -0000 Mailing-List: contact connectors-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: connectors-dev@incubator.apache.org Delivered-To: mailing list connectors-commits@incubator.apache.org Received: (qmail 61030 invoked by uid 99); 18 Nov 2011 02:08:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Nov 2011 02:08:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Fri, 18 Nov 2011 02:08:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DEDFC23888CC; Fri, 18 Nov 2011 02:08:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1203461 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore: Index.java Table.java TableStore.java Date: Fri, 18 Nov 2011 02:08:24 -0000 To: connectors-commits@incubator.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111118020824.DEDFC23888CC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kwright Date: Fri Nov 18 02:08:24 2011 New Revision: 1203461 URL: http://svn.apache.org/viewvc?rev=1203461&view=rev Log: Add methods that allocate node and row numbers Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java?rev=1203461&r1=1203460&r2=1203461&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java (original) +++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java Fri Nov 18 02:08:24 2011 @@ -106,18 +106,4 @@ public class Index implements WHIndex return indexName; } - /** Create the index */ - public void create() - throws WHException - { - // MHL - } - - /** Drop the index */ - public void drop() - throws WHException - { - // MHL - } - } Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1203461&r1=1203460&r2=1203461&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java (original) +++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java Fri Nov 18 02:08:24 2011 @@ -114,20 +114,6 @@ public class Table implements WHTable return tableName; } - /** Create the table */ - public void create() - throws WHException - { - // MHL - } - - /** Drop the table */ - public void drop() - throws WHException - { - // MHL - } - // Protected methods /** Delete a specified table row from all indexes attached to the table. Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1203461&r1=1203460&r2=1203461&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java (original) +++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java Fri Nov 18 02:08:24 2011 @@ -27,11 +27,17 @@ import java.util.*; */ public class TableStore implements WHTableStore { + /** The underlying transactional store */ protected WHTransactionalStore transactionalStore; + + /** The current transaction, if any */ protected WHTransaction currentTransaction = null; + /** Map of table name to table object, good for the current transaction */ protected Map tables = null; + /** Map of index name to index object, good for the current transaction */ protected Map indexes = null; + /** Map of table name to index set, good for the current transaction */ protected Map indexesPerTable = null; /** Constructor */ @@ -102,7 +108,8 @@ public class TableStore implements WHTab TableIndexKey tik = new TableIndexKey(name); TableIndexValue tiv = new TableIndexValue(new String[0]); currentTransaction.put(tik,tiv); - t.create(); + TableRowLimitKey tlk = new TableRowLimitKey(name); + currentTransaction.put(tlk,new TableRowLimitValue(0)); return t; } @@ -157,7 +164,8 @@ public class TableStore implements WHTab tiv = new TableIndexValue(newIndexList); currentTransaction.put(tik,tiv); indexesPerTable.remove(t.getName()); - i.create(); + IndexNodeLimitKey tlk = new IndexNodeLimitKey(name); + currentTransaction.put(tlk,new IndexNodeLimitValue(0)); return i; } @@ -209,6 +217,54 @@ public class TableStore implements WHTab } } + // Row and node number allocators. + // Eventually we should be able to make it so that we allocate multiple row numbers or node numbers + // at a time, which persist cross transaction. That would reduce the number of collisions that happen + // because the row counters are incrementing simultaneously. However, cross-transaction management + // is very tricky because when a transaction is abandoned, the row counter information must revert; + // otherwise the same row numbers can be allocated by two threads inadvertently. The added complexity + // must therefore be worth it, and so far I'm not sure that is the case. + + /** Allocate the next table row number. + */ + public int allocateNewTableRow(String tableName) + throws WHException + { + TableRowLimitKey tlk = new TableRowLimitKey(tableName); + TableRowLimitValue tlv = (TableRowLimitValue)currentTransaction.get(tlk); + if (tlv == null) + throw new WHDeadlockException(); + int rval = tlv.getRowCounter(); + currentTransaction.put(tlk,new TableRowLimitValue(rval+1)); + return rval; + } + + /** Get the current max table row number, plus one. + */ + public int getMaxTableRow(String tableName) + throws WHException + { + TableRowLimitKey tlk = new TableRowLimitKey(tableName); + TableRowLimitValue tlv = (TableRowLimitValue)currentTransaction.get(tlk); + if (tlv == null) + throw new WHDeadlockException(); + return tlv.getRowCounter(); + } + + /** Allocate the next index node number. + */ + public int allocateNextIndexNode(String indexName) + throws WHException + { + IndexNodeLimitKey tlk = new IndexNodeLimitKey(indexName); + IndexNodeLimitValue tlv = (IndexNodeLimitValue)currentTransaction.get(tlk); + if (tlv == null) + throw new WHDeadlockException(); + int rval = tlv.getNodeCounter(); + currentTransaction.put(tlk,new IndexNodeLimitValue(rval+1)); + return rval; + } + // Protected classes and methods protected void deleteTable(Table t) @@ -231,7 +287,8 @@ public class TableStore implements WHTab TableKey tk = new TableKey(t.getName()); currentTransaction.put(tk,null); - t.drop(); + TableRowLimitKey tlk = new TableRowLimitKey(t.getName()); + currentTransaction.put(tlk,null); } protected void deleteIndex(Index i) @@ -262,7 +319,8 @@ public class TableStore implements WHTab indexesPerTable.remove(t.getName()); IndexKey ik = new IndexKey(i.getName()); currentTransaction.put(ik,null); - i.drop(); + IndexNodeLimitKey tlk = new IndexNodeLimitKey(i.getName()); + currentTransaction.put(tlk,null); } protected Table findTable(String name) @@ -482,4 +540,87 @@ public class TableStore implements WHTab return unique; } } + + protected static class TableRowLimitKey extends StringValue + { + /** Constructor */ + public TableRowLimitKey(String name) + { + super(name); + } + + public TableRowLimitKey(byte[] data) + { + super(data); + } + + public boolean equals(Object o) + { + if (!(o instanceof TableRowLimitKey)) + return false; + return super.equals(o); + } + + } + + protected static class TableRowLimitValue extends IntegerValue + { + /** Constructor */ + public TableRowLimitValue(int value) + { + super(value); + } + + public TableRowLimitValue(byte[] data) + { + super(data); + } + + public int getRowCounter() + { + return getValue(); + } + } + + protected static class IndexNodeLimitKey extends StringValue + { + /** Constructor */ + public IndexNodeLimitKey(String name) + { + super(name); + } + + public IndexNodeLimitKey(byte[] data) + { + super(data); + } + + public boolean equals(Object o) + { + if (!(o instanceof IndexNodeLimitKey)) + return false; + return super.equals(o); + } + + } + + protected static class IndexNodeLimitValue extends IntegerValue + { + /** Constructor */ + public IndexNodeLimitValue(int value) + { + super(value); + } + + public IndexNodeLimitValue(byte[] data) + { + super(data); + } + + public int getNodeCounter() + { + return getValue(); + } + } + }