Skip to content

Commit

Permalink
both votertimewin and voterdemo benchmarks working
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeehan16 committed Apr 18, 2014
1 parent 06fe8d8 commit 705b4dc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
Expand Up @@ -22,7 +22,7 @@ protected String toSetStreamName() {
);

public final SQLStmt updateLeaderboard = new SQLStmt(
"INSERT INTO top_three_last_30_sec (contestant_number, num_votes) SELECT tl.contestant_number, count(*) FROM trending_leaderboard tl JOIN contestants c ON c.contestant_number = tl.contestant_number GROUP BY contestant_number;"
"INSERT INTO top_three_last_30_sec (contestant_number, num_votes) SELECT trending_leaderboard.contestant_number, count(*) FROM trending_leaderboard, contestants WHERE trending_leaderboard.contestant_number = contestants.contestant_number GROUP BY trending_leaderboard.contestant_number;"
);

}
Expand Up @@ -46,4 +46,7 @@ public abstract class VoterWinTimeHStoreConstants {
public static final long VOTE_SUCCESSFUL = 0;
public static final long ERR_INVALID_CONTESTANT = 1;
public static final long ERR_VOTER_OVER_VOTE_LIMIT = 2;

public static final long WIN_SIZE = 30;
public static final long STAGE_SIZE = 2;
}
Expand Up @@ -42,8 +42,6 @@
singlePartition = true
)
public class Vote extends VoltProcedure {
public final int windowSize = 30;
public final int slideSize = 2;


// Checks if the vote is for a valid contestant
Expand Down Expand Up @@ -72,11 +70,14 @@ public class Vote extends VoltProcedure {
);

// Find the cutoff vote
public final SQLStmt checkStagingTime = new SQLStmt(
"SELECT min(time) FROM w_staging;"
public final SQLStmt checkStagingTimestamp = new SQLStmt(
"SELECT MAX(time) FROM w_staging;"
);


public final SQLStmt checkWindowTimestamp = new SQLStmt(
"SELECT MIN(time) FROM w_rows;"
);

// Find the cutoff vote
public final SQLStmt deleteCutoffVoteStmt = new SQLStmt(
"DELETE FROM w_rows WHERE time < ?;"
Expand All @@ -87,6 +88,10 @@ public class Vote extends VoltProcedure {
"INSERT INTO w_rows (vote_id, phone_number, state, contestant_number, time) SELECT * FROM w_staging;"
);

public final SQLStmt deleteMostRecentVote = new SQLStmt(
"DELETE FROM w_rows WHERE time = ?;"
);

// Pull aggregate from window
public final SQLStmt deleteLeaderBoardStmt = new SQLStmt(
"DELETE FROM leaderboard;"
Expand All @@ -99,7 +104,7 @@ public class Vote extends VoltProcedure {

// Clear the staging window
public final SQLStmt deleteStagingStmt = new SQLStmt(
"DELETE FROM w_staging;"
"DELETE FROM w_staging WHERE time < ?;"
);

// Put the vote into the staging window
Expand Down Expand Up @@ -134,10 +139,15 @@ public long run(long voteId, long phoneNumber, int contestantNumber, long maxVot
// Post the vote
//TimestampType timestamp = new TimestampType();
voltQueueSQL(insertVoteStmt, voteId, phoneNumber, state, contestantNumber, currentTimestamp);
voltQueueSQL(checkStagingTime);
voltQueueSQL(insertVoteStagingStmt, voteId, phoneNumber, state, contestantNumber, currentTimestamp);
voltQueueSQL(checkStagingTimestamp);
voltQueueSQL(checkWindowTimestamp);
validation = voltExecuteSQL();

if(validation[1].getRowCount() != 0 && currentTimestamp - (int)(validation[1].fetchRow(0).getLong(0)) >= slideSize)
long minWinTimestamp = validation[3].fetchRow(0).getLong(0);
long maxStageTimestamp = validation[2].fetchRow(0).getLong(0);

if(maxStageTimestamp - minWinTimestamp >= VoterWinTimeHStoreConstants.WIN_SIZE + VoterWinTimeHStoreConstants.STAGE_SIZE)
{
//Check the window size and cutoff vote can be done one of two ways:
//1) Two statements: one gets window size, one gets all rows to be deleted
Expand All @@ -146,14 +156,14 @@ public long run(long voteId, long phoneNumber, int contestantNumber, long maxVot
//voltQueueSQL(selectFullWindowStmt);

//validation = voltExecuteSQL();
voltQueueSQL(deleteCutoffVoteStmt, currentTimestamp - windowSize );
voltQueueSQL(deleteCutoffVoteStmt, maxStageTimestamp - VoterWinTimeHStoreConstants.WIN_SIZE);
voltQueueSQL(insertVoteWindowStmt);
voltQueueSQL(deleteMostRecentVote, maxStageTimestamp);
voltQueueSQL(deleteLeaderBoardStmt);
voltQueueSQL(updateLeaderBoardStmt);
voltQueueSQL(deleteStagingStmt);
voltQueueSQL(deleteStagingStmt, maxStageTimestamp);
voltExecuteSQL(true);
}
voltQueueSQL(insertVoteStagingStmt, voteId, phoneNumber, state, contestantNumber, currentTimestamp);
voltExecuteSQL(true);

// Set the return value to 0: successful vote
return VoterWinTimeHStoreConstants.VOTE_SUCCESSFUL;
Expand Down
Expand Up @@ -68,7 +68,7 @@ public class VoterWinTimeSStoreProjectBuilder extends AbstractProjectBuilder {
{ "votes_stream", "phone_number"},
{ "S1", "phone_number"},
{ "W_ROWS", "phone_number"},
{ "leaderboard", "phone_number"}
{ "leaderboard", "contestant_number"}
};

public VoterWinTimeSStoreProjectBuilder() {
Expand Down
Expand Up @@ -15,6 +15,6 @@ protected String toSetStreamName() {
);

public final SQLStmt insertIntoLeaderBoard = new SQLStmt(
"INSERT INTO leaderboard (contestant_number, numvotes, phone_number) SELECT contestant_number, count(*), max(phone_number) FROM W_ROWS GROUP BY contestant_number;"
"INSERT INTO leaderboard (contestant_number, numvotes) SELECT contestant_number, count(*) FROM W_ROWS GROUP BY contestant_number;"
);
}
Expand Up @@ -41,7 +41,6 @@ CREATE TABLE leaderboard
(
contestant_number integer NOT NULL
, numvotes integer NOT NULL
, phone_number integer NOT NULL
);

CREATE VIEW v_votes_by_phone_number
Expand Down

0 comments on commit 705b4dc

Please sign in to comment.