Skip to content

Commit

Permalink
Added VOTE_ID to the VOTES table. Wu Tang! Tiger style!
Browse files Browse the repository at this point in the history
  • Loading branch information
apavlo committed Jul 12, 2012
1 parent 0c22e45 commit 6dfaf3d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/benchmarks/edu/brown/benchmark/voter/PhoneCallGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

public class PhoneCallGenerator {

private long nextVoteId;
private final int contestantCount;
private final Random rand = new Random();
private final int[] votingMap = new int[AREA_CODES.length];
Expand Down Expand Up @@ -67,22 +68,21 @@ public class PhoneCallGenerator {
}

public static class PhoneCall {
public final long voteId;
public final int contestantNumber;
public final long phoneNumber;

protected PhoneCall(int contestantNumber, long phoneNumber) {
protected PhoneCall(long voteId, int contestantNumber, long phoneNumber) {
this.voteId = voteId;
this.contestantNumber = contestantNumber;
this.phoneNumber = phoneNumber;
}
}

//public PhoneCallGenerator(final int contestantCount)
public PhoneCallGenerator(int contestantCount) {

//super(args);

public PhoneCallGenerator(int contestantCount, int clientId) {
this.nextVoteId = clientId * 1000000;
this.contestantCount = contestantCount;
//this.contestantCount = 6; // XXX: FIX THIS

// This is a just a small fudge to make the geographical voting map more interesting for the benchmark!
for(int i = 0; i < votingMap.length; i++) {
Expand Down Expand Up @@ -120,8 +120,10 @@ public PhoneCall receive()
// Build the phone number
long phoneNumber = AREA_CODES[areaCodeIndex] * 10000000L + rand.nextInt(10000000);

// This needs to be globally unique

// Return the generated phone number
return new PhoneCall(contestantNumber, phoneNumber);
return new PhoneCall(this.nextVoteId++, contestantNumber, phoneNumber);
}

}
3 changes: 2 additions & 1 deletion src/benchmarks/edu/brown/benchmark/voter/VoterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void main(String args[]) {
public VoterClient(String args[]) {
super(args);
int numContestants = VoterUtil.getScaledNumContestants(this.getScaleFactor());
this.switchboard = new PhoneCallGenerator(numContestants);
this.switchboard = new PhoneCallGenerator(this.getClientId(), numContestants);
}

@Override
Expand Down Expand Up @@ -103,6 +103,7 @@ protected boolean runOnce() throws IOException {
try {
response = client.callProcedure(callback,
"Vote",
call.voteId,
call.phoneNumber,
call.contestantNumber,
VoterConstants.MAX_VOTES);
Expand Down
6 changes: 3 additions & 3 deletions src/benchmarks/edu/brown/benchmark/voter/procedures/Vote.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public class Vote extends VoltProcedure {

// Records a vote
public final SQLStmt insertVoteStmt = new SQLStmt(
"INSERT INTO votes (phone_number, state, contestant_number) VALUES (?, ?, ?);"
"INSERT INTO votes (vote_id, phone_number, state, contestant_number) VALUES (?, ?, ?, ?);"
);

public long run(long phoneNumber, int contestantNumber, long maxVotesPerPhoneNumber) {
public long run(long voteId, long phoneNumber, int contestantNumber, long maxVotesPerPhoneNumber) {

// Queue up validation statements
voltQueueSQL(checkContestantStmt, contestantNumber);
Expand All @@ -90,7 +90,7 @@ public long run(long phoneNumber, int contestantNumber, long maxVotesPerPhoneNum
final String state = (validation[2].getRowCount() > 0) ? validation[2].fetchRow(0).getString(0) : "XX";

// Post the vote
voltQueueSQL(insertVoteStmt, phoneNumber, state, contestantNumber);
voltQueueSQL(insertVoteStmt, voteId, phoneNumber, state, contestantNumber);
voltExecuteSQL(true);

// Set the return value to 0: successful vote
Expand Down
5 changes: 5 additions & 0 deletions src/benchmarks/edu/brown/benchmark/voter/voter-ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ CREATE TABLE area_code_state
-- voters are not allowed to submit more than <x> votes, x is passed to client application
CREATE TABLE votes
(
vote_id bigint NOT NULL,
phone_number bigint NOT NULL
, state varchar(2) NOT NULL -- REFERENCES area_code_state (state)
, contestant_number integer NOT NULL REFERENCES contestants (contestant_number)
, CONSTRAINT PK_votes PRIMARY KEY
(
vote_id
)
-- PARTITION BY ( phone_number )
);

Expand Down

0 comments on commit 6dfaf3d

Please sign in to comment.