def update()

in atlas-core/src/main/scala/com/netflix/atlas/core/db/BlockStore.scala [118:152]


  def update(timestamp: Long, value: Double, rollup: Boolean): Unit = {
    if (currentBlock == null) {
      currentBlock =
        if (rollup)
          newRollupBlock(alignStart(timestamp), blockSize)
        else
          newArrayBlock(alignStart(timestamp), blockSize)
      BlockStats.inc(currentBlock)
      currentPos = next(currentPos)
      if (blocks(currentPos) != null) BlockStats.dec(blocks(currentPos))
      blocks(currentPos) = currentBlock
      hasData = true
    }
    var pos = ((timestamp - currentBlock.start) / step).asInstanceOf[Int]
    if (pos >= blockSize) {
      // Exceeded window of current block, create a new one for the next
      // interval
      newBlock(alignStart(timestamp), rollup)
      pos = ((timestamp - currentBlock.start) / step).asInstanceOf[Int]
      currentBlock.update(pos, value)
    } else if (pos < 0) {
      // Out of order update received for an older block, try to update the
      // previous block
      val previousPos = (currentPos - 1) % numBlocks
      if (previousPos > 0 && blocks(previousPos) != null) {
        val previousBlock = blocks(previousPos)
        pos = ((timestamp - previousBlock.start) / step).asInstanceOf[Int]
        if (pos >= 0 && pos < blockSize) {
          previousBlock.update(pos, value)
        }
      }
    } else {
      currentBlock.update(pos, value)
    }
  }