Package org.apache.blur.trace

Examples of org.apache.blur.trace.Tracer


        if (startingPosition < 0) {
          // nothing to fetch
          return docs;
        }
        int totalHeap = 0;
        Tracer trace2 = Trace.trace("fetching docs from index");
        int cursor = 0;
        try {
          for (cursor = startingPosition; cursor < numberOfDocsInRow; cursor++) {
            if (maxDocsToFetch <= 0) {
              return docs;
            }
            if (totalHeap >= maxHeap) {
              LOG.warn("Max heap size exceeded for this request [{0}] max [{1}] for [{2}] and selector [{3}]",
                  totalHeap, maxHeap, context, selector);
              return docs;
            }
            if (docsInRowSpanToFetch.fastGet(cursor)) {
              maxDocsToFetch--;
              int docID = primeDocId + cursor;
              segmentReader.document(docID, fieldSelector);
              Document document = fieldSelector.getDocument();
              if (highlighter.shouldHighlight()) {
                docs.add(highlighter.highlight(docID, document, segmentReader));
              } else {
                docs.add(document);
              }
              totalHeap += fieldSelector.getSize();
              fieldSelector.reset();
            }
          }
        } finally {
          if (docsInRowSpanToFetch.nextSetBit(cursor) != -1) {
            moreToFetch.set(true);
          }
          trace2.done();
        }
        return orderDocsBasedOnFamilyOrder(docs, selector);
      } else {
        throw new IOException("Expecting a segment reader got a [" + orgReader + "]");
      }
View Full Code Here


  };

  @SuppressWarnings("unchecked")
  public static <CLIENT, T> T execute(List<Connection> connections, AbstractCommand<CLIENT, T> command, int maxRetries,
      long backOffTime, long maxBackOffTime) throws BlurException, TException, IOException {
    Tracer traceSetup = Trace.trace("execute - setup");
    LocalResources localResources = new LocalResources();
    AtomicReference<Client> client = localResources.client;
    AtomicInteger retries = localResources.retries;
    List<Connection> shuffledConnections = localResources.shuffledConnections;

    retries.set(0);
    shuffledConnections.addAll(connections);

    Collections.shuffle(shuffledConnections, _random.get());
    boolean allBad = true;
    int connectionErrorCount = 0;
    traceSetup.done();
    while (true) {
      for (Connection connection : shuffledConnections) {
        Tracer traceConnectionSetup = Trace.trace("execute - connection setup");
        try {
          if (isBadConnection(connection)) {
            continue;
          }
          client.set(null);
          try {
            client.set(_clientPool.getClient(connection));
          } catch (IOException e) {
            if (handleError(connection, client, retries, command, e, maxRetries, backOffTime, maxBackOffTime)) {
              throw e;
            } else {
              markBadConnection(connection);
              continue;
            }
          }
        } finally {
          traceConnectionSetup.done();
        }
        Tracer trace = null;
        try {
          User user = UserConverter.toThriftUser(UserContext.getUser());
          client.get().setUser(user);
          TraceId traceId = Trace.getTraceId();
          if (traceId != null) {
            client.get().startTrace(traceId.getRootId(), traceId.getRequestId());
            trace = Trace.trace("thrift client", Trace.param("connection", getConnectionStr(client.get())));
          }
          T result = command.call((CLIENT) client.get(), connection);
          allBad = false;
          if (command.isDetachClient()) {
            // if the is detach client is set then the command will return the
            // client to the pool.
            client.set(null);
          }
          return result;
        } catch (RuntimeException e) {
          Throwable cause = e.getCause();
          if (cause instanceof TTransportException) {
            TTransportException t = (TTransportException) cause;
            if (handleError(connection, client, retries, command, t, maxRetries, backOffTime, maxBackOffTime)) {
              Throwable c = t.getCause();
              if (cause instanceof SocketTimeoutException) {
                throw new BlurException(c.getMessage(), BException.toString(c), ErrorType.REQUEST_TIMEOUT);
              }
              throw t;
            }
          } else {
            throw e;
          }
        } catch (TTransportException e) {
          if (handleError(connection, client, retries, command, e, maxRetries, backOffTime, maxBackOffTime)) {
            Throwable c = e.getCause();
            if (c instanceof SocketTimeoutException) {
              throw new BlurException(c.getMessage(), BException.toString(c), ErrorType.REQUEST_TIMEOUT);
            }
            throw e;
          }
        } finally {
          if (trace != null) {
            trace.done();
          }
          if (client.get() != null) {
            returnClient(connection, client);
          }
        }
View Full Code Here

  }

  @Override
  protected void readInternal(byte[] b, int offset, int length) throws IOException {
    Tracer trace = Trace.trace("filesystem - read", Trace.param("file", _path),
        Trace.param("location", getFilePointer()), Trace.param("length", length));
    try {
      long start = System.nanoTime();
      long filePointer = getFilePointer();
      while (length > 0) {
        int amount;
        amount = _inputStream.read(filePointer, b, offset, length);
        length -= amount;
        offset += amount;
        filePointer += amount;
      }
      long end = System.nanoTime();
      _metricsGroup.readAccess.update((end - start) / 1000);
      _metricsGroup.readThroughput.mark(length);
    } finally {
      trace.done();
    }
  }
View Full Code Here

    };
  }

  protected FSDataOutputStream openForOutput(String name) throws IOException {
    Path path = getPath(name);
    Tracer trace = Trace.trace("filesystem - create", Trace.param("path", path));
    try {
      return _fileSystem.create(path);
    } finally {
      trace.done();
    }
  }
View Full Code Here

    Path path = getPath(name);
    FSDataInputStream inputStream = _inputMap.get(path);
    if (inputStream != null) {
      return inputStream;
    }
    Tracer trace = Trace.trace("filesystem - open", Trace.param("path", path));
    try {
      inputStream = _fileSystem.open(path);
      _inputMap.put(path, inputStream);
      return inputStream;
    } finally {
      trace.done();
    }
  }
View Full Code Here

    if (_useCache) {
      Set<String> names = new HashSet<String>(_fileLengthMap.keySet());
      return names.toArray(new String[names.size()]);
    }

    Tracer trace = Trace.trace("filesystem - list", Trace.param("path", _path));
    try {
      FileStatus[] files = _fileSystem.listStatus(_path, new PathFilter() {
        @Override
        public boolean accept(Path path) {
          try {
            return _fileSystem.isFile(path);
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
        }
      });
      String[] result = new String[files.length];
      for (int i = 0; i < result.length; i++) {
        result[i] = files[i].getPath().getName();
      }
      return result;
    } finally {
      trace.done();
    }
  }
View Full Code Here

    return exists(name);
  }

  protected boolean exists(String name) throws IOException {
    Path path = getPath(name);
    Tracer trace = Trace.trace("filesystem - exists", Trace.param("path", path));
    try {
      return _fileSystem.exists(path);
    } finally {
      trace.done();
    }
  }
View Full Code Here

  }

  protected void delete(String name) throws IOException {
    Path path = getPathOrSymlink(name);
    FSDataInputStream inputStream = _inputMap.remove(path);
    Tracer trace = Trace.trace("filesystem - delete", Trace.param("path", path));
    if (inputStream != null) {
      inputStream.close();
    }
    if (_useCache) {
      _symlinkMap.remove(name);
      _symlinkPathMap.remove(name);
    }
    try {
      _fileSystem.delete(path, true);
    } finally {
      trace.done();
    }
  }
View Full Code Here

    return length(name);
  }

  protected long length(String name) throws IOException {
    Path path = getPath(name);
    Tracer trace = Trace.trace("filesystem - length", Trace.param("path", path));
    try {
      return _fileSystem.getFileStatus(path).getLen();
    } finally {
      trace.done();
    }
  }
View Full Code Here

      Path path = _symlinkPathMap.get(name);
      if (path != null) {
        return path;
      }
    }
    Tracer trace = Trace.trace("filesystem - getRealFilePathFromSymlink", Trace.param("name", name));
    try {
      Path linkPath = new Path(_path, name + LNK);
      Path path = readRealPathDataFromSymlinkPath(_fileSystem, linkPath);
      if (_useCache) {
        _symlinkPathMap.put(name, path);
      }
      return path;
    } finally {
      trace.done();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.blur.trace.Tracer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.