Fix: remove fallback LLM slop-crap
This commit is contained in:
@@ -8,14 +8,11 @@ import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChronicleMapFixture implements DataFixtures {
|
||||
|
||||
private ChronicleMap<Long, byte[]> usersById;
|
||||
private Map<Long, byte[]> fallbackUsersById;
|
||||
private Kryo kryo;
|
||||
|
||||
@Override
|
||||
@@ -24,11 +21,9 @@ public class ChronicleMapFixture implements DataFixtures {
|
||||
kryo.setRegistrationRequired(false);
|
||||
kryo.register(User.class);
|
||||
|
||||
Map<Long, byte[]> encodedUsers = new HashMap<>(users.size());
|
||||
int maxValueSize = 1;
|
||||
for (User user : users) {
|
||||
byte[] encoded = serialize(user);
|
||||
encodedUsers.put(user.getId(), encoded);
|
||||
maxValueSize = Math.max(maxValueSize, encoded.length);
|
||||
}
|
||||
|
||||
@@ -40,19 +35,22 @@ public class ChronicleMapFixture implements DataFixtures {
|
||||
.averageValue(new byte[maxValueSize])
|
||||
.create();
|
||||
|
||||
for (Map.Entry<Long, byte[]> entry : encodedUsers.entrySet()) {
|
||||
usersById.put(entry.getKey(), entry.getValue());
|
||||
for (User user : users) {
|
||||
usersById.put(user.getId(), serialize(user));
|
||||
}
|
||||
fallbackUsersById = null;
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable t) {
|
||||
usersById = null;
|
||||
fallbackUsersById = encodedUsers;
|
||||
throw new IllegalStateException(
|
||||
"ChronicleMap initialization failed. Cause: "
|
||||
+ t.getClass().getSimpleName() + " - " + t.getMessage(),
|
||||
t
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findById(long id) {
|
||||
byte[] encoded = usersById != null ? usersById.get(id) : fallbackUsersById.get(id);
|
||||
byte[] encoded = usersById.get(id);
|
||||
return encoded == null ? null : deserialize(encoded);
|
||||
}
|
||||
|
||||
@@ -61,7 +59,6 @@ public class ChronicleMapFixture implements DataFixtures {
|
||||
if (usersById != null) {
|
||||
usersById.close();
|
||||
}
|
||||
fallbackUsersById = null;
|
||||
}
|
||||
|
||||
private byte[] serialize(User user) {
|
||||
|
||||
@@ -4,17 +4,11 @@ import com.benchmark.model.User;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class IkvStoreFixture implements DataFixtures {
|
||||
|
||||
private static final AtomicBoolean FALLBACK_WARNING_PRINTED = new AtomicBoolean(false);
|
||||
|
||||
private final InMemoryFixture fallback = new InMemoryFixture();
|
||||
|
||||
private Object reader;
|
||||
private Object writer;
|
||||
private boolean useFallback;
|
||||
|
||||
@Override
|
||||
public void setup(List<User> users) throws Exception {
|
||||
@@ -24,10 +18,10 @@ public class IkvStoreFixture implements DataFixtures {
|
||||
String mountDirectory = getenv("IKV_MOUNT_DIRECTORY");
|
||||
|
||||
if (accountId == null || accountPassKey == null || storeName == null || mountDirectory == null) {
|
||||
useFallback = true;
|
||||
fallback.setup(users);
|
||||
printFallbackWarning("IKV fixture: required env vars missing (IKV_ACCOUNT_ID, IKV_ACCOUNT_PASSKEY, IKV_STORE_NAME, IKV_MOUNT_DIRECTORY). Using in-memory fallback.");
|
||||
return;
|
||||
throw new IllegalStateException(
|
||||
"IKV fixture requires IKV_ACCOUNT_ID, IKV_ACCOUNT_PASSKEY, IKV_STORE_NAME, and IKV_MOUNT_DIRECTORY. "
|
||||
+ "Results are invalid without a real IKV backend."
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -80,25 +74,21 @@ public class IkvStoreFixture implements DataFixtures {
|
||||
|
||||
// IKV is eventually consistent for reads. Small delay before measurement starts.
|
||||
Thread.sleep(200);
|
||||
useFallback = false;
|
||||
} catch (Throwable t) {
|
||||
useFallback = true;
|
||||
fallback.setup(users);
|
||||
closeQuietly(reader, "shutdownReader");
|
||||
closeQuietly(writer, "shutdownWriter");
|
||||
reader = null;
|
||||
writer = null;
|
||||
printFallbackWarning("IKV fixture: initialization failed, using in-memory fallback. Cause: "
|
||||
+ t.getClass().getSimpleName() + " - " + t.getMessage());
|
||||
throw new IllegalStateException(
|
||||
"IKV fixture initialization failed. Cause: "
|
||||
+ t.getClass().getSimpleName() + " - " + t.getMessage(),
|
||||
t
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findById(long id) throws Exception {
|
||||
if (useFallback) {
|
||||
return fallback.findById(id);
|
||||
}
|
||||
|
||||
String key = Long.toString(id);
|
||||
String name = (String) reader.getClass().getMethod("getStringValue", String.class, String.class)
|
||||
.invoke(reader, key, "name");
|
||||
@@ -117,11 +107,6 @@ public class IkvStoreFixture implements DataFixtures {
|
||||
|
||||
@Override
|
||||
public void teardown() throws Exception {
|
||||
if (useFallback) {
|
||||
fallback.teardown();
|
||||
return;
|
||||
}
|
||||
|
||||
closeQuietly(reader, "shutdownReader");
|
||||
closeQuietly(writer, "shutdownWriter");
|
||||
reader = null;
|
||||
@@ -143,10 +128,4 @@ public class IkvStoreFixture implements DataFixtures {
|
||||
// Ignore cleanup issues for benchmark fixture shutdown.
|
||||
}
|
||||
}
|
||||
|
||||
private static void printFallbackWarning(String message) {
|
||||
if (FALLBACK_WARNING_PRINTED.compareAndSet(false, true)) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user