public ClientKey getKey(MyKey key) { try { return segments[key.segmentNumber].getSegmentKeys().getKey(key.blockNumber, null, false); } catch (IOException e) { this.failOnDiskError(e); return null; } }
@Override public void schedule(ClientContext context) throws InsertException { cb.onBlockSetFinished(this, context); storage.start(); if(!ctx.getCHKOnly) { sender.clearWakeupTime(context); sender.schedule(context); } }
/** Notify clients by calling innerNotifyClients off-thread. */ public final void notifyClients(ClientContext context) { context.getJobRunner(persistent()).queueNormalOrDrop(new PersistentJob() { @Override public boolean run(ClientContext context) { innerNotifyClients(context); return false; } }); }
public void testWriteReadSegmentKeys() throws FetchException, MetadataParseException, IOException, CHKEncodeException, MetadataUnresolvedException, ChecksumFailedException { int dataBlocks = 3, checkBlocks = 3; TestSplitfile test = TestSplitfile.constructSingleSegment(dataBlocks*BLOCK_SIZE, checkBlocks, null, true); StorageCallback cb = test.createStorageCallback(); SplitFileFetcherStorage storage = test.createStorage(cb); SplitFileFetcherSegmentStorage segment = storage.segments[0]; SplitFileSegmentKeys keys = segment.getSegmentKeys(); SplitFileSegmentKeys moreKeys = segment.readSegmentKeys(); assertTrue(keys.equals(moreKeys)); storage.close(); }
public void testChooseKeyOneTry() throws CHKEncodeException, IOException, MetadataUnresolvedException, MetadataParseException, FetchException { int dataBlocks = 3, checkBlocks = 3; TestSplitfile test = TestSplitfile.constructSingleSegment(dataBlocks*BLOCK_SIZE, checkBlocks, null, false); StorageCallback cb = test.createStorageCallback(); FetchContext ctx = test.makeFetchContext(); ctx.maxSplitfileBlockRetries = 0; SplitFileFetcherStorage storage = test.createStorage(cb, ctx); boolean[] tried = new boolean[dataBlocks+checkBlocks]; innerChooseKeyTest(dataBlocks, checkBlocks, storage.segments[0], tried, test, false); assertEquals(storage.chooseRandomKey(), null); cb.waitForFailed(); }
/** Called when a block insert succeeds */ public void onInsertedBlock(int blockNo, ClientCHK key) { try { if(parent.hasFinished()) return; this.setKey(blockNo, key); if(blockChooser.onSuccess(blockNo)) parent.callback.onInsertedBlock(); lazyWriteMetadata(); } catch (IOException e) { if(parent.hasFinished()) return; // Race condition possible as this is a callback parent.failOnDiskError(e); } }
/** Test persistence: Create and then reload. Don't do anything. */ public void testPersistenceReload() throws CHKEncodeException, IOException, MetadataUnresolvedException, MetadataParseException, FetchException, StorageFormatException { int dataBlocks = 2; int checkBlocks = 3; long size = 32768*2-1; assertTrue(dataBlocks * (long)BLOCK_SIZE >= size); TestSplitfile test = TestSplitfile.constructSingleSegment(size, checkBlocks, null, true); StorageCallback cb = test.createStorageCallback(); SplitFileFetcherStorage storage = test.createStorage(cb); // No need to shutdown the old storage. storage = test.createStorage(cb, test.makeFetchContext(), cb.getRAF()); storage.close(); }
public void fail(FetchException e) { synchronized(this) { if(succeeded || failed) return; failed = true; } if(storage != null) context.getChkFetchScheduler(realTimeFlag).removePendingKeys(storage.keyListener, true); if(getter != null) getter.cancel(context); if(storage != null) storage.cancel(); cb.onFailure(e, this, context); }
@Override public void onResume(ClientContext context) throws InsertException, ResumeFailedException { synchronized(this) { if(resumed) return; resumed = true; } for(ClientPutState s : getWaitingFor()) s.onResume(context); if(cb != parent) cb.onResume(context); }
private boolean anySegmentNotEncoded(SplitFileInserterStorage storage) { for(SplitFileInserterSegmentStorage segment : storage.segments) if(!segment.hasEncoded()) return true; if(storage.crossSegments != null) { for(SplitFileInserterCrossSegmentStorage segment : storage.crossSegments) if(!segment.hasEncodedSuccessfully()) return true; } return false; }
public void cancel(ClientContext context) { cancelled = true; USKChecker c; synchronized(this) { c = checker; } if(c != null) c.cancel(context); onCancelled(context); }
private void queueHeal(byte[][] dataBlocks, byte[][] checkBlocks, boolean[] dataBlocksPresent, boolean[] checkBlocksPresent) throws IOException { for(int i=0;i<dataBlocks.length;i++) { if(dataBlocksPresent[i]) continue; if(blockChooser.getRetries(i) == 0) continue; queueHeal(i, dataBlocks[i]); } for(int i=0;i<checkBlocks.length;i++) { if(checkBlocksPresent[i]) continue; if(blockChooser.getRetries(i+dataBlocks.length) == 0) continue; queueHeal(i+dataBlocks.length, checkBlocks[i]); } }
/** * finalize the return bucket * @throws IOException * @throws BinaryBlobAlreadyClosedException */ public void finalizeBucket() throws IOException, BinaryBlobAlreadyClosedException { if (_finalized) { throw new BinaryBlobAlreadyClosedException("Already finalized (closing blob)."); } finalizeBucket(true); }
@Override public void innerOnResume(ClientContext context) throws ResumeFailedException { super.innerOnResume(context); notifyClients(context); } }
@Override protected void notFoundInStore(ClientContext context) { // Ran out of retries. unregisterAll(context); // Rest are non-fatal. If have DNFs, DNF, else network error. cb.onDNF(context); }
/** Cancel the download, stop all FEC decodes, and call close() off-thread when done. */ void cancel() { synchronized(this) { cancelled = true; } for(SplitFileFetcherSegmentStorage segment : segments) segment.cancel(); if(crossSegments != null) { for(SplitFileFetcherCrossSegmentStorage segment : crossSegments) segment.cancel(); } }
@Override public boolean run(ClientContext context) { if(callback instanceof USKFetcherTagCallback) ((USKFetcherTagCallback)callback).setTag(USKFetcherTag.this, context); callback.onCancelled(context); return false; }
private boolean allSegmentsCompletedOrFailed() { for(SplitFileInserterSegmentStorage segment : segments) { if(!segment.hasCompletedOrFailed()) return false; } if(crossSegments != null) { for(SplitFileInserterCrossSegmentStorage segment : crossSegments) { if(!segment.hasCompletedOrFailed()) return false; } } return true; }
private void fail(InsertException e, ClientContext context) { // Cancel all, then call the callback synchronized(this) { if(finished) return; finished = true; } cancelAndFinish(context); cb.onFailure(e, this); }
private boolean anySegmentEncoding(SplitFileInserterStorage storage) { for(SplitFileInserterSegmentStorage segment : storage.segments) if(segment.isEncoding()) return true; if(storage.crossSegments != null) { for(SplitFileInserterCrossSegmentStorage segment : storage.crossSegments) if(segment.isEncoding()) return true; } return false; }