Skip to content

Commit

Permalink
Fix race in workload generator
Browse files Browse the repository at this point in the history
Signed-off-by: draco <dracode01@gmail.com>
  • Loading branch information
dracoooooo committed Jan 19, 2024
1 parent cb4f8ee commit 6edf43d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/collector/H2/H2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void execSession(Session<Long, Long> session, IsolationLevel isolationLev
}
}
transaction.setSuccess(true);
break;
} catch (SQLException e) {
connection.rollback();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/collector/mysql/MySQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void execSession(Session<Long, Long> session, IsolationLevel isolationLev
}
}
transaction.setSuccess(true);
break;
} catch (SQLException e) {
connection.rollback();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/collector/postgresql/PostgreSQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void execSession(Session<Long, Long> session, IsolationLevel isolationLev
}
}
transaction.setSuccess(true);
break;
} catch (SQLException e) {
connection.rollback();
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/generator/general/GeneralGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.apache.commons.math3.distribution.ZipfDistribution;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -49,7 +49,7 @@ public GeneralGenerator(Properties config) {
@Override
public History<Long, Long> generate() {
var history = new History<Long, Long>();
var counts = new ConcurrentHashMap<Long, Long>();
var counts = new HashMap<Long, Long>();
ExecutorService executor = Executors.newFixedThreadPool((int) this.session);
var todo = new ArrayList<Callable<Void>>();
for (var iSession = 0; iSession < this.session; iSession++) {
Expand All @@ -71,8 +71,10 @@ public History<Long, Long> generate() {
long var = keyDistribution.sample();
long val = 0L;
if (type == Operation.Type.WRITE) {
val = counts.getOrDefault(var, 1L);
counts.put(var, val + 1);
synchronized (counts) {
val = counts.getOrDefault(var, 1L);
counts.put(var, val + 1);
}
}
synchronized (history) {
history.addOperation(history.getTransaction(txnId), type, var, val);
Expand Down

0 comments on commit 6edf43d

Please sign in to comment.