/* * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 * (the "License"). You may not use this work except in compliance with the License, which is * available at www.apache.org/licenses/LICENSE-2.0 * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied, as more fully set forth in the License. * * See the NOTICE file distributed with this work for information regarding copyright ownership. */ package alluxio.master.file; import alluxio.exception.FileDoesNotExistException; import alluxio.heartbeat.HeartbeatExecutor; import alluxio.master.file.meta.Inode; import alluxio.master.file.meta.InodeTree; import alluxio.master.file.meta.LockedInodePath; import alluxio.master.file.meta.PersistenceState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.concurrent.NotThreadSafe; /** * Lost files periodic check. */ @NotThreadSafe final class LostFileDetector implements HeartbeatExecutor { private static final Logger LOG = LoggerFactory.getLogger(LostFileDetector.class); private final FileSystemMaster mFileSystemMaster; private final InodeTree mInodeTree; /** * Constructs a new {@link LostFileDetector}. */ public LostFileDetector(FileSystemMaster fileSystemMaster, InodeTree inodeTree) { mFileSystemMaster = fileSystemMaster; mInodeTree = inodeTree; } @Override public void heartbeat() { for (long fileId : mFileSystemMaster.getLostFiles()) { // update the state try (LockedInodePath inodePath = mInodeTree .lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) { Inode<?> inode = inodePath.getInode(); if (inode.getPersistenceState() != PersistenceState.PERSISTED) { inode.setPersistenceState(PersistenceState.LOST); } } catch (FileDoesNotExistException e) { LOG.error("Exception trying to get inode from inode tree", e); } } } @Override public void close() { // Nothing to clean up } }