Skip to content

Commit

Permalink
added new file to correctness demos
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Aug 25, 2014
1 parent 5e51020 commit 0bb0f88
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 8 deletions.
Expand Up @@ -42,6 +42,7 @@ public abstract class VoterDemoHStoreConstants {

public static final String OUTPUT_FILE = "logs/demohstoreout.txt";
public static final String OVERWRITE_FILE = "logs/demohstorecurrent.txt";
public static final String CONTESTANTS_FILE = "logs/hstorecontestants.txt";
public static final String VOTE_FILE = "demo/demo-votes.txt";
public static final int DELETE_CODE = -1;
public static final boolean SOCKET_CONTROL = true;
Expand Down
Expand Up @@ -41,7 +41,7 @@

import org.voltdb.VoltTable;

import edu.brown.benchmark.voterexperiments.demosstorecorrect.VoterDemoSStoreConstants;
import edu.brown.benchmark.voterexperiments.demohstorecorrect.VoterDemoHStoreConstants;
import edu.brown.rand.RandomDistribution.Zipf;

public abstract class VoterDemoHStoreUtil {
Expand Down Expand Up @@ -319,6 +319,11 @@ private static void closeAllFiles(ArrayList<PrintWriter> p)
}
}

public static void writeToContestantsFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes) throws IOException
{
writeToFile(v,tableNames,numVotes,VoterDemoHStoreConstants.CONTESTANTS_FILE);
}

public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes) throws IOException
{
ArrayList<PrintWriter> out = new ArrayList<PrintWriter>();
Expand Down Expand Up @@ -362,5 +367,47 @@ public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int
}
closeAllFiles(out);
}

public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes, String filename) throws IOException
{
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(filename, false)));
if(numVotes == VoterDemoHStoreConstants.DELETE_CODE)
{
p.print("####DELETECANDIDATE####\n");
}
else
p.print("####" + numVotes + "####\n");

for(int i = 0; i < v.length; i++)
{
String tableName = tableNames.get(i);
p.print("**" + tableName + "**\n");
int j = 0;
while(j < v[i].getRowCount())
{
for(int k = 0; k < v[i].getColumnCount(); k++)
{
if(k > 0)
{
p.print(",");
}

p.print((v[i].fetchRow(j).get(k)).toString());
}
p.print("\n");
j++;
}
if(tableName.endsWith("Three"))
{
while(j < 3)
{
p.print("-----,0\n");
j++;
}
}
p.print("---------------------------\n");
}
p.close();
}

}
Expand Up @@ -121,7 +121,8 @@ public class DeleteContestant extends VoltProcedure {
public final SQLStmt getActualVoteCountStmt = new SQLStmt( "SELECT totalcnt, successcnt FROM proc_one_count WHERE row_id = 1;");
public final SQLStmt getTrendingCountStmt = new SQLStmt("SELECT count(*) FROM w_rows;");
public final SQLStmt getRemainingContestants = new SQLStmt("SELECT count(*) FROM contestants;");
public final SQLStmt getRemovedContestant = new SQLStmt("SELECT contestant_name, num_votes FROM removed_contestant WHERE row_id = 1;");
public final SQLStmt getRemovedContestants = new SQLStmt("SELECT row_id, contestant_name, num_votes FROM removed_contestant ORDER BY row_id DESC;");
public final SQLStmt getAllRemainingContestants = new SQLStmt("SELECT c.contestant_name, v.num_votes FROM v_votes_by_contestant v JOIN contestants c ON v.contestant_number = c.contestant_number ORDER BY num_votes DESC;");
public final SQLStmt getVotesTilNextDeleteStmt = new SQLStmt( "SELECT cnt FROM votes_next_delete WHERE row_id=1;");
/////////////////////////////
//END GET RESULTS
Expand Down Expand Up @@ -162,6 +163,13 @@ private void printResults() throws IOException

VoltTable[] v = voltExecuteSQL();
VoterDemoHStoreUtil.writeToFile(v, tableNames, VoterDemoHStoreConstants.DELETE_CODE);

voltQueueSQL(getAllRemainingContestants);
tableNames.add("RemainingContestants");
voltQueueSQL(getRemovedContestants);
tableNames.add("RemovedContestants");
v = voltExecuteSQL();
VoterDemoHStoreUtil.writeToContestantsFile(v, tableNames, VoterDemoHStoreConstants.DELETE_CODE);
}

public long run() {
Expand Down
Expand Up @@ -39,7 +39,6 @@
import org.voltdb.VoltTable;
import org.voltdb.types.TimestampType;

import edu.brown.benchmark.voter.VoterConstants;
import edu.brown.benchmark.voterexperiments.demohstorecorrect.VoterDemoHStoreConstants;
import edu.brown.benchmark.voterexperiments.demohstorecorrect.VoterDemoHStoreUtil;

Expand Down Expand Up @@ -141,7 +140,8 @@ public class Vote extends VoltProcedure {
public final SQLStmt getActualVoteCountStmt = new SQLStmt( "SELECT totalcnt, successcnt FROM proc_one_count WHERE row_id = 1;");
public final SQLStmt getTrendingCountStmt = new SQLStmt("SELECT count(*) FROM w_rows;");
public final SQLStmt getRemainingContestants = new SQLStmt("SELECT count(*) FROM contestants;");
public final SQLStmt getRemovedContestant = new SQLStmt("SELECT contestant_name, num_votes FROM removed_contestant WHERE row_id = 1;");
public final SQLStmt getRemovedContestants = new SQLStmt("SELECT row_id, contestant_name, num_votes FROM removed_contestant ORDER BY row_id DESC;");
public final SQLStmt getAllRemainingContestants = new SQLStmt("SELECT c.contestant_name, v.num_votes FROM v_votes_by_contestant v JOIN contestants c ON v.contestant_number = c.contestant_number ORDER BY num_votes DESC;");
public final SQLStmt getVotesTilNextDeleteStmt = new SQLStmt( "SELECT cnt FROM votes_next_delete WHERE row_id=1;");
/////////////////////////////
//END GET RESULTS
Expand Down Expand Up @@ -183,6 +183,12 @@ private void printResults(int numVotes) throws IOException
VoltTable[] v = voltExecuteSQL();
VoterDemoHStoreUtil.writeToFile(v, tableNames, numVotes);

voltQueueSQL(getAllRemainingContestants);
tableNames.add("RemainingContestants");
voltQueueSQL(getRemovedContestants);
tableNames.add("RemovedContestants");
v = voltExecuteSQL();
VoterDemoHStoreUtil.writeToContestantsFile(v, tableNames, VoterDemoHStoreConstants.DELETE_CODE);
}


Expand Down
Expand Up @@ -42,6 +42,7 @@ public abstract class VoterDemoSStoreConstants {

public static final String OUTPUT_FILE = "logs/demosstoreout.txt";
public static final String OVERWRITE_FILE = "logs/demosstorecurrent.txt";
public static final String CONTESTANTS_FILE = "logs/sstorecontestants.txt";
public static final String VOTE_FILE = "demo/demo-votes.txt";
public static final int DELETE_CODE = -1;
public static final boolean SOCKET_CONTROL = true;
Expand Down
Expand Up @@ -318,6 +318,11 @@ private static void closeAllFiles(ArrayList<PrintWriter> p)
}
}

public static void writeToContestantsFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes) throws IOException
{
writeToFile(v,tableNames,numVotes,VoterDemoSStoreConstants.CONTESTANTS_FILE);
}

public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes) throws IOException
{
ArrayList<PrintWriter> out = new ArrayList<PrintWriter>();
Expand Down Expand Up @@ -361,5 +366,47 @@ public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int
}
closeAllFiles(out);
}

public static void writeToFile(VoltTable[] v, ArrayList<String> tableNames, int numVotes, String filename) throws IOException
{
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(filename, false)));
if(numVotes == VoterDemoSStoreConstants.DELETE_CODE)
{
p.print("####DELETECANDIDATE####\n");
}
else
p.print("####" + numVotes + "####\n");

for(int i = 0; i < v.length; i++)
{
String tableName = tableNames.get(i);
p.print("**" + tableName + "**\n");
int j = 0;
while(j < v[i].getRowCount())
{
for(int k = 0; k < v[i].getColumnCount(); k++)
{
if(k > 0)
{
p.print(",");
}

p.print((v[i].fetchRow(j).get(k)).toString());
}
p.print("\n");
j++;
}
if(tableName.endsWith("Three"))
{
while(j < 3)
{
p.print("-----,0\n");
j++;
}
}
p.print("---------------------------\n");
}
p.close();
}

}
Expand Up @@ -49,7 +49,6 @@
import org.voltdb.VoltTable;
import org.voltdb.types.TimestampType;

import edu.brown.benchmark.voterexperiments.demohstorecorrect.VoterDemoHStoreConstants;
import edu.brown.benchmark.voterexperiments.demosstorecorrect.VoterDemoSStoreConstants;
import edu.brown.benchmark.voterexperiments.demosstorecorrect.VoterDemoSStoreUtil;

Expand Down Expand Up @@ -133,7 +132,8 @@ protected void toSetTriggerTableName()
public final SQLStmt getActualVoteCountStmt = new SQLStmt( "SELECT totalcnt, successcnt FROM proc_one_count WHERE row_id = 1;");
public final SQLStmt getTrendingCountStmt = new SQLStmt("SELECT count(*) FROM trending_leaderboard;");
public final SQLStmt getRemainingContestants = new SQLStmt("SELECT count(*) FROM contestants;");
public final SQLStmt getRemovedContestant = new SQLStmt("SELECT contestant_name, num_votes FROM removed_contestant WHERE row_id = 1;");
public final SQLStmt getRemovedContestants = new SQLStmt("SELECT row_id, contestant_name, num_votes FROM removed_contestant ORDER BY row_id DESC;");
public final SQLStmt getAllRemainingContestants = new SQLStmt("SELECT c.contestant_name, v.num_votes FROM v_votes_by_contestant v JOIN contestants c ON v.contestant_number = c.contestant_number ORDER BY num_votes DESC;");
public final SQLStmt getVotesTilNextDeleteStmt = new SQLStmt( "SELECT cnt FROM votes_next_delete WHERE row_id=1;");
/////////////////////////////
//END GET RESULTS
Expand Down Expand Up @@ -174,6 +174,13 @@ private void printResults() throws IOException

VoltTable[] v = voltExecuteSQL();
VoterDemoSStoreUtil.writeToFile(v, tableNames, VoterDemoSStoreConstants.DELETE_CODE);

voltQueueSQL(getAllRemainingContestants);
tableNames.add("RemainingContestants");
voltQueueSQL(getRemovedContestants);
tableNames.add("RemovedContestants");
v = voltExecuteSQL();
VoterDemoSStoreUtil.writeToContestantsFile(v, tableNames, VoterDemoSStoreConstants.DELETE_CODE);
}

public long run() {
Expand All @@ -197,7 +204,7 @@ public long run() {

if(remainingContestants <= 1)
{
return VoterDemoHStoreConstants.BM_FINISHED;
return VoterDemoSStoreConstants.BM_FINISHED;
}

voltQueueSQL(insertRemovedContestant, remainingContestants, lowestConName, lowestConVotes);
Expand Down
Expand Up @@ -140,7 +140,8 @@ public class Vote extends VoltProcedure {
public final SQLStmt getActualVoteCountStmt = new SQLStmt( "SELECT totalcnt, successcnt FROM proc_one_count WHERE row_id = 1;");
public final SQLStmt getTrendingCountStmt = new SQLStmt("SELECT count(*) FROM trending_leaderboard;");
public final SQLStmt getRemainingContestants = new SQLStmt("SELECT count(*) FROM contestants;");
public final SQLStmt getRemovedContestant = new SQLStmt("SELECT contestant_name, num_votes FROM removed_contestant WHERE row_id = 1;");
public final SQLStmt getRemovedContestants = new SQLStmt("SELECT row_id, contestant_name, num_votes FROM removed_contestant ORDER BY row_id DESC;");
public final SQLStmt getAllRemainingContestants = new SQLStmt("SELECT c.contestant_name, v.num_votes FROM v_votes_by_contestant v JOIN contestants c ON v.contestant_number = c.contestant_number ORDER BY num_votes DESC;");
public final SQLStmt getVotesTilNextDeleteStmt = new SQLStmt( "SELECT cnt FROM votes_next_delete WHERE row_id=1;");
/////////////////////////////
//END GET RESULTS
Expand Down Expand Up @@ -182,6 +183,12 @@ private void printResults(int numVotes) throws IOException
VoltTable[] v = voltExecuteSQL();
VoterDemoSStoreUtil.writeToFile(v, tableNames, numVotes);

voltQueueSQL(getAllRemainingContestants);
tableNames.add("RemainingContestants");
voltQueueSQL(getRemovedContestants);
tableNames.add("RemovedContestants");
v = voltExecuteSQL();
VoterDemoSStoreUtil.writeToContestantsFile(v, tableNames, VoterDemoSStoreConstants.DELETE_CODE);
}


Expand Down

0 comments on commit 0bb0f88

Please sign in to comment.