Fix kExists

This commit is contained in:
Andrea Cavalli 2022-02-11 12:19:32 +01:00
parent 5ebc9abe43
commit f9335d890f
2 changed files with 8 additions and 27 deletions

View File

@ -3,24 +3,16 @@ package it.cavallium.dbengine.database.disk;
import static io.net5.buffer.api.StandardAllocationTypes.OFF_HEAP; import static io.net5.buffer.api.StandardAllocationTypes.OFF_HEAP;
import static it.cavallium.dbengine.database.LLUtils.INITIAL_DIRECT_READ_BYTE_BUF_SIZE_BYTES; import static it.cavallium.dbengine.database.LLUtils.INITIAL_DIRECT_READ_BYTE_BUF_SIZE_BYTES;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.rocksdb.KeyMayExist.KeyMayExistEnum.kExistsWithValue;
import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import io.net5.buffer.api.AllocationType;
import io.net5.buffer.api.AllocatorControl;
import io.net5.buffer.api.Buffer; import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.BufferAllocator; import io.net5.buffer.api.BufferAllocator;
import io.net5.buffer.api.CompositeBuffer;
import io.net5.buffer.api.MemoryManager;
import io.net5.buffer.api.Send;
import io.net5.buffer.api.StandardAllocationTypes;
import io.net5.buffer.api.WritableComponent; import io.net5.buffer.api.WritableComponent;
import io.net5.buffer.api.internal.Statics;
import io.net5.buffer.api.unsafe.UnsafeMemoryManager;
import io.net5.util.internal.PlatformDependent; import io.net5.util.internal.PlatformDependent;
import it.cavallium.dbengine.client.DatabaseOptions; import it.cavallium.dbengine.client.DatabaseOptions;
import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.LLUtils.DirectBuffer;
import it.cavallium.dbengine.database.RepeatedElementList; import it.cavallium.dbengine.database.RepeatedElementList;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.List; import java.util.List;
@ -31,9 +23,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.rocksdb.ColumnFamilyHandle; import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.CompactRangeOptions; import org.rocksdb.CompactRangeOptions;
import org.rocksdb.FileOperationInfo;
import org.rocksdb.FlushOptions; import org.rocksdb.FlushOptions;
import org.rocksdb.Holder; import org.rocksdb.Holder;
import org.rocksdb.KeyMayExist.KeyMayExistEnum;
import org.rocksdb.KeyMayExistWorkaround; import org.rocksdb.KeyMayExistWorkaround;
import org.rocksdb.ReadOptions; import org.rocksdb.ReadOptions;
import org.rocksdb.RocksDB; import org.rocksdb.RocksDB;
@ -43,7 +35,6 @@ import org.rocksdb.Transaction;
import org.rocksdb.WriteBatch; import org.rocksdb.WriteBatch;
import org.rocksdb.WriteOptions; import org.rocksdb.WriteOptions;
import reactor.core.scheduler.Schedulers; import reactor.core.scheduler.Schedulers;
import sun.misc.Unsafe;
public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements RocksDBColumn public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements RocksDBColumn
permits StandardRocksDBColumn, OptimisticRocksDBColumn, PessimisticRocksDBColumn { permits StandardRocksDBColumn, OptimisticRocksDBColumn, PessimisticRocksDBColumn {
@ -129,18 +120,16 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
var resultWritable = ((WritableComponent) resultBuffer).writableBuffer(); var resultWritable = ((WritableComponent) resultBuffer).writableBuffer();
var keyMayExist = db.keyMayExist(cfh, readOptions, keyNioBuffer.rewind(), resultWritable.clear()); var keyMayExist = db.keyMayExist(cfh, readOptions, keyNioBuffer.rewind(), resultWritable.clear());
var keyMayExistState = KeyMayExistWorkaround.getExistenceState(keyMayExist); KeyMayExistEnum keyMayExistState = keyMayExist.exists;
int keyMayExistValueLength = KeyMayExistWorkaround.getValueLength(keyMayExist); int keyMayExistValueLength = keyMayExist.valueLength;
// At the beginning, size reflects the expected size, then it becomes the real data size // At the beginning, size reflects the expected size, then it becomes the real data size
int size = keyMayExistState == 2 ? keyMayExistValueLength : -1; int size = keyMayExistState == kExistsWithValue ? keyMayExistValueLength : -1;
switch (keyMayExistState) { switch (keyMayExistState) {
// kNotExist case kNotExist: {
case 0: {
resultBuffer.close(); resultBuffer.close();
return null; return null;
} }
// kExistsWithoutValue case kExistsWithoutValue: {
case 1: {
assert keyMayExistValueLength == 0; assert keyMayExistValueLength == 0;
resultWritable.clear(); resultWritable.clear();
// real data size // real data size
@ -150,8 +139,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
return null; return null;
} }
} }
// kExistsWithValue case kExistsWithValue: {
case 2: {
// real data size // real data size
this.lastDataSizeMetric.set(size); this.lastDataSizeMetric.set(size);
assert size >= 0; assert size >= 0;

View File

@ -2,13 +2,6 @@ package org.rocksdb;
public class KeyMayExistWorkaround { public class KeyMayExistWorkaround {
/**
* @return real value length
*/
public static int getValueLength(KeyMayExist keyMayExist) {
return keyMayExist.valueLength;
}
/** /**
* 0 = not exists * 0 = not exists
* *