Java Code Examples for org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot#NO_SNAPSHOT_ID

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot#NO_SNAPSHOT_ID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: INodeReference.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * When destroying a reference node (WithName or DstReference), we call this
 * method to identify the snapshot which is the latest snapshot before the
 * reference node's creation. 
 */
static int getPriorSnapshot(INodeReference ref) {
  WithCount wc = (WithCount) ref.getReferredINode();
  WithName wn = null;
  if (ref instanceof DstReference) {
    wn = wc.getLastWithName();
  } else if (ref instanceof WithName) {
    wn = wc.getPriorWithName((WithName) ref);
  }
  if (wn != null) {
    INode referred = wc.getReferredINode();
    if (referred.isFile() && referred.asFile().isWithSnapshot()) {
      return referred.asFile().getDiffs().getPrior(wn.lastSnapshotId);
    } else if (referred.isDirectory()) {
      DirectoryWithSnapshotFeature sf = referred.asDirectory()
          .getDirectoryWithSnapshotFeature();
      if (sf != null) {
        return sf.getDiffs().getPrior(wn.lastSnapshotId);
      }
    }
  }
  return Snapshot.NO_SNAPSHOT_ID;
}
 
Example 2
Source File: INodeDirectory.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** Call cleanSubtree(..) recursively down the subtree. */
public QuotaCounts cleanSubtreeRecursively(final BlockStoragePolicySuite bsps,
    final int snapshot,
    int prior, final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes, final Map<INode, INode> excludedNodes) {
  QuotaCounts counts = new QuotaCounts.Builder().build();
  // in case of deletion snapshot, since this call happens after we modify
  // the diff list, the snapshot to be deleted has been combined or renamed
  // to its latest previous snapshot. (besides, we also need to consider nodes
  // created after prior but before snapshot. this will be done in 
  // DirectoryWithSnapshotFeature)
  int s = snapshot != Snapshot.CURRENT_STATE_ID
      && prior != Snapshot.NO_SNAPSHOT_ID ? prior : snapshot;
  for (INode child : getChildrenList(s)) {
    if (snapshot != Snapshot.CURRENT_STATE_ID && excludedNodes != null
        && excludedNodes.containsKey(child)) {
      continue;
    } else {
      QuotaCounts childCounts = child.cleanSubtree(bsps, snapshot, prior,
          collectedBlocks, removedINodes);
      counts.add(childCounts);
    }
  }
  return counts;
}
 
Example 3
Source File: INode.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** Is this inode in the latest snapshot? */
public final boolean isInLatestSnapshot(final int latestSnapshotId) {
  if (latestSnapshotId == Snapshot.CURRENT_STATE_ID || latestSnapshotId == Snapshot.NO_SNAPSHOT_ID) {
    return false;
  }
  // if parent is a reference node, parent must be a renamed node. We can 
  // stop the check at the reference node.
  if (parent != null && parent.isReference()) {
    return true;
  }
  final INodeDirectory parentDir = getParent();
  if (parentDir == null) { // root
    return true;
  }
  if (!parentDir.isInLatestSnapshot(latestSnapshotId)) {
    return false;
  }
  final INode child = parentDir.getChild(getLocalNameBytes(), latestSnapshotId);
  if (this == child) {
    return true;
  }
  return child != null && child.isReference() &&
      this == child.asReference().getReferredINode();
}
 
Example 4
Source File: INodeReference.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * When destroying a reference node (WithName or DstReference), we call this
 * method to identify the snapshot which is the latest snapshot before the
 * reference node's creation. 
 */
static int getPriorSnapshot(INodeReference ref) {
  WithCount wc = (WithCount) ref.getReferredINode();
  WithName wn = null;
  if (ref instanceof DstReference) {
    wn = wc.getLastWithName();
  } else if (ref instanceof WithName) {
    wn = wc.getPriorWithName((WithName) ref);
  }
  if (wn != null) {
    INode referred = wc.getReferredINode();
    if (referred.isFile() && referred.asFile().isWithSnapshot()) {
      return referred.asFile().getDiffs().getPrior(wn.lastSnapshotId);
    } else if (referred.isDirectory()) {
      DirectoryWithSnapshotFeature sf = referred.asDirectory()
          .getDirectoryWithSnapshotFeature();
      if (sf != null) {
        return sf.getDiffs().getPrior(wn.lastSnapshotId);
      }
    }
  }
  return Snapshot.NO_SNAPSHOT_ID;
}
 
Example 5
Source File: INodeDirectory.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** Call cleanSubtree(..) recursively down the subtree. */
public QuotaCounts cleanSubtreeRecursively(final BlockStoragePolicySuite bsps,
    final int snapshot,
    int prior, final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes, final Map<INode, INode> excludedNodes) {
  QuotaCounts counts = new QuotaCounts.Builder().build();
  // in case of deletion snapshot, since this call happens after we modify
  // the diff list, the snapshot to be deleted has been combined or renamed
  // to its latest previous snapshot. (besides, we also need to consider nodes
  // created after prior but before snapshot. this will be done in 
  // DirectoryWithSnapshotFeature)
  int s = snapshot != Snapshot.CURRENT_STATE_ID
      && prior != Snapshot.NO_SNAPSHOT_ID ? prior : snapshot;
  for (INode child : getChildrenList(s)) {
    if (snapshot != Snapshot.CURRENT_STATE_ID && excludedNodes != null
        && excludedNodes.containsKey(child)) {
      continue;
    } else {
      QuotaCounts childCounts = child.cleanSubtree(bsps, snapshot, prior,
          collectedBlocks, removedINodes);
      counts.add(childCounts);
    }
  }
  return counts;
}
 
Example 6
Source File: INode.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** Is this inode in the latest snapshot? */
public final boolean isInLatestSnapshot(final int latestSnapshotId) {
  if (latestSnapshotId == Snapshot.CURRENT_STATE_ID || latestSnapshotId == Snapshot.NO_SNAPSHOT_ID) {
    return false;
  }
  // if parent is a reference node, parent must be a renamed node. We can 
  // stop the check at the reference node.
  if (parent != null && parent.isReference()) {
    return true;
  }
  final INodeDirectory parentDir = getParent();
  if (parentDir == null) { // root
    return true;
  }
  if (!parentDir.isInLatestSnapshot(latestSnapshotId)) {
    return false;
  }
  final INode child = parentDir.getChild(getLocalNameBytes(), latestSnapshotId);
  if (this == child) {
    return true;
  }
  return child != null && child.isReference() &&
      this == child.asReference().getReferredINode();
}
 
Example 7
Source File: INodeReference.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps, int snapshot, int prior,
    BlocksMapUpdateInfo collectedBlocks, List<INode> removedINodes) {
  if (snapshot == Snapshot.CURRENT_STATE_ID
      && prior == Snapshot.NO_SNAPSHOT_ID) {
    QuotaCounts counts = new QuotaCounts.Builder().build();
    this.computeQuotaUsage(bsps, counts, true);
    destroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
    return counts;
  } else {
    // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to 
    // the previous WithName instance
    if (prior == Snapshot.NO_SNAPSHOT_ID) {
      prior = getPriorSnapshot(this);
    }
    // if prior is not NO_SNAPSHOT_ID, and prior is not before the
    // to-be-deleted snapshot, we can quit here and leave the snapshot
    // deletion work to the src tree of rename
    if (snapshot != Snapshot.CURRENT_STATE_ID
        && prior != Snapshot.NO_SNAPSHOT_ID
        && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
      return new QuotaCounts.Builder().build();
    }
    return getReferredINode().cleanSubtree(bsps, snapshot, prior,
        collectedBlocks, removedINodes);
  }
}
 
Example 8
Source File: INodeDirectory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Search for the given INode in the children list and the deleted lists of
 * snapshots.
 * @return {@link Snapshot#CURRENT_STATE_ID} if the inode is in the children
 * list; {@link Snapshot#NO_SNAPSHOT_ID} if the inode is neither in the
 * children list nor in any snapshot; otherwise the snapshot id of the
 * corresponding snapshot diff list.
 */
public int searchChild(INode inode) {
  INode child = getChild(inode.getLocalNameBytes(), Snapshot.CURRENT_STATE_ID);
  if (child != inode) {
    // inode is not in parent's children list, thus inode must be in
    // snapshot. identify the snapshot id and later add it into the path
    DirectoryDiffList diffs = getDiffs();
    if (diffs == null) {
      return Snapshot.NO_SNAPSHOT_ID;
    }
    return diffs.findSnapshotDeleted(inode);
  } else {
    return Snapshot.CURRENT_STATE_ID;
  }
}
 
Example 9
Source File: INodeReference.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private int getSelfSnapshot() {
  INode referred = getReferredINode().asReference().getReferredINode();
  int snapshot = Snapshot.NO_SNAPSHOT_ID;
  if (referred.isFile() && referred.asFile().isWithSnapshot()) {
    snapshot = referred.asFile().getDiffs().getPrior(lastSnapshotId);
  } else if (referred.isDirectory()) {
    DirectoryWithSnapshotFeature sf = referred.asDirectory()
        .getDirectoryWithSnapshotFeature();
    if (sf != null) {
      snapshot = sf.getDiffs().getPrior(lastSnapshotId);
    }
  }
  return snapshot;
}
 
Example 10
Source File: INodeSymlink.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps,
    final int snapshotId, int priorSnapshotId,
    final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  if (snapshotId == Snapshot.CURRENT_STATE_ID
      && priorSnapshotId == Snapshot.NO_SNAPSHOT_ID) {
    destroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
  }
  return new QuotaCounts.Builder().nameSpace(1).build();
}
 
Example 11
Source File: INodeReference.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyAndCollectBlocks(BlockStoragePolicySuite bsps,
    BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  int snapshot = getSelfSnapshot();
  if (removeReference(this) <= 0) {
    getReferredINode().destroyAndCollectBlocks(bsps, collectedBlocks,
        removedINodes);
  } else {
    int prior = getPriorSnapshot(this);
    INode referred = getReferredINode().asReference().getReferredINode();
    
    if (snapshot != Snapshot.NO_SNAPSHOT_ID) {
      if (prior != Snapshot.NO_SNAPSHOT_ID && snapshot <= prior) {
        // the snapshot to be deleted has been deleted while traversing 
        // the src tree of the previous rename operation. This usually 
        // happens when rename's src and dst are under the same 
        // snapshottable directory. E.g., the following operation sequence:
        // 1. create snapshot s1 on /test
        // 2. rename /test/foo/bar to /test/foo2/bar
        // 3. create snapshot s2 on /test
        // 4. rename foo2 again
        // 5. delete snapshot s2
        return;
      }
      try {
        QuotaCounts counts = referred.cleanSubtree(bsps, snapshot, prior,
            collectedBlocks, removedINodes);
        INodeReference ref = getReferredINode().getParentReference();
        if (ref != null) {
          ref.addSpaceConsumed(counts.negation(), true);
        }
      } catch (QuotaExceededException e) {
        LOG.error("should not exceed quota while snapshot deletion", e);
      }
    }
  }
}
 
Example 12
Source File: INodeReference.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps,
    final int snapshot, int prior, final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  // since WithName node resides in deleted list acting as a snapshot copy,
  // the parameter snapshot must be non-null
  Preconditions.checkArgument(snapshot != Snapshot.CURRENT_STATE_ID);
  // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to the
  // previous WithName instance
  if (prior == Snapshot.NO_SNAPSHOT_ID) {
    prior = getPriorSnapshot(this);
  }
  
  if (prior != Snapshot.NO_SNAPSHOT_ID
      && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
    return new QuotaCounts.Builder().build();
  }

  QuotaCounts counts = getReferredINode().cleanSubtree(bsps, snapshot, prior,
      collectedBlocks, removedINodes);
  INodeReference ref = getReferredINode().getParentReference();
  if (ref != null) {
    try {
      ref.addSpaceConsumed(counts.negation(), true);
    } catch (QuotaExceededException e) {
      Log.warn("Should not have QuotaExceededException");
    }
  }
  
  if (snapshot < lastSnapshotId) {
    // for a WithName node, when we compute its quota usage, we only count
    // in all the nodes existing at the time of the corresponding rename op.
    // Thus if we are deleting a snapshot before/at the snapshot associated 
    // with lastSnapshotId, we do not need to update the quota upwards.
    counts = new QuotaCounts.Builder().build();
  }
  return counts;
}
 
Example 13
Source File: INodeReference.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyAndCollectBlocks(BlockStoragePolicySuite bsps,
    BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  int snapshot = getSelfSnapshot();
  if (removeReference(this) <= 0) {
    getReferredINode().destroyAndCollectBlocks(bsps, collectedBlocks,
        removedINodes);
  } else {
    int prior = getPriorSnapshot(this);
    INode referred = getReferredINode().asReference().getReferredINode();
    
    if (snapshot != Snapshot.NO_SNAPSHOT_ID) {
      if (prior != Snapshot.NO_SNAPSHOT_ID && snapshot <= prior) {
        // the snapshot to be deleted has been deleted while traversing 
        // the src tree of the previous rename operation. This usually 
        // happens when rename's src and dst are under the same 
        // snapshottable directory. E.g., the following operation sequence:
        // 1. create snapshot s1 on /test
        // 2. rename /test/foo/bar to /test/foo2/bar
        // 3. create snapshot s2 on /test
        // 4. rename foo2 again
        // 5. delete snapshot s2
        return;
      }
      try {
        QuotaCounts counts = referred.cleanSubtree(bsps, snapshot, prior,
            collectedBlocks, removedINodes);
        INodeReference ref = getReferredINode().getParentReference();
        if (ref != null) {
          ref.addSpaceConsumed(counts.negation(), true);
        }
      } catch (QuotaExceededException e) {
        LOG.error("should not exceed quota while snapshot deletion", e);
      }
    }
  }
}
 
Example 14
Source File: INodeReference.java    From big-c with Apache License 2.0 5 votes vote down vote up
private int getSelfSnapshot() {
  INode referred = getReferredINode().asReference().getReferredINode();
  int snapshot = Snapshot.NO_SNAPSHOT_ID;
  if (referred.isFile() && referred.asFile().isWithSnapshot()) {
    snapshot = referred.asFile().getDiffs().getPrior(lastSnapshotId);
  } else if (referred.isDirectory()) {
    DirectoryWithSnapshotFeature sf = referred.asDirectory()
        .getDirectoryWithSnapshotFeature();
    if (sf != null) {
      snapshot = sf.getDiffs().getPrior(lastSnapshotId);
    }
  }
  return snapshot;
}
 
Example 15
Source File: INodeReference.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps, int snapshot, int prior,
    BlocksMapUpdateInfo collectedBlocks, List<INode> removedINodes) {
  if (snapshot == Snapshot.CURRENT_STATE_ID
      && prior == Snapshot.NO_SNAPSHOT_ID) {
    QuotaCounts counts = new QuotaCounts.Builder().build();
    this.computeQuotaUsage(bsps, counts, true);
    destroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
    return counts;
  } else {
    // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to 
    // the previous WithName instance
    if (prior == Snapshot.NO_SNAPSHOT_ID) {
      prior = getPriorSnapshot(this);
    }
    // if prior is not NO_SNAPSHOT_ID, and prior is not before the
    // to-be-deleted snapshot, we can quit here and leave the snapshot
    // deletion work to the src tree of rename
    if (snapshot != Snapshot.CURRENT_STATE_ID
        && prior != Snapshot.NO_SNAPSHOT_ID
        && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
      return new QuotaCounts.Builder().build();
    }
    return getReferredINode().cleanSubtree(bsps, snapshot, prior,
        collectedBlocks, removedINodes);
  }
}
 
Example 16
Source File: INodeReference.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps,
    final int snapshot, int prior, final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  // since WithName node resides in deleted list acting as a snapshot copy,
  // the parameter snapshot must be non-null
  Preconditions.checkArgument(snapshot != Snapshot.CURRENT_STATE_ID);
  // if prior is NO_SNAPSHOT_ID, we need to check snapshot belonging to the
  // previous WithName instance
  if (prior == Snapshot.NO_SNAPSHOT_ID) {
    prior = getPriorSnapshot(this);
  }
  
  if (prior != Snapshot.NO_SNAPSHOT_ID
      && Snapshot.ID_INTEGER_COMPARATOR.compare(snapshot, prior) <= 0) {
    return new QuotaCounts.Builder().build();
  }

  QuotaCounts counts = getReferredINode().cleanSubtree(bsps, snapshot, prior,
      collectedBlocks, removedINodes);
  INodeReference ref = getReferredINode().getParentReference();
  if (ref != null) {
    try {
      ref.addSpaceConsumed(counts.negation(), true);
    } catch (QuotaExceededException e) {
      Log.warn("Should not have QuotaExceededException");
    }
  }
  
  if (snapshot < lastSnapshotId) {
    // for a WithName node, when we compute its quota usage, we only count
    // in all the nodes existing at the time of the corresponding rename op.
    // Thus if we are deleting a snapshot before/at the snapshot associated 
    // with lastSnapshotId, we do not need to update the quota upwards.
    counts = new QuotaCounts.Builder().build();
  }
  return counts;
}
 
Example 17
Source File: INodeDirectory.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Search for the given INode in the children list and the deleted lists of
 * snapshots.
 * @return {@link Snapshot#CURRENT_STATE_ID} if the inode is in the children
 * list; {@link Snapshot#NO_SNAPSHOT_ID} if the inode is neither in the
 * children list nor in any snapshot; otherwise the snapshot id of the
 * corresponding snapshot diff list.
 */
public int searchChild(INode inode) {
  INode child = getChild(inode.getLocalNameBytes(), Snapshot.CURRENT_STATE_ID);
  if (child != inode) {
    // inode is not in parent's children list, thus inode must be in
    // snapshot. identify the snapshot id and later add it into the path
    DirectoryDiffList diffs = getDiffs();
    if (diffs == null) {
      return Snapshot.NO_SNAPSHOT_ID;
    }
    return diffs.findSnapshotDeleted(inode);
  } else {
    return Snapshot.CURRENT_STATE_ID;
  }
}
 
Example 18
Source File: INodeSymlink.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public QuotaCounts cleanSubtree(BlockStoragePolicySuite bsps,
    final int snapshotId, int priorSnapshotId,
    final BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) {
  if (snapshotId == Snapshot.CURRENT_STATE_ID
      && priorSnapshotId == Snapshot.NO_SNAPSHOT_ID) {
    destroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
  }
  return new QuotaCounts.Builder().nameSpace(1).build();
}