Skip to content

[voltdb]: update subtree v2 using STARTS WITH #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion filescale_init/build_with_volt.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# copy the following command lines into test.sh
set -xe

cd $HADOOP_HOME
./sbin/stop-dfs.sh

export DATABASE="VOLT"
export VOLT_SERVER="localhost"

if [ -z "$1" ]
then
Expand All @@ -14,7 +16,7 @@ fi

# compile stored procedures
cd ~/hadoop/filescale_init/voltdb && bash clean_procedures.sh $IP
cd .. && javac HdfsMetaInfoSchema.java && java HdfsMetaInfoSchema
cd ../src/main/java && javac HdfsMetaInfoSchema.java && java HdfsMetaInfoSchema
cd ~/hadoop/filescale_init/voltdb && bash create_procedures.sh $IP

# restart hadoop hdfs
Expand Down
7 changes: 7 additions & 0 deletions filescale_init/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>

<dependency>
<groupId>org.voltdb</groupId>
<artifactId>voltdbclient</artifactId>
<version>9.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
44 changes: 0 additions & 44 deletions filescale_init/src/main/java/HdfsMetaInfoSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,50 +264,6 @@ private HdfsMetaInfoSchema() throws SQLException {
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}

// key-value API test
IgniteCluster cluster = ignite_client.cluster();
cluster.active(true);
cluster.enableWal("inodes");
cluster.baselineAutoAdjustEnabled(false);

Collection<String> collection = ignite_client.cacheNames();
System.out.println("cache names = " + collection);

IgniteCache<BinaryObject, BinaryObject> inodesBinary = ignite_client.cache("inodes").withKeepBinary();
System.out.println(">> Updating inode record:");

BinaryObjectBuilder inodeKeyBuilder = ignite_client.binary().builder("InodeKey");
BinaryObject inodeKey = inodeKeyBuilder.setField("parentName", "/").setField("name", "hello").build();
BinaryObjectBuilder inodeBuilder = ignite_client.binary().builder("INode");
BinaryObject inode = inodeBuilder
.setField("id", 11111L, Long.class)
.setField("parent", 0L, Long.class)
.setField("parentName", "/")
.setField("name", "hello")
.setField("accessTime", 22222L, Long.class)
.setField("modificationTime", 33333L, Long.class)
.setField("header", 0L, Long.class)
.setField("permission", 777L, Long.class)
.build();
System.out.printf("The dir: %s, id: %s \n", inode.field("parentName"), inode.field("name"), inode.field("id"));
inodesBinary.put(inodeKey, inode);

IgniteCompute compute = ignite_client.compute();
// Execute closure on all cluster nodes.
IgniteCallable<String> call = new WalPointerTask();
String res = compute.call(call);
System.out.printf("Last Wal pointer: " + res);
ignite_client.close();

// SQL test
try {
Statement st = connection.createStatement();
st.execute("delete from inodes where id = 11111;");
st.close();
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
}

public Connection getConnection() {
Expand Down
2 changes: 1 addition & 1 deletion filescale_init/voltdb/SetPermission.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.voltdb.*;

// https://docs.voltdb.com/tutorial/Part5.php
public class SetPermissions extends VoltProcedure {
public class SetPermission extends VoltProcedure {

public final SQLStmt sql = new SQLStmt("UPDATE inodes SET permission = ? WHERE id = ?;");

Expand Down
71 changes: 71 additions & 0 deletions filescale_init/voltdb/UpdateSubtreeV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import org.voltdb.*;
import java.util.*;

// https://docs.voltdb.com/tutorial/Part5.php
public class UpdateSubtreeV2 extends VoltProcedure {
public final SQLStmt sql1 = new SQLStmt(
"SELECT id, name, accessTime, modificationTime, permission,"
+ "header, parent, parentName from inodes WHERE parentName STARTS WITH ?;");

public final SQLStmt sql2 = new SQLStmt("INSERT INTO inodes("
+ "id, name, accessTime, modificationTime, permission, header, parent, parentName"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?);");

public final SQLStmt sql3 = new SQLStmt("DELETE FROM inodes where parentName STARTS WITH ?;");

public long run(final long dir_id, final long dest_id, final String old_parent_name,
final String new_parent_name, final long new_parent) throws VoltAbortException {
// 1. find subtree records
voltQueueSQL(sql1, old_parent_name);
VoltTable[] res = voltExecuteSQL();

// 2. update subtree records
Long id = null;
String name = null;
Long accessTime = null;
Long modificationTime = null;
Long permission = null;
Long header = null;
Long parent = null;
String parentName = null;
for (int j = 0; j < res.length; ++j) {
for (int i = 0; i < res[j].getRowCount(); ++i) {
VoltTableRow row = res[j].fetchRow(i);
id = row.getLong(0);
name = row.getString(1);
accessTime = row.getLong(2);
modificationTime = row.getLong(3);
permission = row.getLong(4);
header = row.getLong(5);
parent = row.getLong(6);
parentName = row.getString(7);

if (id == dir_id) {
id += dest_id;
parent = new_parent;
parentName = new_parent_name;
} else {
id += dest_id;
parent += dest_id;
parentName = new_parent_name + parentName.substring(old_parent_name.length());
}
voltQueueSQL(sql2,
id,
name,
accessTime,
modificationTime,
permission,
header,
parent,
parentName);
}
}
voltExecuteSQL();

// 3. delete old subtree records
voltQueueSQL(sql3, old_parent_name);
voltExecuteSQL();

return getUniqueId();
}
}
3 changes: 3 additions & 0 deletions filescale_init/voltdb/docker/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@
"create",
"--deployment=/root/voltdb-ent/deployment.xml",
"--host=" + sys.argv[3]])

# run voltdb
# ./deploy.py 1 0 0.0.0.0 &
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ public static long updateSubtree(final long dir_id, final long dest_id, final St
if (env.equals("VOLT")) {
try {
VoltTable[] results = obj.getVoltClient()
.callProcedure("UpdateSubtree", dir_id, dest_id, old_parent_name,
.callProcedure("UpdateSubtreeV2", dir_id, dest_id, old_parent_name,
new_parent_name, new_parent).getResults();
VoltTable result = results[0];
result.resetRowPosition();
Expand All @@ -2137,7 +2137,7 @@ public static long updateSubtree(final long dir_id, final long dest_id, final St
System.err.println(ex.getMessage());
}
if (LOG.isInfoEnabled()) {
LOG.info("txnId: " + res + " updateSubtree [UPDATE]: " + dir_id);
LOG.info("txnId: " + res + " updateSubtree v2 [UPDATE]: " + dir_id);
}
return res;
}
Expand Down