summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/evergreen/import_compatibility_test.sh
blob: 3c3c8364d66a4a7a093bc24d942da5199baf322a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
#
# Test importing of files created in previous versions of WiredTiger.
# Test that we can downgrade a database after importing a file.

set -e

# build_branch --
#     1: branch
build_branch()
{
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "Building branch: \"$1\""
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="

    # Clone if it doesn't already exist.
    if [ ! -d "$1" ]; then
        git clone --quiet https://github.com/wiredtiger/wiredtiger.git "$1"
    fi
    cd "$1"

    git checkout --quiet "$1"

    config=""
    config+="--enable-snappy "
    config+="--disable-standalone-build "
    (sh build_posix/reconf &&
         ./configure $config && make -j $(grep -c ^processor /proc/cpuinfo)) > /dev/null
    cd ..
}

# create_file --
#     1: branch
#     2: file
create_file()
{
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "Branch \"$1\" creating and populating \"$2\""
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="

    wt_cmd="$1/wt"
    test_dir="$1/WT_TEST/"
    uri="file:$2"

    # Make the home directory.
    mkdir -p $test_dir

    # Create the file and populate with a few key/values.
    $wt_cmd -h $test_dir create -c "key_format=S,value_format=S" $uri
    $wt_cmd -h $test_dir write $uri abc 123 def 456 hij 789
}

# import_file --
#     1: dest branch
#     2: source branch
#     3: file
import_file()
{
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "Importing file \"$3\" from \"$1\" to \"$2\""
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="

    wt_cmd="$1/wt"
    test_dir="$1/WT_TEST/"
    mkdir -p $test_dir

    # Move the file across to the destination branch's home directory.
    import_file="$2/WT_TEST/$3"
    cp $import_file $test_dir

    # Run import via the wt tool.
    uri="file:$3"
    $wt_cmd -h $test_dir create -c "import=(enabled,repair=true)" $uri
}

# verify_file --
#     1: branch
#     2: file
verify_file()
{
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "Branch \"$1\" verifying \"$2\""
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="

    wt_cmd="$1/wt"
    test_dir="$1/WT_TEST/"
    uri="file:$2"

    $wt_cmd -h $test_dir verify $uri
}

# cleanup_branch --
#     1: branch
cleanup_branch()
{
    test_dir="$1/WT_TEST/"
    if [ -d $test_dir ]; then
        rm -rf $test_dir
    fi
}

# import_compatibility_test --
#     1: newer branch
#     2: older branch
import_compatibility_test()
{
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
    echo "Testing import compatibility between \"$1\" and \"$2\""
    echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="

    # Remove any leftover data files.
    cleanup_branch $1
    cleanup_branch $2

    # Create a file in the older branch.
    create_file $2 test_import

    # Now import it into the newer branch and verify.
    import_file $1 $2 test_import
    verify_file $1 test_import

    # Now downgrade by running wt from the older branch and dumping the table contents.
    #
    # Before trying this, we must remove the base configuration. The wt tool produces this file
    # however MongoDB will not so we should emulate this.
    rm $1/WT_TEST/WiredTiger.basecfg
    $2/wt -h $1/WT_TEST/ dump file:test_import
}

# Release branches.
#
# Go all the way back to mongodb-4.2 since that's the first release where we don't support live
# import.
release_branches=(develop mongodb-5.0 mongodb-4.4 mongodb-4.2)

# Build each of the release branches.
for b in ${release_branches[@]}; do
    build_branch $b
done

for i in ${!release_branches[@]}; do
    newer=${release_branches[$i]}

    # MongoDB v4.2 doesn't support live import so it should only ever be used as the "older" branch
    # that we're importing from.
    if [ $newer = mongodb-4.2 ]; then
        continue
    fi

    older=${release_branches[$i+1]}
    import_compatibility_test $newer $older
done