Commit 3f924a15 authored by Miguel Martinez Pedreira's avatar Miguel Martinez Pedreira
Browse files

Minor changes for Cassandra ls/find. Missing * on pattern expansion. Check BS applied

parent 2c417933
......@@ -78,26 +78,32 @@ public class LFNCSDUtils {
/**
* @param command
* @param base
* @param start_path
* @param pattern
* @param metadata
* @param flags
* @return list of lfns that fit the patterns, if any
*/
public static Collection<LFN_CSD> recurseAndFilterLFNs(final String command, final String base, final String pattern, final String metadata, final int flags) {
public static Collection<LFN_CSD> recurseAndFilterLFNs(final String command, final String start_path, final String pattern, final String metadata, final int flags) {
final Set<LFN_CSD> ret;
final AtomicInteger counter_left = new AtomicInteger();
// we create a base for search and a file pattern
int index = 0;
String path = start_path;
String file_pattern = (pattern == null ? "*" : pattern);
if (!start_path.endsWith("/") && pattern == null) {
file_pattern = start_path.substring(start_path.lastIndexOf('/') + 1);
path = start_path.substring(0, start_path.lastIndexOf('/') + 1);
}
// choose to use sorted/unsorted type according to flag (-s)
if ((flags & LFNCSDUtils.FIND_NO_SORT) != 0)
ret = new LinkedHashSet<>();
else
ret = new TreeSet<>();
String path = base;
String file_pattern = pattern;
int index = 0;
// Split the base into directories, change asterisk and ints. to regex format
// Split the base into directories, change asterisk and interrogation marks to regex format
ArrayList<String> path_parts;
if (!path.endsWith("/"))
path += "*/";
......@@ -327,6 +333,17 @@ public class LFNCSDUtils {
}
}
/**
* @param base_path
* @param pattern
* @param flags
* @param metadata
* @return list of files for find command
*/
public static Collection<LFN_CSD> find(final String base_path, final String pattern, final int flags, final String metadata) {
return recurseAndFilterLFNs("find", base_path, pattern, metadata, flags);
}
/**
* @param path
* @param flags
......@@ -337,13 +354,7 @@ public class LFNCSDUtils {
// if need to resolve wildcard and recurse, we call the recurse method
if (path.contains("*")) {
String pattern = "*";
String base = path;
if (!path.endsWith("/")) {
pattern = path.substring(path.lastIndexOf('/') + 1);
base = path.substring(0, path.lastIndexOf('/') + 1);
}
return recurseAndFilterLFNs("ls", base, pattern, null, flags);
return recurseAndFilterLFNs("ls", path, null, null, flags);
}
// otherwise we should be able to create the LFN_CSD from the path
......
......@@ -89,12 +89,12 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
/**
* Local cache to hold the hierarchy
*/
public static final ExpirationCache<String, UUID> dirCache = new ExpirationCache<>(80000); // TODO: should change size?
public static final ExpirationCache<String, UUID> dirCache = new ExpirationCache<>(80000);
/**
* Local cache to hold recently inserted folders
*/
public static final ExpirationCache<String, Integer> rifs = new ExpirationCache<>(5000); // TODO: should change size?
public static final ExpirationCache<String, Integer> rifs = new ExpirationCache<>(5000);
/**
* Owner
......@@ -748,6 +748,8 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
public boolean insert(String append_table, ConsistencyLevel level) {
// lfn | ctime | dir | gowner | jobid | link | md5 | owner | perm | pfns
// | size | type
boolean res = false;
String tindex = "catalogue.lfn_index";
if (append_table != null)
tindex += append_table;
......@@ -793,7 +795,7 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
BatchStatement bs = new BatchStatement(BatchStatement.Type.LOGGED);
bs.setConsistencyLevel(cl);
// Insert the entry in the index // TODO: use IF NOT EXISTS to avoid collisions when inserting paths
// Insert the entry in the index // TODO: (double-check) use IF NOT EXISTS to avoid collisions when inserting paths ?
statement = getOrInsertPreparedStatement(session, "INSERT INTO " + tindex + " (path_id,path,ctime,child_id,flag)" + " VALUES (?,?,?,?,?)");
bs.add(statement.bind(parent_id, child, ctime, id, Integer.valueOf(flag)));
......@@ -833,15 +835,14 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
}
}
session.execute(bs);
ResultSet rs = session.execute(bs);
res = rs.wasApplied();
} catch (Exception e) {
System.err.println("Exception trying to insert: " + e);
// TODO: shall we try to delete here from the tables?
return false;
}
return true;
return res;
}
/**
......
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