Package org.xtreemfs.babudb.lsmdb

Examples of org.xtreemfs.babudb.lsmdb.LSN


                return new ReplicationClientAdapter(client, receiver);
            }
        });
       
        hbt = new HeartbeatThread(states, BASIC_PORT);
        hbt.start(new LSN(0,0L));
        hbt.waitForStartup();
    }
View Full Code Here


       
        // infarct the hbt and invalidate the expected lsn
        hbt.infarction();
        Thread.sleep(HeartbeatThread.MAX_DELAY_BETWEEN_HEARTBEATS);
        synchronized (lsn) {
            lsn.set(new LSN(-1, -1L));
            lastHeartbeat.set(0);
        }
       
        // remain a few beats idle, just to make sure the HBT has a flatline
        Thread.sleep(3 * HeartbeatThread.MAX_DELAY_BETWEEN_HEARTBEATS);
       
        // update the hbt and re-animate it too
        lsn.set(new LSN(1, 1L));
        lastHeartbeat.set(Long.MAX_VALUE - MAX_DELAY_BETWEEN_HBS_ALLOWED);
        hbt.updateLSN(new LSN(1, 1L));
       
        // again let it do some work
        Thread.sleep(3 * HeartbeatThread.MAX_DELAY_BETWEEN_HEARTBEATS);
    }
View Full Code Here

        final String fileName = "testFile";
        final long offsetStart = 815L;
        final long offsetEnd = 4711L;
        final String chunkResult = "chunkResult";
        final int port = 12345;
        final LSN lsn = new LSN(345, 1337L);
       
        // registers operations at the handler
        Map<Integer, Operation> ops = new HashMap<Integer, Operation>();
        ops.put(ReplicationServiceConstants.PROC_ID_HEARTBEAT, new Operation() {
                       
            @Override
            public int getProcedureId() {
                return ReplicationServiceConstants.PROC_ID_HEARTBEAT;
            }
           
            @Override
            public Message getDefaultRequest() {
                return HeartbeatMessage.getDefaultInstance();
            }

            @Override
            public void processRequest(Request rq) {
                HeartbeatMessage hbm = (HeartbeatMessage) rq.getRequestMessage();
                assertEquals(port, hbm.getPort());
                assertEquals(lsn.getViewId(), hbm.getLsn().getViewId());
                assertEquals(lsn.getSequenceNo(), hbm.getLsn().getSequenceNo());
               
                rq.sendSuccess(ErrorCodeResponse.getDefaultInstance());
            }
        });
        ops.put(ReplicationServiceConstants.PROC_ID_CHUNK, new Operation() {
View Full Code Here

    @Override
    public LSN checkpoint(boolean incViewId) throws BabuDBException {
        Logging.logMessage(Logging.LEVEL_ERROR, this,
            "Mock tried to create CP. With inc. viewID set %s.", incViewId);
       
        LSN onDisk = txnMan.getLatestOnDiskLSN();
        if (incViewId) {
            txnMan.onDisk.set(new LSN(onDisk.getViewId() + 1, 0L));
        }
        return onDisk;
    }
View Full Code Here

   
        if (lock.get()) {
            throw new BabuDBException(ErrorCode.REPLICATION_FAILURE, "Serivce has been locked!");
        } else {
            synchronized (onDisk) {
                LSN lsn = onDisk.get();
                lsn = new LSN(lsn.getViewId(), lsn.getSequenceNo() + 1L);
                onDisk.set(lsn);
                Logging.logMessage(Logging.LEVEL_ERROR, this, "TxnMan of mock '%s' has " +
                    "retrieved a new transaction to perform (%s) with LSN %s.", name,
                    txn.toString(), lsn.toString());
            }
        }
    }
View Full Code Here

                    if (accessCounter.decrementAndGet() == 0) {
                        accessCounter.notify();
                    }
                }
               
                LSN assignedByDiskLogger = localFuture.getAssignedLSN();
                LogEntry le = new LogEntry(payload, new ListenerWrapper(future, result),
                                           PAYLOAD_TYPE_TRANSACTION);
                le.assignId(assignedByDiskLogger.getViewId(), assignedByDiskLogger.getSequenceNo());
               
                ReplicateResponse rp = replMan.replicate(le);
                if (!rp.hasFailed()) {
                    replMan.subscribeListener(rp);
                }
View Full Code Here

    public ParticipantsStates(int syncN, Set<InetSocketAddress> participants,
            ClientFactory clientFactory) throws UnknownParticipantException {
       
        assert(participants!=null);
       
        latestCommon = new LSN(0,0L);
        this.syncN = ((syncN > 0) ? syncN - 1 : syncN);
        participantsCount = deadSlaves = participants.size();
        availableSlaves = 0;
       
        /*
 
View Full Code Here

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

        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

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

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.