Return-Path: X-Original-To: apmail-ignite-user-archive@minotaur.apache.org Delivered-To: apmail-ignite-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0947810192 for ; Sat, 9 May 2015 18:55:11 +0000 (UTC) Received: (qmail 75813 invoked by uid 500); 9 May 2015 18:55:10 -0000 Delivered-To: apmail-ignite-user-archive@ignite.apache.org Received: (qmail 75790 invoked by uid 500); 9 May 2015 18:55:10 -0000 Mailing-List: contact user-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@ignite.incubator.apache.org Delivered-To: mailing list user@ignite.incubator.apache.org Received: (qmail 75780 invoked by uid 99); 9 May 2015 18:55:10 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 May 2015 18:55:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 7498CC124B for ; Sat, 9 May 2015 18:55:10 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.973 X-Spam-Level: X-Spam-Status: No, score=0.973 tagged_above=-999 required=6.31 tests=[SPF_SOFTFAIL=0.972, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id cLSQrhe0CaS1 for ; Sat, 9 May 2015 18:55:00 +0000 (UTC) Received: from mwork.nabble.com (mwork.nabble.com [162.253.133.43]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 4F3B52123F for ; Sat, 9 May 2015 18:55:00 +0000 (UTC) Received: from malf.nabble.com (unknown [162.253.133.59]) by mwork.nabble.com (Postfix) with ESMTP id 9FF981DBD0F5 for ; Sat, 9 May 2015 11:50:49 -0700 (PDT) Date: Sat, 9 May 2015 11:47:33 -0700 (PDT) From: pgarg To: user@ignite.incubator.apache.org Message-ID: <1431197253363-245.post@n6.nabble.com> In-Reply-To: <1431197016931-244.post@n6.nabble.com> References: <1431196992062-243.post@n6.nabble.com> <1431197016931-244.post@n6.nabble.com> Subject: Re: Local secondary file system - problem to list files MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit /commented by alexandre verri/ The code: /public static void main(String[] args) throws IOException { // New configuration. final IgniteConfiguration cfg = new IgniteConfiguration(); final String filesystemName = "myFs"; final String metaCacheName = "myMetaCache"; final String dataCacheName = "myDataCache"; // Data cache configuration. final CacheConfiguration dataCacheCfg = new CacheConfiguration(); dataCacheCfg.setName(dataCacheName); dataCacheCfg.setOffHeapMaxMemory(500 * 1024 * 1024); dataCacheCfg.setCacheMode(CacheMode.PARTITIONED); dataCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(512)); // Meta cache configuration. final CacheConfiguration metaCacheCfg = new CacheConfiguration(); metaCacheCfg.setName(metaCacheName); metaCacheCfg.setCacheMode(CacheMode.REPLICATED); metaCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); // Filesystem configuration. final FileSystemConfiguration fsConfig = new FileSystemConfiguration(); fsConfig.setSecondaryFileSystem(new DefaultLocalSecondaryFilesystem(Paths.get("/home/averri/ignite"))); fsConfig.setDefaultMode(IgfsMode.DUAL_SYNC); fsConfig.setName(filesystemName); fsConfig.setMetaCacheName(metaCacheName); fsConfig.setDataCacheName(dataCacheName); fsConfig.setIpcEndpointEnabled(false); cfg.setFileSystemConfiguration(fsConfig); cfg.setCacheConfiguration(dataCacheCfg, metaCacheCfg); final Ignite ignite = Ignition.start(cfg); // Get the filesystem. final IgniteFileSystem fs = ignite.fileSystem(filesystemName); // List the contents of the directory. fs.listFiles(new IgfsPath("/myDir")).forEach(f -> System.out.println("### File: " + f.toString())); }/ The DefaultLocalSecondaryFilesystem class: public class DefaultLocalSecondaryFilesystem implements IgfsSecondaryFileSystem { /// The root of the secondary filesystem. private final Path root; public DefaultLocalSecondaryFilesystem(Path root) throws IOException { if (root == null) { throw new IllegalArgumentException("The root of DefaultLocalSecondaryFilesystem cannot be null."); } try { Files.createDirectory(root); } catch (FileAlreadyExistsException e) { // Ignore. } this.root = root; } @Override public boolean exists(IgfsPath igPath) { return Files.exists(resolve(igPath)); } @Override public IgfsFile update(IgfsPath path, Map props) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public void rename(IgfsPath src, IgfsPath dest) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public boolean delete(IgfsPath path, boolean recursive) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public void mkdirs(IgfsPath path) throws IgniteException { call(() -> Files.createDirectories(resolve(path))); } @Override public void mkdirs(IgfsPath path, Map props) throws IgniteException { // TODO: to consider the props. mkdirs(path); } @Override public Collection listPaths(IgfsPath path) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public Collection listFiles(IgfsPath path) throws IgniteException { return call(() -> Files.list(resolve(path)).map(this::info).collect(Collectors.toList())); } @Override public IgfsSecondaryFileSystemPositionedReadable open(IgfsPath path, int bufSize) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public OutputStream create(IgfsPath path, boolean overwrite) throws IgniteException { return call(() -> Files.newOutputStream(resolve(path), overwrite ? StandardOpenOption.WRITE : StandardOpenOption.CREATE)); } @Override public OutputStream create(IgfsPath path, int bufSize, boolean overwrite, int replication, long blockSize, Map props) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public OutputStream append(IgfsPath path, int bufSize, boolean create, Map props) throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public IgfsFile info(IgfsPath igPath) throws IgniteException { return call(() -> { final Path fsPath = resolve(igPath); if (Files.exists(fsPath)) { IgfsFileInfo info = new IgfsFileInfo(Files.isDirectory(fsPath), new HashMap<>()); // TODO: How to calculate the last parameter? return new IgfsFileImpl(igPath, info, 0); } return null; }); } @Override public long usedSpaceSize() throws IgniteException { throw new UnsupportedOperationException("Not implemented yet."); } @Override public Map properties() { // TODO: Implement. return new ConcurrentHashMap<>(); } private Path resolve(IgfsPath igPath) { return root.resolve(igPath.toString().replaceFirst("[/\\\\]", "")); } private IgfsFile info(Path fsPath) { final int length = root.toString().length(); return info(new IgfsPath(fsPath.toString().substring(length).replaceAll("\\\\", "/"))); } private static T call(Callable callable) throws IgniteException { if (callable != null) { try { return callable.call(); } catch (Exception e) { throw new IgniteException(e); } } return null; } } / In this code example, the file '/home/averri/ignite/myDir/test.txt' exists only in the first node. If we call the method listFiles in the second node, there will be no files. ----- /This post is migrated from now discontinued Apache Ignite forum at http://apacheignite.readme.io/v1.0/discuss/ -- View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Local-secondary-file-system-problem-to-list-files-tp243p245.html Sent from the Apache Ignite Users mailing list archive at Nabble.com.