Package net.sf.joafip.kvstore.service

Examples of net.sf.joafip.kvstore.service.HeapException


   * @throws HeapException
   */
  private boolean assertRecordSizeValue(final boolean freeRecord)
      throws HeapException {
    if (recordSize <= 0) {
      throw new HeapException("record size must be defined");
    }
    final int minimal;
    if (freeRecord) {
      minimal = FREE_RECORD_HEADER_SIZE;
    } else {
      minimal = DATA_RECORD_HEADER_SIZE;
    }
    if (recordSize < minimal) {
      throw new HeapException("record size too small: areaSize="
          + recordSize + ", minimal=" + minimal + ", free record="
          + freeRecord);
    }
    return true;
  }
View Full Code Here


  /**
   * @throws HeapException
   */
  private boolean assertRecordSizeKnew() throws HeapException {
    if (recordSize <= 0) {
      throw new HeapException("record size is unknow");
    }
    return true;
  }
View Full Code Here

  /**
   * @throws HeapException
   */
  private boolean assertDataAssociatedSizeKnew() throws HeapException {
    if (dataAssociatedSize == null) {
      throw new HeapException("data associated size is unknow");
    }
    return true;
  }
View Full Code Here

    // final int offset=numberOfByteReadWrote;
    final int read = readFileToIoBuffer(dataAssociatedSize + 4);// +4 for
    // crc32
    // AS-SERT
    if (read != dataAssociatedSize + 4) {
      throw new HeapException("expected " + (dataAssociatedSize + 4)
          + " but read " + read);
    }
    dataAssociated = readBytes(dataAssociatedSize);
    readAndCheckCrc32(0);
  }
View Full Code Here

          lastHeapRecord = heapRecord;
          heapRecord = heapRecordIterator.getNextHeapRecord();
        }
        final long nextId = header.getNextDataRecordIdentifier();
        if (nextId <= identifier) {
          throw new HeapException("bad data record identifier");
        }
        checkLastRecord(header, lastHeapRecord);
      } catch (RBTException exception) {
        throw new HeapException(exception);
      }

      checkTotalNumberOfRecord(freeRecordCount, dataRecordCount);
    }
  }
View Full Code Here

  }

  private void checkFreeNodeInTree(final HeapRecord heapRecord)
      throws RBTException, HeapException {
    if (!heapRecord.isFreeRecord()) {
      throw new HeapException("must be a free node");
    }
    final HeapFreeNode node = (HeapFreeNode) heapRecord.getFreeNode();
    if (node.getPositionInFile() != heapRecord.getPositionInFile()) {
      throw new HeapException(
          "position in file mismatch: heap record is "
              + heapRecord.getPositionInFile()
              + " and free node is " + node.getPositionInFile());
    }
    if (node.getRecordSize() != heapRecord.getRecordSize()) {
      throw new HeapException("area size mismatch: heap record is "
          + heapRecord.getRecordSize() + " and free node is "
          + node.getRecordSize());
    }

    HeapFreeNode found;
    found = (HeapFreeNode) freeNodeTree.search(heapRecord.getRecordSize());
    if (found == null) {
      throw new HeapException("free record must exist in free tree\n"
          + heapRecord);
    }
    while (found.getPositionInFile() != heapRecord.getPositionInFile()) {
      found = (HeapFreeNode) freeNodeTree.next(found);
      if (found == null
          || found.getRecordSize() != heapRecord.getRecordSize()) {
        throw new HeapException("free record must exist in free tree");
      }
    }
  }
View Full Code Here

   * @throws RBTException
   */
  private void checkDataNodeInTree(final HeapRecord heapRecord)
      throws HeapException, RBTException {
    if (heapRecord.isFreeRecord()) {
      throw new HeapException("must be a data record");
    }
    final DataRecordIdentifier identifier = heapRecord.getNodeIdentifier();
    final HeapIdNode foundIdNode = (HeapIdNode) idNodeTree
        .search(identifier);
    if (foundIdNode == null) {
      throw new HeapException("record for data, node #" + identifier
          + " must be in node identifier tree");
    }
    if (foundIdNode.getPositionInFile() != heapRecord.getPositionInFile()) {
      throw new HeapException("data record detached from id tree");
    }
  }
View Full Code Here

  private void checkLastRecord(final HeapHeader header,
      final HeapRecord lastHeapRecord) throws HeapException {
    if (lastHeapRecord == null) {
      if (header.getLastRecordPositionInFile() != -1) {
        throw new HeapException(
            "last record position in file must be undefined");
      }
      if (header.getEndOfRecordPositionInFile() != HeapHeader.HEAP_HEADER_SIZE) {
        throw new HeapException(
            "end of record position in file must be end of header size");
      }
    } else {
      if (header.getLastRecordPositionInFile() != lastHeapRecord
          .getPositionInFile()) {
        throw new HeapException(
            "last record position in file must be last record position");
      }
      if (header.getEndOfRecordPositionInFile() != lastHeapRecord
          .getPositionInFile() + lastHeapRecord.getRecordSize()) {
        throw new HeapException(
            "end of record position in file must be end of last record");
      }
    }
  }
View Full Code Here

    final RedBlackTreeIntegrityChecker<DataRecordIdentifier> idNodeTreeChecker =
    /**/new RedBlackTreeIntegrityChecker<DataRecordIdentifier>(idNodeTree);
    try {
      idNodeTreeChecker.checkTree();
    } catch (RBTException exception) {
      throw new HeapException("identifier tree corruption", exception);
    }
    final RedBlackTreeIntegrityChecker<Integer> freeNodeTreeChecker =
    /**/new RedBlackTreeIntegrityChecker<Integer>(freeNodeTree);
    try {
      freeNodeTreeChecker.checkTree();
    } catch (RBTException exception) {
      throw new HeapException("free node tree corruption", exception);
    }
  }
View Full Code Here

      final int dataRecordCount) throws HeapException {
    try {
      final int numberOfRecord = idNodeTree.getNumberOfElement()
          + freeNodeTree.getNumberOfElement();
      if (dataRecordCount + freeRecordCount != numberOfRecord) {
        throw new HeapException(
            "bad number of record count: dataRecordCount="
                + dataRecordCount + ", freeRecordCount="
                + freeRecordCount + ", idNode="
                + idNodeTree.getNumberOfElement()
                + ", freeNode="
                + freeNodeTree.getNumberOfElement()
                + ", freeNode+idNode=" + numberOfRecord);
      }
    } catch (RBTException exception) {
      throw new HeapException("failed get number of element", exception);
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.kvstore.service.HeapException

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.