Skip to content

Commit 29ce61a

Browse files
authored
Ensure that there's always at least one record in the Epinions trust table (#281)
Fixes #273
1 parent 05f9865 commit 29ce61a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/main/java/com/oltpbenchmark/benchmarks/epinions/EpinionsLoader.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,15 @@ public void afterLoad() {
108108
final int lo = i * loadPerThread;
109109
final int hi = Math.min(this.num_users, (i + 1) * loadPerThread);
110110

111+
// To ensure that we don't wind up with an empty trust table for
112+
// small scales we have the first loader thread ensure that at
113+
// least a single trust record is inserted.
114+
final boolean firstLoader = (i == 0);
115+
111116
threads.add(new LoaderThread(this.benchmark) {
112117
@Override
113118
public void load(Connection conn) throws SQLException {
114-
loadTrust(conn, lo, hi);
119+
loadTrust(conn, lo, hi, firstLoader);
115120
}
116121

117122
@Override
@@ -309,7 +314,7 @@ private void loadReviews(Connection conn, int lo, int hi) throws SQLException {
309314
* Zipfian distribution Trusted users are not correlated to heavy
310315
* reviewers (drawn using a scrambled distribution)
311316
*/
312-
public void loadTrust(Connection conn, int lo, int hi) throws SQLException {
317+
public void loadTrust(Connection conn, int lo, int hi, boolean firstLoader) throws SQLException {
313318
Table catalog_tbl = this.benchmark.getCatalog().getTable("trust");
314319
String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType());
315320

@@ -324,6 +329,12 @@ public void loadTrust(Connection conn, int lo, int hi) throws SQLException {
324329
for (int i = lo; i < hi; i++) {
325330
long timestamp = System.currentTimeMillis();
326331
int trust_count = numTrust.nextInt();
332+
// To avoid having an empty trust table during small scale
333+
// tests, we make sure that at least one trust record is
334+
// inserted to the table.
335+
if (firstLoader && i == lo) {
336+
trust_count = Math.max(trust_count, 1);
337+
}
327338
for (int tc = 0; tc < trust_count; ) {
328339
int u_id = reviewed.nextInt();
329340
if (!trusted.contains(u_id)) {

0 commit comments

Comments
 (0)