Package org.xtreemfs.babudb.lsmdb

Examples of org.xtreemfs.babudb.lsmdb.LSN


                    return name.endsWith(".dbl");
                }
            });
           
            DiskLogIterator it = new DiskLogIterator(logFiles, from);
            LSN nextLSN = null;
           
            // apply log entries to databases ...
            while (it.hasNext()) {
                LogEntry le = null;
                try {
                    le = it.next();
                    byte type = le.getPayloadType();
                   
                    Logging.logMessage(Logging.LEVEL_DEBUG, this,
                        "Reading entry LSN(%s) of type (%d) with %d bytes payload from log.", le.getLSN()
                                .toString(), (int) type, le.getPayload().remaining());
                   
                    // in normal there are only transactions to be replayed
                    if (type == PAYLOAD_TYPE_TRANSACTION) {
                        txnMan.replayTransaction(le);
                       
                        // create, copy and delete are not replayed (this block
                        // is for backward
                        // compatibility)
                    } else if (type != PAYLOAD_TYPE_CREATE && type != PAYLOAD_TYPE_COPY
                        && type != PAYLOAD_TYPE_DELETE) {
                       
                        // get the processing logic for the dedicated logEntry
                        // type
                        InMemoryProcessing processingLogic = txnMan.getProcessingLogic().get(type);
                       
                        // deserialize the arguments retrieved from the logEntry
                        OperationInternal operation = processingLogic.convertToOperation(processingLogic
                                .deserializeRequest(le.getPayload()));
                       
                        // execute the in-memory logic
                        try {
                            processingLogic.process(operation);
                        } catch (BabuDBException be) {
                           
                            // there might be false positives if a snapshot to
                            // delete has already been deleted, a snapshot to
                            // create has already been created, or an insertion
                            // has been applied to a database that has already
                            // been deleted
                           
                            // FIXME: A clean solution needs to be provided that
                            // is capable of distinguishing between a corrupted
                            // database and a "false positive". False positives
                            // may occur because management operations are
                            // immediately applied to the persistent database
                            // state rather than being applied when the log is
                            // replayed.
                            // A clean solution would involve a single immutable
                            // configuration file per database/snapshot, which
                            // resides in the database directory and is written
                            // when the first checkpoint is created. When a
                            // database/snapshot gets deleted, an additional
                            // (empty) file is created that indicates the
                            // deletion. When old log files are removed in
                            // response to a checkpoint, the system disposes of
                            // all directories of databases and snapshots that
                            // were deleted in these log files.
                            if (!(type == PAYLOAD_TYPE_SNAP && (be.getErrorCode() == ErrorCode.SNAP_EXISTS || be
                                    .getErrorCode() == ErrorCode.NO_SUCH_DB))
                                && !(type == PAYLOAD_TYPE_SNAP_DELETE && be.getErrorCode() == ErrorCode.NO_SUCH_SNAPSHOT)
                                && !(type == PAYLOAD_TYPE_INSERT && be.getErrorCode().equals(
                                    ErrorCode.NO_SUCH_DB))) {
                               
                                throw be;
                            }
                        }
                    }
                   
                    // set LSN
                    nextLSN = new LSN(le.getViewId(), le.getLogSequenceNo() + 1L);
                } finally {
                    if (le != null) {
                        le.free();
                    }
                }
               
            }
           
            it.destroy();
           
            if (nextLSN != null) {
                return nextLSN;
            } else {
                return new LSN(1, 1);
            }
           
        } catch (IOException ex) {
           
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot load database operations log, "
View Full Code Here


     * Test of getViewId method, of class LSN.
     */
    @Test
    public void testGetViewId() {
        System.out.println("getViewId");
        LSN instance = new LSN(1,9);
        int expResult = 1;
        int result = instance.getViewId();
        assertEquals(expResult, result);

    }
View Full Code Here

     * Test of getSequenceNo method, of class LSN.
     */
    @Test
    public void testGetSequenceNo() {
        System.out.println("getSequenceNo");
        LSN instance = new LSN(1,9);
        long expResult = 9;
        long result = instance.getSequenceNo();
        assertEquals(expResult, result);

    }
View Full Code Here

     * Test of compareTo method, of class LSN.
     */
    @Test
    public void testCompareTo() {
        System.out.println("compareTo");
        LSN one = new LSN(1,100);
        LSN two = new LSN(2,100);
        int expResult = -1;
        int result = one.compareTo(two);
        assertEquals(expResult, result);
       
        one = new LSN(1,100);
        two = new LSN(2,100);
        expResult = 1;
        result = two.compareTo(one);
        assertEquals(expResult, result);
       
        one = new LSN(1,100);
        two = new LSN(1,100);
        expResult = 0;
        result = two.compareTo(one);
        assertEquals(expResult, result);
       
        one = new LSN(1,99);
        two = new LSN(1,100);
        expResult = -1;
        result = one.compareTo(two);
        assertEquals(expResult, result);
       
        one = new LSN(1,99);
        two = new LSN(1,100);
        expResult = 1;
        result = two.compareTo(one);
        assertEquals(expResult, result);

    }
View Full Code Here

    }
   
    @Before
    public void setUp() throws Exception {
        FSUtils.delTree(new File(testdir));
        l = new DiskLogger(testdir, new LSN(1, 1L), SyncMode.FSYNC, 0, 0);
        l.start();
        l.waitForStartup();
    }
View Full Code Here

        copyFile(tmpFile, logFile);
        tmpFile.delete();
       
        // restart the disk logger and append new log entries
        l.shutdown();
        l = new DiskLogger(testdir, new LSN(1, 200L), SyncMode.FSYNC, 0, 0);
        l.start();
       
        for (int i = 99; i < 120; i++) {
            String pl = "Entry " + (i + 1);
            ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
View Full Code Here

        it.destroy();
       
        // create and test iterators that starts at different LSNs
        for (int k : new int[] { 1, 100, 101, 200, 201, 300, 77, 112, 189, 222 }) {
           
            LSN lsn = new LSN(1, k);
           
            it = new DiskLogIterator(logFiles, lsn);
            assertTrue(it.hasNext());
            for (int i = (int) lsn.getSequenceNo(); i <= numLogFiles * 100; i++) {
                LogEntry next = it.next();
                String entry = new String(next.getPayload().array());
                assertEquals("Entry " + i, entry);
                next.free();
            }
View Full Code Here

    public void testSyncListener() throws Exception {
       
        final int numEntries = 1000;
        final int numRuns = 10;
       
        LSN lsn = new LSN(1, 0);
        for (int j = 0; j < numRuns; j++) {
           
            final AtomicInteger count = new AtomicInteger(0);
            int totalSize = 0;
           
            SyncListener sl = new SyncListener() {
               
                public void synced(LSN lsn) {
                    synchronized (count) {
                        count.incrementAndGet();
                        count.notifyAll();
                    }
                }
               
                public void failed(Exception ex) {
                    fail("this should not happen");
                   
                    synchronized (count) {
                        count.incrementAndGet();
                        count.notifyAll();
                    }
                }
            };
           
            for (int i = 0; i < numEntries; i++) {
               
                String pl = "Entry " + (i + 1);
                ReusableBuffer plb = ReusableBuffer.wrap(pl.getBytes());
                LogEntry e = new LogEntry(plb, sl, LogEntry.PAYLOAD_TYPE_INSERT);
                int entrySize = LogEntry.headerLength + e.getPayload().remaining();
               
                totalSize += entrySize;
                l.append(e);
            }
           
            synchronized (count) {
                while (count.get() < numEntries)
                    count.wait(5);
            }
           
            LSN newLSN = null;
            try {
                l.lock();
                newLSN = l.switchLogFile(false);
            } finally {
                l.unlock();
View Full Code Here

    testGen2.initialize(testSeed);
   
    assert (RandomGenerator.MAX_SEQUENCENO<((long) Integer.MAX_VALUE)) : "This test cannot handle such a big MAX_SEQUENCENO.";
    int viewID = random.nextInt(RandomGenerator.MAX_VIEWID-(RandomGenerator.MAX_VIEWID/2))+1;
    long sequenceNO = random.nextInt((int) (RandomGenerator.MAX_SEQUENCENO-1L))+1L;
    LSN testLSN = new LSN(viewID,sequenceNO);
   
    for (int i=0;i<NO_TESTS_PER_CASE;i++){
      assertEquals(testGen1.getInsertGroup(testLSN).toString(), testGen2.getInsertGroup(testLSN).toString());
      if (sequenceNO<RandomGenerator.MAX_SEQUENCENO)
        testLSN = new LSN(viewID,++sequenceNO);
      else
        testLSN = new LSN(++viewID,sequenceNO = 1L);
    }
  }
View Full Code Here

    testGen1.initialize(testSeed);
    testGen2.initialize(testSeed);
 
    assert (RandomGenerator.MAX_SEQUENCENO<((long) Integer.MAX_VALUE)) : "This test cannot handle such a big MAX_SEQUENCENO.";   
    for (int i=0;i<NO_TESTS_PER_CASE;i++){
      LSN testLSN = new LSN(random.nextInt(RandomGenerator.MAX_VIEWID-1)+1,random.nextInt((int) (RandomGenerator.MAX_SEQUENCENO-1L))+1L);
      assertEquals(testGen1.getLookupGroup(testLSN).toString(), testGen2.getLookupGroup(testLSN).toString());
    }   
  }
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.lsmdb.LSN

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.