Commit 4a468599 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Split large query of a set of GUIDs in chunks, just like for LFNs

parent 27a0125c
......@@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
......@@ -268,24 +269,31 @@ public final class GUIDUtils {
final StringBuilder sb = new StringBuilder();
for (final UUID u : tableEntry.getValue()) {
if (sb.length() > 0)
sb.append(',');
final ArrayList<UUID> allGUIDs = new ArrayList<>(tableEntry.getValue());
sb.append("string2binary('").append(u.toString()).append("')");
}
final String q = "SELECT * FROM G" + tableName + "L WHERE guid IN (" + sb.toString() + ");";
for (int i = 0; i < allGUIDs.size(); i += IndexTableEntry.MAX_QUERY_LENGTH) {
sb.setLength(0);
final List<UUID> sublist = allGUIDs.subList(i, Math.min(i + IndexTableEntry.MAX_QUERY_LENGTH, allGUIDs.size()));
if (!db.query(q))
throw new IllegalStateException("Failed executing query: " + q);
for (final UUID u : sublist) {
if (sb.length() > 0)
sb.append(',');
while (db.moveNext())
try {
ret.add(new GUID(db, h.hostIndex, tableName.intValue()));
} catch (final Exception e) {
logger.log(Level.WARNING, "Exception instantiating some guid from " + tableName, e);
sb.append("string2binary('").append(u.toString()).append("')");
}
final String q = "SELECT SQL_NO_CACHE * FROM G" + tableName + "L WHERE guid IN (" + sb.toString() + ");";
if (!db.query(q))
throw new IllegalStateException("Failed executing query: " + q);
while (db.moveNext())
try {
ret.add(new GUID(db, h.hostIndex, tableName.intValue()));
} catch (final Exception e) {
logger.log(Level.WARNING, "Exception instantiating some guid from " + tableName, e);
}
}
}
}
}
......@@ -325,7 +333,7 @@ public final class GUIDUtils {
monitor.incrementCounter("GUID_db_lookup");
db.setReadOnly(true);
db.setQueryTimeout(600);
if (!db.query("SELECT * FROM G" + tableName + "L WHERE guid=string2binary(?);", false, guid.toString()))
......
......@@ -103,8 +103,10 @@ public class IndexTableEntry implements Serializable, Comparable<IndexTableEntry
return getLFN(sPath, false);
}
// Restrict how many LFNs can be queried in a single request
private static final int MAX_QUERY_LENGTH = 100;
/**
* Restrict how many LFNs can be queried in a single request
*/
static final int MAX_QUERY_LENGTH = 100;
/**
* Get the LFN from this table
......@@ -132,12 +134,12 @@ public class IndexTableEntry implements Serializable, Comparable<IndexTableEntry
for (int chunk = 0; chunk < queries; chunk++) {
final List<String> sublist = path.subList(chunk * MAX_QUERY_LENGTH, Math.min((chunk + 1) * MAX_QUERY_LENGTH, path.size()));
final StringBuilder q = new StringBuilder("SELECT ");
if (sublist.size()>1)
if (sublist.size() > 1)
q.append("SQL_NO_CACHE ");
q.append("* FROM L" + tableName + "L WHERE ");
boolean first = true;
......@@ -233,10 +235,10 @@ public class IndexTableEntry implements Serializable, Comparable<IndexTableEntry
final List<UUID> sublist = uuidsAsList.subList(chunk * MAX_QUERY_LENGTH, Math.min((chunk + 1) * MAX_QUERY_LENGTH, uuidsAsList.size()));
final StringBuilder sb = new StringBuilder("SELECT ");
if (sublist.size()>1)
if (sublist.size() > 1)
sb.append("SQL_NO_CACHE ");
sb.append("* FROM L" + tableName + "L WHERE guid IN (");
boolean first = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment