From: Bryan T. <tho...@us...> - 2007-04-23 18:58:44
|
Update of /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2382/src/java/com/bigdata/scaleup Modified Files: PartitionedIndexView.java PartitionMetadata.java MasterJournal.java SegmentMetadata.java MetadataIndex.java ResourceState.java SlaveJournal.java AbstractPartitionTask.java IResourceMetadata.java JournalMetadata.java Added Files: IPartitionMetadata.java Log Message: Refactored the MetadataIndex to extend UnisolatedBTree and put it to some use in the MetadataService and validated aspects of its use in the test case for the metadata service. Index: MetadataIndex.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/MetadataIndex.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MetadataIndex.java 16 Apr 2007 10:02:49 -0000 1.9 --- MetadataIndex.java 23 Apr 2007 18:58:37 -0000 1.10 *************** *** 52,60 **** import org.CognitiveWeb.extser.LongPacker; - import com.bigdata.btree.BTree; import com.bigdata.btree.BTreeMetadata; import com.bigdata.btree.IIndex; import com.bigdata.btree.IndexSegment; import com.bigdata.isolation.IsolatedBTree; import com.bigdata.journal.Journal; import com.bigdata.journal.Tx; --- 52,61 ---- import org.CognitiveWeb.extser.LongPacker; import com.bigdata.btree.BTreeMetadata; import com.bigdata.btree.IIndex; import com.bigdata.btree.IndexSegment; + import com.bigdata.io.SerializerUtil; import com.bigdata.isolation.IsolatedBTree; + import com.bigdata.isolation.UnisolatedBTree; import com.bigdata.journal.Journal; import com.bigdata.journal.Tx; *************** *** 79,99 **** * restart-safe so that resources are eventually deleted. */ ! public class MetadataIndex extends BTree { /** ! * The name of the metadata index, which is the always the same as the name ! * under which the corresponding {@link PartitionedIndexView} was registered. ! * ! * @todo rename as managedIndexName (and the access method as well). */ ! private final String name; /** ! * The name of the metadata index, which is the always the same as the name ! * under which the corresponding {@link PartitionedIndexView} was registered. */ ! final public String getName() { ! return name; } --- 80,96 ---- * restart-safe so that resources are eventually deleted. */ ! public class MetadataIndex extends UnisolatedBTree { /** ! * The name of the managed index. */ ! private final String managedIndexName; /** ! * The name of the managed index. */ ! final public String getManagedIndexName() { ! return managedIndexName; } *************** *** 138,143 **** * @param store * The backing store. - * @param branchingFactor - * The branching factor. * @param indexUUID * The unique identifier for the metadata index. --- 135,138 ---- *************** *** 145,157 **** * The unique identifier for the managed scale-out index. * @param managedIndexName ! * The name of the managed scale out index. */ ! public MetadataIndex(IRawStore store, int branchingFactor, UUID indexUUID, UUID managedIndexUUID, String managedIndexName) { ! super(store, branchingFactor, indexUUID, ! PartitionMetadata.Serializer.INSTANCE); ! this.name = managedIndexName; // --- 140,151 ---- * The unique identifier for the managed scale-out index. * @param managedIndexName ! * The managedIndexName of the managed scale out index. */ ! public MetadataIndex(IRawStore store, UUID indexUUID, UUID managedIndexUUID, String managedIndexName) { ! super(store, indexUUID ); ! this.managedIndexName = managedIndexName; // *************** *** 164,168 **** super(store, metadata); ! name = ((MetadataIndexMetadata)metadata).getName(); managedIndexUUID = ((MetadataIndexMetadata)metadata).getManagedIndexUUID(); --- 158,162 ---- super(store, metadata); ! managedIndexName = ((MetadataIndexMetadata)metadata).getName(); managedIndexUUID = ((MetadataIndexMetadata)metadata).getManagedIndexUUID(); *************** *** 177,181 **** /** ! * Extends the {@link BTreeMetadata} record to also hold the name of the * partitioned index. * --- 171,175 ---- /** ! * Extends the {@link BTreeMetadata} record to also hold the managedIndexName of the * partitioned index. * *************** *** 183,187 **** * @version $Id$ */ ! public static class MetadataIndexMetadata extends BTreeMetadata implements Externalizable { private static final long serialVersionUID = -7309267778881420043L; --- 177,181 ---- * @version $Id$ */ ! public static class MetadataIndexMetadata extends UnisolatedBTreeMetadata implements Externalizable { private static final long serialVersionUID = -7309267778881420043L; *************** *** 191,195 **** /** ! * The name of the metadata index, which is the always the same as the name * under which the corresponding {@link PartitionedIndexView} was registered. */ --- 185,189 ---- /** ! * The managedIndexName of the metadata index, which is the always the same as the managedIndexName * under which the corresponding {@link PartitionedIndexView} was registered. */ *************** *** 231,235 **** super(mdi); ! this.name = mdi.getName(); this.managedIndexUUID = mdi.getManagedIndexUUID(); --- 225,229 ---- super(mdi); ! this.name = mdi.getManagedIndexName(); this.managedIndexUUID = mdi.getManagedIndexUUID(); *************** *** 340,344 **** if(index == -1) return null; ! return (PartitionMetadata) super.valueAt( index ); } --- 334,340 ---- if(index == -1) return null; ! byte[] val = (byte[]) super.valueAt(index); ! ! return (PartitionMetadata) SerializerUtil.deserialize(val); } *************** *** 356,360 **** public PartitionMetadata get(byte[] key) { ! return (PartitionMetadata) super.lookup(key); } --- 352,360 ---- public PartitionMetadata get(byte[] key) { ! byte[] val = (byte[]) super.lookup(key); ! ! if(val==null) return null; ! ! return (PartitionMetadata) SerializerUtil.deserialize(val); } *************** *** 385,395 **** } ! PartitionMetadata oldval = (PartitionMetadata) super.insert(key, ! val); ! if (oldval != null && oldval.partId != val.partId) { throw new IllegalArgumentException("Expecting: partId=" ! + oldval.partId + ", but have partId=" + val.partId); } --- 385,400 ---- } ! byte[] newval = SerializerUtil.serialize(val); ! ! byte[] oldval2 = (byte[])super.insert(key, newval); ! PartitionMetadata oldval = oldval2 == null ? null ! : (PartitionMetadata) SerializerUtil.deserialize(oldval2); ! ! if (oldval != null && oldval.getPartitionId() != val.getPartitionId()) { throw new IllegalArgumentException("Expecting: partId=" ! + oldval.getPartitionId() + ", but have partId=" ! + val.getPartitionId()); } *************** *** 411,415 **** public PartitionMetadata remove(byte[] key) { ! return (PartitionMetadata) super.remove(key); } --- 416,425 ---- public PartitionMetadata remove(byte[] key) { ! byte[] oldval2 = (byte[])super.remove(key); ! ! PartitionMetadata oldval = oldval2 == null ? null ! : (PartitionMetadata) SerializerUtil.deserialize(oldval2); ! ! return oldval; } Index: JournalMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/JournalMetadata.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JournalMetadata.java 29 Mar 2007 17:01:33 -0000 1.3 --- JournalMetadata.java 23 Apr 2007 18:58:37 -0000 1.4 *************** *** 53,66 **** * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ - * - * @todo make this persistence capable by modifying the value serializer to - * use the {@link IResourceMetadata} interface. */ public class JournalMetadata implements IResourceMetadata { ! protected final String filename; ! protected final long nbytes; ! protected final ResourceState state; ! protected final UUID uuid; public final boolean isIndexSegment() { --- 53,63 ---- * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public class JournalMetadata implements IResourceMetadata { ! private final String filename; ! private final long nbytes; ! private final ResourceState state; ! private final UUID uuid; public final boolean isIndexSegment() { Index: IResourceMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/IResourceMetadata.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IResourceMetadata.java 13 Apr 2007 15:04:24 -0000 1.4 --- IResourceMetadata.java 23 Apr 2007 18:58:37 -0000 1.5 *************** *** 44,48 **** package com.bigdata.scaleup; - import java.io.File; import java.util.UUID; --- 44,47 ---- Index: AbstractPartitionTask.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/AbstractPartitionTask.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractPartitionTask.java 13 Apr 2007 15:04:24 -0000 1.6 --- AbstractPartitionTask.java 23 Apr 2007 18:58:37 -0000 1.7 *************** *** 370,382 **** // assume only the last segment is live. ! final SegmentMetadata oldSeg = (SegmentMetadata)pmd.resources[pmd.resources.length-1]; ! newSegs[0] = new SegmentMetadata(oldSeg.filename, oldSeg.nbytes, ! ResourceState.Dead, oldSeg.uuid); newSegs[1] = new SegmentMetadata(outFile.toString(), outFile .length(), ResourceState.Live, builder.segmentUUID); ! mdi.put(fromKey, new PartitionMetadata(0, pmd.dataServices, newSegs)); return null; --- 370,383 ---- // assume only the last segment is live. ! final SegmentMetadata oldSeg = (SegmentMetadata) pmd.getResources()[pmd ! .getResources().length - 1]; ! newSegs[0] = new SegmentMetadata(oldSeg.getFile(), oldSeg.size(), ! ResourceState.Dead, oldSeg.getUUID()); newSegs[1] = new SegmentMetadata(outFile.toString(), outFile .length(), ResourceState.Live, builder.segmentUUID); ! mdi.put(fromKey, new PartitionMetadata(0, pmd.getDataServices(), newSegs)); return null; --- NEW FILE: IPartitionMetadata.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 Apr 23, 2007 */ package com.bigdata.scaleup; import java.util.UUID; import com.bigdata.btree.IndexSegment; import com.bigdata.journal.Journal; /** * A description of the metadata state for a partition of a scale-out index. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public interface IPartitionMetadata { /** * The unique partition identifier. */ public int getPartitionId(); /** * The ordered list of data services on which data for this partition will * be written and from which data for this partition may be read. * * @todo refactor into a dataService UUID (required) and an array of zero or * more media replication services for failover. */ public UUID[] getDataServices(); /** * Zero or more files containing {@link Journal}s or {@link IndexSegment}s * holding live data for this partition. The entries in the array reflect * the creation time of the index segments. The earliest resource is listed * first. The most recently created resource is listed last. Only the * {@link ResourceState#Live} resources must be read in order to provide a * consistent view of the data for the index partition. * {@link ResourceState#Dead} resources will eventually be scheduled for * restart-safe deletion. * * @see ResourceState */ public IResourceMetadata[] getResources(); } Index: SlaveJournal.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/SlaveJournal.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SlaveJournal.java 16 Apr 2007 10:02:49 -0000 1.9 --- SlaveJournal.java 23 Apr 2007 18:58:37 -0000 1.10 *************** *** 52,55 **** --- 52,56 ---- import com.bigdata.btree.IIndex; import com.bigdata.btree.IndexSegment; + import com.bigdata.io.SerializerUtil; import com.bigdata.isolation.IIsolatableIndex; import com.bigdata.isolation.UnisolatedBTree; *************** *** 246,251 **** final UUID managedIndexUUID = btree.getIndexUUID(); ! MetadataIndex mdi = new MetadataIndex(this, ! BTree.DEFAULT_BRANCHING_FACTOR, metadataIndexUUID, managedIndexUUID, name); --- 247,251 ---- final UUID managedIndexUUID = btree.getIndexUUID(); ! MetadataIndex mdi = new MetadataIndex(this, metadataIndexUUID, managedIndexUUID, name); *************** *** 254,258 **** * * @todo specify the DataSerivce(s) that will accept writes for this ! * index partition. This should be done as part of refactoring the * metadata index into a first level service. */ --- 254,258 ---- * * @todo specify the DataSerivce(s) that will accept writes for this ! * index partition. This should be done as part of refactoring the * metadata index into a first level service. */ *************** *** 378,386 **** while (itr.hasNext()) { ! final PartitionMetadata pmd = (PartitionMetadata) itr.next(); ! for (int i = 0; i < pmd.resources.length; i++) { ! IResourceMetadata rmd = pmd.resources[i]; if (rmd.isIndexSegment()) { --- 378,389 ---- while (itr.hasNext()) { ! final PartitionMetadata pmd = (PartitionMetadata) SerializerUtil ! .deserialize((byte[]) itr.next()); ! final IResourceMetadata[] resources = pmd.getResources(); ! ! for (int i = 0; i < resources.length; i++) { ! IResourceMetadata rmd = resources[i]; if (rmd.isIndexSegment()) { *************** *** 399,403 **** } ! File dir = master.getPartitionDirectory(name, pmd.partId); if (!dir.delete()) { --- 402,406 ---- } ! File dir = master.getPartitionDirectory(name, pmd.getPartitionId()); if (!dir.delete()) { Index: SegmentMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/SegmentMetadata.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SegmentMetadata.java 13 Apr 2007 15:04:24 -0000 1.6 --- SegmentMetadata.java 23 Apr 2007 18:58:37 -0000 1.7 *************** *** 61,77 **** * The name of the file containing the {@link IndexSegment}. */ ! final public String filename; /** * The size of that file in bytes. */ ! final public long nbytes; /** * The life-cycle state for that {@link IndexSegment}. */ ! final public ResourceState state; ! final public UUID uuid; public final boolean isIndexSegment() { --- 61,77 ---- * The name of the file containing the {@link IndexSegment}. */ ! private String filename; /** * The size of that file in bytes. */ ! private long nbytes; /** * The life-cycle state for that {@link IndexSegment}. */ ! private ResourceState state; ! private UUID uuid; public final boolean isIndexSegment() { *************** *** 114,131 **** } ! public String getFile() { return filename; } ! public long size() { return nbytes; } ! public ResourceState state() { return state; } ! public UUID getUUID() { return uuid; } --- 114,138 ---- } ! final public String getFile() { ! return filename; + } ! final public long size() { ! return nbytes; } ! final public ResourceState state() { ! return state; + } ! final public UUID getUUID() { ! return uuid; + } Index: PartitionedIndexView.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/PartitionedIndexView.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PartitionedIndexView.java 15 Apr 2007 18:17:05 -0000 1.5 --- PartitionedIndexView.java 23 Apr 2007 18:58:37 -0000 1.6 *************** *** 184,192 **** int n = 0; ! for(int i=0; i<pmd.resources.length; i++) { ! if(pmd.resources[i].state() != ResourceState.Live) continue; ! segs[n++] = (IndexSegment) master.getIndex(getName(), pmd.resources[i]); } --- 184,194 ---- int n = 0; ! IResourceMetadata[] resources = pmd.getResources(); ! ! for(int i=0; i<resources.length; i++) { ! if(resources[i].state() != ResourceState.Live) continue; ! segs[n++] = (IndexSegment) master.getIndex(getName(), resources[i]); } *************** *** 250,254 **** PartitionMetadata pmd = mdi.find(key); ! ReadOnlyFusedView view = views.get(pmd.partId); if(view==null) { --- 252,256 ---- PartitionMetadata pmd = mdi.find(key); ! ReadOnlyFusedView view = views.get(pmd.getPartitionId()); if(view==null) { *************** *** 279,283 **** // place the view in the cache. ! views.put(pmd.partId, view); } --- 281,285 ---- // place the view in the cache. ! views.put(pmd.getPartitionId(), view); } *************** *** 309,332 **** final int liveCount = pmd.getLiveCount(); ! IResourceMetadata[] resources = new IResourceMetadata[liveCount + 1]; ! int n = 0; ! resources[n++] = journalResource; ! for (int i = 0; i < resources.length; i++) { ! IResourceMetadata seg = pmd.resources[i]; if (seg.state() != ResourceState.Live) continue; ! resources[n++] = seg; } ! assert n == resources.length; ! return resources; } --- 311,336 ---- final int liveCount = pmd.getLiveCount(); ! IResourceMetadata[] tmp = new IResourceMetadata[liveCount + 1]; ! int n = 0; ! tmp[n++] = journalResource; ! // @todo this should probably be a loop out to pmd.getResources().length ! for (int i = 0; i < tmp.length; i++) { ! // @todo refactor out of loop. ! IResourceMetadata seg = pmd.getResources()[i]; if (seg.state() != ResourceState.Live) continue; ! tmp[n++] = seg; } ! assert n == tmp.length; ! return tmp; } *************** *** 334,338 **** public String getName() { ! return mdi.getName(); } --- 338,342 ---- public String getName() { ! return mdi.getManagedIndexName(); } Index: PartitionMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/PartitionMetadata.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PartitionMetadata.java 23 Apr 2007 17:22:16 -0000 1.9 --- PartitionMetadata.java 23 Apr 2007 18:58:37 -0000 1.10 *************** *** 44,61 **** package com.bigdata.scaleup; - import java.io.DataInput; import java.io.Externalizable; import java.io.IOException; import java.util.UUID; ! import com.bigdata.btree.DataOutputBuffer; ! import com.bigdata.btree.IValueSerializer; import com.bigdata.btree.IndexSegment; - import com.bigdata.isolation.UnisolatedBTree; import com.bigdata.journal.Journal; /** - * A description of the {@link IndexSegment}s containing the user data for a - * partition. * * @todo provide a persistent event log or just integrate the state changes over --- 44,60 ---- package com.bigdata.scaleup; import java.io.Externalizable; import java.io.IOException; + import java.io.ObjectInput; + import java.io.ObjectOutput; import java.util.UUID; ! import org.CognitiveWeb.extser.LongPacker; ! import org.CognitiveWeb.extser.ShortPacker; ! import com.bigdata.btree.IndexSegment; import com.bigdata.journal.Journal; /** * * @todo provide a persistent event log or just integrate the state changes over *************** *** 66,75 **** * @version $Id$ */ ! public class PartitionMetadata /*implements Externalizable*/ { /** * The unique partition identifier. */ ! final protected int partId; /** --- 65,79 ---- * @version $Id$ */ ! public class PartitionMetadata implements IPartitionMetadata, Externalizable { ! ! /** ! * ! */ ! private static final long serialVersionUID = 5234405541356126104L; /** * The unique partition identifier. */ ! private int partId; /** *************** *** 80,84 **** * more media replication services for failover. */ ! final protected UUID[] dataServices; /** --- 84,88 ---- * more media replication services for failover. */ ! private UUID[] dataServices; /** *************** *** 94,98 **** * @see ResourceState */ ! final protected IResourceMetadata[] resources; public PartitionMetadata(int partId, UUID[] dataServices ) { --- 98,109 ---- * @see ResourceState */ ! private IResourceMetadata[] resources; ! ! /** ! * De-serialization constructor. ! */ ! public PartitionMetadata() { ! ! } public PartitionMetadata(int partId, UUID[] dataServices ) { *************** *** 132,135 **** --- 143,155 ---- } + + public int getPartitionId() { + return partId; + } + + public IResourceMetadata[] getResources() { + return resources; + } + /** * The #of data services on which the data for this partition will be *************** *** 247,367 **** } ! /** ! * Serialization for an index segment metadata entry. ! * ! * FIXME convert to use {@link UnisolatedBTree} (so byte[] values that we ! * (de-)serialize one a one-by-one basis ourselves), implement ! * {@link Externalizable} and use explicit versioning and packed integers. ! * ! * @author <a href="mailto:tho...@us...">Bryan Thompson</a> ! * @version $Id$ ! */ ! public static class Serializer implements IValueSerializer { ! ! /** ! * ! */ ! private static final long serialVersionUID = 4307076612127034103L; ! ! public transient static final PartitionMetadata.Serializer INSTANCE = new Serializer(); ! ! // private static final transient int VERSION0 = 0x0; ! public Serializer() { ! } ! ! public void putValues(DataOutputBuffer os, Object[] values, int nvals) ! throws IOException { ! for (int i = 0; i < nvals; i++) { ! ! PartitionMetadata val = (PartitionMetadata) values[i]; ! ! final int nservices = val.dataServices.length; ! ! final int nresources = val.resources.length; ! ! os.writeInt(val.partId); ! ! os.writeInt(nservices); ! ! os.writeInt(nresources); ! for( int j=0; j<nservices; j++) { ! ! final UUID serviceUUID = val.dataServices[j]; ! ! os.writeLong(serviceUUID.getMostSignificantBits()); ! ! os.writeLong(serviceUUID.getLeastSignificantBits()); ! ! } ! ! for (int j = 0; j < nresources; j++) { ! IResourceMetadata rmd = val.resources[j]; ! os.writeBoolean(rmd.isIndexSegment()); ! ! os.writeUTF(rmd.getFile()); ! os.writeLong(rmd.size()); ! os.writeInt(rmd.state().valueOf()); ! final UUID resourceUUID = rmd.getUUID(); ! ! os.writeLong(resourceUUID.getMostSignificantBits()); ! ! os.writeLong(resourceUUID.getLeastSignificantBits()); ! } ! } } ! public void getValues(DataInput is, Object[] values, int nvals) ! throws IOException { ! ! for (int i = 0; i < nvals; i++) { ! ! final int partId = is.readInt(); ! ! final int nservices = is.readInt(); ! ! final int nresources = is.readInt(); ! ! final UUID[] services = new UUID[nservices]; ! ! final IResourceMetadata[] resources = new IResourceMetadata[nresources]; ! ! for (int j = 0; j < nservices; j++) { ! services[j] = new UUID(is.readLong()/*MSB*/,is.readLong()/*LSB*/); ! ! } ! ! for (int j = 0; j < nresources; j++) { ! boolean isIndexSegment = is.readBoolean(); ! ! String filename = is.readUTF(); ! long nbytes = is.readLong(); ! ResourceState state = ResourceState.valueOf(is.readInt()); ! UUID uuid = new UUID(is.readLong()/*MSB*/,is.readLong()/*LSB*/); ! resources[j] = (isIndexSegment ? new SegmentMetadata( ! filename, nbytes, state, uuid) ! : new JournalMetadata(filename, nbytes, state, uuid)); ! } ! values[i] = new PartitionMetadata(partId, services, resources); ! } } --- 267,370 ---- } ! private static final transient short VERSION0 = 0x0; ! ! public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { ! final short version = ShortPacker.unpackShort(in); ! ! if(version!=VERSION0) { ! throw new IOException("Unknown version: "+version); ! ! } ! ! partId = (int) LongPacker.unpackLong(in); ! final int nservices = ShortPacker.unpackShort(in); ! ! final int nresources = ShortPacker.unpackShort(in); ! ! dataServices = new UUID[nservices]; ! ! resources = new IResourceMetadata[nresources]; ! for (int j = 0; j < nservices; j++) { ! dataServices[j] = new UUID(in.readLong()/*MSB*/,in.readLong()/*LSB*/); ! ! } ! ! for (int j = 0; j < nresources; j++) { ! boolean isIndexSegment = in.readBoolean(); ! ! String filename = in.readUTF(); ! long nbytes = LongPacker.unpackLong(in); ! ResourceState state = ResourceState.valueOf(ShortPacker.unpackShort(in)); ! UUID uuid = new UUID(in.readLong()/*MSB*/,in.readLong()/*LSB*/); ! resources[j] = (isIndexSegment ? new SegmentMetadata( ! filename, nbytes, state, uuid) ! : new JournalMetadata(filename, nbytes, state, uuid)); } + + } ! public void writeExternal(ObjectOutput out) throws IOException { ! ShortPacker.packShort(out, VERSION0); ! ! final int nservices = dataServices.length; ! ! final int nresources = resources.length; ! ! assert nservices < Short.MAX_VALUE; ! assert nresources < Short.MAX_VALUE; ! ! LongPacker.packLong(out,partId); ! ! ShortPacker.packShort(out,(short)nservices); ! ShortPacker.packShort(out,(short)nresources); ! for( int j=0; j<nservices; j++) { ! ! final UUID serviceUUID = dataServices[j]; ! ! out.writeLong(serviceUUID.getMostSignificantBits()); ! ! out.writeLong(serviceUUID.getLeastSignificantBits()); ! ! } ! ! /* ! * Note: we serialize using the IResourceMetadata interface so that we ! * can handle different subclasses and then special case the ! * deserialization based on the boolean flag. This is significantly more ! * compact than using an Externalizable for each ResourceMetadata object ! * since we do not have to write the class names for those objects. ! */ ! for (int j = 0; j < nresources; j++) { ! IResourceMetadata rmd = resources[j]; ! out.writeBoolean(rmd.isIndexSegment()); ! ! out.writeUTF(rmd.getFile()); ! LongPacker.packLong(out,rmd.size()); ! ShortPacker.packShort(out,rmd.state().valueOf()); ! final UUID resourceUUID = rmd.getUUID(); ! ! out.writeLong(resourceUUID.getMostSignificantBits()); ! ! out.writeLong(resourceUUID.getLeastSignificantBits()); } Index: MasterJournal.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/MasterJournal.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** MasterJournal.java 16 Apr 2007 10:02:49 -0000 1.8 --- MasterJournal.java 23 Apr 2007 18:58:37 -0000 1.9 *************** *** 922,926 **** */ ! File outFile = getSegmentFile(name,pmd.partId); IndexSegmentBuilder builder = new IndexSegmentBuilder(outFile, --- 922,926 ---- */ ! File outFile = getSegmentFile(name,pmd.getPartitionId()); IndexSegmentBuilder builder = new IndexSegmentBuilder(outFile, *************** *** 935,939 **** * update the metadata index for this partition. */ ! mdi.put(separatorKey, new PartitionMetadata(0, pmd.dataServices, new SegmentMetadata[] { new SegmentMetadata("" + outFile, outFile.length(), ResourceState.Live, --- 935,939 ---- * update the metadata index for this partition. */ ! mdi.put(separatorKey, new PartitionMetadata(0, pmd.getDataServices(), new SegmentMetadata[] { new SegmentMetadata("" + outFile, outFile.length(), ResourceState.Live, *************** *** 961,965 **** // output file for the merged segment. ! File outFile = getSegmentFile(name, pmd.partId); // merge the data from the btree on the slave and the index --- 961,965 ---- // output file for the merged segment. ! File outFile = getSegmentFile(name, pmd.getPartitionId()); // merge the data from the btree on the slave and the index *************** *** 1005,1017 **** // assume only the last segment is live. ! final SegmentMetadata oldSeg = (SegmentMetadata)pmd.resources[pmd.resources.length-1]; ! newSegs[0] = new SegmentMetadata(oldSeg.filename, oldSeg.nbytes, ! ResourceState.Dead, oldSeg.uuid); newSegs[1] = new SegmentMetadata(outFile.toString(), outFile .length(), ResourceState.Live, builder.segmentUUID); ! mdi.put(separatorKey, new PartitionMetadata(0, pmd.dataServices, newSegs)); // /* --- 1005,1018 ---- // assume only the last segment is live. ! final SegmentMetadata oldSeg = (SegmentMetadata) pmd.getResources()[pmd ! .getResources().length - 1]; ! newSegs[0] = new SegmentMetadata(oldSeg.getFile(), oldSeg.size(), ! ResourceState.Dead, oldSeg.getUUID()); newSegs[1] = new SegmentMetadata(outFile.toString(), outFile .length(), ResourceState.Live, builder.segmentUUID); ! mdi.put(separatorKey, new PartitionMetadata(0, pmd.getDataServices(), newSegs)); // /* *************** *** 1032,1040 **** // assuming at most one dead and one live segment. ! if(pmd.resources.length>1) { ! final SegmentMetadata deadSeg = (SegmentMetadata)pmd.resources[0]; ! if(deadSeg.state!=ResourceState.Dead) { throw new AssertionError(); --- 1033,1041 ---- // assuming at most one dead and one live segment. ! if(pmd.getResources().length>1) { ! final SegmentMetadata deadSeg = (SegmentMetadata)pmd.getResources()[0]; ! if(deadSeg.state()!=ResourceState.Dead) { throw new AssertionError(); *************** *** 1042,1046 **** } ! File deadSegFile = new File(deadSeg.filename); if(deadSegFile.exists() && !deadSegFile.delete() ) { --- 1043,1047 ---- } ! File deadSegFile = new File(deadSeg.getFile()); if(deadSegFile.exists() && !deadSegFile.delete() ) { Index: ResourceState.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/scaleup/ResourceState.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ResourceState.java 13 Apr 2007 15:04:24 -0000 1.2 --- ResourceState.java 23 Apr 2007 18:58:37 -0000 1.3 *************** *** 66,72 **** public String toString() {return name;} ! public int valueOf() {return id;} ! static public ResourceState valueOf(int id) { switch(id) { case 0: return New; --- 66,72 ---- public String toString() {return name;} ! public short valueOf() {return (short)id;} ! static public ResourceState valueOf(short id) { switch(id) { case 0: return New; |