Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add Close function for boltdb backend #2392

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

HusterWan
Copy link
Contributor

Signed-off-by: Michael Wan zirenwan@gmail.com

Ⅰ. Describe what this PR did

When testing d2p-migrator, I found I need close the boltdb store after used, so that the pouchd can take charge of the volume store.

So I add a Shutdown function for the Store

Ⅱ. Does this pull request fix one issue?

none

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

add TestBoltdbClose case

Ⅳ. Describe how to verify it

none

Ⅴ. Special notes for reviews

none

@codecov
Copy link

codecov bot commented Oct 31, 2018

Codecov Report

Merging #2392 into master will increase coverage by 0.04%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2392      +/-   ##
==========================================
+ Coverage    68.4%   68.45%   +0.04%     
==========================================
  Files         271      271              
  Lines       18263    18269       +6     
==========================================
+ Hits        12493    12506      +13     
+ Misses       4347     4345       -2     
+ Partials     1423     1418       -5
Flag Coverage Δ
#criv1alpha1test 31.83% <0%> (+0.03%) ⬆️
#criv1alpha2test 35.8% <0%> (-0.02%) ⬇️
#integrationtest 39.62% <0%> (-0.1%) ⬇️
#nodee2etest 33.27% <0%> (-0.05%) ⬇️
#unittest 25.5% <66.66%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pkg/meta/backend.go 100% <ø> (ø) ⬆️
pkg/meta/local.go 61.76% <0%> (-1.24%) ⬇️
pkg/meta/store.go 67.69% <100%> (+5.19%) ⬆️
pkg/meta/boltdb.go 69.41% <100%> (+0.73%) ⬆️
cri/ocicni/cni_manager.go 59.18% <0%> (-12.25%) ⬇️
apis/server/utils.go 71.15% <0%> (-3.85%) ⬇️
daemon/mgr/container.go 59.8% <0%> (-0.22%) ⬇️
ctrd/container.go 59.76% <0%> (ø) ⬆️
cri/v1alpha2/cri.go 68.29% <0%> (ø) ⬆️
cri/v1alpha2/cri_utils.go 90.8% <0%> (ø) ⬆️
... and 6 more

@@ -201,6 +202,18 @@ func TestBoltdbRemove(t *testing.T) {
}
}

func TestBoltdbClose(t *testing.T) {
if err := boltdbStore.Shutdown(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you just immediately shutdown the boltdbStore? I could not find the initialization code of boltdbStore.
Is this test depends on other test to initialize the boltdbStore? Is it reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stay with the origin test cases, but i think your advice is reasonable, i will update it

@@ -270,3 +270,8 @@ func (s *Store) KeysWithPrefix(prefix string) ([]string, error) {
func (s *Store) Path(key string) string {
return s.backend.Path(key)
}

// Shutdown releases all resources used by the backend
func (s *Store) Shutdown() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where to call the function Shutdown

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it in d2p-migrator :)

@pouchrobot pouchrobot added size/XL and removed size/S labels Oct 31, 2018
@HusterWan HusterWan force-pushed the zr/volume-store branch 2 times, most recently from 25bc6a3 to 42c564b Compare October 31, 2018 10:14
func ensureFileNotExist(file string) error {
_, err := os.Stat(file)
if err == nil {
os.Remove(file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, file is a directory path, using os.RemoveAll instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid, file is a file path

if err := ensureFileNotExist(dbFile); err != nil {
t.Fatal(err)
}
defer ensureFileNotExist(dbFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about creating a test wrapper? like

func storeTestWrapper(t *testing.T, name string, test func(*Store)) {
	dbDir := path.Join("/tmp", utils.RandString(8, name, ""))
	if err := ensureFileNotExist(dbDir); err != nil {
		t.Fatal(err)
	}
	defer ensureFileNotExist(dbDir)

	s, err := initLocalStore(dbDir)
	if err != nil {
		t.Fatal(err)
	}

	test(s)
}
func TestGet(t *testing.T) {
	storeTestWrapper(t, "TestGet", func(s *Store) {
              // xxx
	})
}

Don't repeat yourself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great advice

Signed-off-by: Michael Wan <zirenwan@gmail.com>
@zhuangqh
Copy link
Contributor

zhuangqh commented Nov 1, 2018

LGTM

1 similar comment
@rudyfly
Copy link
Collaborator

rudyfly commented Nov 1, 2018

LGTM

@rudyfly rudyfly merged commit 8776494 into AliyunContainerService:master Nov 1, 2018
@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants