Exemple #1
0
 public synchronized void setInstanceDescriptor(UbaCoordinate ubaCoordinate, InstanceDescriptor id)
     throws Exception {
   InstanceDescriptor got = instanceDescriptor.get();
   if (got != null && !got.equals(id)) {
     instancePath.writeInstanceDescriptor(ubaCoordinate, id);
     ensureCerts(id);
     startupId.incrementAndGet();
     unexpectedRestartTimestamp.set(-1);
     redeploy.set(true);
     LOG.info("Instance changed from " + got + " to " + id);
   } else if (!instancePath.script("status").exists()) {
     startupId.incrementAndGet();
     unexpectedRestartTimestamp.set(-1);
     redeploy.set(true);
     LOG.info("Missing status script from " + got + " to " + id);
   }
   if (!redeploy.get()) {
     LOG.debug("Service:" + instancePath.toHumanReadableName() + " has NOT changed.");
   } else {
     instanceDescriptor.set(id);
   }
   if (id.restartTimestampGMTMillis > lastRestart.get()) {
     restartAtTimestamp.set(id.restartTimestampGMTMillis);
   }
 }
  private InputStream getInputStream(
      final String fileName, final AtomicLong size, final List<Closeable> resources)
      throws IOException, FileNotFoundException {
    InputStream inStream = null;

    if (fileName.endsWith("zip")) {
      final ZipArchive zipArchive = new ZipArchive(new File(fileName));

      final Enumeration<ZipArchiveEntry> entries = zipArchive.entries();
      while (entries.hasMoreElements()) {
        final ZipArchiveEntry entry = entries.nextElement();
        if (!entry.isDirectory() && entry.getName().endsWith("fb2")) {
          size.set(entry.getSize());
          inStream = entry.open();
          resources.add(inStream);
          break;
        }
      }
      resources.add(zipArchive);
    } else {
      final File f = new File(fileName);
      size.set(f.length());
      inStream = new FileInputStream(f);
      resources.add(inStream);
    }
    return inStream;
  }
Exemple #3
0
    public void receive(Message msg) {
      byte[] buf = msg.getRawBuffer();
      byte type = buf[msg.getOffset()];

      switch (type) {
        case START:
          ByteBuffer tmp = ByteBuffer.wrap(buf, 1 + msg.getOffset(), Global.LONG_SIZE);
          num_msgs = (int) tmp.getLong();
          print = num_msgs / 10;
          current_value.set(0);
          total_bytes.set(0);
          start = System.currentTimeMillis();
          break;
        case DATA:
          long new_val = current_value.incrementAndGet();
          total_bytes.addAndGet(msg.getLength() - Global.INT_SIZE);
          if (print > 0 && new_val % print == 0) System.out.println("received " + new_val);
          if (new_val >= num_msgs) {
            long time = System.currentTimeMillis() - start;
            double msgs_sec = (current_value.get() / (time / 1000.0));
            double throughput = total_bytes.get() / (time / 1000.0);
            System.out.println(
                String.format(
                    "\nreceived %d messages in %d ms (%.2f msgs/sec), throughput=%s",
                    current_value.get(), time, msgs_sec, Util.printBytes(throughput)));
            break;
          }
          break;
        default:
          System.err.println("Type " + type + " is invalid");
      }
    }
  public void testMaxSizeVirtualMemory() {
    final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
    final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
    final BootstrapCheck.MaxSizeVirtualMemoryCheck check =
        new BootstrapCheck.MaxSizeVirtualMemoryCheck() {
          @Override
          long getMaxSizeVirtualMemory() {
            return maxSizeVirtualMemory.get();
          }

          @Override
          long getRlimInfinity() {
            return rlimInfinity;
          }
        };

    final RuntimeException e =
        expectThrows(
            RuntimeException.class,
            () ->
                BootstrapCheck.check(
                    true, false, Collections.singletonList(check), "testMaxSizeVirtualMemory"));
    assertThat(e.getMessage(), containsString("max size virtual memory"));

    maxSizeVirtualMemory.set(rlimInfinity);

    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxSizeVirtualMemory");

    // nothing should happen if max size virtual memory is not
    // available
    maxSizeVirtualMemory.set(Long.MIN_VALUE);
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxSizeVirtualMemory");
  }
  public void testMaxMapCountCheck() {
    final int limit = 1 << 18;
    final AtomicLong maxMapCount = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapCheck.MaxMapCountCheck check =
        new BootstrapCheck.MaxMapCountCheck() {
          @Override
          long getMaxMapCount() {
            return maxMapCount.get();
          }
        };

    RuntimeException e =
        expectThrows(
            RuntimeException.class,
            () ->
                BootstrapCheck.check(
                    true, false, Collections.singletonList(check), "testMaxMapCountCheck"));
    assertThat(e.getMessage(), containsString("max virtual memory areas vm.max_map_count"));

    maxMapCount.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));

    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxMapCountCheck");

    // nothing should happen if current vm.max_map_count is not
    // available
    maxMapCount.set(-1);
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testMaxMapCountCheck");
  }
Exemple #6
0
 public void resetStats() {
   super.resetStats();
   num_sent_msgs.set(0);
   num_sent_frags.set(0);
   num_received_frags.set(0);
   num_received_msgs.set(0);
 }
  /** @param sinceSCN */
  @Override
  public synchronized void start(long sinceSCN) {
    _log.info("Start golden gate evert producer requested.");
    if (_currentState == State.RUNNING) {
      _log.error("Thread already running! ");
      return;
    }
    _scn.set(TrailFilePositionSetter.USE_LATEST_SCN);

    if (sinceSCN > 0) {
      _scn.set(sinceSCN);
    } else {
      if (getMaxScnReaderWriter() != null) {
        try {
          long scn = getMaxScnReaderWriter().getMaxScn();

          // If the max scn is greater than 0, then honor it.
          if (scn > 0) {
            // apply the restart SCN offset
            long newScn =
                (scn >= _pConfig.getRestartScnOffset()) ? scn - _pConfig.getRestartScnOffset() : 0;
            _log.info(
                "Checkpoint read = "
                    + scn
                    + " restartScnOffset= "
                    + _pConfig.getRestartScnOffset()
                    + " Adjusted SCN= "
                    + newScn);
            if (newScn > 0) {
              _scn.set(newScn);
            }
          } else // If the max scn is set to <0, this is a special case that we use to let the trail
          // file notifier that you want to override the default behaviour of starting with
          // the latest scn.
          {
            _log.info(
                "Overridding default behaviour (start with latest scn), using scn : "
                    + scn
                    + " to start the relay");
            if (scn != TrailFilePositionSetter.USE_EARLIEST_SCN
                && scn != TrailFilePositionSetter.USE_LATEST_SCN)
              throw new DatabusException(
                  "The scn you have passed is neither EARLIEST or LATEST  setting, cannot proceed with using this scn");

            _scn.set(scn);
          }

        } catch (DatabusException e) {
          _log.warn("Could not read saved maxScn: Defaulting to startSCN=" + _scn.get());
        }
      }
    }

    if (_worker == null) {
      _log.info("Starting with scn = " + _scn.get());
      _worker = new WorkerThread();
      _worker.setDaemon(true);
      _worker.start();
    }
  }
Exemple #8
0
  public void reset() {
    blobOpenCount.set(0);
    clobOpenCount.set(0);

    connectionStat.reset();
    statementStat.reset();
    resultSetStat.reset();
    connectionHoldHistogram.reset();

    lock.writeLock().lock();
    try {
      Iterator<Map.Entry<String, JdbcSqlStat>> iter = sqlStatMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, JdbcSqlStat> entry = iter.next();
        JdbcSqlStat stat = entry.getValue();
        if (stat.getExecuteCount() == 0 && stat.getRunningCount() == 0) {
          stat.setRemoved(true);
          iter.remove();
        } else {
          stat.reset();
        }
      }
    } finally {
      lock.writeLock().unlock();
    }

    for (JdbcConnectionStat.Entry connectionStat : connections.values()) {
      connectionStat.reset();
    }
  }
  @Test
  public void testRespectsTime() throws Exception {
    final long startTime = System.nanoTime();
    final AtomicLong currentTime = new AtomicLong(startTime);
    Ticker ticker =
        new Ticker() {
          @Override
          public long read() {
            return currentTime.get();
          }
        };
    ProportionalZoneFailureDetector detector =
        new ProportionalZoneFailureDetector(2, Duration.ONE_HOUR, 0.9, ticker);

    for (int i = 0; i < 2; i++) {
      detector.onStartupFailure(loc1, entity1, new Throwable("simulated failure"));
    }
    assertTrue(detector.hasFailed(loc1));

    currentTime.set(startTime + TimeUnit.MILLISECONDS.toNanos(1000 * 60 * 60 - 1));
    assertTrue(detector.hasFailed(loc1));

    currentTime.set(startTime + TimeUnit.MILLISECONDS.toNanos(1000 * 60 * 60 + 1));
    assertFalse(detector.hasFailed(loc1));
  }
Exemple #10
0
  public static void init(Map<String, String> props) {

    // TODO - check if a clone is in process and prompt to kill it
    // for now kill any resharder threads that might be running
    if (OpLogWriter.isRunning()) {
      MessageLog.push("ERROR:, clone operation in progress.", Config.class.getSimpleName());
    }

    _done = false;
    _ts = 0;

    if (props != null) {
      for (Entry<String, String> prop : props.entrySet()) {
        setProperty(prop.getKey(), prop.getValue());
      }
    }

    loadDefaults();

    _chunks = new HashMap<String, List<Chunk>>();

    _docCount.set(0);
    _orphanCount.set(0);
    _oplogCount.set(0);
    _oplogReads.set(0);

    _nodes = _logDB.getCollection("nodes");

    if (props == null) _nodes.drop();
  }
Exemple #11
0
 /** Resets all the performance counters. */
 public void resetPerformanceCounters() {
   classLoadingCount.set(0);
   classLoadingTime.set(0);
   classLoadingPrefetchCacheCount.set(0);
   resourceLoadingCount.set(0);
   resourceLoadingTime.set(0);
 }
  public void testMaxNumberOfThreadsCheck() {
    final int limit = 1 << 11;
    final AtomicLong maxNumberOfThreads = new AtomicLong(randomIntBetween(1, limit - 1));
    final BootstrapCheck.MaxNumberOfThreadsCheck check =
        new BootstrapCheck.MaxNumberOfThreadsCheck() {
          @Override
          long getMaxNumberOfThreads() {
            return maxNumberOfThreads.get();
          }
        };

    final RuntimeException e =
        expectThrows(
            RuntimeException.class,
            () ->
                BootstrapCheck.check(
                    true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck"));
    assertThat(e.getMessage(), containsString("max number of threads"));

    maxNumberOfThreads.set(randomIntBetween(limit + 1, Integer.MAX_VALUE));

    BootstrapCheck.check(
        true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");

    // nothing should happen if current max number of threads is
    // not available
    maxNumberOfThreads.set(-1);
    BootstrapCheck.check(
        true, false, Collections.singletonList(check), "testMaxNumberOfThreadsCheck");
  }
 public void resetValues() {
   clients = 0;
   end = 0;
   start = 0;
   rxTime = 0;
   received.set(0);
   sent.set(0);
 }
 /** get returns the last value set */
 public void testGetSet() {
   AtomicLong ai = new AtomicLong(1);
   assertEquals(1, ai.get());
   ai.set(2);
   assertEquals(2, ai.get());
   ai.set(-3);
   assertEquals(-3, ai.get());
 }
 private void setIndex(EtcdKeysResponse response) {
   if (response != null && response.node != null) {
     index.set(response.node.modifiedIndex + 1);
     LOGGER.debug("Index received={}, next={}", response.node.modifiedIndex, index.get());
   } else {
     index.set(response.etcdIndex + 1);
     LOGGER.debug("Index received={}, next={}", response.node.modifiedIndex, index.get());
   }
 }
Exemple #16
0
 protected void resetStats() {
   downstreamIdleTime.set(0);
   upstreamIdleTime.set(0);
   queuedBatches.set(0);
   doneBatches.set(0);
   totalProcessingTime.reset();
   startTime = currentTimeMillis();
   endTime = 0;
 }
  @Override
  public synchronized void reset() {

    val.set(0);
    total.set(0);
    updateCount.set(0);

    super.reset();
  }
  public synchronized void clear() {
    super.clear();

    executionError.set(0);
    fatalError.set(0);
    if (flowStatistics != null) {
      flowStatistics.clear();
    }
  }
  public void startProcessTimer() {
    if (startNanos.compareAndSet(0, System.nanoTime())) {
      pipelineContext.start();
      executionStartTime.set(DateTime.now());
    }

    intervalWallStart.set(System.nanoTime());
    intervalCpuStart.set(currentThreadCpuTime());
    intervalUserStart.set(currentThreadUserTime());
  }
 public void rollback() throws CanalStoreException {
   final ReentrantLock lock = this.lock;
   lock.lock();
   try {
     getSequence.set(ackSequence.get());
     getMemSize.set(ackMemSize.get());
   } finally {
     lock.unlock();
   }
 }
  public synchronized void cancel() {
    if (timer != null) {
      timer.cancel();
    }

    timer = null;
    delay.set(-1L);
    startTime.set(-1L);
    taskExecuted = false;
  }
 public double getRecentHitRate() {
   long r = requests.get();
   long h = hits.get();
   try {
     return ((double) (h - lastHits.get())) / (r - lastRequests.get());
   } finally {
     lastRequests.set(r);
     lastHits.set(h);
   }
 }
Exemple #23
0
 public synchronized void reset() {
   setComputedDropRate(0.0);
   _lastIntervalCountTotal = 0;
   _lastIntervalDroppedCountTotal = 0;
   _lastIntervalDroppedRate = 0.0;
   _lastResetTime = _clock.currentTimeMillis();
   _lastNotDroppedTime.set(_lastResetTime);
   _countTotal.set(0);
   _noOverrideDropCountTotal.set(0);
   _droppedCountTotal.set(0);
 }
  public synchronized void next() {
    lastValue.set(currentValue.get());

    if (currentValue.get() == wrapAround) {
      currentValue.set(0);
      generation++;
      isWrapped = true;
    } else {
      currentValue.incrementAndGet();
      isWrapped = false;
    }
  }
Exemple #25
0
 @Override
 public void run() {
   if (iter.get() > lastIter) {
     double p = accepts.get() / (double) iters2.get() * 100;
     logger.info(
         String.format(
             Locale.US, "[%s] Accepted %s of %s steps (%.2f %%).", iter, accepts, iters2, p));
     accepts.set(0);
     iters2.set(0);
     lastIter = iter.get();
   }
 }
 public static void resetStats() {
   firstRequestStart.set(null);
   lastRequestStart.set(null);
   firstRequestEnd.set(null);
   lastRequestEnd.set(null);
   startedRequests.set(0L);
   completedRequests.set(0L);
   concurrency.set(0L);
   maxConcurrency.set(0L);
   totConcurrency.set(0L);
   avgConcurrency.set(0.0D);
 }
  public void update(long val) {

    if (val < min.get()) {
      min.set(val);
    }

    if (val > max.get()) {
      max.set(val);
    }

    sum.addAndGet(val);

    count.addAndGet(1);
  }
  /**
   * May be called to refresh the state attributes used to detect changes e.g., file existence, size
   * and last-modified time once re-loading is successfully completed. If the file does not exist
   * then the attributes are reset to an &quot;unknown&quot; state.
   *
   * @throws IOException If failed to access the file (if exists)
   * @see #resetReloadAttributes()
   */
  public void updateReloadAttributes() throws IOException {
    if (exists()) {
      long size = size();
      FileTime modifiedTime = lastModified();

      if (size >= 0L && modifiedTime != null) {
        lastExisted.set(true);
        lastSize.set(size);
        lastModified.set(modifiedTime.toMillis());
        return;
      }
    }

    resetReloadAttributes();
  }
Exemple #29
0
 /** {@inheritDoc} */
 public void ping() {
   long newPingTime = System.currentTimeMillis();
   log.debug(
       "Pinging client with id {} at {}, last ping sent at {}",
       new Object[] {getId(), newPingTime, lastPingSent.get()});
   if (lastPingSent.get() == 0) {
     lastPongReceived.set(newPingTime);
   }
   Ping pingRequest = new Ping();
   pingRequest.setEventType(Ping.PING_CLIENT);
   lastPingSent.set(newPingTime);
   int now = (int) (newPingTime & 0xffffffff);
   pingRequest.setValue2(now);
   ping(pingRequest);
 }
  public void testHeapSizeCheck() {
    final int initial = randomIntBetween(0, Integer.MAX_VALUE - 1);
    final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE);
    final AtomicLong initialHeapSize = new AtomicLong(initial);
    final AtomicLong maxHeapSize = new AtomicLong(max);

    final BootstrapCheck.HeapSizeCheck check =
        new BootstrapCheck.HeapSizeCheck() {
          @Override
          long getInitialHeapSize() {
            return initialHeapSize.get();
          }

          @Override
          long getMaxHeapSize() {
            return maxHeapSize.get();
          }
        };

    final RuntimeException e =
        expectThrows(
            RuntimeException.class,
            () ->
                BootstrapCheck.check(
                    true, false, Collections.singletonList(check), "testHeapSizeCheck"));
    assertThat(
        e.getMessage(),
        containsString(
            "initial heap size ["
                + initialHeapSize.get()
                + "] "
                + "not equal to maximum heap size ["
                + maxHeapSize.get()
                + "]"));

    initialHeapSize.set(maxHeapSize.get());

    BootstrapCheck.check(true, false, Collections.singletonList(check), "testHeapSizeCheck");

    // nothing should happen if the initial heap size or the max
    // heap size is not available
    if (randomBoolean()) {
      initialHeapSize.set(0);
    } else {
      maxHeapSize.set(0);
    }
    BootstrapCheck.check(true, false, Collections.singletonList(check), "testHeapSizeCheck");
  }