Search in sources :

Example 1 with IgfsMetrics

use of org.apache.ignite.igfs.IgfsMetrics in project ignite by apache.

the class IgfsMetricsSelfTest method testBlockMetrics.

/**
     * Test block metrics.
     *
     * @throws Exception If failed.
     */
@SuppressWarnings({ "ResultOfMethodCallIgnored", "ConstantConditions" })
public void testBlockMetrics() throws Exception {
    IgfsEx igfs = (IgfsEx) igfsPrimary[0];
    IgfsPath fileRemote = new IgfsPath("/fileRemote");
    IgfsPath file1 = new IgfsPath("/primary/file1");
    IgfsPath file2 = new IgfsPath("/primary/file2");
    // Create remote file and write some data to it.
    IgfsOutputStream out = igfsSecondary.create(fileRemote, 256, true, null, 1, 256, null);
    int rmtBlockSize = igfsSecondary.info(fileRemote).blockSize();
    out.write(new byte[rmtBlockSize]);
    out.close();
    // Start metrics measuring.
    IgfsMetrics initMetrics = igfs.metrics();
    // Create empty file.
    igfs.create(file1, 256, true, null, 1, 256, null).close();
    int blockSize = igfs.info(file1).blockSize();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 0, 0, 0);
    // Write two blocks to the file.
    IgfsOutputStream os = igfs.append(file1, false);
    os.write(new byte[blockSize * 2]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 2, 0, blockSize * 2);
    // Write one more file (one block).
    os = igfs.create(file2, 256, true, null, 1, 256, null);
    os.write(new byte[blockSize]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 0, 0, 0, 3, 0, blockSize * 3);
    // Read data from the first file.
    IgfsInputStream is = igfs.open(file1);
    is.readFully(0, new byte[blockSize * 2]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 2, 0, blockSize * 2, 3, 0, blockSize * 3);
    // Read data from the second file with hits.
    is = igfs.open(file2);
    is.read(new byte[blockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Clear the first file.
    igfs.create(file1, true).close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Delete the second file.
    igfs.delete(file2, false);
    checkBlockMetrics(initMetrics, igfs.metrics(), 3, 0, blockSize * 3, 3, 0, blockSize * 3);
    // Read remote file.
    is = igfs.open(fileRemote);
    is.read(new byte[rmtBlockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 4, 1, blockSize * 3 + rmtBlockSize, 3, 0, blockSize * 3);
    // Lets wait for blocks will be placed to cache
    U.sleep(300);
    // Read remote file again.
    is = igfs.open(fileRemote);
    is.read(new byte[rmtBlockSize]);
    is.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 3, 0, blockSize * 3);
    IgfsMetrics metrics = igfs.metrics();
    assert metrics.secondarySpaceSize() == rmtBlockSize;
    // Write some data to the file working in DUAL mode.
    os = igfs.append(fileRemote, false);
    os.write(new byte[rmtBlockSize]);
    os.close();
    // Additional block read here due to file ending synchronization.
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 4, 1, blockSize * 3 + rmtBlockSize);
    metrics = igfs.metrics();
    assert metrics.secondarySpaceSize() == rmtBlockSize * 2;
    igfs.delete(fileRemote, false);
    U.sleep(300);
    assert igfs.metrics().secondarySpaceSize() == 0;
    // Write partial block to the first file.
    os = igfs.append(file1, false);
    os.write(new byte[blockSize / 2]);
    os.close();
    checkBlockMetrics(initMetrics, igfs.metrics(), 5, 1, blockSize * 3 + rmtBlockSize * 2, 5, 1, blockSize * 7 / 2 + rmtBlockSize);
    igfs.resetMetrics();
    metrics = igfs.metrics();
    assert metrics.blocksReadTotal() == 0;
    assert metrics.blocksReadRemote() == 0;
    assert metrics.blocksWrittenTotal() == 0;
    assert metrics.blocksWrittenRemote() == 0;
    assert metrics.bytesRead() == 0;
    assert metrics.bytesReadTime() == 0;
    assert metrics.bytesWritten() == 0;
    assert metrics.bytesWriteTime() == 0;
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsMetrics(org.apache.ignite.igfs.IgfsMetrics) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 2 with IgfsMetrics

use of org.apache.ignite.igfs.IgfsMetrics in project ignite by apache.

the class HadoopIgfs20FileSystemAbstractSelfTest method testStatus.

/** @throws Exception If failed. */
public void testStatus() throws Exception {
    Path file1 = new Path("/file1");
    try (FSDataOutputStream file = fs.create(file1, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()))) {
        file.write(new byte[1024 * 1024]);
    }
    FsStatus status = fs.getFsStatus();
    assertEquals(getClientFsUser(), fs.getFileStatus(file1).getOwner());
    assertEquals(4, grid(0).cluster().nodes().size());
    long used = 0, max = 0;
    for (int i = 0; i < 4; i++) {
        IgniteFileSystem igfs = grid(i).fileSystem("igfs");
        IgfsMetrics metrics = igfs.metrics();
        used += metrics.localSpaceSize();
        max += metrics.maxSpaceSize();
    }
    assertEquals(used, status.getUsed());
    assertEquals(max, status.getCapacity());
}
Also used : Path(org.apache.hadoop.fs.Path) IgfsPath(org.apache.ignite.igfs.IgfsPath) CreateFlag(org.apache.hadoop.fs.CreateFlag) IgfsMetrics(org.apache.ignite.igfs.IgfsMetrics) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) FsStatus(org.apache.hadoop.fs.FsStatus)

Example 3 with IgfsMetrics

use of org.apache.ignite.igfs.IgfsMetrics in project ignite by apache.

the class IgfsMetricsSelfTest method testMultipleClose.

/** @throws Exception If failed. */
public void testMultipleClose() throws Exception {
    IgniteFileSystem fs = igfsPrimary[0];
    IgfsOutputStream out = fs.create(new IgfsPath("/primary/file"), false);
    out.close();
    out.close();
    IgfsInputStream in = fs.open(new IgfsPath("/primary/file"));
    in.close();
    in.close();
    IgfsMetrics m = fs.metrics();
    assertEquals(0, m.filesOpenedForWrite());
    assertEquals(0, m.filesOpenedForRead());
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsMetrics(org.apache.ignite.igfs.IgfsMetrics) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Example 4 with IgfsMetrics

use of org.apache.ignite.igfs.IgfsMetrics in project ignite by apache.

the class IgfsMetricsSelfTest method testMetrics.

/** @throws Exception If failed. */
public void testMetrics() throws Exception {
    IgniteFileSystem fs = igfsPrimary[0];
    assertNotNull(fs);
    IgfsMetrics m = fs.metrics();
    assertNotNull(m);
    assertEquals(0, m.directoriesCount());
    assertEquals(0, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    fs.mkdirs(new IgfsPath("/primary/dir1"));
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(2, m.directoriesCount());
    assertEquals(0, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    fs.mkdirs(new IgfsPath("/primary/dir1/dir2/dir3"));
    fs.mkdirs(new IgfsPath("/primary/dir4"));
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(0, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    IgfsOutputStream out1 = fs.create(new IgfsPath("/primary/dir1/file1"), false);
    IgfsOutputStream out2 = fs.create(new IgfsPath("/primary/dir1/file2"), false);
    IgfsOutputStream out3 = fs.create(new IgfsPath("/primary/dir1/dir2/file"), false);
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(3, m.filesOpenedForWrite());
    out1.write(new byte[10]);
    out2.write(new byte[20]);
    out3.write(new byte[30]);
    out1.close();
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(2, m.filesOpenedForWrite());
    out2.close();
    out3.close();
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    IgfsOutputStream out = fs.append(new IgfsPath("/primary/dir1/file1"), false);
    out.write(new byte[20]);
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(1, m.filesOpenedForWrite());
    out.write(new byte[20]);
    out.close();
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    IgfsInputStream in1 = fs.open(new IgfsPath("/primary/dir1/file1"));
    IgfsInputStream in2 = fs.open(new IgfsPath("/primary/dir1/file2"));
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(2, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    in1.close();
    in2.close();
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(5, m.directoriesCount());
    assertEquals(3, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    fs.delete(new IgfsPath("/primary/dir1/file1"), false);
    fs.delete(new IgfsPath("/primary/dir1/dir2"), true);
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(3, m.directoriesCount());
    assertEquals(1, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
    fs.clear();
    m = fs.metrics();
    assertNotNull(m);
    assertEquals(0, m.directoriesCount());
    assertEquals(0, m.filesCount());
    assertEquals(0, m.filesOpenedForRead());
    assertEquals(0, m.filesOpenedForWrite());
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsMetrics(org.apache.ignite.igfs.IgfsMetrics) IgniteFileSystem(org.apache.ignite.IgniteFileSystem) IgfsOutputStream(org.apache.ignite.igfs.IgfsOutputStream)

Aggregations

IgfsMetrics (org.apache.ignite.igfs.IgfsMetrics)4 IgfsPath (org.apache.ignite.igfs.IgfsPath)4 IgniteFileSystem (org.apache.ignite.IgniteFileSystem)3 IgfsInputStream (org.apache.ignite.igfs.IgfsInputStream)3 IgfsOutputStream (org.apache.ignite.igfs.IgfsOutputStream)3 CreateFlag (org.apache.hadoop.fs.CreateFlag)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FsStatus (org.apache.hadoop.fs.FsStatus)1 Path (org.apache.hadoop.fs.Path)1