Fix compatibility
This commit is contained in:
parent
92bb13336d
commit
1bd1cb87de
@ -4,13 +4,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class Column {
|
||||
|
||||
private final String name;
|
||||
|
||||
private Column(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public record Column(String name) {
|
||||
|
||||
public static Column dictionary(String name) {
|
||||
return new Column("hash_map_" + name);
|
||||
@ -28,32 +22,4 @@ public class Column {
|
||||
public static String toString(byte[] name) {
|
||||
return new String(name, StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Column)) {
|
||||
return false;
|
||||
}
|
||||
Column column = (Column) o;
|
||||
return Objects.equals(name, column.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", Column.class.getSimpleName() + "[", "]")
|
||||
.add("name='" + name + "'")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import it.cavallium.dbengine.lucene.analyzer.TextFieldsAnalyzer;
|
||||
import it.cavallium.dbengine.lucene.analyzer.TextFieldsSimilarity;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
@ -16,7 +17,11 @@ public interface LLDatabaseConnection {
|
||||
|
||||
Mono<? extends LLDatabaseConnection> connect();
|
||||
|
||||
Mono<? extends LLKeyValueDatabase> getDatabase(String name, List<Column> columns, boolean lowMemory, boolean inMemory);
|
||||
Mono<? extends LLKeyValueDatabase> getDatabase(String name,
|
||||
List<Column> columns,
|
||||
Map<String, String> extraFlags,
|
||||
boolean lowMemory,
|
||||
boolean inMemory);
|
||||
|
||||
Mono<? extends LLLuceneIndex> getLuceneIndex(String name,
|
||||
int instancesCount,
|
||||
|
@ -16,16 +16,16 @@ public interface LLKeyValueDatabase extends LLSnapshottable, LLKeyValueDatabaseS
|
||||
|
||||
@Deprecated
|
||||
default Mono<? extends LLDictionary> getDeprecatedSet(String name, UpdateMode updateMode) {
|
||||
return getDictionary(Column.deprecatedSet(name).getName().getBytes(StandardCharsets.US_ASCII), updateMode);
|
||||
return getDictionary(Column.deprecatedSet(name).name().getBytes(StandardCharsets.US_ASCII), updateMode);
|
||||
}
|
||||
|
||||
default Mono<? extends LLDictionary> getDictionary(String name, UpdateMode updateMode) {
|
||||
return getDictionary(Column.dictionary(name).getName().getBytes(StandardCharsets.US_ASCII), updateMode);
|
||||
return getDictionary(Column.dictionary(name).name().getBytes(StandardCharsets.US_ASCII), updateMode);
|
||||
}
|
||||
|
||||
default Mono<DatabaseInt> getInteger(String singletonListName, String name, int defaultValue) {
|
||||
return this
|
||||
.getSingleton(Column.special(singletonListName).getName().getBytes(StandardCharsets.US_ASCII),
|
||||
.getSingleton(Column.special(singletonListName).name().getBytes(StandardCharsets.US_ASCII),
|
||||
name.getBytes(StandardCharsets.US_ASCII),
|
||||
Ints.toByteArray(defaultValue)
|
||||
)
|
||||
@ -34,7 +34,7 @@ public interface LLKeyValueDatabase extends LLSnapshottable, LLKeyValueDatabaseS
|
||||
|
||||
default Mono<DatabaseLong> getLong(String singletonListName, String name, long defaultValue) {
|
||||
return this
|
||||
.getSingleton(Column.special(singletonListName).getName().getBytes(StandardCharsets.US_ASCII),
|
||||
.getSingleton(Column.special(singletonListName).name().getBytes(StandardCharsets.US_ASCII),
|
||||
name.getBytes(StandardCharsets.US_ASCII),
|
||||
Longs.toByteArray(defaultValue)
|
||||
)
|
||||
|
@ -14,6 +14,7 @@ import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
@ -53,6 +54,7 @@ public class LLLocalDatabaseConnection implements LLDatabaseConnection {
|
||||
@Override
|
||||
public Mono<LLLocalKeyValueDatabase> getDatabase(String name,
|
||||
List<Column> columns,
|
||||
Map<String, String> extraFlags,
|
||||
boolean lowMemory,
|
||||
boolean inMemory) {
|
||||
return Mono
|
||||
@ -62,6 +64,7 @@ public class LLLocalDatabaseConnection implements LLDatabaseConnection {
|
||||
basePath.resolve("database_" + name),
|
||||
columns,
|
||||
new LinkedList<>(),
|
||||
extraFlags,
|
||||
crashIfWalError,
|
||||
lowMemory,
|
||||
inMemory
|
||||
|
@ -20,6 +20,7 @@ import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -66,6 +67,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
private final Path dbPath;
|
||||
private final boolean inMemory;
|
||||
private final String name;
|
||||
private final boolean enableColumnsBug;
|
||||
private RocksDB db;
|
||||
private final Map<Column, ColumnFamilyHandle> handles;
|
||||
private final ConcurrentHashMap<Long, Snapshot> snapshotsHandles = new ConcurrentHashMap<>();
|
||||
@ -76,6 +78,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
Path path,
|
||||
List<Column> columns,
|
||||
List<ColumnFamilyHandle> handles,
|
||||
Map<String, String> extraFlags,
|
||||
boolean crashIfWalError,
|
||||
boolean lowMemory,
|
||||
boolean inMemory) throws IOException {
|
||||
@ -87,7 +90,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||
for (Column column : columns) {
|
||||
descriptors
|
||||
.add(new ColumnFamilyDescriptor(column.getName().getBytes(StandardCharsets.US_ASCII)));
|
||||
.add(new ColumnFamilyDescriptor(column.name().getBytes(StandardCharsets.US_ASCII)));
|
||||
}
|
||||
|
||||
// Get databases directory path
|
||||
@ -105,6 +108,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
60,
|
||||
true
|
||||
);
|
||||
this.enableColumnsBug = "true".equals(extraFlags.getOrDefault("enableColumnBug", "false"));
|
||||
|
||||
createIfNotExists(descriptors, options, inMemory, this.dbPath, dbPathString);
|
||||
|
||||
@ -119,8 +123,19 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
);
|
||||
createInMemoryColumns(descriptors, inMemory, handles);
|
||||
this.handles = new HashMap<>();
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
this.handles.put(columns.get(i), handles.get(i));
|
||||
if (enableColumnsBug) {
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
this.handles.put(columns.get(i), handles.get(i));
|
||||
}
|
||||
} else {
|
||||
handles: for (ColumnFamilyHandle handle : handles) {
|
||||
for (Column column : columns) {
|
||||
if (Arrays.equals(column.name().getBytes(StandardCharsets.US_ASCII), handle.getName())) {
|
||||
this.handles.put(column, handle);
|
||||
continue handles;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// compactDb(db, handles);
|
||||
@ -398,7 +413,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
public Mono<LLLocalSingleton> getSingleton(byte[] singletonListColumnName, byte[] name, byte[] defaultValue) {
|
||||
return Mono
|
||||
.fromCallable(() -> new LLLocalSingleton(db,
|
||||
handles.get(Column.special(Column.toString(singletonListColumnName))),
|
||||
getCfh(singletonListColumnName),
|
||||
(snapshot) -> snapshotsHandles.get(snapshot.getSequenceNumber()),
|
||||
LLLocalKeyValueDatabase.this.name,
|
||||
name,
|
||||
@ -412,19 +427,29 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
@Override
|
||||
public Mono<LLLocalDictionary> getDictionary(byte[] columnName, UpdateMode updateMode) {
|
||||
return Mono
|
||||
.fromCallable(() -> new LLLocalDictionary(
|
||||
allocator,
|
||||
db,
|
||||
handles.get(Column.special(Column.toString(columnName))),
|
||||
name,
|
||||
Column.toString(columnName),
|
||||
dbScheduler,
|
||||
(snapshot) -> snapshotsHandles.get(snapshot.getSequenceNumber()),
|
||||
updateMode
|
||||
))
|
||||
.fromCallable(() -> {
|
||||
return new LLLocalDictionary(
|
||||
allocator,
|
||||
db,
|
||||
getCfh(columnName),
|
||||
name,
|
||||
Column.toString(columnName),
|
||||
dbScheduler,
|
||||
(snapshot) -> snapshotsHandles.get(snapshot.getSequenceNumber()),
|
||||
updateMode
|
||||
);
|
||||
})
|
||||
.subscribeOn(dbScheduler);
|
||||
}
|
||||
|
||||
private ColumnFamilyHandle getCfh(byte[] columnName) throws RocksDBException {
|
||||
ColumnFamilyHandle cfh = handles.get(Column.special(Column.toString(columnName)));
|
||||
if (!enableColumnsBug) {
|
||||
assert Arrays.equals(cfh.getName(), columnName);
|
||||
}
|
||||
return cfh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Long> getProperty(String propertyName) {
|
||||
return Mono.fromCallable(() -> db.getAggregatedLongProperty(propertyName))
|
||||
|
@ -57,7 +57,7 @@ public class DbTestUtils {
|
||||
.then(new LLLocalDatabaseConnection(DbTestUtils.ALLOCATOR, wrkspcPath, true).connect())
|
||||
.flatMap(conn -> conn.getDatabase("testdb",
|
||||
List.of(Column.dictionary("testmap"), Column.special("ints"), Column.special("longs")),
|
||||
false, true
|
||||
Map.of(), false, true
|
||||
)),
|
||||
action,
|
||||
db -> db.close().then(Mono.fromCallable(() -> {
|
||||
|
@ -132,7 +132,7 @@ public class OldDatabaseTests {
|
||||
})
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.then(new LLLocalDatabaseConnection(PooledByteBufAllocator.DEFAULT, wrkspcPath, true).connect())
|
||||
.flatMap(conn -> conn.getDatabase("testdb", List.of(Column.dictionary("testmap")), false, true));
|
||||
.flatMap(conn -> conn.getDatabase("testdb", List.of(Column.dictionary("testmap")), Map.of(), false, true));
|
||||
}
|
||||
|
||||
private static final ByteBuf DUMMY_VALUE;
|
||||
|
Loading…
Reference in New Issue
Block a user