diff --git a/docs/Metrics-System.md b/docs/Metrics-System.md index c991eb91e156..0fea6d150de8 100644 --- a/docs/Metrics-System.md +++ b/docs/Metrics-System.md @@ -51,7 +51,6 @@ The following shows the details of the available metrics. * CapacityTotal: Total capacity of the file system in bytes. * CapacityUsed: Used capacity of the file system in bytes. * CapacityFree: Free capacity of the file system in bytes. -* FilesPinned: Total number of the files pinned. * PathsTotal: Total number of files and directories in the file system. * UnderFsCapacityTotal: Total capacity of the under file system in bytes. * UnderFsCapacityUsed: Used capacity of the under file system in bytes. @@ -64,7 +63,7 @@ The following shows the details of the available metrics. * FilesCreated: Total number of files created. * FilesFreed: Total number of files freed. * FilesPersisted: Total number of the files persisted. -* NewBlocksRequested: Total number of new blocks requested. +* FilesPinned: Total number of the files pinned. * PathsDeleted: Total number of files and directories deleted. * PathsMounted: Total number of paths mounted. * PathsRenamed: Total number of files and directories renamed. @@ -76,8 +75,9 @@ The following shows the details of the available metrics. * FreeFileOps: Total number of FreeFile operations. * GetFileBlockInfoOps: Total number of GetFileBlockInfo operations. * GetFileInfoOps: Total number of GetFileInfo operations. +* NewBlocksGot: Total number of new blocks got. * MountOps: Total number of Mount operations. -* NewBlockRequestOps: Total number of NewBlockRequest operations. +* GetNewBlockOps: Total number of GetNewBlock operations. * RenamePathOps: Total number of the RenamePath operations. * SetStateOps: Total number of the SetState operations. * UnmountOps: Total number of Unmount operations. diff --git a/servers/src/main/java/tachyon/master/MasterSource.java b/servers/src/main/java/tachyon/master/MasterSource.java index b4d4ba87d144..21d7a01b74c9 100644 --- a/servers/src/main/java/tachyon/master/MasterSource.java +++ b/servers/src/main/java/tachyon/master/MasterSource.java @@ -43,12 +43,10 @@ public class MasterSource implements Source { mMetricRegistry.counter(MetricRegistry.name("CompleteFileOps")); private final Counter mFilesCompleted = mMetricRegistry.counter(MetricRegistry.name("FilesCompleted")); - private final Counter mFreeFileOps = mMetricRegistry.counter(MetricRegistry.name("FreeFileOps")); private final Counter mFilesFreed = mMetricRegistry.counter(MetricRegistry.name("FilesFreed")); - private final Counter mFilesCreated = mMetricRegistry.counter(MetricRegistry.name("FilesCreated")); private final Counter mCreateFileOps = @@ -83,11 +81,10 @@ public class MasterSource implements Source { mMetricRegistry.counter(MetricRegistry.name("GetFileBlockInfoOps")); private final Counter mFileBlockInfosGot = mMetricRegistry.counter(MetricRegistry.name("FileBlockInfosGot")); - private final Counter mNewBlockRequestOps = - mMetricRegistry.counter(MetricRegistry.name("NewBlockRequestOps")); - private final Counter mNewBlocksRequested = - mMetricRegistry.counter(MetricRegistry.name("NewBlocksRequested")); - + private final Counter mGetNewBlockOps = + mMetricRegistry.counter(MetricRegistry.name("GetNewBlockOps")); + private final Counter mNewBlocksGot = + mMetricRegistry.counter(MetricRegistry.name("NewBlocksGot")); private final Counter mSetStateOps = mMetricRegistry.counter(MetricRegistry.name("SetStateOps")); @@ -196,19 +193,19 @@ public MetricRegistry getMetricRegistry() { return mMetricRegistry; } - public void incCompleteFileOps() { - mCompleteFileOps.inc(); + public void incCompleteFileOps(long n) { + mCompleteFileOps.inc(n); } - public void incFilesCompleted() { - mFilesCompleted.inc(); + public void incFilesCompleted(long n) { + mFilesCompleted.inc(n); } - public void incFreeFileOps() { - mFreeFileOps.inc(); + public void incFreeFileOps(long n) { + mFreeFileOps.inc(n); } - public void incFilesReleased(long n) { + public void incFilesFreed(long n) { mFilesFreed.inc(n); } @@ -284,11 +281,11 @@ public void incSetStateOps(long n) { mSetStateOps.inc(n); } - public void incNewBlockRequestOps(long n) { - mNewBlockRequestOps.inc(n); + public void incGetNewBlockOps(long n) { + mGetNewBlockOps.inc(n); } - public void incNewBlocksRequested(long n) { - mNewBlocksRequested.inc(n); + public void incNewBlocksGot(long n) { + mNewBlocksGot.inc(n); } } diff --git a/servers/src/main/java/tachyon/master/file/FileSystemMaster.java b/servers/src/main/java/tachyon/master/file/FileSystemMaster.java index 4b7f86add116..f12e72449ffc 100644 --- a/servers/src/main/java/tachyon/master/file/FileSystemMaster.java +++ b/servers/src/main/java/tachyon/master/file/FileSystemMaster.java @@ -25,7 +25,6 @@ import java.util.Set; import java.util.concurrent.Future; -import com.google.common.collect.Iterables; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.thrift.TProcessor; import org.slf4j.Logger; @@ -375,7 +374,7 @@ public List getFileInfoList(long fileId) throws FileDoesNotExistExcept public void completeFile(long fileId, CompleteFileOptions options) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, InvalidFileSizeException, FileAlreadyCompletedException { - MasterContext.getMasterSource().incCompleteFileOps(); + MasterContext.getMasterSource().incCompleteFileOps(1); synchronized (mInodeTree) { long opTimeMs = System.currentTimeMillis(); Inode inode = mInodeTree.getInodeById(fileId); @@ -439,7 +438,7 @@ void completeFileInternal(List blockIds, long fileId, long length, long op currLength -= blockSize; } } - MasterContext.getMasterSource().incFilesCompleted(); + MasterContext.getMasterSource().incFilesCompleted(1); } private void completeFileFromEntry(CompleteFileEntry entry) @@ -494,10 +493,8 @@ InodeTree.CreatePathResult createInternal(TachyonURI path, CreateOptions options mTTLBuckets.insert(inode); - MasterContext.getMasterSource() - .incFilesCreated(Iterables.size(Iterables.filter(created, InodeFile.class))); - MasterContext.getMasterSource() - .incDirectoriesCreated(Iterables.size(Iterables.filter(created, InodeDirectory.class))); + MasterContext.getMasterSource().incFilesCreated(1); + MasterContext.getMasterSource().incDirectoriesCreated(created.size() - 1); return createResult; } @@ -542,7 +539,7 @@ private void resetBlockFileFromEntry(ReinitializeFileEntry entry) { * @throws FileDoesNotExistException if the file does not exist */ public long getNewBlockIdForFile(long fileId) throws FileDoesNotExistException { - MasterContext.getMasterSource().incNewBlockRequestOps(1); + MasterContext.getMasterSource().incGetNewBlockOps(1); Inode inode; synchronized (mInodeTree) { inode = mInodeTree.getInodeById(fileId); @@ -550,9 +547,8 @@ public long getNewBlockIdForFile(long fileId) throws FileDoesNotExistException { if (!inode.isFile()) { throw new FileDoesNotExistException(ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId)); } - long newBlock = ((InodeFile) inode).getNewBlockId(); - MasterContext.getMasterSource().incNewBlocksRequested(1); - return newBlock; + MasterContext.getMasterSource().incNewBlocksGot(1); + return ((InodeFile) inode).getNewBlockId(); } /** @@ -1168,7 +1164,7 @@ private void propagatePersisted(Inode inode, boolean replayed) * @throws FileDoesNotExistException if the file does not exist */ public boolean free(long fileId, boolean recursive) throws FileDoesNotExistException { - MasterContext.getMasterSource().incFreeFileOps(); + MasterContext.getMasterSource().incFreeFileOps(1); synchronized (mInodeTree) { Inode inode = mInodeTree.getInodeById(fileId); @@ -1193,7 +1189,7 @@ public boolean free(long fileId, boolean recursive) throws FileDoesNotExistExcep mBlockMaster.removeBlocks(((InodeFile) freeInode).getBlockIds()); } } - MasterContext.getMasterSource().incFilesReleased(freeInodes.size()); + MasterContext.getMasterSource().incFilesFreed(freeInodes.size()); } return true; } diff --git a/servers/src/test/java/tachyon/metrics/MetricsCountersTest.java b/servers/src/test/java/tachyon/metrics/MetricsCountersTest.java index 6de7dbc4f695..91acc1b74098 100644 --- a/servers/src/test/java/tachyon/metrics/MetricsCountersTest.java +++ b/servers/src/test/java/tachyon/metrics/MetricsCountersTest.java @@ -23,7 +23,6 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import com.codahale.metrics.Counter; @@ -79,9 +78,6 @@ public final class MetricsCountersTest { @Rule public TemporaryFolder mTestFolder = new TemporaryFolder(); - @Rule - public ExpectedException mThrown = ExpectedException.none(); - @Before public void before() throws Exception { MasterContext.getConf().set(Constants.MASTER_TTLCHECKER_INTERVAL_MS, @@ -120,6 +116,7 @@ public void createFileTest() throws Exception { // trying to create a file that already exist try { mFileSystemMaster.create(ROOT_FILE_URI, sNestedFileOptions); + Assert.fail("create a file that already exist must throw an eception"); } catch (FileAlreadyExistsException e) { // do nothing } @@ -143,9 +140,10 @@ public void mkdirTest() throws Exception { Assert.assertEquals(1, mCounters.get("CreateDirectoryOps").getCount()); Assert.assertEquals(1, mCounters.get("DirectoriesCreated").getCount()); - // trying to create a file that already exist + // trying to create a directory that already exist try { mFileSystemMaster.mkdir(DIRECTORY_URI, MkdirOptions.defaults()); + Assert.fail("create a directory that already exist must throw an exception"); } catch (FileAlreadyExistsException e) { // do nothing } @@ -166,6 +164,7 @@ public void getFileInfoTest() throws Exception { // trying to get non-existent file info try { mFileSystemMaster.getFileInfo(-1); + Assert.fail("get file info for a non existing file must throw an exception"); } catch (FileDoesNotExistException e) { // do nothing } @@ -198,6 +197,7 @@ public void getFileBlockInfoTest() throws Exception { // trying to get block info list for a non-existent file try { mFileSystemMaster.getFileBlockInfoList(-1); + Assert.fail("get file block info for a non existing file must throw an exception"); } catch (FileDoesNotExistException e) { // do nothing } @@ -220,6 +220,7 @@ public void completeFileTest() throws Exception { // trying to complete a completed file try { completeFile(singleBlocksfileId); + Assert.fail("complete an already completed file must throw an exception"); } catch (FileAlreadyCompletedException e) { // do nothing } @@ -256,7 +257,7 @@ public void getNewBlockIdForFileTest() throws Exception { FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId); Assert.assertEquals(Lists.newArrayList(blockId), fileInfo.getBlockIds()); - Assert.assertEquals(1, mCounters.get("NewBlockRequestOps").getCount()); + Assert.assertEquals(1, mCounters.get("GetNewBlockOps").getCount()); } @Test @@ -325,21 +326,16 @@ public void mountUnmountTest() throws Exception { Assert.assertEquals(1, mCounters.get("PathsMounted").getCount()); Assert.assertEquals(1, mCounters.get("MountOps").getCount()); - mFileSystemMaster.unmount(TEST_URI); - - Assert.assertEquals(1, mCounters.get("PathsUnmounted").getCount()); - Assert.assertEquals(1, mCounters.get("UnmountOps").getCount()); - // trying to mount an existing file - mFileSystemMaster.create(MOUNT_URI, sNestedFileOptions); - try { - mFileSystemMaster.mount(MOUNT_URI, TEST_URI); - } catch (FileAlreadyExistsException e) { - // do nothing - } + Assert.assertFalse(mFileSystemMaster.mount(TEST_URI, MOUNT_URI)); Assert.assertEquals(1, mCounters.get("PathsMounted").getCount()); Assert.assertEquals(2, mCounters.get("MountOps").getCount()); + + mFileSystemMaster.unmount(TEST_URI); + + Assert.assertEquals(1, mCounters.get("PathsUnmounted").getCount()); + Assert.assertEquals(1, mCounters.get("UnmountOps").getCount()); } private long createCompleteFileWithSingleBlock(TachyonURI uri) throws Exception {