Skip to content

update load mount table #161

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 1 commit into from
Sep 5, 2019
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
2 changes: 1 addition & 1 deletion HdfsMetaInfoSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private HdfsMetaInfoSchema() throws SQLException {
+ " lastAllocatedStripedBlockId bigint"
+ ");"
+ "CREATE TABLE mount("
+ " namenode varchar, path varchar, readOnly smallint,"
+ " namenode varchar, path varchar, readOnly int,"
+ " PRIMARY KEY(namenode, path)"
+ ");"
+ "CREATE VIEW namenodes("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DatabaseMountTable {
public DatabaseMountTable() {}

public static void insertEntries(
final String[] namenodes, final String[] paths, final Integer[] readonlys) {
final String[] namenodes, final String[] paths, final Long[] readonlys) {
try {
DatabaseConnection obj = Database.getInstance().getConnection();
String env = System.getenv("DATABASE");
Expand Down Expand Up @@ -243,6 +243,7 @@ public static Boolean isUnified(String filePath) {
return res;
}

// Run a command-line from user
public static void dumpMountTable() {
try {
DatabaseConnection obj = new DatabaseConnection();
Expand Down Expand Up @@ -298,4 +299,41 @@ public static void dumpMountTable() {
System.err.println(ex.getMessage());
}
}

// Run a command-line from user
public static void loadEntries(
final String[] namenodes, final String[] paths, final Long[] readonlys) {
try {
DatabaseConnection obj = new DatabaseConnection();
String env = System.getenv("DATABASE");
if (env.equals("VOLT")) {
try {
obj.getVoltClient().callProcedure("InsertMountEntries", namenodes, paths, readonlys);
} catch (Exception e) {
e.printStackTrace();
}
} else {
String sql =
"INSERT INTO mount("
+ " namenode, path, readOnly"
+ ") VALUES (?, ?, ?) ON CONFLICT(namenode, path) DO NOTHING;";
sql = StringUtils.repeat(sql, namenodes.length);

Connection conn = obj.getConnection();
PreparedStatement pst = conn.prepareStatement(sql);
for (int i = 0; i < namenodes.length; ++i) {
pst.setString(i * 3 + 1, namenodes[i]);
pst.setString(i * 3 + 2, paths[i]);
pst.setLong(i * 3 + 3, readonlys[i]);
}
pst.executeUpdate();
pst.close();
}
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
if (LOG.isInfoEnabled()) {
LOG.info("loadEntries ...");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ public void load(String mounts) throws Exception {

List<String> namenodes = new ArrayList<String>();
List<String> paths = new ArrayList<String>();
List<Integer> readonlys = new ArrayList<Integer>();
List<Long> readonlys = new ArrayList<Long>();

for (int i = 0; i < splitted.length; i = i + 3) {
namenodes.add(splitted[i]);
paths.add((splitted[i + 1]).replaceAll("/$", ""));
readonlys.add(Integer.valueOf(splitted[i + 2]));
if (splitted[i + 1].length() > 1) {
paths.add((splitted[i + 1]).replaceAll("/$", ""));
} else {
paths.add(splitted[i + 1]);
}
readonlys.add(Long.valueOf(splitted[i + 2]));
}

DatabaseMountTable.insertEntries(
DatabaseMountTable.loadEntries(
namenodes.toArray(new String[namenodes.size()]),
paths.toArray(new String[paths.size()]),
readonlys.toArray(new Integer[readonlys.size()]));
readonlys.toArray(new Long[readonlys.size()]));
}
}
2 changes: 1 addition & 1 deletion voltdb/InsertMountEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class InsertMountEntries extends VoltProcedure {
public final SQLStmt sql =
new SQLStmt("UPSERT INTO mount(namenode, path, readOnly) VALUES (?, ?, ?);");

public long run(final String[] namenodes, final String[] paths, final Integer[] readonlys)
public long run(final String[] namenodes, final String[] paths, final long[] readonlys)
throws VoltAbortException {
for (int i = 0; i < namenodes.length; ++i) {
voltQueueSQL(sql, namenodes[i], paths[i], readonlys[i]);
Expand Down