Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scheduleFlush in KinesisSink non-recursive #128

Open
dilyand opened this issue Mar 18, 2021 · 0 comments
Open

Make scheduleFlush in KinesisSink non-recursive #128

dilyand opened this issue Mar 18, 2021 · 0 comments

Comments

@dilyand
Copy link
Contributor

dilyand commented Mar 18, 2021

This function should be called at the end of flush() and should not call itself.

At the end of each flush(), whatever the trigger, we call this function to schedule a flush after TimeThreshold in case we haven't reached the bytes and records limits.

If these limits have been reached in-between, then flush won't happen because of currentTime - lastFlushed >= TimeThreshold and another flush will have already been scheduled.

def scheduleFlush(interval: Long = TimeThreshold): Unit = {
    executorService.schedule(
      new Thread {
        override def run(): Unit = {
          val lastFlushed = EventStorage.getLastFlushTime
          val currentTime = System.currentTimeMillis()
          if (currentTime - lastFlushed >= TimeThreshold) {
            EventStorage.flush()
            scheduleFlush(TimeThreshold)
          } else {
            scheduleFlush(TimeThreshold + lastFlushed - currentTime)
          }
        }
      },
      interval,
      MILLISECONDS
    )
    ()
  }

def scheduleFlush(): Unit = {
    executorService.schedule(
      new Thread {
        override def run(): Unit = {
          val lastFlushed = EventStorage.getLastFlushTime
          val currentTime = System.currentTimeMillis()
          if (currentTime - lastFlushed >= TimeThreshold) {
            EventStorage.flush()
          }
        }
      },
      TimeThreshold,
      MILLISECONDS
    )
    ()
  }

#124 (comment)

@dilyand dilyand mentioned this issue Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant