Search in sources :

Example 11 with MutableInodeFile

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())));
}
Also used : MutableInodeDirectory(alluxio.master.file.meta.MutableInodeDirectory) MutableInodeFile(alluxio.master.file.meta.MutableInodeFile) MutableInode(alluxio.master.file.meta.MutableInode) Inode(alluxio.master.file.meta.Inode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with MutableInodeFile

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Journal(alluxio.proto.journal.Journal) MutableInodeFile(alluxio.master.file.meta.MutableInodeFile) File(alluxio.proto.journal.File) InodeFile(alluxio.master.file.meta.InodeFile) MutableInodeFile(alluxio.master.file.meta.MutableInodeFile) Pair(alluxio.collections.Pair)

Aggregations

MutableInodeFile (alluxio.master.file.meta.MutableInodeFile)12 Test (org.junit.Test)10 Inode (alluxio.master.file.meta.Inode)4 ArrayList (java.util.ArrayList)4 MutableInode (alluxio.master.file.meta.MutableInode)2 MutableInodeDirectory (alluxio.master.file.meta.MutableInodeDirectory)2 Pair (alluxio.collections.Pair)1 InodeFile (alluxio.master.file.meta.InodeFile)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 WriteBatch (alluxio.master.metastore.InodeStore.WriteBatch)1 ReadOption (alluxio.master.metastore.ReadOption)1 File (alluxio.proto.journal.File)1 Journal (alluxio.proto.journal.Journal)1 HashMap (java.util.HashMap)1