Examples of LSN


Examples of org.xtreemfs.babudb.lsmdb.LSN

         * resets this state to the initial state
         */
        void reset() {
            lastUpdate = 0L;
            dead = true;
            lastAcknowledged = new LSN(0,0L);
            openRequests = 0;
        }
View Full Code Here

Examples of org.xtreemfs.babudb.lsmdb.LSN

        final int localSyncN = participantsStates.getLocalSyncN();
        List<ConditionClient> slaves = participantsStates.getConditionClients();
        if (localSyncN > 0) {
           
            // always get the latest available state of all servers
            LSN latest = null;
            Map<ClientInterface ,LSN> states = getStates(slaves, true);
       
            // getting enough slaves has failed
            if (states.size() < localSyncN) {
                throw new BabuDBException(ErrorCode.REPLICATION_FAILURE,
                        "Not enough slaves available to synchronize with!");
               
            } else {
               
                List<LSN> values = new LinkedList<LSN>(states.values());
                Collections.sort(values, Collections.reverseOrder());
                latest = values.get(0);
            }
       
            // synchronize with the most up-to-date slave, if necessary
            LSN localState = babuDB.getState();
            if (localState.compareTo(latest) < 0) {
                for (Entry<ClientInterface, LSN> entry : states.entrySet()) {
                    if (entry.getValue().equals(latest)) {  
                               
                        Logging.logMessage(Logging.LEVEL_INFO, this,
                                "Starting synchronization from '%s' to '%s'.",
                                localState.toString(), latest.toString());
                   
                        BabuDBRequestResultImpl<Object> ready = babuDB.createRequestFuture();
                       
                        replicationStage.manualLoad(ready, latest);
                        ready.get();
                   
                        assert(latest.equals(babuDB.getState())) :
                            "Synchronization failed: (expected=" +
                            latest.toString() + ") != (acknowledged=" +
                            babuDB.getState() + ")";
                        break;
                    }
                }
            }
        }
       
        // take a checkpoint on master-failover (inclusive viewId incrementation), if necessary
        LSN beforeCP = lastOnView.get();
        if (babuDB.getState().getSequenceNo() > 0L) {
            Logging.logMessage(Logging.LEVEL_DEBUG, this, "taking a checkpoint");
            beforeCP = babuDB.checkpoint();
            lastOnView.set(beforeCP);
        }
        Logging.logMessage(Logging.LEVEL_INFO, this,
                "Agreed to synchronize to %s before the next view.", beforeCP.toString());
       
        // wait for the slaves to recognize the master-change and for at least N servers to
        // establish a stable state
        LSN syncState = babuDB.getState();
        final ReplicateResponse result = new ReplicateResponse(syncState, listener,
                slaves.size() - localSyncN);
       
        subscribeListener(result);
       
        for (ConditionClient slave : slaves) {
            slave.synchronize(beforeCP, port).registerListener(
                    new ClientResponseAvailableListener<Object>() {

                        @Override
                        public void responseAvailable(Object r) { /* ignored */ }

                        @Override
                        public void requestFailed(Exception e) {
                            result.decrementPermittedFailures();
                        }
            });
        }
       
        Logging.logMessage(Logging.LEVEL_INFO, this,
                "The next view will start with %s.", syncState.toString());
    }
View Full Code Here

Examples of org.xtreemfs.babudb.lsmdb.LSN

     * {@link ReplicationStage}.
     *
     * @param userService
     */
    public void start(ControlLayerInterface topLayer) {
        LSN latest = babuDB.getState();
        LSN normalized = (latest.getSequenceNo() == 0L) ? new LSN(0,0L) : latest;
           
        // the sequence number of the initial LSN before incrementing the viewID must not be 0
        Logging.logMessage(Logging.LEVEL_DEBUG, this, "Setting last on view " +
           "LSN to '%s', initial was '%s'.", normalized, latest);
       
View Full Code Here

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

Examples of org.xtreemfs.babudb.lsmdb.LSN

     * @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

Examples of org.xtreemfs.babudb.lsmdb.LSN

     * (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

Examples of org.xtreemfs.babudb.lsmdb.LSN

     * 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

Examples of org.xtreemfs.babudb.lsmdb.LSN

     */
    @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

Examples of org.xtreemfs.babudb.lsmdb.LSN

   
    /**
     * 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

Examples of org.xtreemfs.babudb.lsmdb.LSN

        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
TOP
Copyright © 2018 www.massapi.com. 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.