protected synchronized void updateCursor(ManagedCursorImpl cursor, Position newPosition)
      throws InterruptedException, ManagedLedgerException {
    checkFenced();
    // First update the metadata store, so that if we don't succeed we have
    // not changed any other state
    store.updateConsumer(name, cursor.getName(), newPosition);
    Position oldPosition = cursor.setAcknowledgedPosition(newPosition);
    cursors.cursorUpdated(cursor);

    if (oldPosition.getLedgerId() != newPosition.getLedgerId()) {
      // Only trigger a trimming when switching to the next ledger
      trimConsumedLedgersInBackground();
    }
  }