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

[patch] bugfix: do not create metadata file when create/append flag is not set for the agent/agent-sidecar #904

Merged
merged 15 commits into from
Jan 12, 2021

Conversation

kevindiu
Copy link
Contributor

@kevindiu kevindiu commented Dec 28, 2020

Description:

This PR fix a bug when the agent sidecar try to open the metadata.json file and if the file is not exists, the empty file will be created and causing agent failed to start.

Related Issue:

How Has This Been Tested?:

Environment:

  • Go Version: 1.15.2
  • Docker Version: 19.03.8
  • Kubernetes Version: 1.18.2
  • NGT Version: 1.12.1

Types of changes:

  • Bug fix [type/bug]
  • New feature [type/feature]
  • Add tests [type/test]
  • Security related changes [type/security]
  • Add documents [type/documentation]
  • Refactoring [type/refactoring]
  • Update dependencies [type/dependency]
  • Update benchmarks and performances [type/bench]
  • Update CI [type/ci]

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Checklist:

  • I have read the CONTRIBUTING document.
  • I have checked open Pull Requests for the similar feature or fixes?
  • I have added tests and benchmarks to cover my changes.
  • I have ensured all new and existing tests passed.
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly.

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - add changelog comment
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase master

kpango
kpango previously approved these changes Dec 28, 2020
Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

SGTM. please check it by e2e testing.

@codecov
Copy link

codecov bot commented Dec 28, 2020

Codecov Report

Merging #904 (318ba84) into master (c4df6ef) will increase coverage by 0.04%.
The diff coverage is 8.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #904      +/-   ##
==========================================
+ Coverage   19.19%   19.23%   +0.04%     
==========================================
  Files         422      423       +1     
  Lines       19548    19622      +74     
==========================================
+ Hits         3752     3775      +23     
- Misses      15586    15631      +45     
- Partials      210      216       +6     
Impacted Files Coverage Δ
pkg/agent/core/ngt/service/ngt.go 0.00% <0.00%> (ø)
internal/file/file.go 71.42% <50.00%> (+11.42%) ⬆️
internal/db/storage/blob/s3/reader/reader.go 65.51% <0.00%> (-32.19%) ⬇️
internal/errgroup/group.go 92.42% <0.00%> (-1.52%) ⬇️
internal/net/net.go 85.18% <0.00%> (ø)
internal/worker/worker.go 82.29% <0.00%> (+1.04%) ⬆️
internal/worker/queue.go 98.33% <0.00%> (+3.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1cfcd7...b61f5ce. Read the comment docs.

@kpango
Copy link
Collaborator

kpango commented Dec 28, 2020

please check internal testing error.

@@ -170,12 +170,26 @@ func (n *ngt) initNGT(opts ...core.Option) (err error) {
n.core, err = core.New(opts...)
return err
}
if os.IsPermission(err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)

@@ -170,12 +170,26 @@ func (n *ngt) initNGT(opts ...core.Option) (err error) {
n.core, err = core.New(opts...)
return err
}
if os.IsPermission(err) {
log.Debugf("no permission for index path,\tpath: %s,\terr: %v", n.path, err)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

pkg/agent/core/ngt/service/ngt.go Show resolved Hide resolved

log.Debugf("load index from %s", n.path)

agentMetadata, err := metadata.Load(filepath.Join(n.path, metadata.AgentMetadataFileName))
if err != nil {
log.Warnf("cannot read metadata from %s: %s", metadata.AgentMetadataFileName, err)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should check metadata.Load's err is os.IsNotExists or not, if err is os.ErrNotExists we can check kvsdb exsitance.

@github-actions github-actions bot added size/M and removed size/S labels Dec 28, 2020
@kevindiu kevindiu changed the title [bugfix] do not create file when create/append flag is not set [WIP] [bugfix] do not create file when create/append flag is not set Dec 28, 2020
@kevindiu kevindiu changed the title [WIP] [bugfix] do not create file when create/append flag is not set [WIP] [bugfix] do not create metadata file when create/append flag is not set for the agent/agent-sidecar Dec 28, 2020
func Load(path string) (*Metadata, error) {
func Load(path string) (meta *Metadata, err error) {
var fi os.FileInfo
if fi, err = os.Stat(path); 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.

[golangci] reported by reviewdog 🐶
if statements should only be cuddled with assignments used in the if statement itself (wsl)

pkg/agent/core/ngt/service/ngt.go Outdated Show resolved Hide resolved
@kevindiu kevindiu requested review from kpango and rinx January 5, 2021 01:07
@kevindiu
Copy link
Contributor Author

kevindiu commented Jan 5, 2021

/rebase

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Jan 5, 2021

[REBASE] Rebase triggered by kevindiu for branch: bugfix/agent-sidecar/empty-metadata-file-opened

@github-actions github-actions bot force-pushed the bugfix/agent-sidecar/empty-metadata-file-opened branch from ee2cfc2 to 83835bb Compare January 5, 2021 01:15
@kevindiu kevindiu changed the title [WIP] [bugfix] do not create metadata file when create/append flag is not set for the agent/agent-sidecar [bugfix] do not create metadata file when create/append flag is not set for the agent/agent-sidecar Jan 5, 2021
@kevindiu kevindiu changed the title [bugfix] do not create metadata file when create/append flag is not set for the agent/agent-sidecar [patch] bugfix: do not create metadata file when create/append flag is not set for the agent/agent-sidecar Jan 7, 2021
@github-actions github-actions bot added the team/set SET team label Jan 7, 2021
@@ -38,20 +39,27 @@ type NGT struct {
IndexCount uint64 `json:"index_count" yaml:"index_count"`
}

func Load(path string) (*Metadata, error) {
func Load(path string) (meta *Metadata, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[golangci] reported by reviewdog 🐶
exported function Load should have comment or be unexported (golint)

rinx
rinx previously approved these changes Jan 7, 2021
Copy link
Contributor

@rinx rinx left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 1823203 into master Jan 12, 2021
@kpango kpango deleted the bugfix/agent-sidecar/empty-metadata-file-opened branch January 12, 2021 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants