@Override public boolean isCancelled() { return storage.hasFinished(); }
@Override public void onEncode(SendableRequestItem token, ClientKey key, ClientContext context) { BlockInsert block = (BlockInsert) token; // Should already be set. This is a sanity check. try { if(storage.hasFinished()) return; block.segment.setKey(block.blockNumber, (ClientCHK) key); } catch (IOException e) { if(storage.hasFinished()) return; // Race condition possible as this is a callback storage.failOnDiskError(e); } }
/** @return -1 if the insert has finished, 0 if has blocks to send, otherwise Long.MAX_VALUE. */ public long getWakeupTime(ClientContext context, long now) { // LOCKING: hasFinished() uses (this), separate from cooldownLock. // It is safe to use both here (on the request selection thread), one after the other. if (hasFinished()) return -1; if (noBlocksToSend()) return Long.MAX_VALUE; else return 0; }
/** 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); } }
@Override public boolean run(ClientContext context) { // Tell the segments to cancel. boolean allDone = true; for(SplitFileInserterSegmentStorage segment : segments) { if(!segment.cancel()) allDone = false; } if(crossSegments != null) { for(SplitFileInserterCrossSegmentStorage segment : crossSegments) { if(!segment.cancel()) allDone = false; } } if(allDone) { synchronized(this) { // Could have beaten us to it in callback. if(hasFinished()) return false; status = Status.FAILED; } callback.onFailed(e); return true; } else { // Wait for them to finish encoding. return false; } }
public void storeStatus(boolean force) { if(!parent.persistent) return; if(parent.hasFinished()) return; try { DataOutputStream dos; synchronized(this) { if(!force && !metadataDirty) return; if(cancelled) return; try { dos = new DataOutputStream(parent.writeChecksummedTo(parent.segmentStatusOffset(segNo), statusLength)); innerStoreStatus(dos); } catch (IOException e) { Logger.error(this, "Impossible: "+e, e); return; } metadataDirty = false; } // Outside the lock is safe since if we fail we will fail the whole splitfile. dos.close(); } catch (IOException e) { Logger.error(this, "I/O error writing segment status?: "+e, e); parent.failOnDiskError(e); } }
private boolean maybeFail() { // Might have failed. // Have to check segments before checking for failure because of race conditions. if(allSegmentsCompletedOrFailed()) { InsertException e = null; synchronized(this) { if(failing == null) return false; e = failing; if(hasFinished()) { if(logMINOR) Logger.minor(this, "Maybe fail returning true because already finished"); return true; } status = Status.FAILED; } if(logMINOR) Logger.minor(this, "Maybe fail returning true with error "+e); callback.onFailed(e); return true; } else { return false; } }
public void onFailure(int blockNo, InsertException e) { if(logMINOR) Logger.minor(this, "Failed block "+blockNo+" with "+e+" for "+this+" for "+parent); if(parent.hasFinished()) return; // Race condition possible as this is a callback parent.addFailure(e); if(e.isFatal()) { Logger.error(this, "RNF but no key on block "+blockNo+" on "+this); } catch (IOException e1) { if(parent.hasFinished()) return; // Race condition possible as this is a callback parent.failOnDiskError(e1); return;
synchronized(this) { assert(failing == null); if(hasFinished()) return false; status = Status.GENERATING_METADATA;