Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
restore: use cached InfoSchema rather than always fetching from store (
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed May 20, 2020
1 parent 252649b commit 9017536
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -293,10 +292,7 @@ func (rc *Client) GetTableSchema(
dbName model.CIStr,
tableName model.CIStr,
) (*model.TableInfo, error) {
info, err := dom.GetSnapshotInfoSchema(math.MaxInt64)
if err != nil {
return nil, errors.Trace(err)
}
info := dom.InfoSchema()
table, err := info.TableByName(dbName, tableName)
if err != nil {
return nil, errors.Trace(err)
Expand Down
47 changes: 47 additions & 0 deletions tests/br_300_small_tables/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed 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,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu
DB="$TEST_NAME"
TABLES_COUNT=300

run_sql "create schema $DB;"

# generate 300 tables with 1 row content.
i=1
while [ $i -le $TABLES_COUNT ]; do
run_sql "create table $DB.sbtest$i(id int primary key, k int not null, c char(120) not null, pad char(60) not null);"
run_sql "insert into $DB.sbtest$i values ($i, $i, '$i', '$i');"
i=$(($i+1))
done

# backup db
echo "backup start..."
run_br backup db --db "$DB" -s "local://$TEST_DIR/$DB" --pd $PD_ADDR

# truncate every table
# (FIXME: drop instead of truncate. if we drop then create-table will still be executed and wastes time executing DDLs)
i=1
while [ $i -le $TABLES_COUNT ]; do
run_sql "truncate $DB.sbtest$i;"
i=$(($i+1))
done

# restore db
# (FIXME: shouldn't need --no-schema to be fast, currently the alter-auto-id DDL slows things down)
echo "restore start..."
run_br restore db --db $DB -s "local://$TEST_DIR/$DB" --pd $PD_ADDR --no-schema

run_sql "DROP DATABASE $DB;"

0 comments on commit 9017536

Please sign in to comment.