synchronized public long countUnfetchedKeys() { if(finished || tryDecode) return 0; return totalBlocks() - blockChooser.successCount(); }
public synchronized void getUnfetchedKeys(List<Key> keys) throws IOException { if(finished || tryDecode) return; SplitFileSegmentKeys keyList = getSegmentKeys(); for(int i=0;i<totalBlocks();i++) { if(!blockChooser.hasSucceeded(i)) keys.add(keyList.getNodeKey(i, null, false)); } }
public SplitFileFetcherCrossSegmentStorage(SplitFileFetcherStorage parent, int segNo, DataInputStream dis) throws IOException, StorageFormatException { this.parent = parent; this.crossSegmentNumber = segNo; this.codec = parent.fecCodec; this.dataBlockCount = dis.readInt(); this.crossCheckBlockCount = dis.readInt(); this.totalBlocks = dataBlockCount + crossCheckBlockCount; blocksFound = new boolean[totalBlocks]; segments = new SplitFileFetcherSegmentStorage[totalBlocks]; blockNumbers = new int[totalBlocks]; for(int i=0;i<totalBlocks;i++) { int readSeg = dis.readInt(); if(readSeg < 0 || readSeg >= parent.segments.length) throw new StorageFormatException("Invalid segment number "+readSeg); SplitFileFetcherSegmentStorage segment = parent.segments[readSeg]; this.segments[i] = segment; int blockNo = dis.readInt(); if(blockNo < 0 || blockNo >= segment.totalBlocks()) throw new StorageFormatException("Invalid block number "+blockNo+" for segment "+segment.segNo); this.blockNumbers[i] = blockNo; segment.resumeCallback(blockNo, this); } }
for(int i=0;i<blocksFetched.length;i++) { int s = dis.readInt(); if(s < -1 || s >= totalBlocks()) throw new StorageFormatException("Bogus block number in blocksFetched["+i+"]: "+s); blocksFetched[i] = s;
/** Pick a key to fetch. Must not update any persistent field. (Cooldowns etc are fine) */ public int chooseRandomKey() { int chosen; synchronized(this) { if(finished) return -1; if(failedRetries) return -1; if(tryDecode) { if(logMINOR) Logger.minor(this, "Segment decoding so not choosing a key on "+this); return -1; } if(corruptMetadata) return -1; // Will be fetchable after we've found out what blocks we actually have. chosen = blockChooser.chooseKey(); if(chosen != -1) { if(logMINOR) Logger.minor(this, "Chosen key "+chosen+"/"+totalBlocks()+" for "+this+" (retries "+blockChooser.getRetries(chosen)+"/"+blockChooser.maxRetries+")"); } else { if(logMINOR) Logger.minor(this, "No keys chosen for "+this); } } if(chosen == -1) { long cooldownTime = blockChooser.overallCooldownTime(); if(cooldownTime > System.currentTimeMillis()) parent.increaseCooldown(this, cooldownTime); return -1; } else { return chosen; } }
tryDecode = true; long limit = totalBlocks() * CHKBlock.DATA_LENGTH + Math.max(parent.fecCodec.maxMemoryOverheadDecode(blocksForDecode(), checkBlocks), parent.fecCodec.maxMemoryOverheadEncode(blocksForDecode(), checkBlocks));
/** Add a random block that has not been added already or decoded already. * @throws IOException */ private boolean addRandomBlock(SplitFileInserterStorage storage, SplitFileFetcherStorage fetcherStorage, Random random) throws IOException { int segCount = storage.segments.length; boolean[] exhaustedSegments = new boolean[segCount]; for(int i=0;i<segCount;i++) { while(true) { int segNo = random.nextInt(segCount); if(exhaustedSegments[segNo]) continue; SplitFileFetcherSegmentStorage segment = fetcherStorage.segments[segNo]; if(segment.isDecodingOrFinished()) { exhaustedSegments[segNo] = true; break; } while(true) { int blockNo = random.nextInt(segment.totalBlocks()); if(segment.hasBlock(blockNo)) { continue; } ClientCHKBlock block = storage.segments[segNo].encodeBlock(blockNo); boolean success = segment.onGotKey(block.getClientKey().getNodeCHK(), block.getBlock()); assertTrue(success); return true; } } } return false; }
int totalBlocks = totalBlocks(); byte[][] allBlocks = readAllBlocks(); SplitFileSegmentKeys keys = getSegmentKeys();
int total = test.dataBlocks.length+test.checkBlocks.length; for(SplitFileFetcherSegmentStorage segment : storage.segments) { for(int i=0;i<segment.totalBlocks();i++)