@Override protected final void handleResponseHeaders(final O ioTask, final HttpHeaders respHeaders) { if(!fsAccess) { final String location = respHeaders.get(HttpHeaderNames.LOCATION); if(location != null && !location.isEmpty()) { if(location.startsWith(NS_URI_BASE)) { ioTask.getItem().setName(location.substring(NS_URI_BASE.length())); } else if(location.startsWith(OBJ_URI_BASE)) { ioTask.getItem().setName(location.substring(OBJ_URI_BASE.length())); } else { ioTask.getItem().setName(location); Loggers.ERR.warn("Unexpected location value: \"{}\"", location); } // set the paths to null to avoid the path calculation in the ioTaskCallback call ioTask.setSrcPath(null); ioTask.setDstPath(null); } } } }
protected void prepareIoTask(final O ioTask) throws ServerException { ioTask.reset(); if(ioTask instanceof DataIoTask) { ((DataIoTask) ioTask).getItem().setDataInput(itemDataInput); } final String dstPath = ioTask.getDstPath(); final Credential credential = ioTask.getCredential(); if(credential != null) { pathToCredMap.putIfAbsent(dstPath == null ? "" : dstPath, credential); if(requestAuthTokenFunc != null) { authTokens.computeIfAbsent(credential, requestAuthTokenFunc); } } if(requestNewPathFunc != null) { // NOTE: in the distributed mode null dstPath becomes empty one if(dstPath != null && !dstPath.isEmpty()) { if(null == pathMap.computeIfAbsent(dstPath, requestNewPathFunc)) { Loggers.ERR.debug( "Failed to compute the destination path for the I/O task {}", ioTask ); ioTask.setStatus(IoTask.Status.FAIL_UNKNOWN); } } } }
@Override public final void operationComplete(final Future<Void> future) throws Exception { try { ioTask.finishRequest(); } catch(final IllegalStateException e) { LogUtil.exception(Level.DEBUG, e, "{}", ioTask.toString()); } } }
private boolean invokeDelete(final O ioTask) throws IOException { final String dstPath = ioTask.getDstPath(); final I fileItem = ioTask.getItem(); FS_PROVIDER.delete(dstPath == null ? Paths.get(fileItem.getName()) : Paths.get(dstPath, fileItem.getName())); return true; }
final int ioTypeCode = ioTaskResult.getIoType().ordinal(); final MetricsContext ioTypeStats = ioStats.get(ioTypeCode); final IoTask.Status status = ioTaskResult.getStatus(); final long reqDuration = ioTaskResult.getDuration(); final long respLatency = ioTaskResult.getLatency(); final long countBytesDone; if(ioTaskResult instanceof DataIoTask) { ioTypeStats.markPartSucc(countBytesDone, reqDuration, respLatency); } else { final int originCode = ioTaskResult.getOriginCode(); final LoadGenerator<I, O> loadGenerator = generatorsMap.get(originCode); if(loadGenerator.isRecycling()) { latestIoResultsPerItem.put(ioTaskResult.getItem(), ioTaskResult); loadGenerator.recycle(ioTaskResult); } else if(ioResultsOutput != null) {
if (IoType.NOOP.equals(ioTask.getIoType())) { if (concurrencyThrottle.tryAcquire()) { ioTask.startRequest(); sendRequest(null, null, ioTask); ioTask.finishRequest(); concurrencyThrottle.release(); ioTask.setStatus(SUCC); ioTask.startResponse(); complete(null, ioTask); } else { ioTask.setNodeAddr(conn.attr(ATTR_KEY_NODE).get()); ioTask.startRequest(); sendRequest( conn, conn.newPromise().addListener(new RequestSentCallback(ioTask)), ioTask } catch (final ConnectException e) { LogUtil.exception(Level.WARN, e, "Failed to lease the connection for the I/O task"); ioTask.setStatus(IoTask.Status.FAIL_IO); complete(null, ioTask);
protected final void sendRequestData(final Channel channel, final O ioTask) throws IOException { final IoType ioType = ioTask.getIoType(); final I item = ioTask.getItem(); if (item instanceof DataItem) { final DataIoTask dataIoTask = (DataIoTask) ioTask; final I item = ioTask.getItem(); if (item instanceof DataItem) {
@Override public final boolean put(final O ioResult) throws IOException { if(ioResult == null) { // poison close(); return true; } return itemInfoOutput.put(ioResult.getItem().toString()); }
nextIoResult = ioResultsIter.next(); if(delayMicroseconds > 0) { nextFinishTime = nextIoResult.getRespTimeDone(); currTime = IoTask.START_OFFSET_MICROS + nanoTime() / 1000; if(currTime - nextFinishTime > delayMicroseconds) { item = nextIoResult.getItem(); if(markLimit > 0 && markLimit > markBuffer.size()) { markBuffer.add(nextIoResult); item = nextIoResult.getItem(); if(markBuffer.size() < markLimit) { markBuffer.add(nextIoResult);
@Override protected HttpRequest getHttpRequest(final O ioTask, final String nodeAddr) throws URISyntaxException { if(IoType.CREATE.equals(ioTask.getIoType()) && ioTask instanceof DataIoTask) { final DataIoTask dataIoTask = (DataIoTask) ioTask; final List<DataItem> srcItemsToConcat = dataIoTask.getSrcItemsToConcat(); if(srcItemsToConcat != null) { try { return getCopyRangesRequest(dataIoTask, nodeAddr, srcItemsToConcat); } catch(final IOException e) { throw new AssertionError(e); } } else { return super.getHttpRequest(ioTask, nodeAddr); } } else { return super.getHttpRequest(ioTask, nodeAddr); } }
@Override @SuppressWarnings("unchecked") protected final boolean submit(final O ioTask) throws IllegalStateException { if(isClosed() || isInterrupted()) { throw new IllegalStateException(); } ioTask.reset(); if(ioTask instanceof CompositeDataIoTask) { final CompositeDataIoTask compositeTask = (CompositeDataIoTask) ioTask; if(compositeTask.allSubTasksDone()) { return super.submit(ioTask); } else { final List<O> subTasks = compositeTask.getSubTasks(); final int n = subTasks.size(); for(int i = 0; i < n; i += super.submit(subTasks, i, n)) { LockSupport.parkNanos(1); } return true; } } else { return super.submit(ioTask); } }
@Override @SuppressWarnings("unchecked") public final void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws IOException { final Channel channel = ctx.channel(); final O ioTask = (O) channel.attr(NetStorageDriver.ATTR_KEY_IOTASK).get(); if(ioTask != null) { if(driver.isInterrupted() || driver.isClosed()) { ioTask.setStatus(INTERRUPTED); } else if(cause instanceof PrematureChannelClosureException) { LogUtil.exception(Level.WARN, cause, "Premature channel closure"); ioTask.setStatus(FAIL_IO); } else { LogUtil.exception(Level.WARN, cause, "Client handler failure"); ioTask.setStatus(FAIL_UNKNOWN); } if(!driver.isInterrupted()) { try { driver.complete(channel, ioTask); } catch(final Exception e) { LogUtil.exception(Level.DEBUG, e, "Failed to complete the I/O task"); } } } }
originCode = ioTaskResult.getOriginCode(); ioTypeCode = ioTaskResult.getIoType().ordinal(); status = ioTaskResult.getStatus(); reqDuration = ioTaskResult.getDuration(); respLatency = ioTaskResult.getLatency(); if(ioTaskResult instanceof DataIoTask) { countBytesDone = ((DataIoTask) ioTaskResult).getCountBytesDone(); loadGenerator = generatorsMap.get(originCode); if(loadGenerator.isRecycling()) { latestIoResultsPerItem.put(ioTaskResult.getItem(), ioTaskResult); loadGenerator.recycle(ioTaskResult); } else if(ioResultsOutput != null) {
for (int i = from; i < to && isStarted(); i++) { nextIoTask = ioTasks.get(i); if (IoType.NOOP.equals(nextIoTask.getIoType())) { if (concurrencyThrottle.tryAcquire()) { nextIoTask.startRequest(); sendRequest(null, null, nextIoTask); nextIoTask.finishRequest(); concurrencyThrottle.release(); nextIoTask.setStatus(SUCC); nextIoTask.startResponse(); complete(null, nextIoTask); } else { nextIoTask.setNodeAddr(conn.attr(ATTR_KEY_NODE).get()); nextIoTask.startRequest(); sendRequest( conn, conn.newPromise().addListener(new RequestSentCallback(nextIoTask)), for (int i = from; i < to; i++) { nextIoTask = ioTasks.get(i); nextIoTask.setStatus(IoTask.Status.FAIL_IO); complete(null, nextIoTask);
@Override public final int put(final List<O> ioResults) throws IOException { final List<String> itemsInfo = new ArrayList<>(ioResults.size()); for(final O nextIoResult : ioResults) { if(nextIoResult == null) { // poison try { return itemInfoOutput.put(itemsInfo); } finally { close(); } } itemsInfo.add(nextIoResult.getItem().toString()); } return itemInfoOutput.put(itemsInfo); }
while(ioResultsIter.hasNext() && n < limit) { nextIoResult = ioResultsIter.next(); nextFinishTime = nextIoResult.getRespTimeDone(); currTime = IoTask.START_OFFSET_MICROS + nanoTime() / 1000; if(currTime - nextFinishTime > delayMicroseconds) { buffer.add(nextIoResult.getItem()); if(markLimit > 0 && markLimit > markBuffer.size()) { markBuffer.add(nextIoResult); while(ioResultsIter.hasNext() && n < limit) { nextIoResult = ioResultsIter.next(); buffer.add(nextIoResult.getItem()); if(markLimit > 0 && markLimit > markBuffer.size()) { markBuffer.add(nextIoResult);
final IoType ioType = ioTask.getIoType(); if(ioTask instanceof CompositeDataIoTask) { if(CREATE.equals(ioType)) {
for(int i = from; i < to; i ++) { nextIoTask = ioTasks.get(i); nextIoTask.reset(); if(nextIoTask instanceof CompositeDataIoTask) { final CompositeDataIoTask compositeTask = (CompositeDataIoTask) nextIoTask;
@Override public final int put(final List<O> ioResults, final int from, final int to) throws IOException { final int n = to - from; final List<String> itemsInfo = new ArrayList<>(n); O ioResult; for(int i = from; i < to; i ++) { ioResult = ioResults.get(i); if(ioResult == null) { // poison try { return itemInfoOutput.put(itemsInfo, 0, i); } finally { close(); } } itemsInfo.add(ioResult.getItem().toString()); } return itemInfoOutput.put(itemsInfo, 0, n); }