Skip to content

Commit

Permalink
- naming issue fixed
Browse files Browse the repository at this point in the history
- MetricsCountersTest improved
  • Loading branch information
Saverio Veltri committed Dec 18, 2015
1 parent 507019d commit 6a31b27
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 51 deletions.
6 changes: 3 additions & 3 deletions docs/Metrics-System.md
Expand Up @@ -51,7 +51,6 @@ The following shows the details of the available metrics.
* CapacityTotal: Total capacity of the file system in bytes. * CapacityTotal: Total capacity of the file system in bytes.
* CapacityUsed: Used 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. * 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. * PathsTotal: Total number of files and directories in the file system.
* UnderFsCapacityTotal: Total capacity of the under file system in bytes. * UnderFsCapacityTotal: Total capacity of the under file system in bytes.
* UnderFsCapacityUsed: Used capacity of the under file system in bytes. * UnderFsCapacityUsed: Used capacity of the under file system in bytes.
Expand All @@ -64,7 +63,7 @@ The following shows the details of the available metrics.
* FilesCreated: Total number of files created. * FilesCreated: Total number of files created.
* FilesFreed: Total number of files freed. * FilesFreed: Total number of files freed.
* FilesPersisted: Total number of the files persisted. * 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. * PathsDeleted: Total number of files and directories deleted.
* PathsMounted: Total number of paths mounted. * PathsMounted: Total number of paths mounted.
* PathsRenamed: Total number of files and directories renamed. * PathsRenamed: Total number of files and directories renamed.
Expand All @@ -76,8 +75,9 @@ The following shows the details of the available metrics.
* FreeFileOps: Total number of FreeFile operations. * FreeFileOps: Total number of FreeFile operations.
* GetFileBlockInfoOps: Total number of GetFileBlockInfo operations. * GetFileBlockInfoOps: Total number of GetFileBlockInfo operations.
* GetFileInfoOps: Total number of GetFileInfo operations. * GetFileInfoOps: Total number of GetFileInfo operations.
* NewBlocksGot: Total number of new blocks got.
* MountOps: Total number of Mount operations. * 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. * RenamePathOps: Total number of the RenamePath operations.
* SetStateOps: Total number of the SetState operations. * SetStateOps: Total number of the SetState operations.
* UnmountOps: Total number of Unmount operations. * UnmountOps: Total number of Unmount operations.
Expand Down
33 changes: 15 additions & 18 deletions servers/src/main/java/tachyon/master/MasterSource.java
Expand Up @@ -43,12 +43,10 @@ public class MasterSource implements Source {
mMetricRegistry.counter(MetricRegistry.name("CompleteFileOps")); mMetricRegistry.counter(MetricRegistry.name("CompleteFileOps"));
private final Counter mFilesCompleted = private final Counter mFilesCompleted =
mMetricRegistry.counter(MetricRegistry.name("FilesCompleted")); mMetricRegistry.counter(MetricRegistry.name("FilesCompleted"));

private final Counter mFreeFileOps = private final Counter mFreeFileOps =
mMetricRegistry.counter(MetricRegistry.name("FreeFileOps")); mMetricRegistry.counter(MetricRegistry.name("FreeFileOps"));
private final Counter mFilesFreed = private final Counter mFilesFreed =
mMetricRegistry.counter(MetricRegistry.name("FilesFreed")); mMetricRegistry.counter(MetricRegistry.name("FilesFreed"));

private final Counter mFilesCreated = private final Counter mFilesCreated =
mMetricRegistry.counter(MetricRegistry.name("FilesCreated")); mMetricRegistry.counter(MetricRegistry.name("FilesCreated"));
private final Counter mCreateFileOps = private final Counter mCreateFileOps =
Expand Down Expand Up @@ -83,11 +81,10 @@ public class MasterSource implements Source {
mMetricRegistry.counter(MetricRegistry.name("GetFileBlockInfoOps")); mMetricRegistry.counter(MetricRegistry.name("GetFileBlockInfoOps"));
private final Counter mFileBlockInfosGot = private final Counter mFileBlockInfosGot =
mMetricRegistry.counter(MetricRegistry.name("FileBlockInfosGot")); mMetricRegistry.counter(MetricRegistry.name("FileBlockInfosGot"));
private final Counter mNewBlockRequestOps = private final Counter mGetNewBlockOps =
mMetricRegistry.counter(MetricRegistry.name("NewBlockRequestOps")); mMetricRegistry.counter(MetricRegistry.name("GetNewBlockOps"));
private final Counter mNewBlocksRequested = private final Counter mNewBlocksGot =
mMetricRegistry.counter(MetricRegistry.name("NewBlocksRequested")); mMetricRegistry.counter(MetricRegistry.name("NewBlocksGot"));

private final Counter mSetStateOps = private final Counter mSetStateOps =
mMetricRegistry.counter(MetricRegistry.name("SetStateOps")); mMetricRegistry.counter(MetricRegistry.name("SetStateOps"));


Expand Down Expand Up @@ -196,19 +193,19 @@ public MetricRegistry getMetricRegistry() {
return mMetricRegistry; return mMetricRegistry;
} }


public void incCompleteFileOps() { public void incCompleteFileOps(long n) {
mCompleteFileOps.inc(); mCompleteFileOps.inc(n);
} }


public void incFilesCompleted() { public void incFilesCompleted(long n) {
mFilesCompleted.inc(); mFilesCompleted.inc(n);
} }


public void incFreeFileOps() { public void incFreeFileOps(long n) {
mFreeFileOps.inc(); mFreeFileOps.inc(n);
} }


public void incFilesReleased(long n) { public void incFilesFreed(long n) {
mFilesFreed.inc(n); mFilesFreed.inc(n);
} }


Expand Down Expand Up @@ -284,11 +281,11 @@ public void incSetStateOps(long n) {
mSetStateOps.inc(n); mSetStateOps.inc(n);
} }


public void incNewBlockRequestOps(long n) { public void incGetNewBlockOps(long n) {
mNewBlockRequestOps.inc(n); mGetNewBlockOps.inc(n);
} }


public void incNewBlocksRequested(long n) { public void incNewBlocksGot(long n) {
mNewBlocksRequested.inc(n); mNewBlocksGot.inc(n);
} }
} }
22 changes: 9 additions & 13 deletions servers/src/main/java/tachyon/master/file/FileSystemMaster.java
Expand Up @@ -25,7 +25,6 @@
import java.util.Set; import java.util.Set;
import java.util.concurrent.Future; import java.util.concurrent.Future;


import com.google.common.collect.Iterables;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.thrift.TProcessor; import org.apache.thrift.TProcessor;
import org.slf4j.Logger; import org.slf4j.Logger;
Expand Down Expand Up @@ -375,7 +374,7 @@ public List<FileInfo> getFileInfoList(long fileId) throws FileDoesNotExistExcept
public void completeFile(long fileId, CompleteFileOptions options) public void completeFile(long fileId, CompleteFileOptions options)
throws BlockInfoException, FileDoesNotExistException, InvalidPathException, throws BlockInfoException, FileDoesNotExistException, InvalidPathException,
InvalidFileSizeException, FileAlreadyCompletedException { InvalidFileSizeException, FileAlreadyCompletedException {
MasterContext.getMasterSource().incCompleteFileOps(); MasterContext.getMasterSource().incCompleteFileOps(1);
synchronized (mInodeTree) { synchronized (mInodeTree) {
long opTimeMs = System.currentTimeMillis(); long opTimeMs = System.currentTimeMillis();
Inode inode = mInodeTree.getInodeById(fileId); Inode inode = mInodeTree.getInodeById(fileId);
Expand Down Expand Up @@ -439,7 +438,7 @@ void completeFileInternal(List<Long> blockIds, long fileId, long length, long op
currLength -= blockSize; currLength -= blockSize;
} }
} }
MasterContext.getMasterSource().incFilesCompleted(); MasterContext.getMasterSource().incFilesCompleted(1);
} }


private void completeFileFromEntry(CompleteFileEntry entry) private void completeFileFromEntry(CompleteFileEntry entry)
Expand Down Expand Up @@ -494,10 +493,8 @@ InodeTree.CreatePathResult createInternal(TachyonURI path, CreateOptions options


mTTLBuckets.insert(inode); mTTLBuckets.insert(inode);


MasterContext.getMasterSource() MasterContext.getMasterSource().incFilesCreated(1);
.incFilesCreated(Iterables.size(Iterables.filter(created, InodeFile.class))); MasterContext.getMasterSource().incDirectoriesCreated(created.size() - 1);
MasterContext.getMasterSource()
.incDirectoriesCreated(Iterables.size(Iterables.filter(created, InodeDirectory.class)));
return createResult; return createResult;
} }


Expand Down Expand Up @@ -542,17 +539,16 @@ private void resetBlockFileFromEntry(ReinitializeFileEntry entry) {
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
*/ */
public long getNewBlockIdForFile(long fileId) throws FileDoesNotExistException { public long getNewBlockIdForFile(long fileId) throws FileDoesNotExistException {
MasterContext.getMasterSource().incNewBlockRequestOps(1); MasterContext.getMasterSource().incGetNewBlockOps(1);
Inode inode; Inode inode;
synchronized (mInodeTree) { synchronized (mInodeTree) {
inode = mInodeTree.getInodeById(fileId); inode = mInodeTree.getInodeById(fileId);
} }
if (!inode.isFile()) { if (!inode.isFile()) {
throw new FileDoesNotExistException(ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId)); throw new FileDoesNotExistException(ExceptionMessage.FILEID_MUST_BE_FILE.getMessage(fileId));
} }
long newBlock = ((InodeFile) inode).getNewBlockId(); MasterContext.getMasterSource().incNewBlocksGot(1);
MasterContext.getMasterSource().incNewBlocksRequested(1); return ((InodeFile) inode).getNewBlockId();
return newBlock;
} }


/** /**
Expand Down Expand Up @@ -1168,7 +1164,7 @@ private void propagatePersisted(Inode inode, boolean replayed)
* @throws FileDoesNotExistException if the file does not exist * @throws FileDoesNotExistException if the file does not exist
*/ */
public boolean free(long fileId, boolean recursive) throws FileDoesNotExistException { public boolean free(long fileId, boolean recursive) throws FileDoesNotExistException {
MasterContext.getMasterSource().incFreeFileOps(); MasterContext.getMasterSource().incFreeFileOps(1);
synchronized (mInodeTree) { synchronized (mInodeTree) {
Inode inode = mInodeTree.getInodeById(fileId); Inode inode = mInodeTree.getInodeById(fileId);


Expand All @@ -1193,7 +1189,7 @@ public boolean free(long fileId, boolean recursive) throws FileDoesNotExistExcep
mBlockMaster.removeBlocks(((InodeFile) freeInode).getBlockIds()); mBlockMaster.removeBlocks(((InodeFile) freeInode).getBlockIds());
} }
} }
MasterContext.getMasterSource().incFilesReleased(freeInodes.size()); MasterContext.getMasterSource().incFilesFreed(freeInodes.size());
} }
return true; return true;
} }
Expand Down
30 changes: 13 additions & 17 deletions servers/src/test/java/tachyon/metrics/MetricsCountersTest.java
Expand Up @@ -23,7 +23,6 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.codahale.metrics.Counter; import com.codahale.metrics.Counter;
Expand Down Expand Up @@ -79,9 +78,6 @@ public final class MetricsCountersTest {
@Rule @Rule
public TemporaryFolder mTestFolder = new TemporaryFolder(); public TemporaryFolder mTestFolder = new TemporaryFolder();


@Rule
public ExpectedException mThrown = ExpectedException.none();

@Before @Before
public void before() throws Exception { public void before() throws Exception {
MasterContext.getConf().set(Constants.MASTER_TTLCHECKER_INTERVAL_MS, MasterContext.getConf().set(Constants.MASTER_TTLCHECKER_INTERVAL_MS,
Expand Down Expand Up @@ -120,6 +116,7 @@ public void createFileTest() throws Exception {
// trying to create a file that already exist // trying to create a file that already exist
try { try {
mFileSystemMaster.create(ROOT_FILE_URI, sNestedFileOptions); mFileSystemMaster.create(ROOT_FILE_URI, sNestedFileOptions);
Assert.fail("create a file that already exist must throw an eception");
} catch (FileAlreadyExistsException e) { } catch (FileAlreadyExistsException e) {
// do nothing // do nothing
} }
Expand All @@ -143,9 +140,10 @@ public void mkdirTest() throws Exception {
Assert.assertEquals(1, mCounters.get("CreateDirectoryOps").getCount()); Assert.assertEquals(1, mCounters.get("CreateDirectoryOps").getCount());
Assert.assertEquals(1, mCounters.get("DirectoriesCreated").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 { try {
mFileSystemMaster.mkdir(DIRECTORY_URI, MkdirOptions.defaults()); mFileSystemMaster.mkdir(DIRECTORY_URI, MkdirOptions.defaults());
Assert.fail("create a directory that already exist must throw an exception");
} catch (FileAlreadyExistsException e) { } catch (FileAlreadyExistsException e) {
// do nothing // do nothing
} }
Expand All @@ -166,6 +164,7 @@ public void getFileInfoTest() throws Exception {
// trying to get non-existent file info // trying to get non-existent file info
try { try {
mFileSystemMaster.getFileInfo(-1); mFileSystemMaster.getFileInfo(-1);
Assert.fail("get file info for a non existing file must throw an exception");
} catch (FileDoesNotExistException e) { } catch (FileDoesNotExistException e) {
// do nothing // do nothing
} }
Expand Down Expand Up @@ -198,6 +197,7 @@ public void getFileBlockInfoTest() throws Exception {
// trying to get block info list for a non-existent file // trying to get block info list for a non-existent file
try { try {
mFileSystemMaster.getFileBlockInfoList(-1); mFileSystemMaster.getFileBlockInfoList(-1);
Assert.fail("get file block info for a non existing file must throw an exception");
} catch (FileDoesNotExistException e) { } catch (FileDoesNotExistException e) {
// do nothing // do nothing
} }
Expand All @@ -220,6 +220,7 @@ public void completeFileTest() throws Exception {
// trying to complete a completed file // trying to complete a completed file
try { try {
completeFile(singleBlocksfileId); completeFile(singleBlocksfileId);
Assert.fail("complete an already completed file must throw an exception");
} catch (FileAlreadyCompletedException e) { } catch (FileAlreadyCompletedException e) {
// do nothing // do nothing
} }
Expand Down Expand Up @@ -256,7 +257,7 @@ public void getNewBlockIdForFileTest() throws Exception {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId); FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(Lists.newArrayList(blockId), fileInfo.getBlockIds()); Assert.assertEquals(Lists.newArrayList(blockId), fileInfo.getBlockIds());


Assert.assertEquals(1, mCounters.get("NewBlockRequestOps").getCount()); Assert.assertEquals(1, mCounters.get("GetNewBlockOps").getCount());
} }


@Test @Test
Expand Down Expand Up @@ -325,21 +326,16 @@ public void mountUnmountTest() throws Exception {
Assert.assertEquals(1, mCounters.get("PathsMounted").getCount()); Assert.assertEquals(1, mCounters.get("PathsMounted").getCount());
Assert.assertEquals(1, mCounters.get("MountOps").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 // trying to mount an existing file
mFileSystemMaster.create(MOUNT_URI, sNestedFileOptions); Assert.assertFalse(mFileSystemMaster.mount(TEST_URI, MOUNT_URI));
try {
mFileSystemMaster.mount(MOUNT_URI, TEST_URI);
} catch (FileAlreadyExistsException e) {
// do nothing
}


Assert.assertEquals(1, mCounters.get("PathsMounted").getCount()); Assert.assertEquals(1, mCounters.get("PathsMounted").getCount());
Assert.assertEquals(2, mCounters.get("MountOps").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 { private long createCompleteFileWithSingleBlock(TachyonURI uri) throws Exception {
Expand Down

0 comments on commit 6a31b27

Please sign in to comment.