# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# This file is intended to be sourced. After sourcing the KUDU_COMMON_ARGS will be set.
# KUDU_COMMON_ARGS should be passed to both the master and tservers on startup.
#
# KUDU_BUILD_DIR or USE_KUDU_DEBUG_BUILD must be set before this is sourced (default
# values are set in impala-config.sh). If KUDU_BUILD_DIR is set then KUDU_HOME should
# also be set otherwise the web pages may not function (but that should be the only
# problem).

if [[ -n "$KUDU_BUILD_DIR" ]]; then
  KUDU_BIN_DIR="$KUDU_BUILD_DIR/bin"
  KUDU_WWW_DIR="$KUDU_HOME/www"
else
  KUDU_BIN_DIR="$IMPALA_KUDU_HOME"
  if $USE_KUDU_DEBUG_BUILD; then
    KUDU_BIN_DIR+=/debug/bin
  else
    KUDU_BIN_DIR+=/release/bin
  fi
  KUDU_WWW_DIR="$KUDU_BIN_DIR/../lib/kudu/www"
fi

KUDU_COMMON_ARGS=("-webserver_doc_root=$KUDU_WWW_DIR")

# Add a dummy flag with value IBelongToTheMiniCluster so the process is easily
# identifiable in case the pid file is removed.
KUDU_COMMON_ARGS+=("-vmodule=IBelongToTheMiniCluster")
KUDU_COMMON_ARGS+=("-memory_limit_hard_bytes=2147483648") # 2gb
KUDU_COMMON_ARGS+=("-block_cache_capacity_mb=256")

HOLE_PUNCH_TEST_FILE=${NODE_DIR}/var/lib/kudu/hole_punch_test
if ! fallocate -p -o 1 -l 1 "$HOLE_PUNCH_TEST_FILE" &>/dev/null; then
  KUDU_COMMON_ARGS+=("-block_manager=file")
fi
rm -f "$HOLE_PUNCH_TEST_FILE"
