Details
-
New Feature
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
0.1
-
None
-
None
Description
We made changes to the driver to support using other databases besides MySQL
(namely PostgreSQL) and we found that some of the logic in the loader implictly
relies on MySQL as a backend. The patch has been tested to work on PostgreSQL
8.4 as well as MySQL 5. It also includes the counter_cache method submitted
earlier.
The patch can be downloaded here: http://www.eecs.berkeley.edu/~rean/olio-
workload-20090811.patch and it's also pasted at the bottom of this ticket
(which method is preferred link or paste?)
Overview:
- The columns are now populated with the proper data types (MySQL JDBC
implicity converted String data into the column data type, e.g. String data
would automatically be converted into Float data when used to populate a Float
column). - Clearing tables is now handled differently.
- Instead of getClearStatement(), there is a clear() method.
- Ensures compatibility with databases that do not automatically reset
the auto-increment (e.g. Postgres). - First attempts to empty the table with RESTART IDENTITY.
- If *RESTART IDENTITY *is not supported, attempt without it.
- Refactored some code and cleaned up spacing and formatting.
- Added an extra log message for BatchUpdateExceptions (for convenience
when debugging a failed run). - All functionality should still be same (i.e. no regression).
— Patch starts here —
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Address.java
workload-mod/src/org/apache/olio/workload/loader/Address.java
— workload/src/org/apache/olio/workload/loader/Address.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Address.java
2009-07-01 17:59:55.000000000 -0700
@@ -40,31 +40,42 @@
public static final String[] STREETEXTS =
;
static Logger logger = Logger.getLogger(Address.class.getName());
- String[] fields = new String[8];
+ String[] fields = new String[6];
+ Float[] ffields = new Float[2];
- public String getClearStatement() {
- return "truncate table addresses";
+ public void clear() throws SQLExceptionUnknown macro: {+ ThreadConnection c = ThreadConnection.getInstance();+ try { + c.prepareStatement("truncate table addresses restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table addresses"); + c.executeUpdate(); + } }
public void prepare() {
ThreadResource tr = ThreadResource.getInstance();
Random r = tr.getRandom();
StringBuilder buffer = tr.getBuffer();
- buffer.append(r.makeNString(1, 5)).append(' '); // number
- RandomUtil.randomName(r, buffer, 1, 11); // street
+
+ buffer.append(r.makeNString(1, 5)).append(' '); // street1 (number)
+ RandomUtil.randomName(r, buffer, 1, 11); // street1 (name)
String streetExt = STREETEXTS[r.random(0, STREETEXTS.length - 1)]; - if (streetExt.length() > 0)
+ if (streetExt.length() > 0) { buffer.append(' ').append(streetExt); + }
- fields[0] = buffer.toString();
+ fields[0] = buffer.toString(); // street1
- int toggle = r.random(0, 1); // street2
- if (toggle > 0)
+ int toggle = r.random(0, 1); // street2
+ if (toggle > 0) { fields[1] = r.makeCString(5, 20); + }
- fields[2] = r.makeCString(4, 14); // city
- fields[3] = r.makeCString(2, 2).toUpperCase(); // state
- fields[4] = r.makeNString(5, 5); // zip
+ fields[2] = r.makeCString(4, 14); // city
+ fields[3] = r.makeCString(2, 2).toUpperCase(); // state
+ fields[4] = r.makeNString(5, 5); // zip
toggle = r.random(0, 1);
if (toggle == 0)
- // Latitude, we do not get addresses in polar circles. So the limit
- fields[6] = String.format("%.6f", r.drandom(-66.560556d, 66.560556d));
- - fields[7] = String.format("%.6f", r.drandom(-179.999999d, 180d));
+
+ // Latitude & Longitude. We do not get addresses in polar circles,
hence the limit.
+ ffields[0] = new Float(String.format("%.6f", r.drandom(-66.560556d,
66.560556d)));
+ ffields[1] = new Float(String.format("%.6f", r.drandom(-179.999999d,
180d)));
}
public void load() {
@@ -84,12 +95,15 @@
try {
PreparedStatement s = c.prepareStatement(STATEMENT);
int i;
- for (i = 0; i < fields.length; i++)
- {
- if (fields[i] != null)
+ for (i = 0; i < fields.length; i++)Unknown macro: {+ if (fields[i] != null) { s.setString(i + 1, fields[i]); - else + } else { s.setNull(i + 1, Types.VARCHAR); + }
+ }
+ for (i = 0; i < ffields.length; i++) { + s.setFloat(7 + i, ffields[i]); }
c.addBatch();
} catch (SQLException e) {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Attendees.java
workload-mod/src/org/apache/olio/workload/loader/Attendees.java
— workload/src/org/apache/olio/workload/loader/Attendees.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Attendees.java
2009-07-01 18:00:22.000000000 -0700
@@ -46,8 +46,15 @@
int eventId;
LinkedHashSet<Integer> userIdSet;
- public String getClearStatement() {
- return "truncate table events_users";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table events_users restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table events_users"); + c.executeUpdate(); + }
}
public void prepare() {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Comments.java
workload-mod/src/org/apache/olio/workload/loader/Comments.java
— workload/src/org/apache/olio/workload/loader/Comments.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Comments.java
2009-07-01 18:00:46.000000000 -0700
@@ -49,9 +49,15 @@
int[] ratings;
Date createdTimestamp;
-
- public String getClearStatement() {
- return "truncate table comments";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table comments restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table comments"); + c.executeUpdate(); + }
}
public void prepare() {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Documents.java
workload-mod/src/org/apache/olio/workload/loader/Documents.java
— workload/src/org/apache/olio/workload/loader/Documents.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Documents.java
2009-07-01 18:01:04.000000000 -0700
@@ -44,8 +44,15 @@
int eventId;
- public String getClearStatement() {
- return "truncate table documents";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table documents restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table documents"); + c.executeUpdate(); + }
}
public void prepare() { @@ -53,7 +60,6 @@ ++eventId; }
-
public void load() {
ThreadConnection c = ThreadConnection.getInstance();
try {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/EventImages.java
workload-mod/src/org/apache/olio/workload/loader/EventImages.java
— workload/src/org/apache/olio/workload/loader/EventImages.java
2009-08-11 11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/EventImages.java
2009-07-01 18:01:16.000000000 -0700
@@ -20,9 +20,8 @@
public class EventImages extends Images {
public void prepare() { - imageId = getSequence(); - ++imageId; - imageKey = imageId; - prefix = "e"; + imageId = getSequence(); + ++imageId; + prefix = "e"; }
}
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/EventTag.java
workload-mod/src/org/apache/olio/workload/loader/EventTag.java
— workload/src/org/apache/olio/workload/loader/EventTag.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/EventTag.java
2009-07-01 18:01:29.000000000 -0700
@@ -47,26 +47,36 @@
int eventId;
int [] tagIds;
- public String getClearStatement() {
- return "truncate table taggings";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table taggings restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table taggings"); + c.executeUpdate(); + }
}
public void prepare() {
eventId = getSequence() + 1;
+
ThreadResource tr = ThreadResource.getInstance();
Random r = tr.getRandom();
- int numTags = r.random(1, 7); // Avg is 4 tags per event
+ int numTags = r.random(1, 7); // Average is 4 tags per event.
LinkedHashSet<Integer> tagSet = new LinkedHashSet<Integer>(numTags);
- for (int i = 0; i < numTags; i++)
+
+ for (int i = 0; i < numTags; i++) { while (!tagSet.add(RandomUtil.randomTagId(r, 0.1d))); + }
tagIds = new int[tagSet.size()];
int idx = 0;
- for (int tagId : tagSet)
+ for (int tagId : tagSet) { tagIds[idx++] = tagId; + }
}
-
public void load() {
ThreadConnection c = ThreadConnection.getInstance();
try {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Friends.java
workload-mod/src/org/apache/olio/workload/loader/Friends.java
— workload/src/org/apache/olio/workload/loader/Friends.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Friends.java
2009-07-01 18:01:46.000000000 -0700
@@ -38,15 +38,22 @@
// We use on average of 15 friends. Random 2..28 Friends.
private static final String STATEMENT = "insert into invites " +
- "(user_id, user_id_target, is_accepted) values (?, ?, 1)";
+ "(user_id, user_id_target, is_accepted) values (?, ?, TRUE)";
static Logger logger = Logger.getLogger(Friends.class.getName());
int id;
int[] friends;
- public String getClearStatement() {
- return "truncate table invites";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table invites restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table invites"); + c.executeUpdate(); + }
}
public void prepare() {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Images.java
workload-mod/src/org/apache/olio/workload/loader/Images.java
— workload/src/org/apache/olio/workload/loader/Images.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Images.java
2009-07-01 18:02:08.000000000 -0700
@@ -42,16 +42,22 @@
static Logger logger = Logger.getLogger(Comments.class.getName());
- int imageKey, imageId;
+ int imageId;
String prefix;
- public String getClearStatement() {
- return "truncate table images";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table images restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table images"); + c.executeUpdate(); + }
}
public abstract void prepare();
-
public void load() {
ThreadConnection c = ThreadConnection.getInstance();
try { @@ -62,7 +68,7 @@ s.setInt(4, 1280); s.setInt(5, 960); s.setString(6, prefix + imageId + "t.jpg"); - s.setInt(7, this.imageKey); + s.setInt(7, this.imageId); c.addBatch(); } catch (SQLException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Person.java
workload-mod/src/org/apache/olio/workload/loader/Person.java
— workload/src/org/apache/olio/workload/loader/Person.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Person.java
2009-07-01 18:02:29.000000000 -0700
@@ -47,9 +47,15 @@
String[] fields = new String[10];
int addressId, thumbnail, imageId;
-
- public String getClearStatement() {
- return "truncate table users";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table users restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table users"); + c.executeUpdate(); + }
}
public void prepare() {
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/
PersonImages.java workload-mod/src/org/apache/olio/workload/loader/
PersonImages.java
— workload/src/org/apache/olio/workload/loader/PersonImages.java
2009-08-11 11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/PersonImages.java
2009-07-01 18:02:34.000000000 -0700
@@ -23,10 +23,9 @@
public class PersonImages extends Images {
public void prepare() { - int i = getSequence(); - ++i; - imageId = i; - imageKey = ScaleFactors.events + i; - prefix = "p"; + int i = getSequence(); + ++i; + imageId = ScaleFactors.events + i; + prefix = "p"; }
}
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/SocialEvent.java
workload-mod/src/org/apache/olio/workload/loader/SocialEvent.java
— workload/src/org/apache/olio/workload/loader/SocialEvent.java
2009-08-11 11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/SocialEvent.java
2009-07-01 18:02:55.000000000 -0700
@@ -29,6 +29,7 @@
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.sql.Types;
import java.text.DateFormat;
import java.util.logging.Level;
@@ -43,69 +44,86 @@
private static final String STATEMENT = "insert into events " +
"(title, description, telephone, " +
- "event_timestamp, event_date, summary, created_at, address_id, " +
- "total_score, num_votes, disabled, user_id, image_id, document_id)
" +
- "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "summary, event_timestamp, event_date, created_at, address_id, " +
+ "total_score, num_votes, user_id, image_id, document_id, disabled)
" +
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TRUE)";
- private static final String[] EVT_MINUTES = { "00", "15", "30", "45" };
+ private static final Integer[] EVT_MINUTES = { 0, 15, 30, 45 };
static Logger logger = Logger.getLogger(SocialEvent.class.getName());
int id;
- String[] fields = new String[6];
- Date createdTimestamp;
- int[] ifields = new int[7];
+ String[] fields = new String[4];
+ Timestamp dTime;
+ Date[] dfields = new Date[2];
+ int[] ifields = new int[6];
-
- public String getClearStatement() {
- return "truncate table events";
+ public void clear() throws SQLException {
+ ThreadConnection c = ThreadConnection.getInstance();
+ try { + c.prepareStatement("truncate table events restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table events"); + c.executeUpdate(); + }
}
public void prepare() { id = getSequence() + 1; + ThreadResource tr = ThreadResource.getInstance(); Random r = tr.getRandom(); StringBuilder buffer = tr.getBuffer(); - fields[0] = RandomUtil.randomText(r, 20, 100); //title + + fields[0] = RandomUtil.randomText(r, 20, 100); // title fields[1] = RandomUtil.randomText(r, 1024, 4096); // description - fields[2] = RandomUtil.randomPhone(r, buffer); //phone - DateFormat dateFormat = tr.getDateFormat(); // eventtimestamp - String eventDate = dateFormat.format( - r.makeDateInInterval(BASE_DATE, 0, 540)); - - int eventHr = r.random(7, 21); - String eventMin = EVT_MINUTES[r.random(0, 3)]; // eventtimestamp - fields[3] = String.format("%s %02d:%s:00", - eventDate, eventHr, eventMin); - fields[4] = eventDate; // eventdate - fields[5] = RandomUtil.randomText(r, 500, 1024); // summary + fields[2] = RandomUtil.randomPhone(r, buffer); // telephone + fields[3] = RandomUtil.randomText(r, 500, 1024); // summary - createdTimestamp = r.makeDateInInterval( //createdtimestamp - BASE_DATE, -540, 0); + // DateFormat dateFormat = tr.getDateFormat(); + // String eventDate = dateFormat.format(r.makeDateInInterval (BASE_DATE, 0, 540)); + // int eventHr = r.random(7, 21); + // String eventMin = EVT_MINUTES[r.random(0, 3)]; + // fields[3] = String.format("%s %02d:%s:00", eventDate, eventHr, eventMin); + + Date eventDate = r.makeDateInInterval(BASE_DATE, 0, 540); + long eventHour = r.random(7, 21); + long eventMins = EVT_MINUTES[r.random(0, 3)]; + long eventTime = eventDate.getTime() + (eventHour * 60 + eventMins) * 3600; + + dTime = new Timestamp(eventTime); // event_timestamp + dfields[0] = eventDate; // event_date + dfields[1] = r.makeDateInInterval( // created_at + BASE_DATE, -540, 0); - ifields[0] = r.random(1, ScaleFactors.users); - ifields[1] = 0; - ifields[2] = 0; - ifields[3] = 1; - ifields[4] = r.random(1, ScaleFactors.users); - ifields[5] = id; - ifields[6] = id; - - // The rest is initialized to 0 anyway, leave it that way. + ifields[0] = r.random(1, ScaleFactors.users); // address_id + ifields[1] = 0; // total_score + ifields[2] = 0; // num_votes + ifields[3] = r.random(1, ScaleFactors.users); // user_id + ifields[4] = id; // image_id + ifields[5] = id; // document_id }
public void load() {
ThreadConnection c = ThreadConnection.getInstance();
try {
PreparedStatement s = c.prepareStatement(STATEMENT);
- for (int i = 0; i < fields.length; i++)
- if (fields[i] != null)
+ int i;
+ for (i = 0; i < fields.length; i++) {
+ if (fields[i] != null) { s.setString(i + 1, fields[i]);- else+ } else { s.setNull(i + 1, Types.VARCHAR); - s.setDate(7, createdTimestamp); - for (int i = 0; i < ifields.length; i++) + }+ }+ s.setTimestamp(5, dTime);
{ + s.setDate(6 + i, dfields[i]); + }
+ for (i = 0; i < dfields.length; i++)+ for (i = 0; i < ifields.length; i++)
{ s.setInt(8 + i, ifields[i]); + }c.addBatch();
} catch (SQLException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/Tag.java
workload-mod/src/org/apache/olio/workload/loader/Tag.java-
- workload/src/org/apache/olio/workload/loader/Tag.java 2009-08-11
11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/Tag.java 2009-07-13
17:58:14.000000000 -0700
@@ -36,16 +36,23 @@
// Note that the tag id in the database is autoincrement and may
// not coincide with this tag id/name when using multi-thread loading.
private static final String STATEMENT = "insert into tags " +
- workload/src/org/apache/olio/workload/loader/Tag.java 2009-08-11
-
- "(name, id) values (?, ?)";
+ "(name, id, taggings_count) values " +
+ "(?, ?, 0)";
static Logger logger = Logger.getLogger(Tag.class.getName());
int id;
String tag;
-
- public String getClearStatement() {
- return "truncate table tags";
+ public void clear() throws SQLExceptionUnknown macro: {+ ThreadConnection c = ThreadConnection.getInstance();+ try { + c.prepareStatement("truncate table tags restart identity"); + c.executeUpdate(); + } catch (SQLException e) { + c.prepareStatement("truncate table tags"); + c.executeUpdate(); + } }
public void prepare()
{ @@ -53,7 +60,6 @@ tag = UserName.getUserName(id); }-
public void load() {
ThreadConnection c = ThreadConnection.getInstance();
try
/**
- * For tags, we won't know the refcount till all the data is loaded.
- * So we update the table at postload.
+ * For tags, we won't know the taggings_count until all the taggings are
loaded.
*/
public void postLoad() {
-// ThreadConnection c = ThreadConnection.getInstance();
-// try { -// c.prepareStatement("update SOCIALEVENTTAG set refcount = " + -// "(select count(*) from SOCIALEVENTTAG_SOCIALEVENT " + -// "where socialeventtagid = " + -// "SOCIALEVENTTAG.socialeventtagid)"); -// c.executeUpdate(); -// }catch (SQLException e)
{ -// logger.log(Level.SEVERE, e.getMessage(), e); -// }-
{ + c.prepareStatement("UPDATE tags SET taggings_count = " + + "(SELECT COUNT(*) FROM taggings WHERE taggings.tag_id = tags.id)"); + c.executeUpdate(); + }
+ ThreadConnection c = ThreadConnection.getInstance();
+ trycatch (SQLException e)
{ + logger.log(Level.SEVERE, e.getMessage(), e); + }
}
}
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/framework/
Loadable.java workload-mod/src/org/apache/olio/workload/loader/framework/
Loadable.java
— workload/src/org/apache/olio/workload/loader/framework/Loadable.java
2009-08-11 11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/framework/
Loadable.java 2009-07-01 18:06:56.000000000 -0700
@@ -19,6 +19,8 @@
*/
package org.apache.olio.workload.loader.framework;
+import java.sql.SQLException;
+
public abstract class Loadable
- public abstract String getClearStatement();
+ public abstract void clear() throws SQLException;
public abstract void prepare();
diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/framework/
Loader.java workload-mod/src/org/apache/olio/workload/loader/framework/
Loader.java
— workload/src/org/apache/olio/workload/loader/framework/Loader.java
2009-08-11 11:30:59.000000000 -0700
+++ workload-mod/src/org/apache/olio/workload/loader/framework/
Loader.java 2009-07-01 17:57:10.000000000 -0700
@@ -155,10 +155,8 @@
Future f = l.loader.pool.submit(new Runnable() {
public void run() {
- ThreadConnection c = ThreadConnection.getInstance();
try { - c.prepareStatement(l.getClearStatement()); - c.executeUpdate(); + l.clear(); }catch (SQLException e)
{ logger.log(Level.SEVERE, l.loader.name + ": " + e.getMessage(), e); diff -x .svn -ruN workload/src/org/apache/olio/workload/loader/framework/ ThreadConnection.java workload-mod/src/org/apache/olio/workload/loader/ framework/ThreadConnection.java --- workload/src/org/apache/olio/workload/loader/framework/ ThreadConnection.java 2009-08-11 11:30:59.000000000 -0700 +++ workload-mod/src/org/apache/olio/workload/loader/framework/ ThreadConnection.java 2009-07-01 18:14:34.000000000 -0700 @@ -194,10 +194,15 @@ logger.fine(name + ": Loaded " + batchName); break; // We won't retry if everything is OK. }catch (BatchUpdateException e) {
{ resetConnection(); logger.log(Level.WARNING, name + - ": Retry loading.", e); + ": Retry loading.", e); }
+
+ // Added to provide more information on possible exceptions.
+ logger.log(Level.WARNING, name +
+ ": Possible BatchUpdateException Failure",
e.getNextException());
+
if (retry == 0)else
{ int[] stats = e.getUpdateCounts(); int successes = 0; @@ -232,7 +237,7 @@ }
void flush() throws SQLException
{ - statement.executeBatch(); + statement.executeBatch(); if (COMMIT_TX) conn.commit(); }