Search in sources :

Example 1 with FileName

use of org.apache.crail.metadata.FileName in project incubator-crail by apache.

the class CoreDataStore method lookup.

public Upcoming<CrailNode> lookup(String path) throws Exception {
    FileName name = new FileName(path);
    if (CrailConstants.DEBUG) {
        LOG.info("lookupDirectory: path " + path);
    }
    RpcFuture<RpcGetFile> fileRes = rpcConnection.getFile(name, false);
    return new LookupNodeFuture(this, path, fileRes);
}
Also used : FileName(org.apache.crail.metadata.FileName) RpcGetFile(org.apache.crail.rpc.RpcGetFile)

Example 2 with FileName

use of org.apache.crail.metadata.FileName in project incubator-crail by apache.

the class CoreDataStore method rename.

public Upcoming<CrailNode> rename(String src, String dst) throws Exception {
    FileName srcPath = new FileName(src);
    FileName dstPath = new FileName(dst);
    if (CrailConstants.DEBUG) {
        LOG.info("rename: srcname " + src + ", dstname " + dst);
    }
    RpcFuture<RpcRenameFile> renameRes = rpcConnection.renameFile(srcPath, dstPath);
    return new RenameNodeFuture(this, src, dst, renameRes);
}
Also used : FileName(org.apache.crail.metadata.FileName) RpcRenameFile(org.apache.crail.rpc.RpcRenameFile)

Example 3 with FileName

use of org.apache.crail.metadata.FileName in project incubator-crail by apache.

the class CrailFsck method directoryDump.

public void directoryDump(String filename, boolean randomize) throws Exception {
    CrailConfiguration conf = new CrailConfiguration();
    CrailConstants.updateConstants(conf);
    CoreDataStore fs = new CoreDataStore(conf);
    DirectoryInputStream iter = fs._listEntries(filename, randomize);
    System.out.println("#hash   \t\tname\t\tfilecomponent");
    int i = 0;
    while (iter.hasRecord()) {
        DirectoryRecord record = iter.nextRecord();
        String path = CrailUtils.combinePath(record.getParent(), record.getFile());
        FileName hash = new FileName(path);
        System.out.format(i + ": " + "%08d\t\t%s\t%d\n", record.isValid() ? 1 : 0, padRight(record.getFile(), 8), hash.getFileComponent());
        i++;
    }
    iter.close();
    fs.closeFileSystem();
}
Also used : FileName(org.apache.crail.metadata.FileName) DirectoryRecord(org.apache.crail.core.DirectoryRecord) CrailConfiguration(org.apache.crail.conf.CrailConfiguration) CoreDataStore(org.apache.crail.core.CoreDataStore) DirectoryInputStream(org.apache.crail.core.DirectoryInputStream)

Example 4 with FileName

use of org.apache.crail.metadata.FileName in project incubator-crail by apache.

the class NameNodeService method getFile.

@Override
public short getFile(RpcRequestMessage.GetFileReq request, RpcResponseMessage.GetFileRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_GET_FILE, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    FileName fileHash = request.getFileName();
    boolean writeable = request.isWriteable();
    // rpc
    AbstractNode fileInfo = fileTree.retrieveFile(fileHash, errorState);
    if (errorState.getError() != RpcErrors.ERR_OK) {
        return errorState.getError();
    }
    if (fileInfo == null) {
        return RpcErrors.ERR_GET_FILE_FAILED;
    }
    if (writeable && !fileInfo.tokenFree()) {
        return RpcErrors.ERR_TOKEN_TAKEN;
    }
    if (writeable) {
        fileInfo.updateToken();
    }
    fileTable.put(fileInfo.getFd(), fileInfo);
    BlockInfo fileBlock = fileInfo.getBlock(0);
    response.setFileInfo(fileInfo);
    response.setFileBlock(fileBlock);
    if (writeable) {
        response.shipToken();
    }
    if (CrailConstants.DEBUG) {
        LOG.info("getFile: fd " + fileInfo.getFd() + ", isDir " + fileInfo.getType().isDirectory() + ", token " + fileInfo.getToken() + ", capacity " + fileInfo.getCapacity());
    }
    return RpcErrors.ERR_OK;
}
Also used : BlockInfo(org.apache.crail.metadata.BlockInfo) FileName(org.apache.crail.metadata.FileName)

Example 5 with FileName

use of org.apache.crail.metadata.FileName in project incubator-crail by apache.

the class NameNodeService method removeFile.

@Override
public short removeFile(RpcRequestMessage.RemoveFileReq request, RpcResponseMessage.DeleteFileRes response, RpcNameNodeState errorState) throws Exception {
    // check protocol
    if (!RpcProtocol.verifyProtocol(RpcProtocol.CMD_REMOVE_FILE, request, response)) {
        return RpcErrors.ERR_PROTOCOL_MISMATCH;
    }
    // get params
    FileName fileHash = request.getFileName();
    // rpc
    AbstractNode parentInfo = fileTree.retrieveParent(fileHash, errorState);
    if (errorState.getError() != RpcErrors.ERR_OK) {
        return errorState.getError();
    }
    if (parentInfo == null) {
        return RpcErrors.ERR_CREATE_FILE_FAILED;
    }
    AbstractNode fileInfo = fileTree.retrieveFile(fileHash, errorState);
    if (errorState.getError() != RpcErrors.ERR_OK) {
        return errorState.getError();
    }
    if (fileInfo == null) {
        return RpcErrors.ERR_GET_FILE_FAILED;
    }
    response.setParentInfo(parentInfo);
    response.setFileInfo(fileInfo);
    fileInfo = parentInfo.removeChild(fileInfo.getComponent());
    if (fileInfo == null) {
        return RpcErrors.ERR_GET_FILE_FAILED;
    }
    appendToDeleteQueue(fileInfo);
    if (CrailConstants.DEBUG) {
        LOG.info("removeFile: filename, fd " + fileInfo.getFd());
    }
    return RpcErrors.ERR_OK;
}
Also used : FileName(org.apache.crail.metadata.FileName)

Aggregations

FileName (org.apache.crail.metadata.FileName)12 IOException (java.io.IOException)3 BlockInfo (org.apache.crail.metadata.BlockInfo)2 RpcGetFile (org.apache.crail.rpc.RpcGetFile)2 FileNotFoundException (java.io.FileNotFoundException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CrailNodeType (org.apache.crail.CrailNodeType)1 CrailConfiguration (org.apache.crail.conf.CrailConfiguration)1 CoreDataStore (org.apache.crail.core.CoreDataStore)1 DirectoryInputStream (org.apache.crail.core.DirectoryInputStream)1 DirectoryRecord (org.apache.crail.core.DirectoryRecord)1 DataNodeInfo (org.apache.crail.metadata.DataNodeInfo)1 FileInfo (org.apache.crail.metadata.FileInfo)1 RpcCreateFile (org.apache.crail.rpc.RpcCreateFile)1 RpcDeleteFile (org.apache.crail.rpc.RpcDeleteFile)1 RpcGetLocation (org.apache.crail.rpc.RpcGetLocation)1