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

[db] KvWithVersion to handle both versioned and non-versioned namespace #4518

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dustinxie
Copy link
Member

@dustinxie dustinxie commented Dec 10, 2024

Description

as title.
based on (#4517)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
36.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

if b.versioned[ns] {
return b.db.Put(b.version, ns, key, value)
}
return b.kvBase.Put(ns, key, value)
Copy link
Member

Choose a reason for hiding this comment

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

Using kvBase in kvWithVersion is strange, I would recommend splitting it up. for example:

KvVersioned interface{
    Version(string, []byte) (uint64, error)
    SetVersion(uint64) KVStore
    Plain() KVStore
}

Copy link
Member Author

Choose a reason for hiding this comment

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

do you mean add a Plain() interface?
this is internal implementation, for non-versioned namespace, it is a regular Put/Get/Delete, same as now

kv := KvWithVersion{
db: b.db,
kvBase: b.kvBase,
versioned: make(map[string]bool),
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as db and kvBase, if versioned will not be updated, passing pointer is fine.

Comment on lines +82 to +83
db: db,
kvBase: db.Base(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may need to review the implementation of BoltDBWithVersion. From the name, BoltDBWithVersion sounds like an implementation of KVStoreWithVersion. Moreover, db.Base() is a weird interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants