private static void ReadState( DataInput input, CountMinSketchState state) { var depth = input.ReadInt(); var width = input.ReadInt(); var rowsTable = input.ReadInt(); var table = new long[rowsTable][]; for (var i = 0; i < rowsTable; i++) { var colsRows = input.ReadInt(); table[i] = new long[colsRows]; for (var j = 0; j < colsRows; j++) { table[i][j] = input.ReadLong(); } } var rowsHash = input.ReadInt(); var hash = new long[rowsHash]; for (var i = 0; i < rowsTable; i++) { hash[i] = input.ReadLong(); } var total = input.ReadLong(); state.Hashes = new CountMinSketchStateHashes(depth, width, table, hash, total); var hasTopk = input.ReadBoolean(); state.Topk = null; if (hasTopk) { var topkMax = input.ReadInt(); var topMap = new OrderedDictionary<long, object>( Comparers.Default<long>().Inverse()); var refMap = new Dictionary<ByteBuffer, long>(); var numRows = input.ReadInt(); for (var i = 0; i < numRows; i++) { var freq = input.ReadLong(); var numEntries = input.ReadInt(); if (numEntries == 1) { var buf = ReadBytes(input); topMap.Put(freq, buf); refMap.Put(buf, freq); } else { Deque<ByteBuffer> q = new ArrayDeque<ByteBuffer>(numEntries); for (var j = 0; j < numEntries; j++) { var buf = ReadBytes(input); q.AddLast(buf); refMap.Put(buf, freq); } topMap.Put(freq, q); } } state.Topk = new CountMinSketchStateTopk(topkMax, topMap, refMap); } }
/// <summary> /// Clean an inode while we move it from the deleted list of post to the /// deleted list of prior. /// </summary> /// <param name="bsps">The block storage policy suite.</param> /// <param name="inode">The inode to clean.</param> /// <param name="post">The post snapshot.</param> /// <param name="prior">The id of the prior snapshot.</param> /// <param name="collectedBlocks">Used to collect blocks for later deletion.</param> /// <returns>Quota usage update.</returns> private static QuotaCounts CleanDeletedINode(BlockStoragePolicySuite bsps, INode inode, int post, int prior, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode > removedINodes) { QuotaCounts counts = new QuotaCounts.Builder().Build(); Deque <INode> queue = new ArrayDeque <INode>(); queue.AddLast(inode); while (!queue.IsEmpty()) { INode topNode = queue.PollFirst(); if (topNode is INodeReference.WithName) { INodeReference.WithName wn = (INodeReference.WithName)topNode; if (wn.GetLastSnapshotId() >= post) { wn.CleanSubtree(bsps, post, prior, collectedBlocks, removedINodes); } } else { // For DstReference node, since the node is not in the created list of // prior, we should treat it as regular file/dir if (topNode.IsFile() && topNode.AsFile().IsWithSnapshot()) { INodeFile file = topNode.AsFile(); counts.Add(file.GetDiffs().DeleteSnapshotDiff(bsps, post, prior, file, collectedBlocks , removedINodes)); } else { if (topNode.IsDirectory()) { INodeDirectory dir = topNode.AsDirectory(); DirectoryWithSnapshotFeature.ChildrenDiff priorChildrenDiff = null; DirectoryWithSnapshotFeature sf = dir.GetDirectoryWithSnapshotFeature(); if (sf != null) { // delete files/dirs created after prior. Note that these // files/dirs, along with inode, were deleted right after post. DirectoryWithSnapshotFeature.DirectoryDiff priorDiff = sf.GetDiffs().GetDiffById( prior); if (priorDiff != null && priorDiff.GetSnapshotId() == prior) { priorChildrenDiff = priorDiff.GetChildrenDiff(); counts.Add(priorChildrenDiff.DestroyCreatedList(bsps, dir, collectedBlocks, removedINodes )); } } foreach (INode child in dir.GetChildrenList(prior)) { if (priorChildrenDiff != null && priorChildrenDiff.Search(Diff.ListType.Deleted, child.GetLocalNameBytes()) != null) { continue; } queue.AddLast(child); } } } } } return(counts); }