Esempio n. 1
0
 public boolean flushSome(int maxPages) {
   myFile.flushSomePages(maxPages);
   if (!myFile.isDirty()) {
     force();
     return true;
   }
   return false;
 }
Esempio n. 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);
 }
Esempio n. 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);
   }
 }
Esempio n. 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;
  }
Esempio n. 5
0
 public void writeBytes(long address, byte[] bytes, int off, int len) {
   markDirty();
   myFile.put(address, bytes, off, len);
 }
Esempio n. 6
0
 public void readBytes(long address, byte[] bytes) {
   myFile.get(address, bytes, 0, bytes.length);
 }
Esempio n. 7
0
 public boolean isCompactNecessary() {
   return ((double) myWasteSize) / myFile.length() > 0.25 && myWasteSize > 3 * FileUtil.MEGABYTE;
 }
Esempio n. 8
0
 public long getFileSize() {
   return myFile.length();
 }
Esempio n. 9
0
 private void fillInHeader(int magic, int wasteSize) {
   myFile.putInt(HEADER_MAGIC_OFFSET, magic);
   myFile.putInt(HEADER_WASTE_SIZE_OFFSET, wasteSize);
 }
Esempio n. 10
0
 public boolean isDirty() {
   return myIsDirty || myFile.isDirty();
 }
Esempio n. 11
0
 public void force() {
   markClean();
   myFile.force();
 }
Esempio n. 12
0
 public void dispose() {
   if (!myFile.isDisposed()) {
     markClean();
     myFile.dispose();
   }
 }