Package org.xtreemfs.babudb.lsmdb

Examples of org.xtreemfs.babudb.lsmdb.LSN


            }
           
            // get the responses
            for (int i = 0; i < numRqs; i++) {
                try{
                    LSN val = rps.get(i).get();
                    result.put(clients.get(i), val);
                } catch (Exception e) {
                    Logging.logMessage(Logging.LEVEL_INFO, this,
                            "Could not receive state of '%s', because: %s.",
                            clients.get(i), e.getMessage());
View Full Code Here


     * @param listener
     * @param to
     */
    public void manualLoad(BabuDBRequestResultImpl<Object> listener, LSN to) {
       
        LSN start = babudb.getState();
       
        if (start.equals(to)) {
           
            listener.finished(to);
        } else {
       
            this.listener = listener;
            LSN end = new LSN(
                        // we have to assume, that there is an entry following the
                        // state we would like to establish, because the request
                        // logic will always exclude the 'end' of this range
                        to.getViewId(), to.getSequenceNo() + 1L);
           
View Full Code Here

     * (non-Javadoc)
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() throws ConnectionLostException, InterruptedException{
        LSN actual = stage.getBabuDB().getState();
        LSN until = (stage.missing == null) ? new LSN(actual.getViewId() + 1,0L) :
                                              stage.missing.end;
               
        MasterClient master = slaveView.getSynchronizationPartner(until);
       
        // make the request and get the result synchronously
        Logging.logMessage(Logging.LEVEL_INFO, stage, "Loading DB since %s from %s.",
                actual.toString(), master.getDefaultServerAddress().toString());
        ClientResponseFuture<DBFileMetaDataSet, DBFileMetaDatas> rp = master.load(actual);
        DBFileMetaDataSet result = null;
        try {
            result = rp.get()
        } catch (ErrorCodeException e) {
            // connection is lost
            throw new ConnectionLostException(e.getMessage(), e.getCode());
        } catch (Exception e) {
            // failure on transmission --> retry
            throw new ConnectionLostException(e.getMessage(), ErrorCode.UNKNOWN);
        }
       
        // switch log file by triggering a manual checkpoint,
        // if the response was empty
        if (result.size() == 0) {
           
            try {
                stage.lastOnView.set(stage.getBabuDB().checkpoint());
            } catch (BabuDBException e) {
                // system failure on switching the lock file --> retry
                Logging.logError(Logging.LEVEL_WARN, this, e);
                return;
            }
            Logging.logMessage(Logging.LEVEL_DEBUG, this,
            "Logfile switched at LSN %s.", stage.getBabuDB().getState().toString());
           
            finished(false);
            return;
        }
       
        // backup the old dbs
        stage.getBabuDB().stopBabuDB();
        try {
            fileIO.backupFiles();
        } catch (IOException e) {
            // file backup failed --> retry
            Logging.logError(Logging.LEVEL_WARN, this, e);
           
            if (stage.isInterrupted()) {
                try {
                    stage.getBabuDB().startBabuDB();
                } catch (BabuDBException e1) {
                    Logging.logError(Logging.LEVEL_ERROR, this, e1);
                }
            }
            return;
        }
       
        // #chunks >= #files
        final AtomicInteger openChunks = new AtomicInteger(result.size());
       
        // request the chunks
        LSN lsn = null;
        for (DBFileMetaData fileData : result) {
           
            // validate the informations
            final String fileName = fileData.file;
            String parentName = new File(fileName).getParentFile().getName();
            if (LSMDatabase.isSnapshotFilename(parentName)) {
                if (lsn == null)
                    lsn = LSMDatabase.getSnapshotLSNbyFilename(parentName);
                else if (!lsn.equals(LSMDatabase.
                        getSnapshotLSNbyFilename(parentName))){
                    Logging.logMessage(Logging.LEVEL_WARN, this,
                            "Indexfiles had ambiguous LSNs: %s",
                            "LOAD will be retried.");
                    return;
View Full Code Here

     * Method to execute, after the Load was finished successfully.
     *
     * @param loaded - induces whether the DBS had to be reload or not
     */
    private void finished(boolean loaded) {
        LSN actual = stage.getBabuDB().getState();
        LSN next = new LSN (actual.getViewId(), actual.getSequenceNo() + 1L);

        if (stage.missing != null &&
            next.compareTo(stage.missing.end) < 0) {
           
            stage.missing = new Range(actual, stage.missing.end);
           
            stage.setLogic(REQUEST, "There are still some logEntries " +
                    "missing after loading the database.");
View Full Code Here

     */
    @Override
    public void run() throws InterruptedException, ConnectionLostException, Exception {
        assert (stage.missing.start != null: "PROGRAMATICAL ERROR!";
       
        LSN lsnAtLeast = stage.missing.end;
       
        Logging.logMessage(Logging.LEVEL_INFO, this,
                "Replica-range is missing: from %s to %s",
                stage.missing.start.toString(),
                lsnAtLeast.toString());
       
        // get the missing logEntries
        ClientResponseFuture<ReusableBuffer[], LogEntries> rp = null;   
        ReusableBuffer[] logEntries = null;
       
       
        MasterClient master = slaveView.getSynchronizationPartner(lsnAtLeast);
       
        Logging.logMessage(Logging.LEVEL_INFO, this, "Replica-Range will be" +
            " retrieved from %s.", master.getDefaultServerAddress());
       
        try {
            rp = master.replica(stage.missing.start, stage.missing.end);
            logEntries = rp.get();
           
            // enhancement if the request had detected a master-failover
            if (logEntries.length == 0) {
                stage.lastOnView.set(stage.getBabuDB().checkpoint());
                finish();
                return;
            }
           
            final AtomicInteger count = new AtomicInteger(logEntries.length);
            // insert all logEntries
            LSN check = null;
            for (ReusableBuffer le : logEntries) {
                try {
                    final LogEntry logentry = LogEntry.deserialize(le, this.checksum);
                    final LSN lsn = logentry.getLSN();
                   
                    // assertion whether the received entry does match the order
                    // or not
                    assert (check == null ||
                           (check.getViewId() == lsn.getViewId() &&
                            check.getSequenceNo()+1L == lsn.getSequenceNo()) ||
                            check.getViewId()+1 == lsn.getViewId() &&
                            lsn.getSequenceNo() == 1L) : "ERROR: last LSN (" +
                            check.toString() + ") received LSN (" +
                            lsn.toString() + ")!";
                    check = lsn;
                   
                    // we have to switch the log-file
                    if (lsn.getSequenceNo() == 1L &&
                        stage.getBabuDB().getState().getViewId() < lsn.getViewId()) {
                       
                        stage.lastOnView.set(stage.getBabuDB().checkpoint());
                    }
                   
                    stage.getBabuDB().appendToLocalPersistenceManager(logentry,
View Full Code Here

   
    /**
     * Method to decide which logic shall be used next.
     */
    private void finish() {
        LSN actual = stage.getBabuDB().getState();
        LSN next = new LSN (actual.getViewId(), actual.getSequenceNo() + 1L);
       
        // we are still missing some entries (the request was too large)
        // update the missing entries
        if (next.compareTo(stage.missing.end) < 0) {
            stage.missing = new Range(actual, stage.missing.end);

         // all went fine --> back to basic
        } else {
            stage.missing = null;
View Full Code Here

        final StageRequest op = stage.getQueue().take();
       
        // filter dummy stage request
        if (op == StageRequest.NOOP_REQUEST) return;
       
        final LSN lsn = op.getLSN();
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "Replicate requested: %s",
                lsn.toString());
       
        LSN lastAsync = lastAsyncInserted.get();
        LSN actual = stage.getBabuDB().getState();
        actual = (lastAsync == null || actual.compareTo(lastAsync) >= 0) ? actual : lastAsync;
        LSN expected = new LSN(actual.getViewId(), actual.getSequenceNo() + 1L);
       
        // check the LSN of the logEntry to write
        if (lsn.compareTo(actual) <= 0) {
            // entry was already inserted
            stage.finalizeRequest(op);
View Full Code Here

     */
    @Override
    public void processRequest(Request rq) {
        LSNRange request = (LSNRange) rq.getRequestMessage();
       
        final LSN start = new LSN(request.getStart().getViewId(),
                                  request.getStart().getSequenceNo());
        final LSN end = new LSN(request.getEnd().getViewId(),
                                request.getEnd().getSequenceNo());
       
        LogEntries.Builder result = LogEntries.newBuilder();
        ReusableBuffer resultPayLoad = BufferPool.allocate(0);
       
        Logging.logMessage(Logging.LEVEL_INFO, this, "REQUEST received " +
                "(start: %s, end: %s) from %s", start.toString(),
                end.toString(), rq.getSenderAddress().toString());
       
        // enhancement to prevent slaves from loading the DB from the master unnecessarily
        if (start.equals(lastOnView.get())) {
           
            Logging.logMessage(Logging.LEVEL_INFO, this,
                   "REQUEST answer is empty (there has been a failover only).");
           
            rq.sendSuccess(result.build());
            return
        }
       
        final LSN firstEntry = new LSN(start.getViewId(),
                                       start.getSequenceNo() + 1L);
       
        assert (firstEntry.compareTo(end) < 0) :
            "At least one LogEntry has to be requested!";
       
        DiskLogIterator it = null;
        LogEntry le = null;
        synchronized (babuInterface.getCheckpointerLock()) {
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testStateRequest() throws Exception {
       
        LSN result = client.state().get();
        assertEquals(testLSN, result);
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testVolatileStateRequest() throws Exception {
       
        LSN result = client.volatileState().get();
        assertEquals(testLSN, result);
    }
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.