Exemplo n.º 1
0
 public static LongList getLongList(HttpServletRequest request, String s) {
   long[] array = getLongArray(request, s);
   LongList list = new LongList();
   for (int k = 0; k < array.length; k++) {
     list.add(array[k]);
   }
   return list;
 }
Exemplo n.º 2
0
  protected void replaySoft() {
    if (CC.ASSERT && !commitLock.isHeldByCurrentThread()) throw new AssertionError();

    LongList written = CC.PARANOID ? new LongList() : null;

    for (int lockPos = 0; lockPos < locks.length; lockPos++) {
      locks[lockPos].writeLock().lock();
      try {
        // update index table
        long[] table = committedIndexTable[lockPos].table;
        indexValLoop:
        for (int pos = 0; pos < table.length; ) {
          long recidOffset = table[pos++];
          long val = table[pos++];
          if (recidOffset == 0 || val == -1) continue indexValLoop;

          realVol.ensureAvailable(Fun.roundUp(recidOffset + 8, StoreDirect.PAGE_SIZE));
          realVol.putLong(recidOffset, val);

          if (CC.PARANOID) {
            // check this is index page
            if (!Fun.arrayContains(indexPages, Fun.roundDown(recidOffset, PAGE_SIZE))) {
              throw new AssertionError("not index page");
            }
          }
        }
        committedIndexTable[lockPos].clear();

        // write data
        table = committedDataLongs[lockPos].table;
        dataLoop:
        for (int pos = 0; pos < table.length; ) {
          long volOffset = table[pos++];
          long walPointer = table[pos++];
          if (volOffset == 0 || walPointer == -1) continue dataLoop;

          byte[] b = wal.walGetByteArray2(walPointer);
          if (CC.ASSERT) assertRecord(volOffset, b);

          realVol.ensureAvailable(Fun.roundUp(volOffset + b.length, StoreDirect.PAGE_SIZE));
          realVol.putData(volOffset, b, 0, b.length);
          if (CC.ASSERT && b.length > MAX_REC_SIZE) throw new AssertionError();

          if (CC.PARANOID) written.add((volOffset << 16) | b.length);
        }
        committedDataLongs[lockPos].clear();
      } finally {
        locks[lockPos].writeLock().unlock();
      }
    }
    structuralLock.lock();
    try {
      // flush modified Long Stack pages
      dataLoop:
      for (int pos = 0; pos < committedPageLongStack.table.length; ) {
        long volOffset = committedPageLongStack.table[pos++];
        long walPointer = committedPageLongStack.table[pos++];
        if (volOffset == 0 || walPointer == -1) continue dataLoop;

        byte[] b = wal.walGetByteArray2(walPointer);
        if (CC.ASSERT) assertLongStackPage(volOffset, b);

        realVol.ensureAvailable(Fun.roundUp(volOffset + b.length, StoreDirect.PAGE_SIZE));
        realVol.putData(volOffset, b, 0, b.length);

        if (CC.PARANOID) written.add((volOffset << 16) | b.length);
      }
      committedPageLongStack.clear();

      if (CC.PARANOID) {
        byte[] headVolBuf = new byte[headVolBackup.length];
        headVol.getData(0, headVolBuf, 0, headVolBuf.length);
        if (!Arrays.equals(headVolBuf, headVolBackup)) throw new AssertionError();
      }

      // update page header
      realVol.putData(0, headVolBackup, 0, headVolBackup.length);
    } finally {
      structuralLock.unlock();
    }

    if (CC.PARANOID) {
      // check for overlaps
      long[] w = Arrays.copyOf(written.array, written.size);
      Arrays.sort(w);
      for (int i = 0; i < w.length - 1; i++) {
        long offset1 = w[i] >>> 16;
        long size1 = w[i] & 0xFF;
        long offset2 = w[i + 1] >>> 16;
        long size2 = w[i + 1] & 0xFF;

        if (offset1 + size1 > offset2) {
          throw new AssertionError(
              "write overlap conflict at: "
                  + offset1
                  + " + "
                  + size1
                  + " > "
                  + offset2
                  + " ("
                  + size2
                  + ")");
        }
      }
    }
  }