use of alluxio.master.file.meta.MutableInodeFile in project alluxio by Alluxio.
the class InodeStoreTest method manyOperations.
@Test
public void manyOperations() {
writeInode(mRoot);
MutableInodeDirectory curr = mRoot;
List<Long> fileIds = new ArrayList<>();
long numDirs = 100;
// Create 100 nested directories, each containing a file.
for (int i = 1; i < numDirs; i++) {
MutableInodeDirectory dir = inodeDir(i, curr.getId(), "dir" + i);
MutableInodeFile file = inodeFile(i + 1000, i, "file" + i);
fileIds.add(file.getId());
writeInode(dir);
writeInode(file);
writeEdge(curr, dir);
writeEdge(dir, file);
curr = dir;
}
// Check presence and delete files.
for (int i = 0; i < numDirs; i++) {
assertTrue(mStore.get(i).isPresent());
}
for (Long i : fileIds) {
assertTrue(mStore.get(i).isPresent());
Inode inode = mStore.get(i).get();
removeInode(inode);
removeParentEdge(inode);
assertFalse(mStore.get(i).isPresent());
assertFalse(mStore.getChild(inode.getParentId(), inode.getName()).isPresent());
}
long middleDir = numDirs / 2;
// Rename a directory
MutableInodeDirectory dir = mStore.getMutable(middleDir).get().asDirectory();
removeParentEdge(dir);
writeEdge(mRoot, dir);
dir.setParentId(mRoot.getId());
writeInode(dir);
Optional<Inode> renamed = mStore.getChild(mRoot, dir.getName());
assertTrue(renamed.isPresent());
assertTrue(mStore.getChild(renamed.get().asDirectory(), "dir" + (middleDir + 1)).isPresent());
assertEquals(0, Iterables.size(mStore.getChildren(mStore.get(middleDir - 1).get().asDirectory())));
}
use of alluxio.master.file.meta.MutableInodeFile in project alluxio by Alluxio.
the class InodeSyncStream method mergeCreateComplete.
/**
* Merge inode entry with subsequent update inode and update inode file entries.
*
* @param entries list of journal entries
* @return a list of compacted journal entries
*/
public static List<Journal.JournalEntry> mergeCreateComplete(List<alluxio.proto.journal.Journal.JournalEntry> entries) {
List<alluxio.proto.journal.Journal.JournalEntry> newEntries = new ArrayList<>();
// file id : index in the newEntries, InodeFileEntry
Map<Long, Pair<Integer, MutableInodeFile>> fileEntryMap = new HashMap<>();
for (alluxio.proto.journal.Journal.JournalEntry oldEntry : entries) {
if (oldEntry.hasInodeFile()) {
// Use the old entry as a placeholder, to be replaced later
newEntries.add(oldEntry);
fileEntryMap.put(oldEntry.getInodeFile().getId(), new Pair<>(newEntries.size() - 1, MutableInodeFile.fromJournalEntry(oldEntry.getInodeFile())));
} else if (oldEntry.hasUpdateInode()) {
File.UpdateInodeEntry entry = oldEntry.getUpdateInode();
if (fileEntryMap.get(entry.getId()) == null) {
newEntries.add(oldEntry);
continue;
}
MutableInodeFile inode = fileEntryMap.get(entry.getId()).getSecond();
inode.updateFromEntry(entry);
} else if (oldEntry.hasUpdateInodeFile()) {
File.UpdateInodeFileEntry entry = oldEntry.getUpdateInodeFile();
if (fileEntryMap.get(entry.getId()) == null) {
newEntries.add(oldEntry);
continue;
}
MutableInodeFile inode = fileEntryMap.get(entry.getId()).getSecond();
inode.updateFromEntry(entry);
} else {
newEntries.add(oldEntry);
}
}
for (Pair<Integer, MutableInodeFile> pair : fileEntryMap.values()) {
// Replace the old entry placeholder with the new entry,
// to create the file in the same place in the journal
newEntries.set(pair.getFirst(), pair.getSecond().toJournalEntry());
}
return newEntries;
}
Aggregations