use of org.apache.ignite.igfs.IgfsFile in project ignite by apache.
the class IgfsImpl method summary0.
/**
* Get summary for path.
*
* @param path Path.
* @return Summary.
* @throws IgniteCheckedException If failed.
*/
private IgfsPathSummary summary0(IgfsPath path) throws IgniteCheckedException {
IgfsFile info = info(path);
if (info == null)
throw new IgfsPathNotFoundException("Failed to get path summary (path not found): " + path);
IgfsPathSummary sum = new IgfsPathSummary(path);
summaryRecursive(info, sum);
return sum;
}
use of org.apache.ignite.igfs.IgfsFile in project ignite by apache.
the class IgfsMetaManager method synchronize.
/**
* Synchronize directory structure with the secondary file system.
*
* @param fs Secondary file system.
* @param startPath Start path.
* @param startPathInfo Start path info.
* @param endPath End path.
* @param strict Whether all paths must exist in the secondary file system.
* @param created Optional map where data about all created values is put.
* @return File info of the end path.
* @throws IgniteCheckedException If failed.
*/
private IgfsEntryInfo synchronize(IgfsSecondaryFileSystem fs, IgfsPath startPath, IgfsEntryInfo startPathInfo, IgfsPath endPath, boolean strict, @Nullable Map<IgfsPath, IgfsEntryInfo> created) throws IgniteCheckedException {
assert fs != null;
assert startPath != null && startPathInfo != null && endPath != null;
validTxState(true);
IgfsEntryInfo parentInfo = startPathInfo;
List<String> components = endPath.components();
IgfsPath curPath = startPath;
for (int i = startPath.components().size(); i < components.size(); i++) {
curPath = new IgfsPath(curPath, components.get(i));
if (created != null && created.containsKey(curPath))
// Re-use already created info.
parentInfo = created.get(curPath);
else {
// Get file status from the secondary file system.
IgfsFile status;
try {
status = fs.info(curPath);
} catch (IgniteException e) {
throw new IgniteCheckedException("Failed to get path information: " + e, e);
}
if (status != null) {
if (!status.isDirectory() && !curPath.equals(endPath))
throw new IgniteCheckedException("Failed to create path the locally because secondary file " + "system directory structure was modified concurrently and the path is not a directory as " + "expected: " + curPath);
} else {
if (strict) {
throw new IgniteCheckedException("Failed to create path locally due to secondary file system " + "exception: " + curPath);
} else if (created != null)
created.put(curPath.parent(), parentInfo);
return null;
}
// Recreate the path locally.
IgfsEntryInfo curInfo = status.isDirectory() ? IgfsUtils.createDirectory(IgniteUuid.randomUuid(), null, status.properties(), status.accessTime(), status.modificationTime()) : IgfsUtils.createFile(IgniteUuid.randomUuid(), igfsCtx.configuration().getBlockSize(), status.length(), null, null, igfsCtx.igfs().evictExclude(curPath, false), status.properties(), status.accessTime(), status.modificationTime());
assert parentInfo != null;
IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), components.get(i), curInfo);
if (oldId != null)
curInfo = info(oldId);
if (created != null)
created.put(curPath, curInfo);
parentInfo = curInfo;
}
}
return parentInfo;
}
use of org.apache.ignite.igfs.IgfsFile in project ignite by apache.
the class IgfsAbstractSelfTest method checkSetTimes.
/**
* Check setTimes logic for path.
*
* @param path Path.
* @throws Exception If failed.
*/
private void checkSetTimes(IgfsPath path) throws Exception {
if (timesSupported()) {
IgfsFile info = igfs.info(path);
T2<Long, Long> secondaryTimes = dual ? igfsSecondary.times(path.toString()) : null;
assert info != null;
// Change nothing.
igfs.setTimes(path, -1, -1);
IgfsFile newInfo = igfs.info(path);
assert newInfo != null;
assertEquals(info.accessTime(), newInfo.accessTime());
assertEquals(info.modificationTime(), newInfo.modificationTime());
if (dual) {
T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
assertEquals(secondaryTimes.get1(), newSecondaryTimes.get1());
assertEquals(secondaryTimes.get2(), newSecondaryTimes.get2());
}
// Change only access time.
igfs.setTimes(path, -1, info.accessTime() + 1000);
newInfo = igfs.info(path);
assert newInfo != null;
assertEquals(info.accessTime() + 1000, newInfo.accessTime());
assertEquals(info.modificationTime(), newInfo.modificationTime());
if (dual) {
T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
assertEquals(secondaryTimes.get1(), newSecondaryTimes.get1());
}
// Change only modification time.
igfs.setTimes(path, info.modificationTime() + 1000, -1);
newInfo = igfs.info(path);
assert newInfo != null;
assertEquals(info.accessTime() + 1000, newInfo.accessTime());
assertEquals(info.modificationTime() + 1000, newInfo.modificationTime());
if (dual) {
T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
}
// Change both.
igfs.setTimes(path, info.modificationTime() + 2000, info.accessTime() + 2000);
newInfo = igfs.info(path);
assert newInfo != null;
assertEquals(info.accessTime() + 2000, newInfo.accessTime());
assertEquals(info.modificationTime() + 2000, newInfo.modificationTime());
if (dual) {
T2<Long, Long> newSecondaryTimes = igfsSecondary.times(path.toString());
assertEquals(newInfo.modificationTime(), (long) newSecondaryTimes.get1());
assertEquals(newInfo.accessTime(), (long) newSecondaryTimes.get2());
}
}
}
use of org.apache.ignite.igfs.IgfsFile in project ignite by apache.
the class IgfsAbstractSelfTest method testListFiles.
/**
* Test list files routine.
*
* @throws Exception If failed.
*/
public void testListFiles() throws Exception {
create(igfs, paths(DIR, SUBDIR, SUBSUBDIR), paths(FILE));
Collection<IgfsFile> paths = igfs.listFiles(SUBDIR);
assert paths != null;
assert paths.size() == 2;
Iterator<IgfsFile> iter = paths.iterator();
IgfsFile path1 = iter.next();
IgfsFile path2 = iter.next();
assert (SUBSUBDIR.equals(path1.path()) && FILE.equals(path2.path())) || (FILE.equals(path1.path()) && SUBSUBDIR.equals(path2.path()));
}
use of org.apache.ignite.igfs.IgfsFile in project ignite by apache.
the class IgfsDualAbstractSelfTest method testInfoPathMissing.
/**
* Test info routine when the path doesn't exist locally.
*
* @throws Exception If failed.
*/
public void testInfoPathMissing() throws Exception {
create(igfsSecondary, paths(DIR), null);
create(igfs, null, null);
IgfsFile info = igfs.info(DIR);
assert info != null;
assertEquals(DIR, info.path());
}
Aggregations