Example #1
0
 public boolean flushSome(int maxPages) {
   myFile.flushSomePages(maxPages);
   if (!myFile.isDirty()) {
     force();
     return true;
   }
   return false;
 }
Example #2
0
 private void readInHeader(File filePath) throws IOException {
   int magic = myFile.getInt(HEADER_MAGIC_OFFSET);
   if (magic != SAFELY_CLOSED_MAGIC) {
     myFile.dispose();
     throw new IOException(
         "Records table for '" + filePath + "' haven't been closed correctly. Rebuild required.");
   }
   myWasteSize = myFile.getInt(HEADER_WASTE_SIZE_OFFSET);
 }
Example #3
0
 public DataTable(final File filePath, final PagePool pool) throws IOException {
   myFile = new RandomAccessDataFile(filePath, pool);
   if (myFile.length() == 0) {
     markDirty();
   } else {
     readInHeader(filePath);
   }
 }
Example #4
0
  public long allocateSpace(int len) {
    final long result = Math.max(myFile.length(), HEADER_SIZE);

    // Fill them in so we won't give out wrong address from allocateSpace() next time if they still
    // not finished writing to allocated page
    long newLenght = result + len;
    writeBytes(newLenght - 1, new byte[] {0});
    long actualLenght = myFile.length();
    LOG.assertTrue(
        actualLenght == newLenght,
        "Failed to resize the storage at: "
            + myFile.getFile()
            + ". Required: "
            + newLenght
            + ", actual: "
            + actualLenght);
    return result;
  }
Example #5
0
 public void writeBytes(long address, byte[] bytes, int off, int len) {
   markDirty();
   myFile.put(address, bytes, off, len);
 }
Example #6
0
 public void readBytes(long address, byte[] bytes) {
   myFile.get(address, bytes, 0, bytes.length);
 }
Example #7
0
 public boolean isCompactNecessary() {
   return ((double) myWasteSize) / myFile.length() > 0.25 && myWasteSize > 3 * FileUtil.MEGABYTE;
 }
Example #8
0
 public long getFileSize() {
   return myFile.length();
 }
Example #9
0
 private void fillInHeader(int magic, int wasteSize) {
   myFile.putInt(HEADER_MAGIC_OFFSET, magic);
   myFile.putInt(HEADER_WASTE_SIZE_OFFSET, wasteSize);
 }
Example #10
0
 public boolean isDirty() {
   return myIsDirty || myFile.isDirty();
 }
Example #11
0
 public void force() {
   markClean();
   myFile.force();
 }
Example #12
0
 public void dispose() {
   if (!myFile.isDisposed()) {
     markClean();
     myFile.dispose();
   }
 }