Skip to content

Commit

Permalink
*: try to fix download racing bugs (#2458)
Browse files Browse the repository at this point in the history
* *: try to fix download racing bugs

Signed-off-by: xhe <[email protected]>

* fix workflow

Signed-off-by: xhe <[email protected]>

* fix UT

Signed-off-by: xhe <[email protected]>

* fix UT

Signed-off-by: xhe <[email protected]>

* stable test

Signed-off-by: xhe <[email protected]>

* stable test

Signed-off-by: xhe <[email protected]>

* stable test

Signed-off-by: xhe <[email protected]>

* stable test

Signed-off-by: xhe <[email protected]>

* stable test

Signed-off-by: xhe <[email protected]>

---------

Signed-off-by: xhe <[email protected]>
  • Loading branch information
xhebox authored Oct 16, 2024
1 parent c1a14a5 commit 964b40b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrate-dm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# with --dev the first run will fail for unknow reason, just retry it and will success now..
run: |
cd ${{ env.working-directory }}/docker
TIUP_CLUSTER_ROOT=${{ env.working-directory }} ./up.sh --daemon --dev --compose ./docker-compose.dm.yml || TIUP_CLUSTER_ROOT=${{ env.working-directory }} ./up.sh --daemon --dev --compose ./docker-compose.dm.yml
TIUP_CLUSTER_ROOT=${{ env.working-directory }} ./up.sh --daemon --dev --compose ./docker-compose.dm.yml
- name: Check running containers
run: |
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Upload component log
if: ${{ failure() }}
# if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: dm_logs
path: ${{ env.working-directory }}/dm.logs.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integrate-playground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Upload component log
if: ${{ failure() }}
# if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: playground_logs
path: ${{ env.working-directory }}/playground.logs.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion docker/control/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye
FROM golang:1.21


# Use mirrors for poor network...
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/operation/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Download(component, nodeOS, arch string, version string) error {
if err := repo.DownloadComponent(component, version, targetPath); err != nil {
return err
}
} else {
} else if version != "nightly" {
if err := repo.VerifyComponent(component, version, targetPath); err != nil {
os.Remove(targetPath)
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,19 @@ func (r *V1Repository) updateComponentManifest(id string, withYanked bool) (*v1m
// DownloadComponent downloads the component specified by item into local file,
// the component will be removed if hash is not correct
func (r *V1Repository) DownloadComponent(item *v1manifest.VersionItem, target string) error {
// make a tempdir such that every download will not inference each other
targetDir := filepath.Dir(target)
err := r.mirror.Download(item.URL, targetDir)
err := os.MkdirAll(targetDir, 0755)
if err != nil {
return errors.Trace(err)
}

targetDir, err = os.MkdirTemp(targetDir, "download")
if err != nil {
return errors.Trace(err)
}

if err := r.mirror.Download(item.URL, targetDir); err != nil {
return err
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/repository/v1_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"path"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -502,10 +503,14 @@ func TestLatestStableVersionWithPrerelease(t *testing.T) {
}

func TestUpdateComponents(t *testing.T) {
t1 := t.TempDir()
t2 := t.TempDir()

mirror := MockMirror{
Resources: map[string]string{},
}
local := v1manifest.NewMockManifests()
local.RootDir = t1
priv := setNewRoot(t, local)

repo := NewV1Repo(&mirror, Options{GOOS: "plat", GOARCH: "form"}, local)
Expand Down Expand Up @@ -533,7 +538,7 @@ func TestUpdateComponents(t *testing.T) {
assert.Equal(t, 1, len(local.Installed))
assert.Equal(t, "v2.0.1", local.Installed["foo"].Version)
assert.Equal(t, "foo201", local.Installed["foo"].Contents)
assert.Equal(t, "/tmp/mock/components/foo/v2.0.1/foo-2.0.1.tar.gz", local.Installed["foo"].BinaryPath)
assert.Equal(t, filepath.Join(t1, "components/foo/v2.0.1/foo-2.0.1.tar.gz"), local.Installed["foo"].BinaryPath)

// Update
foo.Version = 8
Expand All @@ -552,13 +557,13 @@ func TestUpdateComponents(t *testing.T) {
repo.PurgeTimestamp()
err = repo.UpdateComponents([]ComponentSpec{{
ID: "foo",
TargetDir: "/tmp/mock-mock",
TargetDir: t2,
}})
assert.Nil(t, err)
assert.Equal(t, 1, len(local.Installed))
assert.Equal(t, "v2.0.2", local.Installed["foo"].Version)
assert.Equal(t, "foo202", local.Installed["foo"].Contents)
assert.Equal(t, "/tmp/mock-mock/foo-2.0.2.tar.gz", local.Installed["foo"].BinaryPath)
assert.Equal(t, filepath.Join(t2, "foo-2.0.2.tar.gz"), local.Installed["foo"].BinaryPath)

// Update; already up to date
err = repo.UpdateComponents([]ComponentSpec{{
Expand Down
4 changes: 4 additions & 0 deletions pkg/repository/v1manifest/local_manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ type MockManifests struct {
Saved []string
Installed map[string]MockInstalled
Ks *KeyStore
RootDir string
}

// MockInstalled is used by MockManifests to remember what was installed for a component.
Expand Down Expand Up @@ -401,6 +402,9 @@ func (ms *MockManifests) KeyStore() *KeyStore {

// TargetRootDir implements LocalManifests.
func (ms *MockManifests) TargetRootDir() string {
if ms.RootDir != "" {
return ms.RootDir
}
return "/tmp/mock"
}

Expand Down
15 changes: 12 additions & 3 deletions tests/tiup-playground/test_playground.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ mkdir -p $TIUP_INSTANCE_DATA_DIR
mkdir -p $TEST_DIR/cover

function tiup-playground() {
set +x
# echo "in function"
if [ -f "$TEST_DIR/bin/tiup-playground.test" ]; then
$TEST_DIR/bin/tiup-playground.test -test.coverprofile=$TEST_DIR/cover/cov.itest-$(date +'%s')-$RANDOM.out __DEVEL--i-heard-you-like-tests "$@"
else
$TEST_DIR/../../bin/tiup-playground "$@"
fi
set -x
}

# usage: check_instance_num tidb 1
Expand Down Expand Up @@ -63,9 +65,16 @@ sleep 3
trap "kill_all" EXIT

# wait start cluster successfully
timeout 300 grep -q "TiDB Playground Cluster is started" <(tail -f $outfile)

tiup-playground display | grep -qv "exit"
n=0
while [ "$n" -lt 300 ] && ! grep -q "TiDB Playground Cluster is started" $outfile; do
n=$(( n + 1 ))
sleep 1
done
n=0
while [ "$n" -lt 10 ] && ! tiup-playground display; do
n=$(( n + 1 ))
sleep 1
done
tiup-playground scale-out --db 2
sleep 5

Expand Down

0 comments on commit 964b40b

Please sign in to comment.