Skip to content

Commit

Permalink
backup: fix the lost empty database (pingcap#34519)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Jun 2, 2022
1 parent 1d62b7d commit 2411fbc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions br/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/metautil/metafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
28 changes: 22 additions & 6 deletions br/tests/br_backup_empty/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

set -eu
DB="$TEST_NAME"
DB_COUNT=10

# backup empty.
echo "backup empty cluster start..."
Expand All @@ -34,15 +35,23 @@ 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
echo "TEST: [$TEST_NAME] failed on backup empty cluster!"
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..."
Expand All @@ -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) \
Expand All @@ -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

0 comments on commit 2411fbc

Please sign in to comment.