From: <tho...@us...> - 2010-11-05 15:44:05
|
Revision: 3900 http://bigdata.svn.sourceforge.net/bigdata/?rev=3900&view=rev Author: thompsonbry Date: 2010-11-05 15:43:58 +0000 (Fri, 05 Nov 2010) Log Message: ----------- Conditional invocation of the IAllocationContext specific methods which delegate to the RWStrategy. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/JournalDelegate.java branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java Removed Paths: ------------- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/JournalShadow.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2010-11-04 23:20:34 UTC (rev 3899) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/AbstractJournal.java 2010-11-05 15:43:58 UTC (rev 3900) @@ -2612,14 +2612,39 @@ } - public long write(ByteBuffer data, final long oldAddr, IAllocationContext context) { - return ((RWStrategy)_bufferStrategy).write(data, oldAddr, context); - } + public long write(final ByteBuffer data, final long oldAddr, + final IAllocationContext context) { - public long write(ByteBuffer data, IAllocationContext context) { - return ((RWStrategy)_bufferStrategy).write(data, context); - } + assertCanWrite(); + if (_bufferStrategy instanceof RWStrategy) { + + return ((RWStrategy) _bufferStrategy).write(data, oldAddr, context); + + } else { + + return _bufferStrategy.write(data, oldAddr); + + } + + } + + public long write(final ByteBuffer data, final IAllocationContext context) { + + assertCanWrite(); + + if (_bufferStrategy instanceof RWStrategy) { + + return ((RWStrategy) _bufferStrategy).write(data, context); + + } else { + + return _bufferStrategy.write(data); + + } + + } + // Note: NOP for WORM. Used by RW for eventual recycle protocol. public void delete(final long addr) { @@ -2629,17 +2654,31 @@ } - public void delete(final long addr, IAllocationContext context) { + public void delete(final long addr, final IAllocationContext context) { assertCanWrite(); - ((RWStrategy) _bufferStrategy).delete(addr, context); + if(_bufferStrategy instanceof RWStrategy) { + + ((RWStrategy) _bufferStrategy).delete(addr, context); + + } else { + + _bufferStrategy.delete(addr); + + } } public void detachContext(final IAllocationContext context) { - ((RWStrategy) _bufferStrategy).detachContext(context); + assertCanWrite(); + + if(_bufferStrategy instanceof RWStrategy) { + + ((RWStrategy) _bufferStrategy).detachContext(context); + + } } Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/JournalDelegate.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/JournalDelegate.java 2010-11-04 23:20:34 UTC (rev 3899) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/JournalDelegate.java 2010-11-05 15:43:58 UTC (rev 3900) @@ -38,7 +38,6 @@ import com.bigdata.counters.CounterSet; import com.bigdata.mdi.IResourceMetadata; import com.bigdata.relation.locator.IResourceLocator; -import com.bigdata.rwstore.IAllocationContext; import com.bigdata.sparse.SparseRowStore; public class JournalDelegate implements IJournal { Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java 2010-11-04 23:20:34 UTC (rev 3899) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/RWStrategy.java 2010-11-05 15:43:58 UTC (rev 3900) @@ -40,7 +40,6 @@ import com.bigdata.rawstore.AbstractRawStore; import com.bigdata.rawstore.IAddressManager; import com.bigdata.rwstore.IAllocationContext; -import com.bigdata.rwstore.JournalShadow; import com.bigdata.rwstore.RWStore; import com.bigdata.rwstore.RWStore.StoreCounters; import com.bigdata.util.ChecksumError; @@ -183,8 +182,6 @@ * {@link RWStore}. Shadow allocators may be used to isolate allocation * changes (both allocating slots and releasing slots) across different * processes. - * - * @see JournalShadow */ @Override public long write(final ByteBuffer data, final IAllocationContext context) { Deleted: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/JournalShadow.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/JournalShadow.java 2010-11-04 23:20:34 UTC (rev 3899) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/JournalShadow.java 2010-11-05 15:43:58 UTC (rev 3900) @@ -1,126 +0,0 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package com.bigdata.rwstore; - -import java.nio.ByteBuffer; - -import com.bigdata.journal.AbstractJournal; -import com.bigdata.journal.IBufferStrategy; -import com.bigdata.journal.IJournal; -import com.bigdata.journal.JournalDelegate; -import com.bigdata.journal.RWStrategy; - -/** - * A {@link JournalShadow} wraps an Journal but provides itself as the - * allocation context to be passed through to any interested - * {@link IBufferStrategy}. This is the path by which {@link RWStore} allocators - * are provided with the context for the allocations and deletes made. - * - * @author Martyn Cutcher - */ -public class JournalShadow extends JournalDelegate implements IAllocationContext { - -// private final static AtomicLong s_idCounter = new AtomicLong(23); -// -// final private int m_id = (int) s_idCounter.incrementAndGet(); - - private JournalShadow(final AbstractJournal source) { - - super(source); - - } - - public long write(final ByteBuffer data) { - - return delegate.write(data, this); - - } - - public long write(final ByteBuffer data, final long oldAddr) { - - return delegate.write(data, oldAddr, this); - - } - - public void delete(long oldAddr) { - - delegate.delete(oldAddr, this); - - } - -// public int compareTo(Object o) { -// if (o instanceof JournalShadow) { -// JournalShadow js = (JournalShadow) o; -// return m_id - js.m_id; -// } else { -// return -1; -// } -// } - -// /** -// * TODO: should retrieve from localTransactionService or Journal -// * properties -// */ -// public long minimumReleaseTime() { -// return 0; -// } - - /** - * Release itself from the wrapped Journal, this unlocks the allocator for - * the RWStore - */ - public void detach() { - - delegate.detachContext(this); - - } - - /** - * This factory pattern creates a shadow for a RWStrategy-backed Journal to - * support protected allocations while allowing for deletion and - * re-allocation where possible. If the Journal is not backed by a - * RWStrategy, then the original Journal is returned. - * - * @param journal - * The journal to be shadowed - * - * @return The shadowed journal if necessary and otherwise the - * <i>journal</i>. - */ - public static IJournal newShadow(final AbstractJournal journal) { - - if (journal.getBufferStrategy() instanceof RWStrategy) { - - return new JournalShadow(journal); - - } else { - - return journal; - - } - - } - -} Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java 2010-11-04 23:20:34 UTC (rev 3899) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java 2010-11-05 15:43:58 UTC (rev 3900) @@ -3228,8 +3228,15 @@ ret = new ContextAllocation(this, m_freeFixed.length, null, context); - m_contexts.put(context, ret); + if (m_contexts.put(context, ret) != null) { + + throw new AssertionError(); + + } +// log.warn("Context: ncontexts=" + m_contexts.size() + ", context=" +// + context); + } return ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |