Skip to content

Commit

Permalink
Add a app id to schema change history store to prevent server drop op…
Browse files Browse the repository at this point in the history
…timization from running (#6927)

* Prevent baas server drop optimization from running
* Copy entire evergreen/ directory to remote host
* Renamed add_dummy_app.js; moved fake app id to earlier in script

---------

Co-authored-by: Kirollos Morkos <kiro.morkos@mongodb.com>
  • Loading branch information
Michael Wilkerson-Barker and kmorkos authored Aug 30, 2023
1 parent f47e0bf commit 8b4b08d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-----------

### Internals
* None.
* Add a fake app id to the baas server's schema change history store to prevent server drop optimization from running during integration tests. ([PR #6927](https://github.com/realm/realm-core/pull/6927))

----------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions evergreen/add_fake_appid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Add a fake version to the schema change history store so that the drop optimization does not run.
// Drop optimization runs asynchronously to drop the schema change history store after PBS sync is
// terminated or a PBS app is deleted and there is only one PBS app present at the time of sync
// termination or app deletion.
// This caused issues with CI tests failing once app deletions starting being done asynchronously
let dummy_app = db.schema_change_history.insertOne({"_id" : new ObjectId()});
if (!dummy_app) {
throw "Could not insert a dummy app!";
}
2 changes: 0 additions & 2 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,11 @@ functions:
export AWS_ACCESS_KEY_ID="${baas_secrets_aws_access_key}"
export AWS_SECRET_ACCESS_KEY="${baas_secrets_aws_secret_key}"
export BAAS_HOST_NAME="$BAAS_HOST_NAME"
export REALM_CORE_REVISION="${revision}"
export GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk="
EOF
chmod 700 baas_host_vars.sh
echo "baas remote host created: $BAAS_HOST_NAME"
echo "- using Realm Core revision: ${revision}"
- command: shell.exec
params:
Expand Down
6 changes: 6 additions & 0 deletions evergreen/install_baas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ echo "Building baas app server"
[[ -f "${BAAS_PID_FILE}" ]] && rm "${BAAS_PID_FILE}"
go build -o "${WORK_PATH}/baas_server" cmd/server/main.go

# Based on https://github.com/10gen/baas/pull/10665
# Add a version to the schema change history store so that the drop optimization does not take place
# This caused issues with this test failing once app deletions starting being done asynchronously
echo "Adding fake appid to skip baas server drop optimization"
"${MONGO_BINARIES_DIR}/bin/${MONGOSH}" --quiet mongodb://localhost:26000/__realm_sync "${BASE_PATH}/add_fake_appid.js"

# Start the baas server on port *:9090 with the provided config JSON files
echo "Starting baas app server"

Expand Down
23 changes: 11 additions & 12 deletions evergreen/setup_baas_host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ fi
# shellcheck disable=SC1090
source "${BAAS_HOST_VARS}"

if [[ -n "${GITHUB_KNOWN_HOSTS}" ]]; then
echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${HOME}/.ssh/known_hosts"
else
echo "Warning: GITHUB_KNOWN_HOSTS not defined in baas host vars script - github clone may hang or fail during setup"
if [[ -z "${GITHUB_KNOWN_HOSTS}" ]]; then
# Use a default if not defined, but this may become outdated one day...
GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk="
echo "Info: GITHUB_KNOWN_HOSTS not defined in baas host vars script"
fi
echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${HOME}/.ssh/known_hosts"

DATA_DIR=/data
DATA_TEMP_DIR="${DATA_DIR}/tmp"
Expand All @@ -70,7 +71,7 @@ function setup_data_dir()
data_device=

# Find /data ebs device to be mounted
devices=$(sudo lsblk | grep disk| awk '{print $1}')
devices=$(sudo lsblk | grep disk | awk '{print $1}')
for device in ${devices}; do
is_data=$(sudo file -s "/dev/${device}" | awk '{print $2}')
if [ "${is_data}" == "data" ]; then
Expand Down Expand Up @@ -127,13 +128,12 @@ sudo chmod 600 "${HOME}/.ssh"/*
setup_data_dir

pushd "${BAAS_REMOTE_DIR}" > /dev/null
git clone git@github.com:realm/realm-core.git realm-core
pushd realm-core > /dev/null

git checkout "${REALM_CORE_REVISION}"
git submodule update --init --recursive
if [[ -f "${HOME}/install_baas.sh" ]]; then
cp "${HOME}/install_baas.sh" evergreen/
if [[ -d "${HOME}/evergreen/" ]]; then
cp -R "${HOME}/evergreen/" ./evergreen/
else
echo "evergreen/ directory not found in ${HOME}"
exit 1
fi

INSTALL_BAAS_OPTS=()
Expand All @@ -146,5 +146,4 @@ fi

./evergreen/install_baas.sh -w "${BAAS_WORK_DIR}" "${INSTALL_BAAS_OPTS[@]}" 2>&1

popd > /dev/null # realm-core
popd > /dev/null # /data/baas-remote
18 changes: 12 additions & 6 deletions evergreen/setup_baas_host_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function usage()
echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build"
echo -e "\t-v\t\tEnable verbose script debugging"
echo -e "\t-h\t\tShow this usage summary and exit"
echo "Note: This script must be run from a cloned realm-core/ repository directory."
# Default to 0 if exit code not provided
exit "${1:0}"
}
Expand Down Expand Up @@ -88,7 +89,7 @@ if [[ -n "${VERBOSE}" ]]; then
fi

if [[ -z "${BAAS_HOST_NAME}" ]]; then
echo "Baas hostname not found in baas host vars script: ${BAAS_HOST_VARS}"
echo "Baas remote hostname (BAAS_HOST_NAME) not provided in baas host vars script"
usage 1
fi

Expand All @@ -104,9 +105,15 @@ if [[ -z "${BAAS_USER}" ]]; then
usage 1
fi

if [[ ! -d "${EVERGREEN_PATH}/" ]]; then
echo "This script must be run from the realm-core directory for accessing files in '${EVERGREEN_PATH}/'"
exit 1
fi

if [[ -z "${FILE_DEST_DIR}" ]]; then
FILE_DEST_DIR="/home/${BAAS_USER}"
fi
EVERGREEN_DEST_DIR="${FILE_DEST_DIR}/evergreen"

SSH_USER="$(printf "%s@%s" "${BAAS_USER}" "${BAAS_HOST_NAME}")"

Expand Down Expand Up @@ -149,10 +156,9 @@ done
echo "Transferring setup scripts to ${SSH_USER}:${FILE_DEST_DIR}"
# Copy the baas host vars script to the baas remote host
scp "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${BAAS_HOST_VARS}" "${SSH_USER}:${FILE_DEST_DIR}/"
# Copy the current host and baas scripts from the working copy of realm-core
# This ensures they have the latest copy, esp when running evergreen patches
scp "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${EVERGREEN_PATH}/setup_baas_host.sh" "${SSH_USER}:${FILE_DEST_DIR}/"
scp "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${EVERGREEN_PATH}/install_baas.sh" "${SSH_USER}:${FILE_DEST_DIR}/"
# Copy the entire evergreen/ directory from the working copy of realm-core to the remote host
# This ensures the remote host the latest copy, esp when running evergreen patches
scp -r "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${EVERGREEN_PATH}/" "${SSH_USER}:${FILE_DEST_DIR}/"

echo "Starting remote baas with branch/commit: '${BAAS_BRANCH}'"
SETUP_BAAS_OPTS=()
Expand All @@ -167,4 +173,4 @@ fi
# Also sets up a forward tunnel for port 9090 through the ssh connection to the baas remote host
echo "Running setup script (with forward tunnel to 127.0.0.1:9090)"
ssh "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 -L 9090:127.0.0.1:9090 "${SSH_USER}" \
"${FILE_DEST_DIR}/setup_baas_host.sh" "${SETUP_BAAS_OPTS[@]}" "${FILE_DEST_DIR}/baas_host_vars.sh"
"${EVERGREEN_DEST_DIR}/setup_baas_host.sh" "${SETUP_BAAS_OPTS[@]}" "${FILE_DEST_DIR}/baas_host_vars.sh"

0 comments on commit 8b4b08d

Please sign in to comment.