use of io.questdb.cairo.vm.MemoryCMRImpl in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteAndReadWithReadOnlyMem.
@Test
public void testWriteAndReadWithReadOnlyMem() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryCMARW mem = Vm.getCMARWInstance(FF, path, 2 * FF.getPageSize(), -1, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (MemoryMR mem = new MemoryCMRImpl(FF, path, 8L * N, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of io.questdb.cairo.vm.MemoryCMRImpl in project questdb by bluestreak01.
the class CairoMemoryTest method testVirtualMemoryJump.
private void testVirtualMemoryJump(VirtualMemoryFactory factory) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (MemoryARW mem = factory.newInstance(path)) {
for (int i = 0; i < 100; i++) {
mem.putLong(i);
}
mem.jumpTo(0);
for (int i = 0; i < 50; i++) {
mem.putLong(50 - i);
}
// keep previously written data
mem.jumpTo(800);
}
try (MemoryMR roMem = new MemoryCMRImpl(FF, path, 800, MemoryTag.MMAP_DEFAULT)) {
for (int i = 0; i < 50; i++) {
Assert.assertEquals(50 - i, roMem.getLong(i * 8));
}
for (int i = 50; i < 100; i++) {
Assert.assertEquals(i, roMem.getLong(i * 8));
}
}
}
});
}
use of io.questdb.cairo.vm.MemoryCMRImpl in project questdb by bluestreak01.
the class TableReader method reshuffleColumns.
private void reshuffleColumns(int columnCount, long pTransitionIndex) {
final long pIndexBase = pTransitionIndex + 8;
final long pState = pIndexBase + columnCount * 8L;
for (int partitionIndex = 0; partitionIndex < partitionCount; partitionIndex++) {
int base = getColumnBase(partitionIndex);
try {
final Path path = pathGenPartitioned(partitionIndex).$();
final long partitionRowCount = openPartitionInfo.getQuick(partitionIndex * PARTITIONS_SLOT_SIZE + PARTITIONS_SLOT_OFFSET_SIZE);
Vect.memset(pState, columnCount, 0);
for (int i = 0; i < columnCount; i++) {
if (TableUtils.isEntryToBeProcessed(pState, i)) {
final int copyFrom = Unsafe.getUnsafe().getInt(pIndexBase + i * 8L) - 1;
if (copyFrom == i) {
// It appears that column hasn't changed its position. There are three possibilities here:
// 1. Column has been deleted and re-added by the same name. We must check if file
// descriptor is still valid. If it isn't, reload the column from disk
// 2. Column has been forced out of the reader via closeColumnForRemove(). This is required
// on Windows before column can be deleted. In this case we must check for marker
// instance and the column from disk
// 3. Column hasn't been altered and we can skip to next column.
MemoryMR col = columns.getQuick(getPrimaryColumnIndex(base, i));
if ((col instanceof MemoryCMRImpl && col.isDeleted()) || col instanceof NullColumn) {
reloadColumnAt(path, columns, columnTops, bitmapIndexes, base, i, partitionRowCount);
}
continue;
}
if (copyFrom > -1) {
fetchColumnsFrom(base, copyFrom);
copyColumnsTo(this.columns, this.columnTops, this.bitmapIndexes, base, i, partitionRowCount);
int copyTo = Unsafe.getUnsafe().getInt(pIndexBase + i * 8L + 4) - 1;
while (copyTo > -1 && TableUtils.isEntryToBeProcessed(pState, copyTo)) {
copyColumnsTo(this.columns, this.columnTops, this.bitmapIndexes, base, copyTo, partitionRowCount);
copyTo = Unsafe.getUnsafe().getInt(pIndexBase + (copyTo - 1) * 8L + 4);
}
Misc.free(tempCopyStruct.mem1);
Misc.free(tempCopyStruct.mem2);
Misc.free(tempCopyStruct.backwardReader);
Misc.free(tempCopyStruct.forwardReader);
} else {
// new instance
reloadColumnAt(path, columns, columnTops, bitmapIndexes, base, i, partitionRowCount);
}
}
}
for (int i = columnCount; i < this.columnCount; i++) {
int index = getPrimaryColumnIndex(base, i);
Misc.free(columns.getQuick(index));
Misc.free(columns.getQuick(index + 1));
}
} finally {
path.trimTo(rootLen);
}
}
}
use of io.questdb.cairo.vm.MemoryCMRImpl in project questdb by bluestreak01.
the class MemRemappedFileTest method testReadOnlyMemory.
@Test
public void testReadOnlyMemory() {
LOG.info().$("ReadOnlyMemory starting").$();
double micros = test(new MemoryCMRImpl());
LOG.info().$("ReadOnlyMemory took ").$(micros).$("ms").$();
}
use of io.questdb.cairo.vm.MemoryCMRImpl in project questdb by bluestreak01.
the class MemRemappedFileTest method testExtendableOnePageMemory.
@Test
public void testExtendableOnePageMemory() {
LOG.info().$("ExtendableOnePageMemory starting").$();
double micros = test(new MemoryCMRImpl());
LOG.info().$("ExtendableOnePageMemory took ").$(micros).$("ms").$();
}
Aggregations