Package org.xtreemfs.babudb.log

Examples of org.xtreemfs.babudb.log.DiskLogIterator


     * getLogEntryIterator(org.xtreemfs.babudb.lsmdb.LSN)
     */
    @Override
    public DiskLogIterator getLogEntryIterator(LSN from)
            throws LogEntryException, IOException {       
        return new DiskLogIterator(getLogFiles(), from);
    }
View Full Code Here


                                       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()) {
            try {  
                // wait, if there is a checkpoint in proceeding
                babuInterface.waitForCheckpoint();
               
                it = fileIO.getLogEntryIterator(start);
               
                while (it.hasNext() &&
                       result.getLogEntriesCount() <
                       MAX_LOGENTRIES_PER_REQUEST && (le = it.next())
                           .getLSN().compareTo(end) < 0) {
                   
                    try {
                        // we are not at the right position yet -> skip
                        if (le.getLSN().compareTo(firstEntry) < 0) continue;
                   
                        // the first entry was not available ... bad
                        if (le.getLSN().compareTo(firstEntry) > 0 &&
                            result.getLogEntriesCount() == 0) {
                            break;
                        }
                         
                        // add the logEntry to result list
                        assert (le.getPayload().array().length > 0) :
                            "Empty log-entries are not allowed!";
                        ReusableBuffer buf = le.serialize(checksum);
                        result.addLogEntries(
                                org.xtreemfs.babudb.pbrpc.GlobalTypes.LogEntry
                                .newBuilder().setLength(buf.remaining()));
                        int newSize = resultPayLoad.remaining() +
                                      buf.remaining();
                        if (!resultPayLoad.enlarge(newSize)) {
                            ReusableBuffer tmp = BufferPool.allocate(newSize);
                           
                            tmp.put(resultPayLoad);
                            BufferPool.free(resultPayLoad);
                            resultPayLoad = tmp;
                        }
                        resultPayLoad.put(buf);
                        BufferPool.free(buf);
                       
                    } finally {
                        checksum.reset();
                        if (le != null) {
                            le.free();
                            le = null;
                        }
                    }
                }
               
                if (result.getLogEntriesCount() > 0) {
                    // send the response, if the requested log entries are found
                    Logging.logMessage(Logging.LEVEL_DEBUG, this,
                            "REQUEST: returning %d log-entries to %s.",
                            result.getLogEntriesCount(), rq.getSenderAddress().toString());
                   
                    resultPayLoad.flip();
                    rq.sendSuccess(result.build(), resultPayLoad);
                } else {
                    rq.sendSuccess(result.setErrorCode(
                            ErrorCode.LOG_UNAVAILABLE).build());
                }
            } catch (Exception e) {
                Logging.logError(Logging.LEVEL_INFO, this, e);
               
                // clear result
                BufferPool.free(resultPayLoad);
               
                rq.sendSuccess(result.setErrorCode(ErrorCode.BUSY).build());
            } finally {
                if (le != null) le.free();
               
                if (it != null) {
                    try {
                        it.destroy();
                    } catch (IOException e) { /* ignored */ }
                }
            }
        }
    }
View Full Code Here

                public boolean accept(File dir, String name) {
                    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);
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.log.DiskLogIterator

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.