Esempio n. 1
0
  /** if some pages are too old, remove them */
  public void removeOldPages() {
    // the oldest page is in the front of the list, and the most recent page is in the tail of the
    // list
    int duration = curTime - pageStartTimes.get(0).start_time;
    int count = 0;

    // pay special attention to >=, if ==, still need to go ahead.
    while (duration >= Configuration.T_period) {
      count++;
      if (count >= pageStartTimes.size()) break;
      duration = curTime - pageStartTimes.get(count).start_time + 1;
    }

    // all previous data need to be erased.
    for (int i = 0; i < count - 1; i++) {
      m_pStorageManager.deleteByteArray(pageStartTimes.get(i).pageId);
    }

    // shifting, move all the data Item to the front of the list
    for (int j = count - 1; j >= 0 && j < pageStartTimes.size(); j++) {
      pageStartTimes.set(j - count + 1, pageStartTimes.get(j));
    }

    // erase the data at the tail after shifting
    for (int i = 0; i < count - 1; i++) {
      pageStartTimes.remove(pageStartTimes.size() - 1);
    }
  }
Esempio n. 2
0
  /**
   * check the size of linkedhashmap, if the size of the map is larger that the flush threshold,
   * flush all the items in linkedhashmap into disk
   *
   * <p>Think more about
   * it........................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   */
  private void flushBuffer() {

    if (traHash.size() >= Configuration.CapacityPerPage) {

      try {

        byte[] data = BinarySerializer.getByteSerialize(traHash);
        int id = m_pStorageManager.storeByteArray(IStorageManager.NewPage, data);
        countIO++;

        if (pageStartTimes.size() >= 1) {
          removeOldPages(); // too old disk page are discarded
        }

        PageStartTimeItem pstItem = new PageStartTimeItem(curPageStartTime, id);
        pageStartTimes.add(pstItem);

        traHash.clear();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }