List of usage examples for org.apache.hadoop.hdfs.server.namenode INode getPathNames
public static String[] getPathNames(String path)
From source file:io.hops.memcache.PathMemcache.java
License:Apache License
public void set(final String path, final List<INode> inodes) { if (isStarted) { if (INode.getPathNames(path).length != inodes.size()) { return; }// w w w. ja v a2 s .com MemcachedClient mc = mcpool.poll(); if (mc == null) { return; } final String key = getKey(path); final int[] inodeIds = getINodeIds(inodes); final long startTime = System.currentTimeMillis(); mc.set(key, keyExpiry, new CacheEntry(inodeIds)).addListener(new OperationCompletionListener() { @Override public void onComplete(OperationFuture<?> f) throws Exception { long elapsed = System.currentTimeMillis() - startTime; LOG.debug("SET for path (" + path + ") " + key + "=" + Arrays.toString(inodeIds) + " in " + elapsed + " msec"); } }); } }
From source file:io.hops.resolvingcache.InMemoryCache.java
License:Apache License
@Override protected int[] getInternal(String path) throws IOException { String[] pathComponents = INode.getPathNames(path); int[] inodeIds = new int[pathComponents.length]; int parentId = INodeDirectory.ROOT_PARENT_ID; int index = 0; while (index < pathComponents.length) { String cmp = pathComponents[index]; Integer inodeId = cache.get(INode.nameParentKey(parentId, cmp)); if (inodeId != null) { parentId = inodeId;//from w w w . j av a2 s . c om inodeIds[index] = inodeId; } else { break; } index++; } //only the root was found if (index <= 1) return null; return Arrays.copyOf(inodeIds, index); }
From source file:io.hops.resolvingcache.InMemoryCache.java
License:Apache License
@Override protected int getRoundTrips(String path) { return INode.getPathNames(path).length; }
From source file:io.hops.resolvingcache.INodeMemcache.java
License:Apache License
@Override protected int[] getInternal(MemcachedClient mc, String path) throws IOException { String[] pathComponents = INode.getPathNames(path); int[] inodeIds = new int[pathComponents.length]; int parentId = INodeDirectory.ROOT_PARENT_ID; int index = 0; while (index < pathComponents.length) { String cmp = pathComponents[index]; Integer inodeId = getInternal(mc, cmp, parentId); if (inodeId != null) { parentId = inodeId;/*from w w w . j a va 2 s .c om*/ inodeIds[index] = inodeId; } else { break; } index++; } //only the root was found if (index <= 1) return null; return Arrays.copyOf(inodeIds, index); }
From source file:io.hops.resolvingcache.OptimalMemcache.java
License:Apache License
@Override protected void setInternal(MemcachedClient mc, String path, List<INode> inodes) { if (INode.getPathNames(path).length != inodes.size()) return;/*from w w w . j av a 2s .co m*/ int lastIndex = path.lastIndexOf(Path.SEPARATOR); if (lastIndex <= 0) return; INode file = inodes.get(inodes.size() - 1); if (file.isDirectory()) { super.setInternal(mc, path, inodes); return; } String parentPath = path.substring(0, lastIndex); super.setInternal(mc, parentPath, inodes.subList(0, inodes.size() - 1)); setInternal(mc, file); }
From source file:io.hops.resolvingcache.PathMemcache.java
License:Apache License
@Override protected void setInternal(final MemcachedClient mc, final String path, final List<INode> inodes) { if (INode.getPathNames(path).length != inodes.size()) { return;/* w w w . j a v a 2 s . c o m*/ } final String key = getKey(path); final int[] inodeIds = getINodeIds(inodes); final long startTime = System.currentTimeMillis(); mc.set(key, keyExpiry, new CacheEntry(inodeIds)).addListener(new OperationCompletionListener() { @Override public void onComplete(OperationFuture<?> f) throws Exception { long elapsed = System.currentTimeMillis() - startTime; LOG.debug("SET for path (" + path + ") " + key + "=" + Arrays.toString(inodeIds) + " in " + elapsed + " msec"); } }); }
From source file:io.hops.transaction.lock.BaseINodeLock.java
License:Apache License
protected List<INode> fetchINodesUsingMemcache(TransactionLockTypes.INodeLockType lockType, String path, boolean tryToSetParitionKey) throws IOException { int[] inodeIds = PathMemcache.getInstance().get(path); if (inodeIds != null) { if (tryToSetParitionKey) { setPartitioningKey(inodeIds[inodeIds.length - 1]); }/*from w w w . j a v a 2 s.com*/ final String[] names = INode.getPathNames(path); final int[] parentIds = getParentIds(inodeIds); List<INode> inodes = readINodesWhileRespectingLocks(lockType, names, parentIds); if (inodes != null) { if (verifyINodes(inodes, names, parentIds, inodeIds)) { addPathINodes(path, inodes); return inodes; } else { PathMemcache.getInstance().delete(path); } } } return null; }
From source file:io.hops.transaction.lock.RenameINodeLock.java
License:Apache License
@Override protected void acquire(TransactionLocks locks) throws IOException { //[S] consider src = /a/b/c and dst = /d //during the acquire lock of src write locks will be acquired on parent of c and c //during the acquire lock of dst write lock on the root will be acquired but the snapshot //layer will not let the request go to the db as it has already cached the root inode //one simple solution is that to acquire lock on the short path first //setPartitioningKey(PathMemcache.getInstance().getPartitionKey(locks.getInodeParam()[0])); String src = paths[0];//from ww w . ja v a2 s . c o m String dst = paths[1]; Arrays.sort(paths, PATH_COMPARTOR); acquireINodeLocks(); if (legacyRename) // In deprecated rename, it allows to move a dir to an existing destination. { List<INode> dstINodes = getPathINodes(dst); String[] dstComponents = INode.getPathNames(dst); String[] srcComponents = INode.getPathNames(src); INode lastComp = dstINodes.get(dstINodes.size() - 1); if (dstINodes.size() == dstComponents.length && lastComp.isDirectory()) { //the dst exist and is a directory. find(srcComponents[srcComponents.length - 1], lastComp.getId()); } } acquireINodeAttributes(); }