Skip to content

Commit

Permalink
Support skip history generation and load elle history
Browse files Browse the repository at this point in the history
Signed-off-by: draco <dracode01@gmail.com>
  • Loading branch information
dracoooooo committed Jan 21, 2024
1 parent 6edf43d commit 5a218a6
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 27 deletions.
61 changes: 36 additions & 25 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import collector.Collector;
import config.Config;
import generator.general.GeneralGenerator;
import history.History;
import util.HistoryLoaderFactory;
import history.serializer.TextHistorySerializer;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -10,10 +12,7 @@
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import util.ConfigParser;
import util.Profiler;
import util.RuntimeDataSerializer;
import util.RuntimeInfoRecorder;
import util.*;

import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -26,8 +25,6 @@
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.function.Function;

@Slf4j
@Command(name = "DBTest", mixinStandardHelpOptions = true, version = "DBTest 0.1", description = "Test database isolation level.")
Expand Down Expand Up @@ -84,27 +81,38 @@ public void run(Properties config) {

var enableProfile = Boolean.parseBoolean(config.getProperty(Config.PROFILER_ENABLE));
var profiler = Profiler.getInstance();
int nHist = Integer.parseInt(config.getProperty(Config.WORKLOAD_HISTORY));
var skipGeneration = Boolean.parseBoolean(config.getProperty(Config.WORKLOAD_SKIP_GENERATION));
int historyNum = 1;
if (!skipGeneration) {
historyNum = Integer.parseInt(config.getProperty(Config.WORKLOAD_HISTORY));
}
int nBatch = 1;
AtomicInteger bugCount = new AtomicInteger();
if (enableProfile) {
profiler.startTick("run_total_time");
}
BiFunction<Integer, Integer, Void> runOneShot = (Integer currentBatch, Integer totalBatch) -> {
TriFunction<Integer, Integer, Integer, Void> runOneShot = (Integer currentBatch, Integer totalBatch, Integer nHist) -> {
for (int i = 1; i <= nHist; i++) {
// generate history
log.info("Start workload generation {} of {}", i + nHist * currentBatch, nHist * totalBatch);
var history = new GeneralGenerator(config).generate();

// collect result
log.info("Start history collection");
try {
var collectorInstance = collector.getDeclaredConstructor(Properties.class).newInstance(config);
history = collectorInstance.collect(history);
collectorInstance.close();
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException e) {
throw new RuntimeException(e);
History history = null;
if (!skipGeneration) {
// generate history
log.info("Start workload generation {} of {}", i + nHist * currentBatch, nHist * totalBatch);
history = new GeneralGenerator(config).generate();

// collect result
log.info("Start history collection");
try {
var collectorInstance = collector.getDeclaredConstructor(Properties.class).newInstance(config);
history = collectorInstance.collect(history);
collectorInstance.close();
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException |
IllegalAccessException e) {
throw new RuntimeException(e);
}
} else {
var historyPath = config.getProperty(Config.HISTORY_PATH).toLowerCase();
var historyType = config.getProperty(Config.HISTORY_TYPE).toLowerCase();
history = HistoryLoaderFactory.getHistoryLoader(historyType).loadHistory(historyPath);
}

// verify history
Expand All @@ -114,6 +122,7 @@ public void run(Properties config) {
}
boolean result;
try {
// TODO: ww edge in elle history?
var checkerInstance = checker.getDeclaredConstructor(Properties.class).newInstance(config);
result = checkerInstance.verify(history);
if (enableProfile) {
Expand All @@ -129,7 +138,9 @@ public void run(Properties config) {
} catch (IOException e) {

}
new TextHistorySerializer().serializeHistory(history, Paths.get(bugDir.toString(), "bug_hist.txt").toString());
if (!skipGeneration) {
new TextHistorySerializer().serializeHistory(history, Paths.get(bugDir.toString(), "bug_hist.txt").toString());
}
checkerInstance.outputDotFile(Paths.get(bugDir.toString(), "conflict.dot").toString());
} else {
log.info("NO BUG");
Expand All @@ -153,14 +164,14 @@ public void run(Properties config) {
var value = valueList[i];
config.setProperty(variable, value);
log.info("Run one shot {} = {}", variable, value);
runOneShot.apply(i, nBatch);
runOneShot.apply(i, nBatch, historyNum);
var avgTime = profiler.getAvgTime(checker.getName());
var maxMemory = profiler.getMemory(checker.getName());
Profiler.appendToCSV(value, avgTime, maxMemory);
profiler.removeTag(checker.getName());
}
} else {
runOneShot.apply(0, nBatch);
runOneShot.apply(0, nBatch, historyNum);
}

if (enableProfile) {
Expand All @@ -181,7 +192,7 @@ public void run(Properties config) {

// output to the specific dir
var outputPath = config.getProperty(Config.OUTPUT_PATH, Config.DEFAULT_OUTPUT_PATH);
RuntimeDataSerializer.getInstance(outputPath).outputToPath(nHist * nBatch, bugCount.get(), config, enableProfile);
RuntimeDataSerializer.getInstance(outputPath).outputToPath(historyNum * nBatch, bugCount.get(), config, enableProfile);
}

@SneakyThrows
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/checker/PolySI/PolySI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import history.History;
import util.Profiler;

import java.nio.file.Paths;
import java.util.Properties;

public class PolySI<VarType, ValType> implements Checker<VarType, ValType> {
Expand All @@ -25,14 +24,21 @@ public class PolySI<VarType, ValType> implements Checker<VarType, ValType> {
public static final String NAME = "PolySI";
public static IsolationLevel ISOLATION_LEVEL;

private final Properties config;

public PolySI(Properties config) {
this.config = config;
ISOLATION_LEVEL = IsolationLevel.valueOf(config.getProperty(Config.CHECKER_ISOLATION));
assert ISOLATION_LEVEL == IsolationLevel.SNAPSHOT_ISOLATION;
}

@Override
public boolean verify(History<VarType, ValType> history) {
history.addInitSession();
if (config.getProperty(Config.HISTORY_TYPE).equals("elle")) {
history.addInitSessionElle();
} else {
history.addInitSession();
}
Pruning.setEnablePruning(!noPruning);
SIVerifier.setCoalesceConstraints(!noCoalescing);

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class Config {
public static final String WORKLOAD_KEY = "workload.key";
public static final String WORKLOAD_DISTRIBUTION = "workload.distribution";
public static final String WORKLOAD_VARIABLE = "workload.variable";
public static final String WORKLOAD_SKIP_GENERATION = "workload.skipgeneration";

// user history configs
public static final String HISTORY_PATH = "history.path";
public static final String HISTORY_TYPE = "history.type";

// checker configs
public static final String CHECKER_ISOLATION = "checker.isolation";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/exceptions/NotImplementedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package exceptions;

public class NotImplementedException extends RuntimeException {
}
10 changes: 10 additions & 0 deletions src/main/java/history/History.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package history;

import history.loader.ElleHistoryLoader;
import javafx.util.Pair;
import lombok.Data;

Expand Down Expand Up @@ -78,6 +79,15 @@ public void addInitSession() {
initTransaction.setSuccess(true);
}

public void addInitSessionElle() {
Session<KeyType, ValType> initSession = addSession(-1);
Transaction<KeyType, ValType> initTransaction = addTransaction(initSession, -1);
for (var i : keySet) {
addOperation(initTransaction, Operation.Type.WRITE, i, (ValType) new ElleHistoryLoader.ElleValue(null, null));
}
initTransaction.setSuccess(true);
}

public void removeInitSession() {
sessions.remove(-1L);
}
Expand Down
Loading

0 comments on commit 5a218a6

Please sign in to comment.