Package org.cloudera.htrace

Examples of org.cloudera.htrace.TraceScope


      if (createScope != null) createScope.close();
    }
  }

  private void deleteTable() throws IOException {
    TraceScope deleteScope = null;

    try {
      if (admin.tableExists(tableName)) {
        deleteScope = Trace.startSpan("deleteTable", Sampler.ALWAYS);
        util.deleteTable(tableName);
      }
    } finally {
      if (deleteScope != null) deleteScope.close();
    }
  }
View Full Code Here


  private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException {
    LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<Long>(25000);
    HTable ht = new HTable(util.getConfiguration(), this.tableName);
    byte[] value = new byte[300];
    for (int x = 0; x < 5000; x++) {
      TraceScope traceScope = Trace.startSpan("insertData", Sampler.ALWAYS);
      try {
        ht.setAutoFlush(false);
        for (int i = 0; i < 5; i++) {
          long rk = random.nextLong();
          rowKeys.add(rk);
          Put p = new Put(Bytes.toBytes(rk));
          for (int y = 0; y < 10; y++) {
            random.nextBytes(value);
            p.add(Bytes.toBytes(familyName),
                Bytes.toBytes(random.nextLong()),
                value);
          }
          ht.put(p);
        }
        if ((x % 1000) == 0) {
          admin.flush(Bytes.toBytes(tableName));
        }
      } finally {
        traceScope.close();
      }
    }
    admin.flush(Bytes.toBytes(tableName));
    return rowKeys;
  }
View Full Code Here

      TimingResult result = new TimingResult();
      int numAfterDone = 0;
      // Keep trying until the rs is back up and we've gotten a put through
      while (numAfterDone < 10) {
        long start = System.nanoTime();
        TraceScope scope = null;
        try {
          scope = Trace.startSpan(getSpanName(), AlwaysSampler.INSTANCE);
          boolean actionResult = doAction();
          if (actionResult && future.isDone()) {
            numAfterDone ++;
          }
        } catch (Exception e) {
          numAfterDone = 0;
        } finally {
          if (scope != null) {
            scope.close();
          }
        }
        result.addResult(System.nanoTime() - start, scope.getSpan());
      }
      return result;
    }
View Full Code Here

            dataBlockEncoder.getDataBlockEncoding(),
            expectedBlockType);

    boolean useLock = false;
    IdLock.Entry lockEntry = null;
    TraceScope traceScope = Trace.startSpan("HFileReaderV2.readBlock");
    try {
      while (true) {
        if (useLock) {
          lockEntry = offsetLock.getLockEntry(dataBlockOffset);
        }

        // Check cache for block. If found return.
        if (cacheConf.isBlockCacheEnabled()) {
          // Try and get the block from the block cache. If the useLock variable is true then this
          // is the second time through the loop and it should not be counted as a block cache miss.
          HFileBlock cachedBlock = (HFileBlock) cacheConf.getBlockCache().getBlock(cacheKey,
            cacheBlock, useLock, updateCacheMetrics);
          if (cachedBlock != null) {
            validateBlockType(cachedBlock, expectedBlockType);
            if (cachedBlock.getBlockType().isData()) {
              HFile.dataBlockReadCnt.incrementAndGet();

              // Validate encoding type for data blocks. We include encoding
              // type in the cache key, and we expect it to match on a cache hit.
              if (cachedBlock.getDataBlockEncoding() != dataBlockEncoder.getDataBlockEncoding()) {
                throw new IOException("Cached block under key " + cacheKey + " "
                  + "has wrong encoding: " + cachedBlock.getDataBlockEncoding() + " (expected: "
                  + dataBlockEncoder.getDataBlockEncoding() + ")");
              }
            }
            return cachedBlock;
          }
          // Carry on, please load.
        }
        if (!useLock) {
          // check cache again with lock
          useLock = true;
          continue;
        }
        if (Trace.isTracing()) {
          traceScope.getSpan().addTimelineAnnotation("blockCacheMiss");
        }
        // Load block from filesystem.
        long startTimeNs = System.nanoTime();
        HFileBlock hfileBlock = fsBlockReader.readBlockData(dataBlockOffset, onDiskBlockSize, -1,
            pread);
        validateBlockType(hfileBlock, expectedBlockType);

        final long delta = System.nanoTime() - startTimeNs;
        HFile.offerReadLatency(delta, pread);

        // Cache the block if necessary
        if (cacheBlock && cacheConf.shouldCacheBlockOnRead(hfileBlock.getBlockType().getCategory())) {
          cacheConf.getBlockCache().cacheBlock(cacheKey, hfileBlock, cacheConf.isInMemory());
        }

        if (updateCacheMetrics && hfileBlock.getBlockType().isData()) {
          HFile.dataBlockReadCnt.incrementAndGet();
        }

        return hfileBlock;
      }
    } finally {
      traceScope.close();
      if (lockEntry != null) {
        offsetLock.releaseLockEntry(lockEntry);
      }
    }
  }
View Full Code Here

   * limit. If so, flush regions with the biggest memstores until we're down
   * to the lower limit. This method blocks callers until we're down to a safe
   * amount of memstore consumption.
   */
  public void reclaimMemStoreMemory() {
    TraceScope scope = Trace.startSpan("MemStoreFluser.reclaimMemStoreMemory");
    if (isAboveHighWaterMark()) {
      if (Trace.isTracing()) {
        scope.getSpan().addTimelineAnnotation("Force Flush. We're above high water mark.");
      }
      long start = System.currentTimeMillis();
      synchronized (this.blockSignal) {
        boolean blocked = false;
        long startTime = 0;
        while (isAboveHighWaterMark() && !server.isStopped()) {
          if (!blocked) {
            startTime = EnvironmentEdgeManager.currentTimeMillis();
            LOG.info("Blocking updates on " + server.toString() +
            ": the global memstore size " +
            StringUtils.humanReadableInt(server.getRegionServerAccounting().getGlobalMemstoreSize()) +
            " is >= than blocking " +
            StringUtils.humanReadableInt(globalMemStoreLimit) + " size");
          }
          blocked = true;
          wakeupFlushThread();
          try {
            // we should be able to wait forever, but we've seen a bug where
            // we miss a notify, so put a 5 second bound on it at least.
            blockSignal.wait(5 * 1000);
          } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
          }
          long took = System.currentTimeMillis() - start;
          LOG.warn("Memstore is above high water mark and block " + took + "ms");
        }
        if(blocked){
          final long totalTime = EnvironmentEdgeManager.currentTimeMillis() - startTime;
          if(totalTime > 0){
            this.updatesBlockedMsHighWater.add(totalTime);
          }
          LOG.info("Unblocking updates for server " + server.toString());
        }
      }
    } else if (isAboveLowWaterMark()) {
      wakeupFlushThread();
    }
    scope.close();
  }
View Full Code Here

      AtomicLong sequenceId, long nonceGroup, long nonce) throws IOException {
      if (edits.isEmpty()) return this.unflushedEntries.get();
      if (this.closed) {
        throw new IOException("Cannot append; log is closed");
      }
      TraceScope traceScope = Trace.startSpan("FSHlog.append");
      try {
        long txid = 0;
        synchronized (this.updateLock) {
          // get the sequence number from the passed Long. In normal flow, it is coming from the
          // region.
          long seqNum = sequenceId.incrementAndGet();
          // The 'lastSeqWritten' map holds the sequence number of the oldest
          // write for each region (i.e. the first edit added to the particular
          // memstore). . When the cache is flushed, the entry for the
          // region being flushed is removed if the sequence number of the flush
          // is greater than or equal to the value in lastSeqWritten.
          // Use encoded name.  Its shorter, guaranteed unique and a subset of
          // actual  name.
          byte [] encodedRegionName = info.getEncodedNameAsBytes();
          if (isInMemstore) this.oldestUnflushedSeqNums.putIfAbsent(encodedRegionName, seqNum);
          HLogKey logKey = makeKey(
            encodedRegionName, tableName, seqNum, now, clusterIds, nonceGroup, nonce);

          synchronized (pendingWritesLock) {
            doWrite(info, logKey, edits, htd);
            txid = this.unflushedEntries.incrementAndGet();
          }
          this.numEntries.incrementAndGet();
          this.asyncWriter.setPendingTxid(txid);

          if (htd.isDeferredLogFlush()) {
            lastUnSyncedTxid = txid;
          }
          this.latestSequenceNums.put(encodedRegionName, seqNum);
        }
        // TODO: note that only tests currently call append w/sync.
        //       Therefore, this code here is not actually used by anything.
        // Sync if catalog region, and if not then check if that table supports
        // deferred log flushing
        if (doSync &&
            (info.isMetaRegion() ||
            !htd.isDeferredLogFlush())) {
          // sync txn to file system
          this.sync(txid);
        }
        return txid;
      } finally {
        traceScope.close();
      }
    }
View Full Code Here

    throws IOException {
      if (edits.isEmpty()) return this.unflushedEntries.get();
      if (this.closed) {
        throw new IOException("Cannot append; log is closed");
      }
      TraceScope traceScope = Trace.startSpan("FSHlog.append");
      try {
        long txid = 0;
        synchronized (this.updateLock) {
          long seqNum = obtainSeqNum();
          // The 'lastSeqWritten' map holds the sequence number of the oldest
          // write for each region (i.e. the first edit added to the particular
          // memstore). . When the cache is flushed, the entry for the
          // region being flushed is removed if the sequence number of the flush
          // is greater than or equal to the value in lastSeqWritten.
          // Use encoded name.  Its shorter, guaranteed unique and a subset of
          // actual  name.
          byte [] encodedRegionName = info.getEncodedNameAsBytes();
          if (isInMemstore) this.oldestUnflushedSeqNums.putIfAbsent(encodedRegionName, seqNum);
          HLogKey logKey = makeKey(encodedRegionName, tableName, seqNum, now, clusterIds);
          doWrite(info, logKey, edits, htd);
          this.numEntries.incrementAndGet();
          txid = this.unflushedEntries.incrementAndGet();
          if (htd.isDeferredLogFlush()) {
            lastDeferredTxid = txid;
          }
        }
        // Sync if catalog region, and if not then check if that table supports
        // deferred log flushing
        if (doSync &&
            (info.isMetaRegion() ||
            !htd.isDeferredLogFlush())) {
          // sync txn to file system
          this.sync(txid);
        }
        return txid;
      } finally {
        traceScope.close();
      }
    }
View Full Code Here

          }
          Throwable errorThrowable = null;
          String error = null;
          Pair<Message, CellScanner> resultPair = null;
          CurCall.set(call);
          TraceScope traceScope = null;
          try {
            if (!started) {
              throw new ServerNotRunningYetException("Server is not running yet");
            }
            if (call.tinfo != null) {
              traceScope = Trace.startSpan(call.toTraceString(), call.tinfo);
            }

            // make the call
          RequestContext.set(userProvider.create(call.connection.user), getRemoteIp(),
            call.connection.service);
          // make the call
          resultPair = call(call.service, call.md, call.param, call.cellScanner, call.timestamp,
              status);
          } catch (Throwable e) {
            LOG.debug(getName() + ": " + call.toShortString(), e);
            errorThrowable = e;
            error = StringUtils.stringifyException(e);
          } finally {
            if (traceScope != null) {
              traceScope.close();
            }
            // Must always clear the request context to avoid leaking
            // credentials between requests.
            RequestContext.clear();
          }
View Full Code Here

          }
          Throwable errorThrowable = null;
          String error = null;
          Pair<Message, CellScanner> resultPair = null;
          CurCall.set(call);
          TraceScope traceScope = null;
          try {
            if (!started) {
              throw new ServerNotRunningYetException("Server is not running yet");
            }
            if (call.tinfo != null) {
              traceScope = Trace.startSpan(call.toTraceString(), call.tinfo);
            }

            // make the call
          RequestContext.set(userProvider.create(call.connection.user), getRemoteIp(),
            call.connection.service);
          // make the call
          resultPair = call(call.service, call.md, call.param, call.cellScanner, call.timestamp,
              status);
          } catch (Throwable e) {
            LOG.debug(getName() + ": " + call.toShortString(), e);
            errorThrowable = e;
            error = StringUtils.stringifyException(e);
          } finally {
            if (traceScope != null) {
              traceScope.close();
            }
            // Must always clear the request context to avoid leaking
            // credentials between requests.
            RequestContext.clear();
          }
View Full Code Here

    throws IOException {
      if (edits.isEmpty()) return this.unflushedEntries.get();
      if (this.closed) {
        throw new IOException("Cannot append; log is closed");
      }
      TraceScope traceScope = Trace.startSpan("FSHlog.append");
      try {
        long txid = 0;
        synchronized (this.updateLock) {
          long seqNum = obtainSeqNum();
          // The 'lastSeqWritten' map holds the sequence number of the oldest
          // write for each region (i.e. the first edit added to the particular
          // memstore). . When the cache is flushed, the entry for the
          // region being flushed is removed if the sequence number of the flush
          // is greater than or equal to the value in lastSeqWritten.
          // Use encoded name.  Its shorter, guaranteed unique and a subset of
          // actual  name.
          byte [] encodedRegionName = info.getEncodedNameAsBytes();
          if (isInMemstore) this.oldestUnflushedSeqNums.putIfAbsent(encodedRegionName, seqNum);
          HLogKey logKey = makeKey(encodedRegionName, tableName, seqNum, now, clusterIds);
          doWrite(info, logKey, edits, htd);
          this.numEntries.incrementAndGet();
          txid = this.unflushedEntries.incrementAndGet();
          if (htd.isDeferredLogFlush()) {
            lastDeferredTxid = txid;
          }
        }
        // Sync if catalog region, and if not then check if that table supports
        // deferred log flushing
        if (doSync &&
            (info.isMetaRegion() ||
            !htd.isDeferredLogFlush())) {
          // sync txn to file system
          this.sync(txid);
        }
        return txid;
      } finally {
        traceScope.close();
      }
    }
View Full Code Here

TOP

Related Classes of org.cloudera.htrace.TraceScope

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.