Fix error printing, stable column names

This commit is contained in:
Andrea Cavalli 2024-10-24 02:07:12 +02:00
parent 8fa0a94b62
commit 16f8b8e43f
2 changed files with 55 additions and 42 deletions

View File

@ -176,9 +176,18 @@ public class EmbeddedDB implements RocksDBSyncAPI, Closeable {
* Do not try to register a column that may already be registered
*/
private long registerColumn(@NotNull ColumnInstance column) {
synchronized (columnEditLock) {
try {
var columnName = new String(column.cfh().getName(), StandardCharsets.UTF_8);
long id = FastRandomUtils.allocateNewValue(this.columns, column, 1, Long.MAX_VALUE);
long hashCode = columnName.hashCode();
long id;
if (this.columnNamesIndex.get(columnName) == hashCode) {
id = hashCode;
} else if (this.columns.get(hashCode) == null) {
id = hashCode;
} else {
id = FastRandomUtils.allocateNewValue(this.columns, column, 1, Long.MAX_VALUE);
}
Long previous = this.columnNamesIndex.putIfAbsent(columnName, id);
if (previous != null) {
//noinspection resource
@ -191,12 +200,14 @@ public class EmbeddedDB implements RocksDBSyncAPI, Closeable {
throw new RuntimeException(e);
}
}
}
/**
* The column must be unregistered once!!!
* Do not try to unregister a column that may already be unregistered, or that may not be registered
*/
private ColumnInstance unregisterColumn(long id) {
synchronized (columnEditLock) {
var col = this.columns.remove(id);
Objects.requireNonNull(col, () -> "Column does not exist: " + id);
String name;
@ -227,6 +238,7 @@ public class EmbeddedDB implements RocksDBSyncAPI, Closeable {
return col;
}
}
@Override
public void close() throws IOException {

View File

@ -542,8 +542,9 @@ public class GrpcServer extends Server {
private <T> Function<Flux<T>, Flux<T>> onErrorMapFluxWithRequestInfo(String requestName, Message request) {
return flux -> flux.onErrorResume(throwable -> {
var ex = handleError(throwable).asException();
if (ex.getStatus().getCode() == Code.INTERNAL) {
LOG.error("Unexpected internal error during request: {}", request, ex);
if (ex.getStatus().getCode() == Code.INTERNAL && !(throwable instanceof RocksDBException)) {
LOG.error("Unexpected internal error during request \"{}\": {}", requestName, request.toString(), ex);
return Mono.error(RocksDBException.of(RocksDBErrorType.INTERNAL_ERROR, ex.getCause()));
}
return Mono.error(ex);
});
@ -552,7 +553,7 @@ public class GrpcServer extends Server {
private <T> Function<Mono<T>, Mono<T>> onErrorMapMonoWithRequestInfo(String requestName, Message request) {
return flux -> flux.onErrorResume(throwable -> {
var ex = handleError(throwable).asException();
if (ex.getStatus().getCode() == Code.INTERNAL) {
if (ex.getStatus().getCode() == Code.INTERNAL && !(throwable instanceof RocksDBException)) {
LOG.error("Unexpected internal error during request \"{}\": {}", requestName, request.toString(), ex);
return Mono.error(RocksDBException.of(RocksDBErrorType.INTERNAL_ERROR, ex.getCause()));
}