From: Bryan T. <tho...@us...> - 2007-03-22 21:11:59
|
Update of /cvsroot/cweb/bigdata/src/java/com/bigdata/journal In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv3112/src/java/com/bigdata/journal Modified Files: IRootBlockView.java RootBlockView.java TemporaryRawStore.java Options.java FileMetadata.java Journal.java AbstractJournal.java Log Message: Working on service startup and signal handling. Index: TemporaryRawStore.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/TemporaryRawStore.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TemporaryRawStore.java 15 Mar 2007 16:11:13 -0000 1.4 --- TemporaryRawStore.java 22 Mar 2007 21:11:25 -0000 1.5 *************** *** 273,278 **** TransientBufferStrategy tmp = (TransientBufferStrategy)buf; - int segmentId = 0; - File file; --- 273,276 ---- *************** *** 309,313 **** * will be pre-extended to the requested initialExtent. */ ! FileMetadata fileMetadata = new FileMetadata(segmentId, file, BufferMode.Disk, useDirectBuffers, initialExtent, maximumDiskExtent, create, isEmptyFile, deleteOnExit, --- 307,311 ---- * will be pre-extended to the requested initialExtent. */ ! FileMetadata fileMetadata = new FileMetadata(file, BufferMode.Disk, useDirectBuffers, initialExtent, maximumDiskExtent, create, isEmptyFile, deleteOnExit, Index: FileMetadata.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/FileMetadata.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** FileMetadata.java 22 Feb 2007 16:59:34 -0000 1.14 --- FileMetadata.java 22 Mar 2007 21:11:25 -0000 1.15 *************** *** 51,54 **** --- 51,57 ---- import java.nio.channels.FileChannel; import java.nio.channels.FileLock; + import java.util.UUID; + + import org.apache.log4j.Logger; import com.bigdata.rawstore.Bytes; *************** *** 63,66 **** --- 66,74 ---- public class FileMetadata { + /** + * Logger. + */ + public static final Logger log = Logger.getLogger(FileMetadata.class); + static final int SIZE_MAGIC = Bytes.SIZEOF_INT; static final int SIZE_VERSION = Bytes.SIZEOF_INT; *************** *** 77,84 **** final int VERSION1 = 0x1; ! /** ! * The unique segment identifier. ! */ ! final int segment; /** --- 85,92 ---- final int VERSION1 = 0x1; ! // /** ! // * The unique segment identifier. ! // */ ! // final int segment; /** *************** *** 156,161 **** * Prepare a journal file for use by an {@link IBufferStrategy}. * - * @param segmentId - * The unique segment identifier. * @param file * The name of the file to be opened. --- 164,167 ---- *************** *** 197,201 **** * journal. */ ! FileMetadata(int segmentId, File file, BufferMode bufferMode, boolean useDirectBuffers, long initialExtent, long maximumExtent, boolean create, boolean isEmptyFile, boolean deleteOnExit, --- 203,207 ---- * journal. */ ! FileMetadata(File file, BufferMode bufferMode, boolean useDirectBuffers, long initialExtent, long maximumExtent, boolean create, boolean isEmptyFile, boolean deleteOnExit, *************** *** 231,235 **** } ! this.segment = segmentId; this.bufferMode = bufferMode; --- 237,241 ---- } ! // this.segment = segmentId; this.bufferMode = bufferMode; *************** *** 245,249 **** if (exists) { ! System.err.println("Opening existing file: " + file.getAbsoluteFile()); --- 251,255 ---- if (exists) { ! log.info("Opening existing file: " + file.getAbsoluteFile()); *************** *** 266,270 **** } ! System.err.println("Will create file: " + file.getAbsoluteFile()); } --- 272,276 ---- } ! log.info("Will create file: " + file.getAbsoluteFile()); } *************** *** 382,391 **** rootBlock0 = new RootBlockView(true,tmp0); } catch(RootBlockException ex ) { ! System.err.println("Bad root block zero: "+ex); } try { rootBlock1 = new RootBlockView(false,tmp1); } catch(RootBlockException ex ) { ! System.err.println("Bad root block one: "+ex); } if( rootBlock0 == null && rootBlock1 == null ) { --- 388,397 ---- rootBlock0 = new RootBlockView(true,tmp0); } catch(RootBlockException ex ) { ! log.warn("Bad root block zero: "+ex); } try { rootBlock1 = new RootBlockView(false,tmp1); } catch(RootBlockException ex ) { ! log.warn("Bad root block one: "+ex); } if( rootBlock0 == null && rootBlock1 == null ) { *************** *** 518,527 **** final long commitRecordAddr = 0L; final long commitRecordIndexAddr = 0L; ! IRootBlockView rootBlock0 = new RootBlockView(true, segmentId, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr); ! IRootBlockView rootBlock1 = new RootBlockView(false, segmentId, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr); FileChannel channel = raf.getChannel(); channel.write(rootBlock0.asReadOnlyBuffer(), OFFSET_ROOT_BLOCK0); --- 524,536 ---- final long commitRecordAddr = 0L; final long commitRecordIndexAddr = 0L; ! final UUID uuid = UUID.randomUUID(); ! IRootBlockView rootBlock0 = new RootBlockView(true, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr, ! uuid); ! IRootBlockView rootBlock1 = new RootBlockView(false, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr, ! uuid); FileChannel channel = raf.getChannel(); channel.write(rootBlock0.asReadOnlyBuffer(), OFFSET_ROOT_BLOCK0); Index: AbstractJournal.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/AbstractJournal.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractJournal.java 17 Mar 2007 23:14:59 -0000 1.4 --- AbstractJournal.java 22 Mar 2007 21:11:25 -0000 1.5 *************** *** 53,56 **** --- 53,57 ---- import java.util.Map; import java.util.Properties; + import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; *************** *** 76,79 **** --- 77,81 ---- import com.bigdata.rawstore.Bytes; import com.bigdata.rawstore.IRawStore; + import com.bigdata.scaleup.IMetadataIndexManager; import com.bigdata.scaleup.MasterJournal; import com.bigdata.scaleup.SlaveJournal; *************** *** 306,310 **** public AbstractJournal(Properties properties) { ! int segmentId; long initialExtent = Options.DEFAULT_INITIAL_EXTENT; long maximumExtent = Options.DEFAULT_MAXIMUM_EXTENT; --- 308,312 ---- public AbstractJournal(Properties properties) { ! // int segmentId; long initialExtent = Options.DEFAULT_INITIAL_EXTENT; long maximumExtent = Options.DEFAULT_MAXIMUM_EXTENT; *************** *** 352,377 **** } ! /* ! * "segment". ! */ ! ! val = properties.getProperty(Options.SEGMENT); ! ! if (val == null) { ! ! if (bufferMode == BufferMode.Transient) { ! ! val = "0"; ! ! } else { ! ! throw new RuntimeException("Required property: '" ! + Options.SEGMENT + "'"); ! ! } ! ! } ! ! segmentId = Integer.parseInt(val); /* --- 354,379 ---- } ! // /* ! // * "segment". ! // */ ! // ! // val = properties.getProperty(Options.SEGMENT); ! // ! // if (val == null) { ! // ! // if (bufferMode == BufferMode.Transient) { ! // ! // val = "0"; ! // ! // } else { ! // ! // throw new RuntimeException("Required property: '" ! // + Options.SEGMENT + "'"); ! // ! // } ! // ! // } ! // ! // segmentId = Integer.parseInt(val); /* *************** *** 618,627 **** final long commitRecordAddr = 0L; final long commitRecordIndexAddr = 0L; ! IRootBlockView rootBlock0 = new RootBlockView(true, segmentId, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr); ! IRootBlockView rootBlock1 = new RootBlockView(false, segmentId, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr); _bufferStrategy.writeRootBlock(rootBlock0, ForceEnum.No); _bufferStrategy.writeRootBlock(rootBlock1, ForceEnum.No); --- 620,632 ---- final long commitRecordAddr = 0L; final long commitRecordIndexAddr = 0L; ! final UUID uuid = UUID.randomUUID(); ! IRootBlockView rootBlock0 = new RootBlockView(true, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr, ! uuid); ! IRootBlockView rootBlock1 = new RootBlockView(false, nextOffset, firstTxId, lastTxId, commitTimestamp, ! commitCounter, commitRecordAddr, commitRecordIndexAddr, ! uuid); _bufferStrategy.writeRootBlock(rootBlock0, ForceEnum.No); _bufferStrategy.writeRootBlock(rootBlock1, ForceEnum.No); *************** *** 639,643 **** */ ! FileMetadata fileMetadata = new FileMetadata(segmentId, file, BufferMode.Direct, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, --- 644,648 ---- */ ! FileMetadata fileMetadata = new FileMetadata(file, BufferMode.Direct, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, *************** *** 659,663 **** */ ! FileMetadata fileMetadata = new FileMetadata(segmentId, file, BufferMode.Mapped, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, --- 664,668 ---- */ ! FileMetadata fileMetadata = new FileMetadata(file, BufferMode.Mapped, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, *************** *** 679,683 **** */ ! FileMetadata fileMetadata = new FileMetadata(segmentId, file, BufferMode.Disk, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, --- 684,688 ---- */ ! FileMetadata fileMetadata = new FileMetadata(file, BufferMode.Disk, useDirectBuffers, initialExtent, maximumExtent, create, isEmptyFile, deleteOnExit, *************** *** 1114,1121 **** // Create the new root block. IRootBlockView newRootBlock = new RootBlockView( ! !old.isRootBlock0(), old.getSegmentId(), _bufferStrategy .getNextOffset(), firstCommitTime, lastCommitTime, commitTime, newCommitCounter, ! commitRecordAddr, commitRecordIndexAddr); _bufferStrategy.writeRootBlock(newRootBlock, forceOnCommit); --- 1119,1127 ---- // Create the new root block. IRootBlockView newRootBlock = new RootBlockView( ! !old.isRootBlock0(), /*old.getSegmentId(),*/ _bufferStrategy .getNextOffset(), firstCommitTime, lastCommitTime, commitTime, newCommitCounter, ! commitRecordAddr, commitRecordIndexAddr, ! old.getUUID()); _bufferStrategy.writeRootBlock(newRootBlock, forceOnCommit); Index: Options.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/Options.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Options.java 22 Feb 2007 16:59:34 -0000 1.10 --- Options.java 22 Mar 2007 21:11:25 -0000 1.11 *************** *** 116,128 **** /** - * <code>segment</code> - The unique int32 segment identifier (required - * unless this is a {@link BufferMode#Transient} journal). Segment - * identifiers are assigned by a bigdata federation (scale out solution). - * When using the journal as part of an embedded or scale up database you - * may safely assign an arbitrary segment identifier, e.g., zero(0). - */ - public static final String SEGMENT = "segment"; - - /** * <code>create</code> - An optional boolean property (default is * <code>true</code>). When true and the named file is not found, a new --- 116,119 ---- Index: Journal.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/Journal.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** Journal.java 15 Mar 2007 16:11:13 -0000 1.62 --- Journal.java 22 Mar 2007 21:11:25 -0000 1.63 *************** *** 48,81 **** package com.bigdata.journal; - import java.io.File; - import java.io.IOException; - import java.nio.ByteBuffer; - import java.util.Map; import java.util.Properties; - import java.util.concurrent.Callable; - import java.util.concurrent.ConcurrentHashMap; - import java.util.concurrent.ExecutionException; - import java.util.concurrent.ExecutorService; - import java.util.concurrent.Executors; - import org.apache.log4j.Level; - import org.apache.log4j.Logger; - - import com.bigdata.cache.LRUCache; - import com.bigdata.cache.WeakValueCache; - import com.bigdata.isolation.ReadOnlyIsolatedIndex; - import com.bigdata.isolation.UnisolatedBTree; - import com.bigdata.journal.ReadCommittedTx.ReadCommittedIndex; - import com.bigdata.objndx.BTree; - import com.bigdata.objndx.IIndex; - import com.bigdata.objndx.IndexSegment; - import com.bigdata.objndx.ReadOnlyIndex; - import com.bigdata.rawstore.Addr; - import com.bigdata.rawstore.Bytes; - import com.bigdata.rawstore.IRawStore; - import com.bigdata.scaleup.MasterJournal; - import com.bigdata.scaleup.SlaveJournal; import com.bigdata.scaleup.MasterJournal.Options; - import com.bigdata.util.concurrent.DaemonThreadFactory; /** --- 48,54 ---- Index: RootBlockView.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/RootBlockView.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** RootBlockView.java 28 Feb 2007 13:59:10 -0000 1.13 --- RootBlockView.java 22 Mar 2007 21:11:25 -0000 1.14 *************** *** 49,53 **** --- 49,55 ---- import java.nio.ByteBuffer; + import java.util.UUID; + import com.bigdata.objndx.BTreeMetadata; import com.bigdata.rawstore.Addr; import com.bigdata.rawstore.Bytes; *************** *** 63,67 **** * need a magic for the root blocks if we use a checksum. or maybe it is * [magic,checksum,[data]] with the timestamps inside of the checksumed ! * data region. */ public class RootBlockView implements IRootBlockView { --- 65,70 ---- * need a magic for the root blocks if we use a checksum. or maybe it is * [magic,checksum,[data]] with the timestamps inside of the checksumed ! * data region. the {@link #OFFSET_UNUSED1} field might be put to this ! * purpose. */ public class RootBlockView implements IRootBlockView { *************** *** 70,78 **** static final transient short SIZEOF_MAGIC = Bytes.SIZEOF_INT; static final transient short SIZEOF_VERSION = Bytes.SIZEOF_INT; ! static final transient short SIZEOF_SEGMENT_ID = Bytes.SIZEOF_INT; static final transient short SIZEOF_ADDR = Bytes.SIZEOF_LONG; static final transient short SIZEOF_COUNTER = Bytes.SIZEOF_LONG; static final transient short SIZEOF_OFFSET = Bytes.SIZEOF_INT; ! static final transient short SIZEOF_UNUSED = 256; // Note: a chunk of reserved bytes. // static final transient short OFFSET_CHECKSUM = --- 73,82 ---- static final transient short SIZEOF_MAGIC = Bytes.SIZEOF_INT; static final transient short SIZEOF_VERSION = Bytes.SIZEOF_INT; ! // static final transient short SIZEOF_SEGMENT_ID = Bytes.SIZEOF_INT; static final transient short SIZEOF_ADDR = Bytes.SIZEOF_LONG; static final transient short SIZEOF_COUNTER = Bytes.SIZEOF_LONG; static final transient short SIZEOF_OFFSET = Bytes.SIZEOF_INT; ! // Note: a chunk of reserved bytes. ! static final transient short SIZEOF_UNUSED = 256-Bytes.SIZEOF_UUID; // static final transient short OFFSET_CHECKSUM = *************** *** 80,85 **** static final transient short OFFSET_MAGIC = OFFSET_TIMESTAMP0 + SIZEOF_TIMESTAMP; static final transient short OFFSET_VERSION = OFFSET_MAGIC + SIZEOF_MAGIC; ! static final transient short OFFSET_SEGMENT_ID = OFFSET_VERSION + SIZEOF_VERSION; ! static final transient short OFFSET_NEXT_OFFSET= OFFSET_SEGMENT_ID + SIZEOF_SEGMENT_ID; static final transient short OFFSET_FIRST_CMIT = OFFSET_NEXT_OFFSET + SIZEOF_OFFSET; static final transient short OFFSET_LAST_CMIT = OFFSET_FIRST_CMIT + SIZEOF_TIMESTAMP; --- 84,89 ---- static final transient short OFFSET_MAGIC = OFFSET_TIMESTAMP0 + SIZEOF_TIMESTAMP; static final transient short OFFSET_VERSION = OFFSET_MAGIC + SIZEOF_MAGIC; ! static final transient short OFFSET_UNUSED1 = OFFSET_VERSION + SIZEOF_VERSION; ! static final transient short OFFSET_NEXT_OFFSET= OFFSET_UNUSED1 + Bytes.SIZEOF_INT; static final transient short OFFSET_FIRST_CMIT = OFFSET_NEXT_OFFSET + SIZEOF_OFFSET; static final transient short OFFSET_LAST_CMIT = OFFSET_FIRST_CMIT + SIZEOF_TIMESTAMP; *************** *** 89,93 **** static final transient short OFFSET_COMMIT_NDX = OFFSET_COMMIT_REC + SIZEOF_ADDR; static final transient short OFFSET_UNUSED = OFFSET_COMMIT_NDX + SIZEOF_ADDR; ! static final transient short OFFSET_TIMESTAMP1 = OFFSET_UNUSED + SIZEOF_UNUSED; static final transient short SIZEOF_ROOT_BLOCK = OFFSET_TIMESTAMP1 + SIZEOF_TIMESTAMP; --- 93,98 ---- static final transient short OFFSET_COMMIT_NDX = OFFSET_COMMIT_REC + SIZEOF_ADDR; static final transient short OFFSET_UNUSED = OFFSET_COMMIT_NDX + SIZEOF_ADDR; ! static final transient short OFFSET_UUID = OFFSET_UNUSED + SIZEOF_UNUSED; ! static final transient short OFFSET_TIMESTAMP1 = OFFSET_UUID + Bytes.SIZEOF_UUID; static final transient short SIZEOF_ROOT_BLOCK = OFFSET_TIMESTAMP1 + SIZEOF_TIMESTAMP; *************** *** 116,121 **** * other fields are populated from the supplied parameters. * - * @param segmentId - * The segment identifier for the journal. * @param nextOffset * The next offset at which a record will be written on the --- 121,124 ---- *************** *** 147,155 **** * are no historical {@link ICommitRecord}s (this is true when * the store is first created). */ ! RootBlockView(boolean rootBlock0, int segmentId, int nextOffset, long firstCommitTime, long lastCommitTime, long commitTimestamp, long commitCounter, long commitRecordAddr, ! long commitRecordIndexAddr) { if (nextOffset < 0) --- 150,162 ---- * are no historical {@link ICommitRecord}s (this is true when * the store is first created). + * @param uuid + * The unique journal identifier. */ ! // * @param segmentId ! // * The segment identifier for the journal. ! RootBlockView(boolean rootBlock0, /*int segmentId,*/ int nextOffset, long firstCommitTime, long lastCommitTime, long commitTimestamp, long commitCounter, long commitRecordAddr, ! long commitRecordIndexAddr, UUID uuid) { if (nextOffset < 0) *************** *** 186,189 **** --- 193,199 ---- "The commit record address must exist if there is a commit record index."); } + if(uuid == null) { + throw new IllegalArgumentException("UUID is null"); + } buf = ByteBuffer.allocate(SIZEOF_ROOT_BLOCK); *************** *** 196,200 **** buf.putInt(MAGIC); buf.putInt(VERSION0); ! buf.putInt(segmentId); buf.putInt(nextOffset); buf.putLong(firstCommitTime); --- 206,210 ---- buf.putInt(MAGIC); buf.putInt(VERSION0); ! buf.putInt(0); // unused field buf.putInt(nextOffset); buf.putLong(firstCommitTime); *************** *** 205,208 **** --- 215,220 ---- buf.putLong(commitRecordIndexAddr); buf.position(buf.position()+SIZEOF_UNUSED); // skip unused region. + buf.putLong(uuid.getMostSignificantBits()); + buf.putLong(uuid.getLeastSignificantBits()); buf.putLong(rootBlockTimestamp); *************** *** 351,359 **** } ! public int getSegmentId() { ! ! return buf.getInt(OFFSET_SEGMENT_ID); } public String toString() { --- 363,378 ---- } ! public UUID getUUID() { ! ! return new UUID(buf.getLong(OFFSET_UUID)/* MSB */, buf ! .getLong(OFFSET_UUID + 8)/*LSB*/); } + + // public int getSegmentId() { + // + // return buf.getInt(OFFSET_SEGMENT_ID); + // + // } public String toString() { *************** *** 365,369 **** sb.append("{ rootBlockTimestamp="+getRootBlockTimestamp()); sb.append(", version="+getVersion()); ! sb.append(", segmentId="+getSegmentId()); sb.append(", nextOffset="+getNextOffset()); sb.append(", firstCommitTime="+getFirstCommitTime()); --- 384,388 ---- sb.append("{ rootBlockTimestamp="+getRootBlockTimestamp()); sb.append(", version="+getVersion()); ! // sb.append(", segmentId="+getSegmentId()); sb.append(", nextOffset="+getNextOffset()); sb.append(", firstCommitTime="+getFirstCommitTime()); *************** *** 373,376 **** --- 392,396 ---- sb.append(", commitRecordAddr="+Addr.toString(getCommitRecordAddr())); sb.append(", commitRecordIndexAddr="+Addr.toString(getCommitRecordIndexAddr())); + sb.append(", uuid="+getUUID()); sb.append("}"); Index: IRootBlockView.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/java/com/bigdata/journal/IRootBlockView.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** IRootBlockView.java 11 Mar 2007 11:42:45 -0000 1.10 --- IRootBlockView.java 22 Mar 2007 21:11:25 -0000 1.11 *************** *** 49,52 **** --- 49,53 ---- import java.nio.ByteBuffer; + import java.util.UUID; import com.bigdata.rawstore.Addr; *************** *** 97,105 **** /** - * The segment identifier. - */ - public int getSegmentId(); - - /** * The next offset at which a data item would be written on the store. */ --- 98,101 ---- *************** *** 193,196 **** --- 189,197 ---- /** + * The unique journal identifier + */ + public UUID getUUID(); + + /** * A read-only buffer whose contents are the root block. */ |