Search in sources :

Example 1 with IgfsMetaManager

use of org.apache.ignite.internal.processors.igfs.IgfsMetaManager in project ignite by apache.

the class HadoopIgfsDualAbstractSelfTest method testOpenPrefetchOverride.

/**
     * Check how prefetch override works.
     *
     * @throws Exception IF failed.
     */
public void testOpenPrefetchOverride() throws Exception {
    create(igfsSecondary, paths(DIR, SUBDIR), paths(FILE));
    // Write enough data to the secondary file system.
    final int blockSize = IGFS_BLOCK_SIZE;
    IgfsOutputStream out = igfsSecondary.append(FILE, false);
    int totalWritten = 0;
    while (totalWritten < blockSize * 2 + chunk.length) {
        out.write(chunk);
        totalWritten += chunk.length;
    }
    out.close();
    awaitFileClose(igfsSecondary, FILE);
    // Instantiate file system with overridden "seq reads before prefetch" property.
    Configuration cfg = new Configuration();
    cfg.addResource(U.resolveIgniteUrl(PRIMARY_CFG));
    int seqReads = SEQ_READS_BEFORE_PREFETCH + 1;
    cfg.setInt(String.format(PARAM_IGFS_SEQ_READS_BEFORE_PREFETCH, "igfs@"), seqReads);
    FileSystem fs = FileSystem.get(new URI(PRIMARY_URI), cfg);
    // Read the first two blocks.
    Path fsHome = new Path(PRIMARY_URI);
    Path dir = new Path(fsHome, DIR.name());
    Path subdir = new Path(dir, SUBDIR.name());
    Path file = new Path(subdir, FILE.name());
    FSDataInputStream fsIn = fs.open(file);
    final byte[] readBuf = new byte[blockSize * 2];
    fsIn.readFully(0, readBuf, 0, readBuf.length);
    // Wait for a while for prefetch to finish (if any).
    IgfsMetaManager meta = igfs.context().meta();
    IgfsEntryInfo info = meta.info(meta.fileId(FILE));
    IgfsBlockKey key = new IgfsBlockKey(info.id(), info.affinityKey(), info.evictExclude(), 2);
    IgniteCache<IgfsBlockKey, byte[]> dataCache = igfs.context().kernalContext().cache().jcache(igfs.configuration().getDataCacheConfiguration().getName());
    for (int i = 0; i < 10; i++) {
        if (dataCache.containsKey(key))
            break;
        else
            U.sleep(100);
    }
    fsIn.close();
    // Remove the file from the secondary file system.
    igfsSecondary.delete(FILE, false);
    // Try reading the third block. Should fail.
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            IgfsInputStream in0 = igfs.open(FILE);
            in0.seek(blockSize * 2);
            try {
                in0.read(readBuf);
            } finally {
                U.closeQuiet(in0);
            }
            return null;
        }
    }, IOException.class, "Failed to read data due to secondary file system exception: /dir/subdir/file");
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) Path(org.apache.hadoop.fs.Path) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsIpcEndpointConfiguration(org.apache.ignite.igfs.IgfsIpcEndpointConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileSystemConfiguration(org.apache.ignite.configuration.FileSystemConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream) URI(java.net.URI) IOException(java.io.IOException) IgfsMetaManager(org.apache.ignite.internal.processors.igfs.IgfsMetaManager) FileSystem(org.apache.hadoop.fs.FileSystem) IgniteHadoopIgfsSecondaryFileSystem(org.apache.ignite.hadoop.fs.IgniteHadoopIgfsSecondaryFileSystem) IgfsSecondaryFileSystem(org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem) IgfsBlockKey(org.apache.ignite.internal.processors.igfs.IgfsBlockKey) IgfsEntryInfo(org.apache.ignite.internal.processors.igfs.IgfsEntryInfo) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 2 with IgfsMetaManager

use of org.apache.ignite.internal.processors.igfs.IgfsMetaManager in project ignite by apache.

the class IgfsFragmentizerAbstractSelfTest method awaitFileFragmenting.

/**
     * @param gridIdx Grid index.
     * @param path Path to await.
     * @throws Exception If failed.
     */
protected void awaitFileFragmenting(int gridIdx, IgfsPath path) throws Exception {
    IgfsEx igfs = (IgfsEx) grid(gridIdx).fileSystem("igfs");
    IgfsMetaManager meta = igfs.context().meta();
    IgniteUuid fileId = meta.fileId(path);
    if (fileId == null)
        throw new IgfsPathNotFoundException("File not found: " + path);
    IgfsEntryInfo fileInfo = meta.info(fileId);
    do {
        if (fileInfo == null)
            throw new IgfsPathNotFoundException("File not found: " + path);
        if (fileInfo.fileMap().ranges().isEmpty())
            return;
        U.sleep(100);
        fileInfo = meta.info(fileId);
    } while (true);
}
Also used : IgfsEx(org.apache.ignite.internal.processors.igfs.IgfsEx) IgfsMetaManager(org.apache.ignite.internal.processors.igfs.IgfsMetaManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsEntryInfo(org.apache.ignite.internal.processors.igfs.IgfsEntryInfo)

Aggregations

IgfsEntryInfo (org.apache.ignite.internal.processors.igfs.IgfsEntryInfo)2 IgfsMetaManager (org.apache.ignite.internal.processors.igfs.IgfsMetaManager)2 IOException (java.io.IOException)1 URI (java.net.URI)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteHadoopIgfsSecondaryFileSystem (org.apache.ignite.hadoop.fs.IgniteHadoopIgfsSecondaryFileSystem)1 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)1 IgfsIpcEndpointConfiguration (org.apache.ignite.igfs.IgfsIpcEndpointConfiguration)1 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)1 IgfsPath (org.apache.ignite.igfs.IgfsPath)1 IgfsSecondaryFileSystem (org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem)1 IgfsBlockKey (org.apache.ignite.internal.processors.igfs.IgfsBlockKey)1 IgfsEx (org.apache.ignite.internal.processors.igfs.IgfsEx)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1