Skip to content

Commit

Permalink
Avoid unnecessary key_ field fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
d4mian committed May 29, 2014
1 parent 3fd7ea8 commit 39dc6cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/java/voldemort/store/mysql/MysqlStorageEngine.java
Expand Up @@ -168,7 +168,7 @@ public boolean delete(ByteArray key, Version maxVersion) throws PersistenceFailu
Connection conn = null;
PreparedStatement selectStmt = null;
ResultSet rs = null;
String select = "select key_, version_ from " + getName() + " where key_ = ? for update";
String select = "select version_ from " + getName() + " where key_ = ? for update";

try {
conn = datasource.getConnection();
Expand All @@ -177,11 +177,10 @@ public boolean delete(ByteArray key, Version maxVersion) throws PersistenceFailu
rs = selectStmt.executeQuery();
boolean deletedSomething = false;
while(rs.next()) {
byte[] theKey = rs.getBytes("key_");
byte[] version = rs.getBytes("version_");
if((maxVersion == null)
|| (new VectorClock(version).compare(maxVersion) == Occurred.BEFORE)) {
delete(conn, theKey, version);
delete(conn, key.get(), version);
deletedSomething = true;
}
}
Expand Down Expand Up @@ -263,7 +262,7 @@ public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms)
ResultSet results = null;
String insertSql = "insert into " + getName()
+ " (key_, version_, value_) values (?, ?, ?)";
String selectSql = "select key_, version_ from " + getName() + " where key_ = ?";
String selectSql = "select version_ from " + getName() + " where key_ = ?";
try {
conn = datasource.getConnection();
conn.setAutoCommit(false);
Expand All @@ -273,7 +272,6 @@ public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms)
select.setBytes(1, key.get());
results = select.executeQuery();
while(results.next()) {
byte[] thisKey = results.getBytes("key_");
VectorClock version = new VectorClock(results.getBytes("version_"));
Occurred occurred = value.getVersion().compare(version);
if(occurred == Occurred.BEFORE)
Expand All @@ -282,7 +280,7 @@ public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms)
+ " which is superceeded by " + version
+ ".");
else if(occurred == Occurred.AFTER)
delete(conn, thisKey, version.toBytes());
delete(conn, key.get(), version.toBytes());
}

// Okay, cool, now put the value
Expand Down

0 comments on commit 39dc6cd

Please sign in to comment.