backup: fix the lost empty database (#34519)

ref pingcap/tidb#33866
This commit is contained in:
3pointer
2022-05-10 16:32:34 +08:00
committed by GitHub
parent 45415f45be
commit bf7c3efbd7
3 changed files with 25 additions and 9 deletions

View File

@ -1,5 +1,5 @@
# For loading data to TiDB
FROM golang:1.16.4-buster as go-ycsb-builder
FROM golang:1.18-buster as go-ycsb-builder
WORKDIR /go/src/github.com/pingcap/
RUN git clone https://github.com/pingcap/go-ycsb.git --depth=1 && \
cd go-ycsb && \
@ -8,7 +8,7 @@ RUN git clone https://github.com/pingcap/go-ycsb.git --depth=1 && \
# For operating minio S3 compatible storage
FROM minio/mc as mc-builder
FROM golang:1.16.4-buster
FROM golang:1.18-buster
RUN apt-get update && apt-get install -y --no-install-recommends \
git \

View File

@ -335,7 +335,7 @@ func (reader *MetaReader) ReadSchemasFiles(ctx context.Context, output chan<- *T
tableMap[tableInfo.ID] = table
} else {
// empty database
tableMap[0] = table
tableMap[dbInfo.ID] = table
}
return nil
})

View File

@ -16,6 +16,7 @@
set -eu
DB="$TEST_NAME"
DB_COUNT=10
# backup empty.
echo "backup empty cluster start..."
@ -34,7 +35,12 @@ if [ $? -ne 0 ]; then
fi
# backup and restore empty tables.
run_sql "CREATE DATABASE $DB;"
i=1
while [ $i -le $DB_COUNT ]; do
run_sql "CREATE DATABASE $DB$i;"
i=$(($i+1))
done
echo "backup empty db start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_db"
if [ $? -ne 0 ]; then
@ -42,7 +48,10 @@ if [ $? -ne 0 ]; then
exit 1
fi
run_sql "DROP DATABASE $DB"
while [ $i -le $DB_COUNT ]; do
run_sql "DROP DATABASE $DB$i;"
i=$(($i+1))
done
# restore empty.
echo "restore empty db start..."
@ -52,7 +61,7 @@ if [ $? -ne 0 ]; then
exit 1
fi
run_sql "CREATE TABLE $DB.usertable1 ( \
run_sql "CREATE TABLE ${DB}1.usertable1 ( \
YCSB_KEY varchar(64) NOT NULL, \
FIELD0 varchar(1) DEFAULT NULL, \
PRIMARY KEY (YCSB_KEY) \
@ -61,11 +70,18 @@ run_sql "CREATE TABLE $DB.usertable1 ( \
echo "backup empty table start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table"
run_sql "DROP DATABASE $DB;"
while [ $i -le $DB_COUNT ]; do
run_sql "DROP DATABASE $DB$i;"
i=$(($i+1))
done
echo "restore empty table start..."
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table"
# insert one row to make sure table is restored.
run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");"
run_sql "INSERT INTO ${DB}1.usertable1 VALUES (\"a\", \"b\");"
run_sql "DROP DATABASE $DB"
while [ $i -le $DB_COUNT ]; do
run_sql "DROP DATABASE $DB$i;"
i=$(($i+1))
done