Package com.persistit.exception

Examples of com.persistit.exception.CorruptJournalException


        }
    }

    void scanJournalEnd(final long address, final long timestamp, final int recordSize) throws PersistitIOException {
        if (recordSize != JE.OVERHEAD) {
            throw new CorruptJournalException("JE JournalRecord has incorrect length: " + recordSize
                    + " bytes at position " + addressToString(address, timestamp));
        }
        read(address, JE.OVERHEAD);
        final long currentAddress = JE.getCurrentJournalAddress(_readBuffer);
        final long baseAddress = JE.getBaseAddress(_readBuffer);
View Full Code Here


                "JE record wrong base address %3$,d: expected %4$,d at %1$s:%2$,d");
    }

    void scanCheckpoint(final long address, final long timestamp, final int recordSize) throws PersistitIOException {
        if (recordSize != CP.OVERHEAD) {
            throw new CorruptJournalException("CP JournalRecord has incorrect length: " + recordSize
                    + " bytes at position " + addressToString(address, timestamp));
        }
        read(address, CP.OVERHEAD);
        final long systemTimeMillis = CP.getSystemTimeMillis(_readBuffer);
        final Checkpoint checkpoint = new Checkpoint(timestamp, systemTimeMillis, true);
        final long baseAddress = CP.getBaseAddress(_readBuffer);

        if (baseAddress < _baseAddress || baseAddress > _currentAddress) {
            throw new CorruptJournalException("Invalid base journal address " + baseAddress + " for CP record at "
                    + addressToString(address, timestamp));
        }
        _baseAddress = baseAddress;

        _lastValidCheckpoint = checkpoint;
View Full Code Here

     * @throws PersistitIOException
     */
    private void validateMemberFile(final long generation) throws PersistitIOException {
        final File file = JournalManager.generationToFile(_journalFilePath, generation);
        if (!file.exists()) {
            throw new CorruptJournalException("Missing journal file " + file);
        }
        read(generation * _blockSize, JH.OVERHEAD);
        int recordSize = getLength(_readBuffer);

        validate(recordSize, file, 0, JH.OVERHEAD, JH.MAX_LENGTH,
View Full Code Here

            if (item == null) {
                item = new TransactionMapItem(startTimestamp, address);
                item.setCommitTimestamp(ABORTED);
                _abortedTransactionMap.put(key, item);
            } else {
                throw new CorruptJournalException("Duplicate transaction abort records with same timestamp(" + key
                        + "): previous/current=" + item.getStartAddress() + "/"
                        + addressToString(address, startTimestamp));
            }
        } else {
            TransactionMapItem item = _recoveredTransactionMap.get(key);
            if (item == null) {
                if (backchainAddress != 0) {
                    throw new CorruptJournalException("Missing transaction record at with timestamp(" + key
                            + "): previous/current=" + backchainAddress + "/"
                            + addressToString(address, startTimestamp));
                }
                item = new TransactionMapItem(startTimestamp, address);
                _recoveredTransactionMap.put(key, item);

            } else {
                if (backchainAddress == 0) {
                    throw new CorruptJournalException("Duplicate transactions with same timestamp(" + key
                            + "): previous/current=" + item.getStartAddress() + "/"
                            + addressToString(address, startTimestamp));
                }
                if (item.isCommitted()) {
                    throw new CorruptJournalException("Redundant Transaction Commit Record for " + item + " at "
                            + addressToString(address, startTimestamp));
                }
                if (backchainAddress != item.getLastRecordAddress()) {
                    throw new CorruptJournalException("Broken backchain at " + addressToString(address)
                            + " does not match previous record " + item);
                }
                item.setLastRecordAddress(address);
            }
            item.setCommitTimestamp(commitTimestamp);
View Full Code Here

        final TreeDescriptor td = _handleToTreeMap.get(treeHandle);
        final int volumeHandle = td.getVolumeHandle();
        long page = Buffer.decodeLongRecordDescriptorPointer(value.getEncodedBytes(), 0);
        final int size = Buffer.decodeLongRecordDescriptorSize(value.getEncodedBytes(), 0);
        if (size < 0 || size > Value.MAXIMUM_SIZE) {
            throw new CorruptJournalException("Transactional long record specification " + "exceeds maximum size of "
                    + Value.MAXIMUM_SIZE + ":" + size);
        }
        final byte[] rawBytes = value.getEncodedBytes();
        final long startAddress = page;
        value.clear();
        if (size > value.getMaximumSize()) {
            value.setMaximumSize(size);
        }
        value.ensureFit(size);

        int offset = 0; // offset of next segment in the value
        int remainingSize = size;

        System.arraycopy(rawBytes, Buffer.LONGREC_PREFIX_OFFSET, value.getEncodedBytes(), offset,
                Buffer.LONGREC_PREFIX_SIZE);

        offset += Buffer.LONGREC_PREFIX_SIZE;
        remainingSize -= Buffer.LONGREC_PREFIX_SIZE;

        for (int count = 0; page != 0; count++) {

            if (remainingSize == 0) {
                throw new CorruptJournalException("Long record chain has more than " + size
                        + " bytes starting at page " + startAddress + " for transaction at "
                        + addressToString(from, timestamp));
            }
            //
            // Look for the latest version of the page which precedes the
            // record's timestamp.
            //
            final PageNode key = new PageNode(volumeHandle, page, -1, -1);
            PageNode pn = lastPageNodeBefore(_branchMap.get(key), timestamp);
            if (pn == null) {
                pn = lastPageNodeBefore(_pageMap.get(key), timestamp);
            }

            if (pn == null) {
                throw new CorruptJournalException("Long record chain missing page " + page + " at count " + count
                        + " at " + addressToString(from, timestamp));
            }

            _currentAddress = pn.getJournalAddress();
            read(_currentAddress, PA.OVERHEAD);
            final int type = PA.getType(_readBuffer);
            final int recordSize = PA.getLength(_readBuffer);
            final int payloadSize = recordSize - PA.OVERHEAD;
            final int leftSize = PA.getLeftSize(_readBuffer);
            final int bufferSize = PA.getBufferSize(_readBuffer);
            final long pageAddress = PA.getPageAddress(_readBuffer);
            //
            // Verify that this is the valid and appropriate PA record
            //
            if (type != PA.TYPE) {
                throw new CorruptJournalException("Record at " + pn.toStringJournalAddress(this)
                        + " is not a PAGE record");
            }

            if (leftSize < 0 || payloadSize < leftSize || payloadSize > bufferSize) {
                throw new CorruptJournalException("Record at " + pn.toStringJournalAddress(this)
                        + " invalid sizes: recordSize= " + payloadSize + " leftSize=" + leftSize + " bufferSize="
                        + bufferSize);
            }

            if (pageAddress != pn.getPageAddress()) {
                throw new CorruptJournalException("Record at " + pn.toStringJournalAddress(this)
                        + " mismatched page address: expected/actual=" + pn.getPageAddress() + "/" + pageAddress);
            }

            //
            // Verify that this is a PAGE_TYPE_LONG_RECORD
            //
            read(_currentAddress, recordSize);
            final int pageType = JournalRecord.getByte(_readBuffer, PA.OVERHEAD + Buffer.TYPE_OFFSET);

            if (pageType != Buffer.PAGE_TYPE_LONG_RECORD) {
                throw new CorruptJournalException("Long record chain contains invalid page type " + pageType
                        + " for page " + page + " at " + pn.toStringJournalAddress(this) + " in transaction at "
                        + addressToString(from, timestamp));
            }

            final int segmentSize = Math.min(remainingSize, payloadSize - Buffer.HEADER_SIZE);

            System.arraycopy(_readBuffer.array(), _readBuffer.position() + PA.OVERHEAD + Buffer.HEADER_SIZE,
                    value.getEncodedBytes(), offset, segmentSize);
            offset += segmentSize;
            remainingSize -= segmentSize;

            // Next page in chain
            page = JournalRecord.getLong(_readBuffer, PA.OVERHEAD + Buffer.RIGHT_SIBLING_OFFSET);

            if (count > Buffer.MAX_LONG_RECORD_CHAIN) {
                throw new CorruptJournalException("Long record chain has more than " + Buffer.MAX_LONG_RECORD_CHAIN
                        + " pages in starting at page " + startAddress + " for transaction at "
                        + addressToString(from, timestamp));
            }
        }

        if (remainingSize != 0) {
            throw new CorruptJournalException("Long record chain has fewer than " + size + " bytes (" + remainingSize
                    + " not recovered) starting at page " + startAddress + " for transaction at "
                    + addressToString(from, timestamp));
        }
        value.setEncodedSize(size);
    }
View Full Code Here

            final String message) throws CorruptJournalException {
        if (value == expected) {
            return;
        }

        throw new CorruptJournalException(String.format(message, file, address, value, expected));
    }
View Full Code Here

            final String message) throws CorruptJournalException {
        if (value >= min && value <= max) {
            return;
        }

        throw new CorruptJournalException(String.format(message, file, address, value, min, max));
    }
View Full Code Here

        if (files.length == 0) {
            return;
        }

        File rejectedPrimordialFile = null;
        CorruptJournalException savedException = null;

        for (int fileIndex = files.length; --fileIndex >= 0;) {
            final File candidate = files[fileIndex];
            _keystoneFile = candidate;
            final long generation = JournalManager.fileToGeneration(candidate);
            final long size;

            try {
                //
                // Attempt to read and validate a journal file as a candidate
                // keystone.
                //
                final RandomAccessFile raf = new RandomAccessFile(candidate, "r");
                final FileChannel readChannel = raf.getChannel();
                size = Math.min(readChannel.size(), DEFAULT_BUFFER_SIZE);
                if (size < JH.OVERHEAD) {
                    // This file cannot be a valid journal file because
                    // it's too short.
                    throw new CorruptJournalException(String.format(
                            "Invalid Persistit journal file %s - no journal header", candidate));
                }
                _readBufferAddress = 0;
                _readBuffer.limit(JH.MAX_LENGTH);
                readChannel.read(_readBuffer, 0);
View Full Code Here

                    offset += readSize;
                }
                _readBufferAddress = address;
                _readBuffer.flip();
                if (_readBuffer.remaining() < size) {
                    throw new CorruptJournalException("End of file at " + addressToString(address));
                }
            } catch (final IOException e) {
                throw new PersistitIOException("Reading from " + addressToString(address), e);
            }
        }
View Full Code Here

        final int type = getType(_readBuffer);
        final long timestamp = getTimestamp(_readBuffer);
        _persistit.getTimestampAllocator().updateTimestamp(timestamp);

        if (recordSize >= _blockSize || recordSize < OVERHEAD) {
            throw new CorruptJournalException("Bad JournalRecord length " + recordSize + " at position "
                    + addressToString(from, timestamp));
        }

        switch (type) {

        case JE.TYPE:
            scanJournalEnd(from, timestamp, recordSize);
            break;

        case JH.TYPE:
            break;

        case SR.TYPE:
        case DR.TYPE:
        case DT.TYPE:
        case D0.TYPE:
        case D1.TYPE:
            throw new CorruptJournalException("Unexpected record of type " + type + " at " + addressToString(from));

        case IV.TYPE:
            scanIdentifyVolume(from, timestamp, recordSize);
            break;

        case IT.TYPE:
            scanIdentifyTree(from, timestamp, recordSize);
            break;

        case PA.TYPE:
            scanLoadPage(from, timestamp, recordSize);
            break;

        case PM.TYPE:
            scanLoadPageMap(from, timestamp, recordSize);
            break;

        case TM.TYPE:
            scanLoadTransactionMap(from, timestamp, recordSize);
            break;

        case TX.TYPE:
            scanOneTransaction(from, timestamp, recordSize);
            break;

        case CP.TYPE:
            scanCheckpoint(from, timestamp, recordSize);
            break;

        default:
            if (!isValidType(type)) {
                _currentAddress -= OVERHEAD;
                throw new CorruptJournalException("Invalid record type " + type + " at " + addressToString(from));
            }
        }
        _currentAddress = from + recordSize;
        return type;
    }
View Full Code Here

TOP

Related Classes of com.persistit.exception.CorruptJournalException

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.