Package org.xtreemfs.babudb.lsmdb

Examples of org.xtreemfs.babudb.lsmdb.LSN


           
            @Override
            public void enqueueOperation(Object[] args) throws BusyServerException, ServiceLockedException {
               
                assertTrue(args.length == 2);
                LSN receivedLSN = (LSN) args[0];
                assertEquals(testLSN, receivedLSN);
               
                LogEntry receivedEntry = (LogEntry) args[1];
                assertEquals(testEntry.getPayloadType(), receivedEntry.getPayloadType());
                assertEquals(testType, receivedEntry.getPayloadType());
View Full Code Here


    @Override
    public void processRequest(Request rq) {
       
        HeartbeatMessage message = (HeartbeatMessage) rq.getRequestMessage();
        org.xtreemfs.babudb.pbrpc.GlobalTypes.LSN mLSN = message.getLsn();
        LSN lsn = new LSN(mLSN.getViewId(), mLSN.getSequenceNo());
           
        InetSocketAddress participant = new InetSocketAddress(
                rq.getSenderAddress().getAddress(), message.getPort());
       
        Logging.logMessage(Logging.LEVEL_INFO, this, "SynchronizeOperation:  received %s by %s",
                lsn.toString(), participant.toString());
       
        rqMan.createStableState(lsn, participant);
       
        rq.sendSuccess(ErrorCodeResponse.getDefaultInstance());
    }
View Full Code Here

     */
    @Override
    public void processRequest(Request rq) {
       
        LogEntry le = (LogEntry) rq.getAttachment();
        final LSN lsn = le.getLSN();
        try {
           
            Logging.logMessage(Logging.LEVEL_DEBUG, this, "ReplicateOperation:" +
                    " received %s", le.toString());
            rqMan.enqueueOperation(new Object[]{ lsn, le });
View Full Code Here

                m.matches();
                String tmp = m.group(1);
                int viewId = Integer.valueOf(tmp);
                tmp = m.group(2);
                int seqNo = Integer.valueOf(tmp);
                orderedLogList.add(new LSN(viewId, seqNo));
                count++;
            }
            LSN[] copy = orderedLogList.toArray(new LSN[orderedLogList.size()]);
            LSN last = null;
            LSN lastRemoved = null;
            for (LSN lsn : copy) {
                if (last == null)
                    last = lsn;
                else {
                    if (from != null && lsn.compareTo(from) <= 0) {
View Full Code Here

        return this.logSequenceNo;
    }
   
    public LSN getLSN() {
        if (this.viewId == -1 && this.logSequenceNo == -1L) return null;
        else return new LSN(this.viewId, this.logSequenceNo);
    }
View Full Code Here

        if (!hasLock()) {
            throw new IllegalStateException("the lock is held by another thread or the logger is not locked.");
        }
       
        // get last synchronized LSN and increment the viewId if needed
        LSN lastSyncedLSN = null;
        if (incrementViewId){
            int view = currentViewId.getAndIncrement();
            long seq = nextLogSequenceNo.getAndSet(1L) - 1L;
            lastSyncedLSN = new LSN(view, seq);
        } else {
            lastSyncedLSN = new LSN(currentViewId.get(), nextLogSequenceNo.get() - 1L);
        }
       
        dropLogFile();  
        loadLogFile();
       
View Full Code Here

     * <p>Function is used by the Replication.</p>
     *
     * @return the LSN of the latest inserted {@link LogEntry}.
     */
    public LSN getLatestLSN(){
        return new LSN(currentViewId.get(), nextLogSequenceNo.get() - 1L);
    }
View Full Code Here

     */
    final static LSN disassembleLogFileName(String name) {
        String[] parts = name.split(".");
        assert (parts.length == 3);
       
        return new LSN(Integer.parseInt(parts[0]),Long.parseLong(parts[1]));
    }
View Full Code Here

       
        // determine the LSN from which to start the log replay
       
        // to be able to recover from crashes during checkpoints, it is
        // necessary to start with the smallest LSN found on disk
        LSN dbLsn = null;
        for (DatabaseInternal db : databaseManager.getDatabaseList()) {
            if (dbLsn == null)
                dbLsn = db.getLSMDB().getOndiskLSN();
            else {
                LSN onDiskLSN = db.getLSMDB().getOndiskLSN();
                if (!(LSMDatabase.NO_DB_LSN.equals(dbLsn) || LSMDatabase.NO_DB_LSN.equals(onDiskLSN)))
                    dbLsn = dbLsn.compareTo(onDiskLSN) < 0 ? dbLsn : onDiskLSN;
            }
        }
        if (dbLsn == null) {
            // empty database
            dbLsn = new LSN(0, 0);
        } else {
            // need next LSN which is onDisk + 1
            dbLsn = new LSN(dbLsn.getViewId() == 0 ? 1 : dbLsn.getViewId(), dbLsn.getSequenceNo() + 1);
        }
       
        Logging.logMessage(Logging.LEVEL_INFO, this, "starting log replay at LSN %s", dbLsn);
        LSN nextLSN = replayLogs(dbLsn);
        if (dbLsn.compareTo(nextLSN) > 0) {
            nextLSN = dbLsn;
        }
        Logging.logMessage(Logging.LEVEL_INFO, this, "log replay done, using LSN: " + nextLSN);
       
        // set up and start the disk logger
        try {
            logger = new DiskLogger(configuration.getDbLogDir(), nextLSN, configuration.getSyncMode(),
                configuration.getPseudoSyncWait(), configuration.getMaxQueueLength()
                    * Math.max(1, configuration.getNumThreads()));
            logger.setLifeCycleListener(this);
            logger.start();
            logger.waitForStartup();
        } catch (Exception ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot start database operations logger", ex);
        }
        this.txnMan.init(new LSN(nextLSN.getViewId(), nextLSN.getSequenceNo() - 1L));
        this.txnMan.setLogger(logger);
       
        if (configuration.getNumThreads() > 0) {
            worker = new LSMDBWorker[configuration.getNumThreads()];
            for (int i = 0; i < configuration.getNumThreads(); i++) {
                worker[i] = new LSMDBWorker(this, i, configuration.getMaxQueueLength());
                worker[i].start();
            }
        } else {
            // number of workers is 0 => requests will be responded directly.
            assert (configuration.getNumThreads() == 0);
           
            worker = null;
        }
       
        if (dbConfigFile.isConversionRequired())
            AutoConverter.completeConversion(this);
       
        // initialize and start the checkpointer; this has to be separated from
        // the instantiation because the instance has to be there when the log
        // is replayed
        this.dbCheckptr.init(logger, configuration.getCheckInterval(), configuration.getMaxLogfileSize());
       
        final LSN firstLSN = new LSN(1, 1L);
        if (staticInit != null && nextLSN.equals(firstLSN)) {
            Logging.logMessage(Logging.LEVEL_DEBUG, this, "Running initialization script...");
            staticInit.initialize(databaseManager, snapshotManager);
            Logging.logMessage(Logging.LEVEL_DEBUG, this, "... initialization script finished successfully.");
        } else if (staticInit != null) {
View Full Code Here

           
            // determine the LSN from which to start the log replay
           
            // to be able to recover from crashes during checkpoints, it is
            // necessary to start with the smallest LSN found on disk
            LSN dbLsn = null;
            for (DatabaseInternal db : databaseManager.getDatabaseList()) {
                if (dbLsn == null)
                    dbLsn = db.getLSMDB().getOndiskLSN();
                else {
                    LSN onDiskLSN = db.getLSMDB().getOndiskLSN();
                    if (!(LSMDatabase.NO_DB_LSN.equals(dbLsn) || LSMDatabase.NO_DB_LSN.equals(onDiskLSN))) {
                        dbLsn = dbLsn.compareTo(onDiskLSN) < 0 ? dbLsn : onDiskLSN;
                    }
                }
            }
            if (dbLsn == null) {
                // empty database
                dbLsn = new LSN(0, 0);
            } else {
                // need next LSN which is onDisk + 1
                dbLsn = new LSN(dbLsn.getViewId(), dbLsn.getSequenceNo() + 1);
            }
           
            Logging.logMessage(Logging.LEVEL_INFO, this, "starting log replay");
            LSN nextLSN = replayLogs(dbLsn);
            if (dbLsn.compareTo(nextLSN) > 0)
                nextLSN = dbLsn;
            Logging.logMessage(Logging.LEVEL_INFO, this, "log replay done, " + "using LSN: " + nextLSN);
           
            try {
                logger = new DiskLogger(configuration.getDbLogDir(), nextLSN, configuration.getSyncMode(),
                    configuration.getPseudoSyncWait(), configuration.getMaxQueueLength()
                        * configuration.getNumThreads());
                logger.setLifeCycleListener(this);
                logger.start();
                logger.waitForStartup();
            } catch (Exception ex) {
                throw new BabuDBException(ErrorCode.IO_ERROR,
                    "Cannot start " + "database operations logger!", ex);
            }
            this.txnMan.init(new LSN(nextLSN.getViewId(), nextLSN.getSequenceNo() - 1L));
            this.txnMan.setLogger(logger);
           
            if (configuration.getNumThreads() > 0) {
                worker = new LSMDBWorker[configuration.getNumThreads()];
                for (int i = 0; i < configuration.getNumThreads(); i++) {
                    worker[i] = new LSMDBWorker(this, i, configuration.getMaxQueueLength());
                    worker[i].start();
                }
            } else {
                // number of workers is 0 => requests will be responded
                // directly.
                assert (configuration.getNumThreads() == 0);
               
                worker = null;
            }
           
            // restart the checkpointer
            this.dbCheckptr.init(logger, configuration.getCheckInterval(), configuration.getMaxLogfileSize());
           
            Logging.logMessage(Logging.LEVEL_INFO, this, "BabuDB for Java is " + "running (version "
                + BABUDB_VERSION + ")");
           
            this.stopped.set(false);
            return new LSN(nextLSN.getViewId(), nextLSN.getSequenceNo() - 1L);
        }
    }
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.