public BlocksMapUpdateInfo() { toDeleteList = new ChunkedArrayList<>(); toUpdateReplicationInfo = new ChunkedArrayList<>(); }
@Override public boolean add(T e) { if (size == Integer.MAX_VALUE) { throw new RuntimeException("Can't add an additional element to the " + "list; list already has INT_MAX elements."); } if (lastChunk == null) { addChunk(initialChunkCapacity); } else if (lastChunk.size() >= lastChunkCapacity) { int newCapacity = lastChunkCapacity + (lastChunkCapacity >> 1); addChunk(Math.min(newCapacity, maxChunkSize)); } size++; return lastChunk.add(e); }
@Test public void testBasics() { final int N_ELEMS = 100000; ChunkedArrayList<Integer> l = new ChunkedArrayList<Integer>(); assertTrue(l.isEmpty()); // Insert a bunch of elements. for (int i = 0; i < N_ELEMS; i++) { l.add(i); } assertFalse(l.isEmpty()); assertEquals(N_ELEMS, l.size()); // Check that it got chunked. assertTrue(l.getNumChunks() > 10); assertEquals(8192, l.getMaxChunkSize()); }
@Test public void testRemovals() throws Exception { final int NUM_ELEMS = 100000; ChunkedArrayList<Integer> list = new ChunkedArrayList<Integer>(); for (int i = 0; i < NUM_ELEMS; i++) { list.add(i); Iterator<Integer> iter = list.iterator(); for (int i = 0; i < NUM_ELEMS; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(NUM_ELEMS, list.size()); iter = list.iterator(); for (int i = 0; i < NUM_ELEMS; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(NUM_ELEMS / 2, list.size()); iter = list.iterator(); for (int i = 0; i < NUM_ELEMS / 2; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(0, list.size()); Assert.assertTrue(list.isEmpty()); iter = list.iterator(); Assert.assertFalse(iter.hasNext());
@Test public void testGet() throws Exception { final int NUM_ELEMS = 100001; ChunkedArrayList<Integer> list = new ChunkedArrayList<Integer>(); for (int i = 0; i < NUM_ELEMS; i++) { list.add(i); } Assert.assertEquals(Integer.valueOf(100), list.get(100)); Assert.assertEquals(Integer.valueOf(1000), list.get(1000)); Assert.assertEquals(Integer.valueOf(10000), list.get(10000)); Assert.assertEquals(Integer.valueOf(100000), list.get(100000)); Iterator<Integer> iter = list.iterator(); iter.next(); iter.remove(); Assert.assertEquals(Integer.valueOf(1), list.get(0)); iter = list.iterator(); for (int i = 0; i < 500; i++) { iter.next(); } iter.remove(); Assert.assertEquals(Integer.valueOf(502), list.get(500)); Assert.assertEquals(Integer.valueOf(602), list.get(600)); } }
@Test public void testIterator() { ChunkedArrayList<Integer> l = new ChunkedArrayList<Integer>(); for (int i = 0; i < 30000; i++) { l.add(i); } int i = 0; for (int fromList : l) { assertEquals(i, fromList); i++; } }
ChunkedArrayList<INode> removedINodes = new ChunkedArrayList<>(); INode.ReclaimContext context = new INode.ReclaimContext( fsd.getBlockStoragePolicySuite(), collectedBlocks, removedINodes, null); fsd.writeUnlock(); removedINodes.clear(); fsd.getEditLog().logDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache);
@Test public void testBasics() { final int N_ELEMS = 100000; ChunkedArrayList<Integer> l = new ChunkedArrayList<Integer>(); assertTrue(l.isEmpty()); // Insert a bunch of elements. for (int i = 0; i < N_ELEMS; i++) { l.add(i); } assertFalse(l.isEmpty()); assertEquals(N_ELEMS, l.size()); // Check that it got chunked. assertTrue(l.getNumChunks() > 10); assertEquals(8192, l.getMaxChunkSize()); }
@Test public void testRemovals() throws Exception { final int NUM_ELEMS = 100000; ChunkedArrayList<Integer> list = new ChunkedArrayList<Integer>(); for (int i = 0; i < NUM_ELEMS; i++) { list.add(i); Iterator<Integer> iter = list.iterator(); for (int i = 0; i < NUM_ELEMS; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(NUM_ELEMS, list.size()); iter = list.iterator(); for (int i = 0; i < NUM_ELEMS; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(NUM_ELEMS / 2, list.size()); iter = list.iterator(); for (int i = 0; i < NUM_ELEMS / 2; i++) { Assert.assertTrue(iter.hasNext()); Assert.assertEquals(0, list.size()); Assert.assertTrue(list.isEmpty()); iter = list.iterator(); Assert.assertFalse(iter.hasNext());
@Test public void testGet() throws Exception { final int NUM_ELEMS = 100001; ChunkedArrayList<Integer> list = new ChunkedArrayList<Integer>(); for (int i = 0; i < NUM_ELEMS; i++) { list.add(i); } Assert.assertEquals(Integer.valueOf(100), list.get(100)); Assert.assertEquals(Integer.valueOf(1000), list.get(1000)); Assert.assertEquals(Integer.valueOf(10000), list.get(10000)); Assert.assertEquals(Integer.valueOf(100000), list.get(100000)); Iterator<Integer> iter = list.iterator(); iter.next(); iter.remove(); Assert.assertEquals(Integer.valueOf(1), list.get(0)); iter = list.iterator(); for (int i = 0; i < 500; i++) { iter.next(); } iter.remove(); Assert.assertEquals(Integer.valueOf(502), list.get(500)); Assert.assertEquals(Integer.valueOf(602), list.get(600)); } }
@Test public void testIterator() { ChunkedArrayList<Integer> l = new ChunkedArrayList<Integer>(); for (int i = 0; i < 30000; i++) { l.add(i); } int i = 0; for (int fromList : l) { assertEquals(i, fromList); i++; } }
/** * Delete a snapshot of a snapshottable directory * @param snapshotRoot The snapshottable directory * @param snapshotName The name of the to-be-deleted snapshot * @throws IOException */ static INode.BlocksMapUpdateInfo deleteSnapshot( FSDirectory fsd, SnapshotManager snapshotManager, String snapshotRoot, String snapshotName, boolean logRetryCache) throws IOException { final INodesInPath iip = fsd.getINodesInPath4Write(snapshotRoot); if (fsd.isPermissionEnabled()) { FSPermissionChecker pc = fsd.getPermissionChecker(); fsd.checkOwner(pc, iip); } INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo(); ChunkedArrayList<INode> removedINodes = new ChunkedArrayList<INode>(); fsd.writeLock(); try { snapshotManager.deleteSnapshot(iip, snapshotName, collectedBlocks, removedINodes); fsd.removeFromInodeMap(removedINodes); } finally { fsd.writeUnlock(); } removedINodes.clear(); fsd.getEditLog().logDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache); return collectedBlocks; }
/** * Returns a list of blocks on a datanode that are insufficiently * replicated or require recovery, i.e. requiring recovery and * should prevent decommission or maintenance. * <p/> * As part of this, it also schedules replication/recovery work. * * @return List of blocks requiring recovery */ private AbstractList<BlockInfo> handleInsufficientlyStored( final DatanodeDescriptor datanode) { AbstractList<BlockInfo> insufficient = new ChunkedArrayList<>(); processBlocksInternal(datanode, datanode.getBlockIterator(), insufficient, false); return insufficient; }
ChunkedArrayList<String> chunkedList = new ChunkedArrayList<String>(); StopWatch sw = new StopWatch(); sw.start(); for (int i = 0; i < numElems; i++) { chunkedList.add(obj);
/** * Delete a snapshot of a snapshottable directory * @param snapshotRoot The snapshottable directory * @param snapshotName The name of the to-be-deleted snapshot * @throws IOException */ static INode.BlocksMapUpdateInfo deleteSnapshot( FSDirectory fsd, SnapshotManager snapshotManager, String snapshotRoot, String snapshotName, boolean logRetryCache) throws IOException { final INodesInPath iip = fsd.getINodesInPath4Write(snapshotRoot); if (fsd.isPermissionEnabled()) { FSPermissionChecker pc = fsd.getPermissionChecker(); fsd.checkOwner(pc, iip); } INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo(); ChunkedArrayList<INode> removedINodes = new ChunkedArrayList<INode>(); fsd.writeLock(); try { snapshotManager.deleteSnapshot(iip, snapshotName, collectedBlocks, removedINodes); fsd.removeFromInodeMap(removedINodes); } finally { fsd.writeUnlock(); } removedINodes.clear(); fsd.getEditLog().logDeleteSnapshot(snapshotRoot, snapshotName, logRetryCache); return collectedBlocks; }
@Override public boolean add(T e) { if (size == Integer.MAX_VALUE) { throw new RuntimeException("Can't add an additional element to the " + "list; list already has INT_MAX elements."); } if (lastChunk == null) { addChunk(initialChunkCapacity); } else if (lastChunk.size() >= lastChunkCapacity) { int newCapacity = lastChunkCapacity + (lastChunkCapacity >> 1); addChunk(Math.min(newCapacity, maxChunkSize)); } size++; return lastChunk.add(e); }
/** * Generate a {@link SnapshotDiffReport} based on detailed diff information. * @return A {@link SnapshotDiffReport} describing the difference */ public SnapshotDiffReport generateReport() { List<DiffReportEntry> diffReportList = new ChunkedArrayList<>(); for (Map.Entry<INode,byte[][]> drEntry : diffMap.entrySet()) { INode node = drEntry.getKey(); byte[][] path = drEntry.getValue(); diffReportList.add(new DiffReportEntry(DiffType.MODIFY, path, null)); if (node.isDirectory()) { List<DiffReportEntry> subList = generateReport(dirDiffMap.get(node), path, isFromEarlier(), renameMap); diffReportList.addAll(subList); } } return new SnapshotDiffReport(snapshotRoot.getFullPathName(), Snapshot.getSnapshotName(from), Snapshot.getSnapshotName(to), diffReportList); }
ChunkedArrayList<String> chunkedList = new ChunkedArrayList<String>(); StopWatch sw = new StopWatch(); sw.start(); for (int i = 0; i < numElems; i++) { chunkedList.add(obj);
@Override public boolean add(T e) { if (size == Integer.MAX_VALUE) { throw new RuntimeException("Can't add an additional element to the " + "list; list already has INT_MAX elements."); } if (lastChunk == null) { addChunk(initialChunkCapacity); } else if (lastChunk.size() >= lastChunkCapacity) { int newCapacity = lastChunkCapacity + (lastChunkCapacity >> 1); addChunk(Math.min(newCapacity, maxChunkSize)); } size++; return lastChunk.add(e); }
List<INode> removedINodes = new ChunkedArrayList<>(); List<Long> removedUCFiles = new ChunkedArrayList<>();