コード例 #1
0
  public void testRecordGrowFactor() throws Exception {
    paginatedCluster.set(OCluster.ATTRIBUTES.COMPRESSION, ONothingCompression.NAME);
    paginatedCluster.set(OCluster.ATTRIBUTES.RECORD_GROW_FACTOR, 1.5);

    byte[] record = new byte[100];
    Random random = new Random();
    random.nextBytes(record);

    OPhysicalPosition physicalPosition = paginatedCluster
        .createRecord(record, OVersionFactory.instance().createVersion(), (byte) 1);

    OCacheEntry cacheEntry = diskCache.load(1, 1, false);
    OCachePointer pagePointer = cacheEntry.getCachePointer();

    OClusterPage page = new OClusterPage(pagePointer.getDataPointer(), false, ODurablePage.TrackMode.NONE);
    int recordIndex = (int) (physicalPosition.clusterPosition.longValue() & 0xFFFF);

    Assert.assertEquals(page.getRecordSize(recordIndex), ((int) (record.length * 1.5)) + RECORD_SYSTEM_INFORMATION);
    diskCache.release(cacheEntry);

    paginatedCluster.set(OCluster.ATTRIBUTES.RECORD_GROW_FACTOR, 2);
    physicalPosition = paginatedCluster.createRecord(record, OVersionFactory.instance().createVersion(), (byte) 1);

    recordIndex = (int) (physicalPosition.clusterPosition.longValue() & 0xFFFF);
    cacheEntry = diskCache.load(1, 1, false);
    pagePointer = cacheEntry.getCachePointer();

    page = new OClusterPage(pagePointer.getDataPointer(), false, ODurablePage.TrackMode.NONE);

    Assert.assertEquals(page.getRecordSize(recordIndex), record.length * 2 + RECORD_SYSTEM_INFORMATION);
    diskCache.release(cacheEntry);
  }
コード例 #2
0
  public void testCompressionSnappy() throws Exception {
    paginatedCluster.set(OCluster.ATTRIBUTES.COMPRESSION, OSnappyCompression.NAME);
    paginatedCluster.set(OCluster.ATTRIBUTES.RECORD_GROW_FACTOR, 1);

    byte[] record = new byte[100];
    Random random = new Random();
    random.nextBytes(record);

    OPhysicalPosition physicalPosition = paginatedCluster
        .createRecord(record, OVersionFactory.instance().createVersion(), (byte) 1);

    record = OSnappyCompression.INSTANCE.compress(record);

    OCacheEntry cacheEntry = diskCache.load(1, 1, false);
    OCachePointer pagePointer = cacheEntry.getCachePointer();
    int recordIndex = (int) (physicalPosition.clusterPosition.longValue() & 0xFFFF);

    OClusterPage page = new OClusterPage(pagePointer.getDataPointer(), false, ODurablePage.TrackMode.NONE);

    byte[] storedEntity = page.getRecordBinaryValue(recordIndex, 0, page.getRecordSize(recordIndex));
    byte[] storedRecord = new byte[record.length];
    System.arraycopy(storedEntity, OIntegerSerializer.INT_SIZE + OByteSerializer.BYTE_SIZE, storedRecord, 0, storedRecord.length);

    Assert.assertEquals(storedRecord, record);
    diskCache.release(cacheEntry);
  }
コード例 #3
0
  public void testFreeListPointer() throws Exception {
    ODirectMemoryPointer pointer =
        new ODirectMemoryPointer(ODurablePage.MAX_PAGE_SIZE_BYTES + ODurablePage.PAGE_PADDING);
    OCachePointer cachePointer = new OCachePointer(pointer, new OLogSequenceNumber(0, 0));
    cachePointer.incrementReferrer();

    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    OSBTreeValuePage valuePage =
        new OSBTreeValuePage(cacheEntry, ODurablePage.TrackMode.NONE, true);
    valuePage.setNextFreeListPage(124);
    Assert.assertEquals(valuePage.getNextFreeListPage(), 124);

    cachePointer.decrementReferrer();
  }
コード例 #4
0
  public void testRecordOverflowGrowFactor() throws Exception {
    paginatedCluster.set(OCluster.ATTRIBUTES.COMPRESSION, ONothingCompression.NAME);
    paginatedCluster.set(OCluster.ATTRIBUTES.RECORD_GROW_FACTOR, 1.5);
    paginatedCluster.set(OCluster.ATTRIBUTES.RECORD_OVERFLOW_GROW_FACTOR, 2.5);

    byte[] record = new byte[100];
    Random random = new Random();
    random.nextBytes(record);

    ORecordVersion version = OVersionFactory.instance().createVersion();
    OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, version, (byte) 1);

    record = new byte[150];
    random.nextBytes(record);

    paginatedCluster.updateRecord(physicalPosition.clusterPosition, record, version, (byte) 1);

    OCacheEntry cacheEntry = diskCache.load(1, 1, false);
    int recordIndex = (int) (physicalPosition.clusterPosition.longValue() & 0xFFFF);
    OCachePointer pagePointer = cacheEntry.getCachePointer();

    OClusterPage page = new OClusterPage(pagePointer.getDataPointer(), false, ODurablePage.TrackMode.NONE);

    Assert.assertEquals(page.getRecordSize(recordIndex), record.length + RECORD_SYSTEM_INFORMATION);
    diskCache.release(cacheEntry);

    record = new byte[200];
    random.nextBytes(record);

    paginatedCluster.updateRecord(physicalPosition.clusterPosition, record, version, (byte) 1);

    cacheEntry = diskCache.load(1, 1, false);
    pagePointer = cacheEntry.getCachePointer();

    page = new OClusterPage(pagePointer.getDataPointer(), false, ODurablePage.TrackMode.NONE);

    int fullContentSize = 500 + OIntegerSerializer.INT_SIZE + OByteSerializer.BYTE_SIZE; // type + real size

    Assert.assertEquals(page.getRecordSize(recordIndex), 150 + RECORD_SYSTEM_INFORMATION);
    fullContentSize -= 150 + RECORD_SYSTEM_INFORMATION - OByteSerializer.BYTE_SIZE - OLongSerializer.LONG_SIZE;

    Assert.assertEquals(page.getRecordSize(recordIndex + 1), fullContentSize
        + (OByteSerializer.BYTE_SIZE + OLongSerializer.LONG_SIZE));
    diskCache.release(cacheEntry);
  }
コード例 #5
0
    @Override
    public Void call() throws Exception {
      long pageIndex = Math.abs(new Random().nextInt() % PAGE_COUNT);
      int fileNumber = new Random().nextInt(FILE_COUNT);

      OCacheEntry cacheEntry = buffer.load(fileIds.get(fileNumber), pageIndex, false);
      OCachePointer pointer = cacheEntry.getCachePointer();

      byte[] content = pointer.getDataPointer().get(systemOffset, 8);

      buffer.release(cacheEntry);

      Assert.assertTrue(content[0] == 1 || content[0] == 2);
      Assert.assertEquals(
          content,
          new byte[] {content[0], 2, 3, seed, 5, 6, (byte) fileNumber, (byte) (pageIndex & 0xFF)});
      return null;
    }
コード例 #6
0
    private void writeToFile(int fileNumber, long pageIndex) throws IOException {
      OCacheEntry cacheEntry = buffer.load(fileIds.get(fileNumber), pageIndex, false);
      OCachePointer pointer = cacheEntry.getCachePointer();

      pointer.acquireExclusiveLock();
      cacheEntry.markDirty();

      pointer
          .getDataPointer()
          .set(
              systemOffset,
              new byte[] {
                version.byteValue(), 2, 3, seed, 5, 6, (byte) fileNumber, (byte) (pageIndex & 0xFF)
              },
              0,
              8);
      pointer.releaseExclusiveLock();
      buffer.release(cacheEntry);
    }
コード例 #7
0
  public void fillPageDataTest() throws Exception {
    ODirectMemoryPointer pointerOne =
        new ODirectMemoryPointer(ODurablePage.MAX_PAGE_SIZE_BYTES + ODurablePage.PAGE_PADDING);
    OCachePointer cachePointerOne = new OCachePointer(pointerOne, new OLogSequenceNumber(0, 0));
    cachePointerOne.incrementReferrer();

    OCacheEntry cacheEntryOne = new OCacheEntry(0, 0, cachePointerOne, false);
    OSBTreeValuePage valuePageOne =
        new OSBTreeValuePage(cacheEntryOne, ODurablePage.TrackMode.NONE, true);

    byte[] data = new byte[ODurablePage.MAX_PAGE_SIZE_BYTES + 100];
    Random random = new Random();
    random.nextBytes(data);

    int offset = valuePageOne.fillBinaryContent(data, 0);
    Assert.assertEquals(offset, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE);

    ODirectMemoryPointer pointerTwo = new ODirectMemoryPointer(ODurablePage.MAX_PAGE_SIZE_BYTES);
    OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, new OLogSequenceNumber(0, 0));
    cachePointerTwo.incrementReferrer();

    OCacheEntry cacheEntryTwo = new OCacheEntry(0, 0, cachePointerTwo, false);
    OSBTreeValuePage valuePageTwo =
        new OSBTreeValuePage(cacheEntryTwo, ODurablePage.TrackMode.NONE, true);
    offset = valuePageTwo.fillBinaryContent(data, offset);

    Assert.assertEquals(offset, data.length);

    valuePageOne.setNextPage(100);
    Assert.assertEquals(valuePageOne.getNextPage(), 100);

    byte[] readData = new byte[data.length];
    offset = valuePageOne.readBinaryContent(readData, 0);

    Assert.assertEquals(offset, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE);

    offset = valuePageTwo.readBinaryContent(readData, offset);
    Assert.assertEquals(offset, data.length);

    Assert.assertEquals(data, readData);

    cachePointerOne.decrementReferrer();
    cachePointerTwo.decrementReferrer();
  }