Examples of TraceScope


Examples of org.cloudera.htrace.TraceScope

   * badversion is caused by the result of previous correctly setData
   * @return Stat instance
   */
  public Stat setData(String path, byte[] data, int version)
  throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
      traceScope = Trace.startSpan("RecoverableZookeeper.setData");
      RetryCounter retryCounter = retryCounterFactory.create();
      byte[] newData = appendMetaData(data);
      boolean isRetry = false;
      while (true) {
        try {
          return zk.setData(path, newData, version);
        } catch (KeeperException e) {
          switch (e.code()) {
            case CONNECTIONLOSS:
            case SESSIONEXPIRED:
            case OPERATIONTIMEOUT:
              retryOrThrow(retryCounter, e, "setData");
              break;
            case BADVERSION:
              if (isRetry) {
                // try to verify whether the previous setData success or not
                try{
                  Stat stat = new Stat();
                  byte[] revData = zk.getData(path, false, stat);
                  if(Bytes.compareTo(revData, newData) == 0) {
                    // the bad version is caused by previous successful setData
                    return stat;
                  }
                } catch(KeeperException keeperException){
                  // the ZK is not reliable at this moment. just throwing exception
                  throw keeperException;
                }
              }
            // throw other exceptions and verified bad version exceptions
            default:
              throw e;
          }
        }
        retryCounter.sleepUntilNextRetry();
        retryCounter.useRetry();
        isRetry = true;
      }
    } finally {
      if (traceScope != null) traceScope.close();
    }
  }
View Full Code Here

Examples of org.cloudera.htrace.TraceScope

   * @return Path
   */
  public String create(String path, byte[] data, List<ACL> acl,
      CreateMode createMode)
  throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
      traceScope = Trace.startSpan("RecoverableZookeeper.create");
      byte[] newData = appendMetaData(data);
      switch (createMode) {
        case EPHEMERAL:
        case PERSISTENT:
          return createNonSequential(path, newData, acl, createMode);

        case EPHEMERAL_SEQUENTIAL:
        case PERSISTENT_SEQUENTIAL:
          return createSequential(path, newData, acl, createMode);

        default:
          throw new IllegalArgumentException("Unrecognized CreateMode: " +
              createMode);
      }
    } finally {
      if (traceScope != null) traceScope.close();
    }
  }
View Full Code Here

Examples of org.cloudera.htrace.TraceScope

  /**
   * Run multiple operations in a transactional manner. Retry before throwing exception
   */
  public List<OpResult> multi(Iterable<Op> ops)
  throws KeeperException, InterruptedException {
    TraceScope traceScope = null;
    try {
      traceScope = Trace.startSpan("RecoverableZookeeper.multi");
      RetryCounter retryCounter = retryCounterFactory.create();
      Iterable<Op> multiOps = prepareZKMulti(ops);
      while (true) {
        try {
          return zk.multi(multiOps);
        } catch (KeeperException e) {
          switch (e.code()) {
            case CONNECTIONLOSS:
            case SESSIONEXPIRED:
            case OPERATIONTIMEOUT:
              retryOrThrow(retryCounter, e, "multi");
              break;

            default:
              throw e;
          }
        }
        retryCounter.sleepUntilNextRetry();
        retryCounter.useRetry();
    }
    } finally {
      if (traceScope != null) traceScope.close();
    }
  }
View Full Code Here

Examples of org.cloudera.htrace.TraceScope

            dataBlockEncoder.getEffectiveEncodingInCache(isCompaction),
            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);
          if (cachedBlock != null) {
            if (cachedBlock.getBlockType() == BlockType.DATA) {
              HFile.dataBlockReadCnt.incrementAndGet();
            }

            validateBlockType(cachedBlock, expectedBlockType);

            // Validate encoding type for encoded blocks. We include encoding
            // type in the cache key, and we expect it to match on a cache hit.
            if (cachedBlock.getBlockType() == BlockType.ENCODED_DATA
                && cachedBlock.getDataBlockEncoding() != dataBlockEncoder.getEncodingInCache()) {
              throw new IOException("Cached block under key " + cacheKey + " "
                  + "has wrong encoding: " + cachedBlock.getDataBlockEncoding() + " (expected: "
                  + dataBlockEncoder.getEncodingInCache() + ")");
            }
            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);
        hfileBlock = dataBlockEncoder.diskToCacheFormat(hfileBlock, isCompaction);
        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 (hfileBlock.getBlockType() == BlockType.DATA) {
          HFile.dataBlockReadCnt.incrementAndGet();
        }

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

Examples of org.cloudera.htrace.TraceScope

    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, clusterId);
          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

Examples of org.cloudera.htrace.TraceScope

   * 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

Examples of org.cloudera.htrace.TraceScope

          }
          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);
            }
            User user;
            if (call.effectiveUser == null) {
              user = User.create(call.connection.user);
            } else {
              UserGroupInformation ugi = UserGroupInformation.createProxyUser(
                call.effectiveUser, call.connection.user);
              ProxyUsers.authorize(ugi, call.connection.getHostAddress(), conf);
              if (LOG.isDebugEnabled()) {
                LOG.debug("Authorized " + call.connection.user
                  + " to impersonate " + call.effectiveUser);
              }
              user = User.create(ugi);
            }
            RequestContext.set(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

Examples of org.cloudera.htrace.TraceScope

  public EventHandler prepare() throws Exception {
    return this;
  }

  public void run() {
    TraceScope chunk = Trace.startSpan(this.getClass().getSimpleName(), parent);
    try {
      if (getListener() != null) getListener().beforeProcess(this);
      process();
      if (getListener() != null) getListener().afterProcess(this);
    } catch(Throwable t) {
      LOG.error("Caught throwable while processing event " + eventType, t);
    } finally {
      chunk.close();
    }
  }
View Full Code Here

Examples of org.cloudera.htrace.TraceScope

    Trace.removeReceiver(rcvr);
  }

  @Test
  public void testTraceCreateTable() throws Exception {
    TraceScope tableCreationSpan = Trace.startSpan("creating table", Sampler.ALWAYS);
    HTable table;
    try {

      table = TEST_UTIL.createTable("table".getBytes(),
        FAMILY_BYTES);
    } finally {
      tableCreationSpan.close();
    }

    Collection<Span> spans = rcvr.getSpans();
    TraceTree traceTree = new TraceTree(spans);
    Collection<Span> roots = traceTree.getRoots();

    assertEquals(1, roots.size());
    Span createTableRoot = roots.iterator().next();

    assertEquals("creating table", createTableRoot.getDescription());
    Multimap<Long, Span> spansByParentIdMap = traceTree
        .getSpansByParentIdMap();

    int createTableCount = 0;

    for (Span s : spansByParentIdMap.get(createTableRoot.getSpanId())) {
      if (s.getDescription().startsWith("MasterAdminService.CreateTable")) {
        createTableCount++;
      }
    }

    assertTrue(createTableCount >= 1);
    assertTrue(spansByParentIdMap.get(createTableRoot.getSpanId()).size() > 3);
    assertTrue(spans.size() > 5);
   
    Put put = new Put("row".getBytes());
    put.add(FAMILY_BYTES, "col".getBytes(), "value".getBytes());

    TraceScope putSpan = Trace.startSpan("doing put", Sampler.ALWAYS);
    try {
      table.put(put);
    } finally {
      putSpan.close();
    }

    spans = rcvr.getSpans();
    traceTree = new TraceTree(spans);
    roots = traceTree.getRoots();
View Full Code Here

Examples of org.cloudera.htrace.TraceScope

      service.submit(runnable);
    }
  }

  private void createTable() throws IOException {
    TraceScope createScope = null;
    try {
      createScope = Trace.startSpan("createTable", Sampler.ALWAYS);
      util.createTable(tableName, familyName);
    } finally {
      if (createScope != null) createScope.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.