Пример #1
0
 @Test
 public void testNextPowTwo2Long() {
   for (long i = 1; i < 10000L * Integer.MAX_VALUE; i += 1 + i / 100000) {
     long pow = nextPowTwo(i);
     assertTrue(pow >= i);
     assertTrue(pow / 2 < i);
     assertTrue(Long.bitCount(pow) == 1);
   }
 }
Пример #2
0
  /** return positions of (possibly) linked record */
  @Override
  protected long[] offsetsGet(int segment, long indexVal) {
    ;
    if (indexVal >>> 48 == 0) {
      return ((indexVal & MLINKED) != 0) ? null : StoreDirect.EMPTY_LONGS;
    }

    long[] ret = new long[] {indexVal};
    while ((ret[ret.length - 1] & MLINKED) != 0) {
      ret = Arrays.copyOf(ret, ret.length + 1);
      long oldLink = ret[ret.length - 2] & MOFFSET;

      // get WAL position from current transaction, or previous (not yet fully replayed)
      // transactions
      long val = uncommittedDataLongs[segment].get(oldLink);
      if (val == 0) val = committedDataLongs[segment].get(oldLink);
      if (val != 0) {
        //                //was found in previous position, read link from WAL
        //                int file = (int) ((val>>>32) & 0xFFFFL); // get WAL file number
        //                val = val & 0xFFFFFFFFL; // convert to WAL offset;
        //                val = volumes.get(file).getLong(val);
        try {
          val = wal.walGetByteArray(val).readLong();
        } catch (IOException e) {
          throw new DBException.VolumeIOError(e);
        }
      } else {
        // was not found in any transaction, read from main store
        val = vol.getLong(oldLink);
      }
      ret[ret.length - 1] = parity3Get(val);
    }

    if (CC.ASSERT) {
      offsetsVerify(ret);
    }

    if (CC.LOG_STORE && LOG.isLoggable(Level.FINEST)) {
      LOG.log(
          Level.FINEST,
          "indexVal={0}, ret={1}",
          new Object[] {Long.toHexString(indexVal), Arrays.toString(ret)});
    }

    return ret;
  }
Пример #3
0
  @Test
  public void parity1() {
    assertEquals(Long.parseLong("1", 2), parity1Set(0));
    assertEquals(Long.parseLong("10", 2), parity1Set(2));
    assertEquals(Long.parseLong("111", 2), parity1Set(Long.parseLong("110", 2)));
    assertEquals(Long.parseLong("1110", 2), parity1Set(Long.parseLong("1110", 2)));
    assertEquals(Long.parseLong("1011", 2), parity1Set(Long.parseLong("1010", 2)));
    assertEquals(Long.parseLong("11111", 2), parity1Set(Long.parseLong("11110", 2)));

    assertEquals(0, parity1Get(Long.parseLong("1", 2)));
    try {
      parity1Get(Long.parseLong("0", 2));
      fail();
    } catch (DBException.PointerChecksumBroken e) {
      // TODO check mapdb specific error;
    }
    try {
      parity1Get(Long.parseLong("110", 2));
      fail();
    } catch (DBException.PointerChecksumBroken e) {
      // TODO check mapdb specific error;
    }
  }