Skip to content

Commit

Permalink
rocksdb thrift file maintenance
Browse files Browse the repository at this point in the history
Summary:
- Modified the pom.xml project file to automatically create .java stubs
- Removed raw rocks db functions from the .thrift file

Test Plan: ran linkbench against rocks db server

Reviewers: andrewcox, MarkCallaghan

Reviewed By: MarkCallaghan

Differential Revision: https://reviews.facebook.net/D19593
  • Loading branch information
maykov committed Aug 7, 2014
1 parent 4f693b7 commit 5c879c9
Show file tree
Hide file tree
Showing 30 changed files with 101 additions and 1,314 deletions.
27 changes: 25 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
<dependency>
<groupId>com.facebook.swift</groupId>
<artifactId>swift-codec</artifactId>
<version>0.10.0</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.facebook.swift</groupId>
<artifactId>swift-service</artifactId>
<version>0.10.0</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -252,6 +252,29 @@
<excludedGroups>com.facebook.LinkBench.testtypes.ProviderTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<groupId>com.facebook.mojo</groupId>
<artifactId>swift-maven-plugin</artifactId>
<version>0.14.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<idlFiles>
<directory>
${basedir}/src/main/java/com/facebook/rocks/swift/
</directory>
<includes>
<include>*</include>
</includes>
</idlFiles>
<addCloseableInterface>true</addCloseableInterface>
</configuration>
</plugin>
</plugins>
</build>
</project>
18 changes: 18 additions & 0 deletions src/main/java/com/facebook/LinkBench/LinkStoreMysql.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Random;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -134,6 +135,7 @@ private void openConnection() throws Exception {
conn_rw = null;
stmt_ro = null;
stmt_rw = null;
Random rng = new Random();

String jdbcUrl = "jdbc:mysql://"+ host + ":" + port + "/";
if (defaultDB != null) {
Expand All @@ -150,9 +152,25 @@ private void openConnection() throws Exception {
* consistently across different MySql versions (see MySql bug 46675) */
"&useAffectedRows=true";

/* Fix for failing connections at high concurrency, short random delay for
* each */
try {
int t = rng.nextInt(1000) + 100;
//System.err.println("Sleeping " + t + " msecs");
Thread.sleep(t);
} catch (InterruptedException ie) {
}

conn_rw = DriverManager.getConnection(jdbcUrl, user, pwd);
conn_rw.setAutoCommit(false);

try {
int t = rng.nextInt(1000) + 100;
//System.err.println("Sleeping " + t + " msecs");
Thread.sleep(t);
} catch (InterruptedException ie) {
}

conn_ro = DriverManager.getConnection(jdbcUrl, user, pwd);
conn_ro.setAutoCommit(true);

Expand Down
75 changes: 29 additions & 46 deletions src/main/java/com/facebook/LinkBench/LinkStoreRocksDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private RocksService getRocksClient() throws Exception {
}

static synchronized void incrThreads() {
totalThreads++;
totalThreads++;
}

static synchronized boolean isLastThread() {
Expand Down Expand Up @@ -133,10 +133,10 @@ public void initialize(Properties p, Phase currentPhase, int threadId)
incrThreads();
host = ConfigUtil.getPropertyRequired(p, CONFIG_HOST);
port = ConfigUtil.getInt(p, CONFIG_PORT);
writeOptions = new WriteOptions(
ConfigUtil.getBool(p, CONFIG_WRITE_SYNC, false),
ConfigUtil.getBool(p, CONFIG_WRITE_DISABLE_WAL, false)
);
writeOptions = new WriteOptions();
writeOptions.setSync(ConfigUtil.getBool(p, CONFIG_WRITE_SYNC, false));
writeOptions.setDisableWAL(
ConfigUtil.getBool(p, CONFIG_WRITE_DISABLE_WAL, false));
debuglevel = ConfigUtil.getDebugLevel(p);
}

Expand Down Expand Up @@ -184,15 +184,12 @@ private boolean addLinkImpl(String dbid, Link l, boolean noinverse)
AssocVisibility av = AssocVisibility.values()[l.visibility];
String s = "wormhole...";
dbid += "assocs";
TaoAssocCountResult result = getRocksClient().TaoAssocPut(
long result = getRocksClient().TaoAssocPut(
dbid.getBytes(), l.link_type, l.id1, l.id2, l.time,
av, true, Long.valueOf(l.version), l.data, s.getBytes(),
writeOptions);
if (result.getRetCode().getState() != Code.K_OK) {
throw new Exception();
}

return result.getCount() == 1;
return result == 1;
}

/**
Expand All @@ -207,14 +204,10 @@ private boolean addLinksNoCount(String dbid, List<Link> links)
for (Link l:links) {
AssocVisibility av = AssocVisibility.values()[l.visibility];
String s = "wormhole...";
TaoAssocCountResult result =
long result =
getRocksClient().TaoAssocPut(dbid.getBytes(), l.link_type, l.id1,
l.id2, l.time, av, false, Long.valueOf(l.version), l.data,
s.getBytes(), writeOptions);
if (result.getRetCode().getState() != Code.K_OK) {
logger.error("addLinksNoCount failed!");
throw new RuntimeException("addLinksNoCount failed!");
}
}
return true;
}
Expand All @@ -240,12 +233,11 @@ private boolean deleteLinkImpl(String dbid, long id1, long link_type,
}
String s = "wormhole...";
dbid += "assocs";
TaoAssocCountResult result = getRocksClient().TaoAssocDelete(
long result = getRocksClient().TaoAssocDelete(
dbid.getBytes() , link_type, id1, id2,
-1 /*version ignored*/, AssocVisibility.HARD__DELETE, true,
-1 /*version ignored*/, AssocVisibility.HARD_DELETE, true,
s.getBytes(), writeOptions);
return (result.getRetCode().getState() == Code.K_OK &&
result.getCount() == 1);
return result == 1;
}

@Override
Expand Down Expand Up @@ -297,11 +289,12 @@ private Link[] multigetLinksImpl(String dbid, long id1, long link_type,
l.add(new Long(id2s[i]));
}
dbid += "assocs";
TaoAssocGetResult tr = getRocksClient().TaoAssocGetID2s(dbid.getBytes(),
List<TaoAssocGetEntry> tr = getRocksClient().TaoAssocGetID2s(
dbid.getBytes(),
link_type, id1, l);
Link results[] = new Link[tr.getEntries().size()];
Link results[] = new Link[tr.size()];
int i = 0;
for (TaoAssocGetEntry tar : tr.getEntries()) {
for (TaoAssocGetEntry tar : tr) {
results[i] = new Link(id1, link_type, tar.getId2(),
LinkStore.VISIBILITY_DEFAULT, tar.getData(),
(int)(tar.getVersion()), tar.getTime());
Expand Down Expand Up @@ -334,12 +327,12 @@ private Link[] getLinkListImpl(String dbid, long id1, long link_type,
long minTimestamp, long maxTimestamp, int offset, int limit)
throws Exception {
dbid += "assocs";
TaoAssocGetResult tr = getRocksClient().TaoAssocGetTimeRange(
List<TaoAssocGetEntry> tr = getRocksClient().TaoAssocGetTimeRange(
dbid.getBytes(), link_type, id1, minTimestamp, maxTimestamp,
Long.valueOf(offset), Long.valueOf(limit));
Link results[] = new Link[tr.getEntries().size()];
Link results[] = new Link[tr.size()];
int i = 0;
for (TaoAssocGetEntry tar : tr.getEntries()) {
for (TaoAssocGetEntry tar : tr) {
results[i] = new Link(id1, link_type, tar.getId2(),
LinkStore.VISIBILITY_DEFAULT, tar.getData(),
(int)(tar.getVersion()), tar.getTime());
Expand All @@ -362,19 +355,12 @@ public long countLinks(String dbid, long id1, long link_type)

private long countLinksImpl(String dbid, long id1, long link_type)
throws Exception {
long count = 0;
dbid += "assocs";
TaoAssocCountResult result = getRocksClient().TaoAssocCount(
long count = getRocksClient().TaoAssocCount(
dbid.getBytes(), link_type, id1);
boolean found = false;
if (result.getRetCode().getState() == Code.K_OK &&
result.getCount() > 0) {
found = true;
count = result.getCount();
}
if (Level.TRACE.isGreaterOrEqual(debuglevel)) {
logger.trace("Count result: " + id1 + "," + link_type +
" is " + found + " and " + count);
" is " + count);
}
return count;
}
Expand Down Expand Up @@ -465,12 +451,9 @@ private long[] bulkAddNodesImpl(String dbid, List<Node> nodes)
long newIds[] = new long[nodes.size()];
int i = 0;
for (Node n : nodes) {
RetCode code = getRocksClient().TaoFBObjectPut(
getRocksClient().TaoFBObjectPut(
n.id, n.type, (int) n.version, (int) n.version,
(long) n.time, n.data, true, null, writeOptions);
if (code.getState() != Code.K_OK) {
throw new Exception();
}
newIds[i++] = n.id;
}
return newIds;
Expand All @@ -487,16 +470,16 @@ public Node getNode(String dbid, int type, long id) throws Exception {
}

private Node getNodeImpl(String dbid, int type, long id) throws Exception {
ReadOptions ropts = new ReadOptions(false, false, null);
ReadOptions ropts = new ReadOptions();
ropts.setVerifyChecksums(true);
ropts.setFillCache(true);

TaoFBObjectGetResult rgr = getRocksClient().TaoFBObjectGet(id, type);
if (rgr.getRetCode().getState() == (Code.K_NOT_FOUND)) {
if (!rgr.isFound()) {
return null; //Node was not found
} else if (rgr.getRetCode().getState() == (Code.K_OK)) {
} else {
return new Node(
id, type, rgr.getVersion(), (int) rgr.getUpdateTime(), rgr.getData());
} else {
logger.error("IO Error");
return null;
}
}

Expand Down Expand Up @@ -526,8 +509,8 @@ public boolean deleteNode(String dbid, int type, long id) throws Exception {

private boolean deleteNodeImpl(String dbid, int type, long id)
throws Exception {
RetCode retCode = getRocksClient().
getRocksClient().
TaoFBObjectDel(id, type, null, writeOptions);
return (retCode.getState() == Code.K_OK);
return true;
}
}
21 changes: 0 additions & 21 deletions src/main/java/com/facebook/rocks/swift/AssocVisibility.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/com/facebook/rocks/swift/Code.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/com/facebook/rocks/swift/CompressionType.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/com/facebook/rocks/swift/Constants.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/com/facebook/rocks/swift/IOError.java

This file was deleted.

Loading

0 comments on commit 5c879c9

Please sign in to comment.