Skip to content

Commit

Permalink
Remove unused id1_type and id2_type fields from link
Browse files Browse the repository at this point in the history
Summary: Not needed so remove from MySql schema, LinkBench driver and tests

Test Plan: ant test passes

Reviewers: dhruba

Reviewed By: dhruba

Differential Revision: https://reviews.facebook.net/D6645
  • Loading branch information
Tim Armstrong committed Nov 27, 2012
1 parent bc0f5e2 commit dfcf426
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 84 deletions.
3 changes: 0 additions & 3 deletions README_instructions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Execute the following commands in the database:

CREATE TABLE `linktable` (
`id1` bigint(20) unsigned NOT NULL DEFAULT '0',
`id1_type` int(10) unsigned NOT NULL DEFAULT '0',
`id2` bigint(20) unsigned NOT NULL DEFAULT '0',
`id2_type` int(10) unsigned NOT NULL DEFAULT '0',
`link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
`visibility` tinyint(3) NOT NULL DEFAULT '0',
`data` varchar(255) NOT NULL DEFAULT '',
Expand All @@ -56,7 +54,6 @@ Execute the following commands in the database:

CREATE TABLE `counttable` (
`id` bigint(20) unsigned NOT NULL DEFAULT '0',
`id_type` int(10) unsigned NOT NULL DEFAULT '0',
`link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
`count` int(10) unsigned NOT NULL DEFAULT '0',
`time` bigint(20) unsigned NOT NULL DEFAULT '0',
Expand Down
15 changes: 3 additions & 12 deletions src/java/com/facebook/LinkBench/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

public class Link {

public Link(long id1, long link_type, long id2, int id1_type, int id2_type,
public Link(long id1, long link_type, long id2,
byte visibility, byte[] data, int version, long time) {
this.id1 = id1;
this.link_type = link_type;
this.id2 = id2;
this.id1_type = id1_type;
this.id2_type = id2_type;
this.visibility = visibility;
this.data = data;
this.version = version;
Expand All @@ -20,8 +18,6 @@ public Link(long id1, long link_type, long id2, int id1_type, int id2_type,

Link() {
link_type = LinkStore.DEFAULT_LINK_TYPE;
id1_type = LinkStore.ID1_TYPE;
id2_type = LinkStore.ID2_TYPE;
visibility = LinkStore.VISIBILITY_DEFAULT;
}

Expand All @@ -30,7 +26,6 @@ public boolean equals(Object other) {
Link o = (Link) other;
return id1 == o.id1 && id2 == o.id2 &&
link_type == o.link_type &&
id1_type == o.id1_type && id2_type == o.id2_type &&
visibility == o.visibility &&
version == o.version && time == o.time &&
Arrays.equals(data, o.data);
Expand All @@ -41,8 +36,8 @@ public boolean equals(Object other) {

public String toString() {
return String.format("Link(id1=%d, id2=%d, link_type=%d," +
"id1_type=%d, id2_type=%d, visibility=%d, version=%d," +
"time=%d, data=%s", id1, id2, link_type, id1_type, id2_type,
"visibility=%d, version=%d," +
"time=%d, data=%s", id1, id2, link_type,
visibility, version, time, data.toString());
}

Expand All @@ -55,8 +50,6 @@ public Link clone() {
l.id1 = this.id1;
l.link_type = this.link_type;
l.id2 = this.id2;
l.id1_type = this.id1_type;
l.id2_type = this.id2_type;
l.visibility = this.visibility;
l.data = this.data.clone();
l.version = this.version;
Expand All @@ -67,8 +60,6 @@ public Link clone() {
public long id1;
public long link_type;
public long id2;
public int id1_type;
public int id2_type;
public byte visibility;
public byte[] data;
public int version;
Expand Down
4 changes: 1 addition & 3 deletions src/java/com/facebook/LinkBench/LinkBenchLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private long createOutLinks(Random rng,
// Update link counts for this type
LinkCount count = linkTypeCounts.get(link.link_type);
if (count == null) {
count = new LinkCount(id1,link.id1_type, link.link_type,
count = new LinkCount(id1, link.link_type,
link.time, link.version, 1);
linkTypeCounts.put(link.link_type, count);
} else {
Expand Down Expand Up @@ -363,8 +363,6 @@ private long createOutLinks(Random rng,
private Link initLink() {
Link link = new Link();
link.link_type = LinkStore.DEFAULT_LINK_TYPE;
link.id1_type = LinkStore.ID1_TYPE;
link.id2_type = LinkStore.ID2_TYPE;
link.visibility = LinkStore.VISIBILITY_DEFAULT;
link.version = 0;
link.data = new byte[0];
Expand Down
12 changes: 4 additions & 8 deletions src/java/com/facebook/LinkBench/LinkBenchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,6 @@ private boolean oneRequest(boolean recordStats) {
link.link_type = id2chooser.chooseRandomLinkType(rng);
link.id2 = id2chooser.chooseForOp(rng, link.id1, link.link_type,
ID2Chooser.P_ADD_EXIST);
link.id1_type = LinkStore.ID1_TYPE;
link.id2_type = LinkStore.ID2_TYPE;
link.visibility = LinkStore.VISIBILITY_DEFAULT;
link.version = 0;
link.time = System.currentTimeMillis();
Expand Down Expand Up @@ -511,8 +509,6 @@ private boolean oneRequest(boolean recordStats) {
// Update one of the existing links
link.id2 = id2chooser.chooseForOp(rng, link.id1, link.link_type,
ID2Chooser.P_UPDATE_EXIST);
link.id1_type = LinkStore.ID1_TYPE;
link.id2_type = LinkStore.ID2_TYPE;
link.visibility = LinkStore.VISIBILITY_DEFAULT;
link.version = 0;
link.time = System.currentTimeMillis();
Expand Down Expand Up @@ -615,7 +611,7 @@ private boolean oneRequest(boolean recordStats) {
long idToDelete = chooseRequestID(DistributionType.NODE_DELETES,
lastNodeId);
starttime = System.nanoTime();
boolean deleted = nodeStore.deleteNode(dbid, LinkStore.ID1_TYPE,
boolean deleted = nodeStore.deleteNode(dbid, LinkStore.DEFAULT_NODE_TYPE,
idToDelete);
endtime = System.nanoTime();
lastNodeId = idToDelete;
Expand All @@ -627,7 +623,7 @@ private boolean oneRequest(boolean recordStats) {
starttime = System.nanoTime();
long idToFetch = chooseRequestID(DistributionType.NODE_READS,
lastNodeId);
Node fetched = nodeStore.getNode(dbid, LinkStore.ID1_TYPE, idToFetch);
Node fetched = nodeStore.getNode(dbid, LinkStore.DEFAULT_NODE_TYPE, idToFetch);
endtime = System.nanoTime();
lastNodeId = idToFetch;
if (Level.TRACE.isGreaterOrEqual(debuglevel)) {
Expand Down Expand Up @@ -677,7 +673,7 @@ private boolean oneRequest(boolean recordStats) {
*/
private Node createAddNode() {
byte data[] = nodeAddDataGen.fill(rng, new byte[(int)nodeDataSize.choose(rng)]);
return new Node(-1, LinkStore.ID1_TYPE, 1,
return new Node(-1, LinkStore.DEFAULT_NODE_TYPE, 1,
(int)(System.currentTimeMillis()/1000), data);
}

Expand All @@ -686,7 +682,7 @@ private Node createAddNode() {
*/
private Node createUpdateNode(long id) {
byte data[] = nodeUpDataGen.fill(rng, new byte[(int)nodeDataSize.choose(rng)]);
return new Node(id, LinkStore.ID1_TYPE, 2,
return new Node(id, LinkStore.DEFAULT_NODE_TYPE, 2,
(int)(System.currentTimeMillis()/1000), data);
}

Expand Down
5 changes: 1 addition & 4 deletions src/java/com/facebook/LinkBench/LinkCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
public class LinkCount {

public final long id1;
public final int id1_type;
public final long link_type;
public long time;
public long version;
public long count;
public LinkCount(long id1, int id1_type, long link_type,
public LinkCount(long id1, long link_type,
long time, long version, long init_count) {
super();
this.id1 = id1;

this.id1_type = id1_type;
this.link_type = link_type;
this.time = time;
this.version = version;
Expand Down
3 changes: 1 addition & 2 deletions src/java/com/facebook/LinkBench/LinkStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public abstract class LinkStore {
// void createLinkTable();
public static final long DEFAULT_LINK_TYPE = 123456789;
public static final long MAX_ID2 = Long.MAX_VALUE;
public static final int ID1_TYPE = 2048;
public static final int ID2_TYPE = 2048;
public static final int DEFAULT_NODE_TYPE = 2048;

// visibility
public static final byte VISIBILITY_HIDDEN = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ private byte[] linkToBytes(Link a) {
String temp = Long.toString(a.id1) + "." +
Long.toString(a.link_type) + "." +
Long.toString(a.id2) + "." +
Integer.toString(a.id1_type) + "." +
Integer.toString(a.id2_type) + "." +
Byte.toString(a.visibility) + "." +
Bytes.toString(a.data) + "." +
// there must be no (.) in a.data
Expand All @@ -92,12 +90,10 @@ private Link bytesToLink(byte[] blink) throws Exception {
a.id1 = Long.parseLong(tokens[0]);
a.link_type = Long.parseLong(tokens[1]);
a.id2 = Long.parseLong(tokens[2]);
a.id1_type = Integer.parseInt(tokens[3]);
a.id2_type = Integer.parseInt(tokens[4]);
a.visibility = Byte.parseByte(tokens[5]);
a.data = tokens[6].getBytes();
a.version = Integer.parseInt(tokens[7]);
a.time = Long.parseLong(tokens[8]);
a.visibility = Byte.parseByte(tokens[3]);
a.data = tokens[4].getBytes();
a.version = Integer.parseInt(tokens[5]);
a.time = Long.parseLong(tokens[6]);
return a;
}

Expand Down
38 changes: 14 additions & 24 deletions src/java/com/facebook/LinkBench/LinkStoreMysql.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ public boolean addLink(String dbid, Link l, boolean noinverse)
if (update_count != 0) {
int base_count = update_count < 0 ? 0 : 1;
// query to update counttable
// if (id, id_type) is not there yet, add a new record with count = 1
// if (id, link_type) is not there yet, add a new record with count = 1
String updatecount = "INSERT INTO " + dbid + "." + counttable +
"(id, id_type, link_type, count, time, version) " +
"(id, link_type, count, time, version) " +
"VALUES (" + l.id1 +
", " + l.id1_type +
", " + l.link_type +
", " + base_count +
", " + l.time +
Expand All @@ -292,10 +291,8 @@ public boolean addLink(String dbid, Link l, boolean noinverse)

if (update_data) {
// query to update link data (the first query only updates visibility)
String updatedata = "UPDATE " + dbid + "." + linktable +
" SET id1_type = " + l.id1_type +
", id2_type = " + l.id2_type +
", visibility = " + l.visibility +
String updatedata = "UPDATE " + dbid + "." + linktable + " SET" +
" visibility = " + l.visibility +
", data = " + stringLiteral(l.data)+
", time = " + l.time +
", version = " + l.version +
Expand Down Expand Up @@ -330,7 +327,7 @@ private int addLinksNoCount(String dbid, List<Link> links)
// query to insert a link;
StringBuilder sb = new StringBuilder();
sb.append("INSERT INTO " + dbid + "." + linktable +
"(id1, id1_type, id2, id2_type, link_type, " +
"(id1, id2, link_type, " +
"visibility, data, time, version) VALUES ");
boolean first = true;
for (Link l : links) {
Expand All @@ -340,9 +337,7 @@ private int addLinksNoCount(String dbid, List<Link> links)
sb.append(',');
}
sb.append("(" + l.id1 +
", " + l.id1_type +
", " + l.id2 +
", " + l.id2_type +
", " + l.link_type +
", " + l.visibility +
", " + stringLiteral(l.data) +
Expand Down Expand Up @@ -436,16 +431,14 @@ else if (visibility == VISIBILITY_DEFAULT) {
// * otherwise, insert new link with count column = 0
long currentTime = (new Date()).getTime();
String update = "INSERT INTO " + dbid + "." + counttable +
" (id, id_type, link_type, count, time, version) " +
" (id, link_type, count, time, version) " +
"VALUES (" + id1 +
", " + LinkStore.ID1_TYPE +
", " + link_type +
", 0" +
", " + currentTime +
", " + 0 + ") " +
"ON DUPLICATE KEY UPDATE" +
" id_type = " + LinkStore.ID1_TYPE +
", count = IF (count = 0, 0, count - 1)" +
" count = IF (count = 0, 0, count - 1)" +
", time = " + currentTime +
", version = version + 1;";

Expand Down Expand Up @@ -491,7 +484,7 @@ public Link getLink(String dbid, long id1, long link_type, long id2)
public Link[] multigetLinks(String dbid, long id1, long link_type,
long[] id2s) throws Exception {
StringBuilder querySB = new StringBuilder();
querySB.append(" select id1, id2, link_type, id1_type, id2_type," +
querySB.append(" select id1, id2, link_type," +
" visibility, data, time, " +
" version from " + dbid + "." + linktable +
" where id1 = " + id1 + " and link_type = " + link_type +
Expand Down Expand Up @@ -544,7 +537,7 @@ public Link[] getLinkList(String dbid, long id1, long link_type,
long minTimestamp, long maxTimestamp,
int offset, int limit)
throws Exception {
String query = " select id1, id2, link_type, id1_type, id2_type," +
String query = " select id1, id2, link_type," +
" visibility, data, time," +
" version from " + dbid + "." + linktable +
" where id1 = " + id1 + " and link_type = " + link_type +
Expand Down Expand Up @@ -592,12 +585,10 @@ private Link createLinkFromRow(ResultSet rs) throws SQLException {
l.id1 = rs.getLong(1);
l.id2 = rs.getLong(2);
l.link_type = rs.getLong(3);
l.id1_type = rs.getInt(4);
l.id2_type = rs.getInt(5);
l.visibility = rs.getByte(6);
l.data = rs.getBytes(7);
l.time = rs.getLong(8);
l.version = rs.getInt(9);
l.visibility = rs.getByte(4);
l.data = rs.getBytes(5);
l.time = rs.getLong(6);
l.version = rs.getInt(7);
return l;
}

Expand Down Expand Up @@ -657,7 +648,7 @@ public void addBulkCounts(String dbid, List<LinkCount> counts)

StringBuilder sqlSB = new StringBuilder();
sqlSB.append("REPLACE INTO " + dbid + "." + counttable +
"(id, id_type, link_type, count, time, version) " +
"(id, link_type, count, time, version) " +
"VALUES ");
boolean first = true;
for (LinkCount count: counts) {
Expand All @@ -667,7 +658,6 @@ public void addBulkCounts(String dbid, List<LinkCount> counts)
sqlSB.append(",");
}
sqlSB.append("(" + count.id1 +
", " + count.id1_type +
", " + count.link_type +
", " + count.count +
", " + count.time +
Expand Down
2 changes: 1 addition & 1 deletion src/java/com/facebook/LinkBench/NodeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void displayAndResetStats() {
private void genNode(Random rng, long id1, ArrayList<Node> nodeLoadBuffer,
int bulkLoadBatchSize) {
int dataLength = (int)nodeDataLength.choose(rng);
Node node = new Node(id1, LinkStore.ID1_TYPE, System.currentTimeMillis(),
Node node = new Node(id1, LinkStore.DEFAULT_NODE_TYPE, System.currentTimeMillis(),
1, nodeDataGen.fill(rng, new byte[dataLength]));
nodeLoadBuffer.add(node);
if (nodeLoadBuffer.size() >= bulkLoadBatchSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testFullWorkload() throws IOException, Exception {
try {
LinkStoreTestBase.deleteIDRange(testDB, getStoreHandle(true),
startId, idCount);
deleteNodeIDRange(testDB, LinkStore.ID1_TYPE,
deleteNodeIDRange(testDB, LinkStore.DEFAULT_NODE_TYPE,
getStoreHandle(true), startId, idCount);
} catch (Throwable t) {
System.err.println("Error during cleanup:");
Expand Down
Loading

0 comments on commit dfcf426

Please sign in to comment.