From: Bryan T. <tho...@us...> - 2007-02-19 01:05:49
|
Update of /cvsroot/cweb/bigdata/src/java/com/bigdata/journal In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv7992/src/java/com/bigdata/journal Modified Files: Tx.java Journal.java ITx.java Added Files: ValidationError.java Log Message: Working on transaction processing support. --- NEW FILE: ValidationError.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Feb 17, 2007 */ package com.bigdata.journal; /** * An instance of this class is thrown when a transaction {@link ITx#prepare()}s * if there is a write-write conflict that can not be resolved. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public class ValidationError extends RuntimeException { /** * */ private static final long serialVersionUID = 7606167478216451303L; /** * */ public ValidationError() { } /** * @param message */ public ValidationError(String message) { super(message); } /** * @param cause */ public ValidationError(Throwable cause) { super(cause); } /** * @param message * @param cause */ public ValidationError(String message, Throwable cause) { super(message, cause); } } Index: ITx.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/ITx.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ITx.java 17 Feb 2007 21:34:17 -0000 1.2 --- ITx.java 19 Feb 2007 01:05:39 -0000 1.3 *************** *** 70,75 **** * * @exception IllegalStateException ! * If the transaction is not active. If the transaction is * not complete, then it will be aborted. */ public void prepare(); --- 70,79 ---- * * @exception IllegalStateException ! * If the transaction is not active. If the transaction is * not complete, then it will be aborted. + * + * @exception ValidationError + * If the transaction can not be validated. If this exception + * is thrown, then the transaction was aborted. */ public void prepare(); Index: Tx.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/Tx.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Tx.java 17 Feb 2007 21:34:17 -0000 1.29 --- Tx.java 19 Feb 2007 01:05:39 -0000 1.30 *************** *** 57,61 **** import com.bigdata.objndx.IndexSegment; import com.bigdata.objndx.ReadOnlyIndex; - import com.bigdata.rawstore.IRawStore; import com.bigdata.scaleup.MetadataIndex; import com.bigdata.scaleup.PartitionedIndex; --- 57,60 ---- *************** *** 72,75 **** --- 71,89 ---- * rejected and {@link #prepare()} and {@link #commit()} are NOPs. * </p> + * <p> + * The write set of a transaction is written onto a {@link TemporaryStore}. + * Therefore the size limit on the transaction write set is currently 2G, but + * the transaction will run in memory up to 100M. The {@link TemporaryStore} is + * closed and any backing file is deleted as soon as the transaction completes. + * </p> + * <p> + * Each {@link IsolatedBTree} is local to a transaction and is backed by its own + * store. This means that concurrent transactions can execute without + * synchronization (real concurrency) up to the point where they + * {@link #prepare()}. We do not need a read-lock on the indices isolated by + * the transaction since they are <em>historical</em> states that will not + * receive concurrent updates. This might prove to be a nice way to leverage + * multiple processors / cores on a data server. + * </p> * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> *************** *** 93,104 **** * we can get the commit record more cheaply. * - * @todo The write set of a transaction is currently written onto an independent - * store. This means that concurrent transactions can actually execute - * concurrently. We do not even need a read-lock on the indices isolated - * by the transaction since they are read-only. This might prove to be a - * nice way to leverage multiple processors / cores on a data server. The - * size limit on the transaction write set is currently 2G, but the - * transaction will run in memory up to 100M. - * * @todo Support transactions where the indices isolated by the transactions are * {@link PartitionedIndex}es. --- 107,110 ---- *************** *** 130,135 **** * server failed to test the pre-conditions and they were not met * ! * @todo Is it possible to have more than one transaction PREPARE must ! * concurrent PREPARE operations be serialized? */ public class Tx implements IStore, ITx { --- 136,142 ---- * server failed to test the pre-conditions and they were not met * ! * @todo PREPARE operations must be serialized unless they are provably ! * non-overlapping. This will require a handshake with either the ! * {@link Journal} or (more likely) the {@link TransactionServer}. */ public class Tx implements IStore, ITx { *************** *** 196,200 **** * time it is invoked. */ ! final protected IRawStore tmpStore = new TemporaryStore(); /** --- 203,207 ---- * time it is invoked. */ ! final protected TemporaryStore tmpStore = new TemporaryStore(); /** *************** *** 281,287 **** /** ! * Return the commit startTimestamp assigned to this transaction. * ! * @return The commit startTimestamp assigned to this transaction. * * @exception IllegalStateException --- 288,294 ---- /** ! * Return the commit timestamp assigned to this transaction. * ! * @return The commit timestamp assigned to this transaction. * * @exception IllegalStateException *************** *** 318,330 **** /** ! * This method must be invoked any time a transaction completes (aborts or ! * commits) in order to release the hard references to any named btrees ! * isolated within this transaction so that the JVM may reclaim the space ! * allocated to them on the heap. */ ! private void releaseBTrees() { btrees.clear(); } --- 325,346 ---- /** ! * This method must be invoked any time a transaction completes ({@link #abort()}s ! * or {@link #commit()}s) in order to release resources held by that ! * transaction. */ ! protected void releaseResources() { + /* + * Release hard references to any named btrees isolated within this + * transaction so that the JVM may reclaim the space allocated to them + * on the heap. + */ btrees.clear(); + /* + * Delete the TemporaryStore. + */ + tmpStore.close(); + } *************** *** 368,373 **** /* ! * Validate against the current state of the journal's object ! * index. */ --- 384,389 ---- /* ! * Validate against the current state of the various indices ! * on write the transaction has written. */ *************** *** 376,384 **** abort(); ! throw new RuntimeException( ! "Validation failed: write-write conflict"); } } catch (Throwable t) { --- 392,403 ---- abort(); ! throw new ValidationError(); } + } catch( ValidationError ex) { + + throw ex; + } catch (Throwable t) { *************** *** 408,411 **** --- 427,433 ---- * </p> * + * @return The commit timestamp or <code>0L</code> if the transaction was + * read-only. + * * @exception IllegalStateException * if the transaction has not been *************** *** 488,496 **** } finally { ! releaseBTrees(); } ! return getCommitTimestamp(); } --- 510,518 ---- } finally { ! releaseResources(); } ! return readOnly ? 0L : getCommitTimestamp(); } *************** *** 515,519 **** } finally { ! releaseBTrees(); } --- 537,541 ---- } finally { ! releaseResources(); } *************** *** 662,666 **** */ UnisolatedBTree groundState = (UnisolatedBTree)journal.getIndex(name); ! isolated.mergeDown(groundState); --- 684,693 ---- */ UnisolatedBTree groundState = (UnisolatedBTree)journal.getIndex(name); ! ! /* ! * Copy the validated write set for this index down onto the ! * corresponding unisolated index, updating version counters, delete ! * markers, and values as necessary in the unisolated index. ! */ isolated.mergeDown(groundState); Index: Journal.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/Journal.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** Journal.java 17 Feb 2007 21:34:18 -0000 1.51 --- Journal.java 19 Feb 2007 01:05:39 -0000 1.52 *************** *** 1508,1511 **** --- 1508,1525 ---- } + + /** + * True iff there is a transaction that has prepared and not yet committed + * or aborted. + * <p> + * Note: It is illegal for more than one transaction to prepare at a time + * if they have write sets that overlap. Serializability depends on each + * transaction validating against the last committed ground state. + */ + public boolean isPreparedTx() { + + return ! preparedTx.isEmpty(); + + } } |