/** Generate keys for each block and record them. * @throws IOException */ private void generateKeys(byte[][] dataBlocks, int offset) throws IOException { for(int i=0;i<dataBlocks.length;i++) { setKey(i + offset, encodeBlock(dataBlocks[i]).getClientKey()); } }
@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); } }
private void writeCheckBlock(int checkBlockNo, byte[] buf) throws IOException { parent.writeCheckBlock(segNo, checkBlockNo, buf); if(DEBUG_ENCODE) { SplitFileInserterSegmentStorage segment = segments[checkBlockNo + dataBlockCount]; ClientCHK key = segment.encodeBlock(buf).getClientKey(); segment.setKey(blockNumbers[checkBlockNo + dataBlockCount], key); } }
private byte[][] readDataBlocks() throws IOException { RAFLock lock = parent.lockUnderlying(); try { byte[][] data = new byte[dataBlockCount][]; for(int i=0;i<dataBlockCount;i++) { data[i] = segments[i].readDataBlock(blockNumbers[i]); if(DEBUG_ENCODE) { ClientCHK key = segments[i].encodeBlock(data[i]).getClientKey(); segments[i].setKey(blockNumbers[i], key); } } return data; } finally { lock.unlock(); } }
/** 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); } }
assertFalse(chosenBlocks[chosen.blockNumber]); chosenBlocks[chosen.blockNumber] = true; segment.setKey(chosen.blockNumber, segment.encodeBlock(chosen.blockNumber).getClientKey()); segment.onFailure(chosen.blockNumber, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND));
assertEquals(segment.crossCheckBlockCount, 0); assertEquals(storage.getStatus(), Status.ENCODED); segment.setKey(0, segment.encodeBlock(0).getClientKey()); segment.onFailure(0, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND)); assertEquals(storage.getStatus(), Status.ENCODED);