Esempio n. 1
0
 public BSkipList makeIndex(String name, Serializer key, Serializer val) throws IOException {
   if (metaIndex.get(name) != null) {
     throw new IOException("Index already exists");
   }
   int page = allocPage();
   metaIndex.put(name, Integer.valueOf(page));
   BSkipList.init(this, page, spanSize);
   BSkipList bsl = new BSkipList(spanSize, this, page, key, val, true);
   openIndices.put(name, bsl);
   return bsl;
 }
Esempio n. 2
0
  /** Use this constructor with a readonly RAI and init = false for a readonly blockfile */
  public BlockFile(RandomAccessInterface rai, boolean init) throws IOException {
    if (rai == null) {
      throw new NullPointerException();
    }

    file = rai;

    if (init) {
      file.setLength(fileLen);
      writeSuperBlock();
      BSkipList.init(this, METAINDEX_PAGE, spanSize);
    }

    readSuperBlock();
    if (magicBytes != MAGIC) {
      if ((magicBytes & MAGIC_BASE) == MAGIC_BASE) {
        throw new IOException(
            "Expected "
                + MAJOR
                + '.'
                + MINOR
                + " but got "
                + (magicBytes >> 8 & 0xff)
                + '.'
                + (magicBytes & 0xff));
      } else {
        throw new IOException("Bad magic number");
      }
    }
    _wasMounted = mounted != 0;
    if (_wasMounted) log.warn("Warning - file was not previously closed");
    if (fileLen != file.length())
      throw new IOException("Expected file length " + fileLen + " but actually " + file.length());
    if (rai.canWrite()) mount();

    metaIndex = new BSkipList(spanSize, this, METAINDEX_PAGE, new StringBytes(), new IntBytes());
  }