Skip to content

Conversation

yihuang
Copy link
Contributor

@yihuang yihuang commented Apr 6, 2023

Closes: #948
Solution:

  • manage multiple trees together.
  • support copy-on-write on MemNodes
  • support snapshot rewrite at background, catch-up and switch in Commit event.

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

HuangYi added 3 commits April 7, 2023 20:27
Closes: crypto-org-chain#948
Solution:
- support copy-on-write on `MemNode`s
- support snapshot rewrite at background, catch-up and switch in `Commit` event.

better error handling

temp

fix build

revert snapshot rewrite stuff for now
}

func writeFileSync(name string, data []byte) error {
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)

Check failure

Code scanning / gosec

Potential file inclusion via variable

Potential file inclusion via variable
func (t *MultiTree) ApplyChangeSet(changeSets MultiChangeSet, updateCommitInfo bool) ([]byte, int64, error) {
var version int64
if t.lastCommitInfo.Version == 0 && t.initialVersion > 1 {
version = int64(t.initialVersion)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
panic("version overflows uint32")
}

v := uint32(initialVersion)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
fmt.Printf("snapshot loaded: %d %X\n", tree.Version(), tree.RootHash())
} else {
tree = memiavl.NewWithInitialVersion(int64(initialVersion))
tree = memiavl.NewWithInitialVersion(uint32(initialVersion))

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
@yihuang yihuang marked this pull request as ready for review April 9, 2023 16:03
@yihuang yihuang requested a review from a team as a code owner April 9, 2023 16:03
@yihuang yihuang requested review from JayT106, calvinaco and mmsqe and removed request for a team April 9, 2023 16:03
Signed-off-by: yihuang <huang@crypto.com>
@yihuang yihuang requested a review from mmsqe April 10, 2023 08:46
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Merging #959 (421a2c1) into main (72c7b74) will increase coverage by 1.88%.
The diff coverage is 69.32%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #959      +/-   ##
==========================================
+ Coverage   41.19%   43.07%   +1.88%     
==========================================
  Files          62       62              
  Lines        4564     4722     +158     
==========================================
+ Hits         1880     2034     +154     
+ Misses       2455     2452       -3     
- Partials      229      236       +7     
Impacted Files Coverage Δ
memiavl/snapshot.go 55.64% <0.00%> (+1.48%) ⬆️
versiondb/client/restore_app_db.go 0.00% <0.00%> (ø)
versiondb/client/verify.go 0.00% <0.00%> (ø)
memiavl/db.go 48.81% <48.81%> (ø)
memiavl/multitree.go 72.94% <72.94%> (ø)
memiavl/mem_node.go 89.42% <100.00%> (+5.58%) ⬆️
memiavl/node.go 73.84% <100.00%> (ø)
memiavl/persisted_node.go 65.62% <100.00%> (+4.68%) ⬆️
memiavl/tree.go 85.71% <100.00%> (+25.71%) ⬆️
versiondb/client/changeset.go 43.83% <100.00%> (ø)
... and 1 more

@yihuang
Copy link
Contributor Author

yihuang commented Apr 10, 2023

@mmsqe Just did a big change to integrate WAL

@mmsqe
Copy link
Contributor

mmsqe commented Apr 10, 2023

@mmsqe Just did a big change to integrate WAL

do we need make use of iavl proto now

@yihuang
Copy link
Contributor Author

yihuang commented Apr 10, 2023

@mmsqe Just did a big change to integrate WAL

do we need make use of iavl proto now

already using that, just using my fork for now, will open another PR to backport to 0.19.x

EDIT: cosmos/iavl#732

return errors.Wrap(err, "read wal last index failed")
}

snapshotVersion := uint64(t.Version())

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion

// RewriteSnapshot writes the current version of memiavl into a snapshot, and update the `current` symlink.
func (db *DB) RewriteSnapshot() error {
version := uint32(db.lastCommitInfo.Version)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
}
}
return &Tree{version: uint32(version), bwal: wal}, nil
return &Tree{version: uint32(version)}

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
yihuang and others added 2 commits April 10, 2023 17:05
Co-authored-by: mmsqe <tqd0800210105@gmail.com>
Signed-off-by: yihuang <huang@crypto.com>
if err != nil {
return nil, 0, err
}
if err := db.wal.Write(uint64(v), bz); err != nil {

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
@yihuang yihuang enabled auto-merge (squash) April 10, 2023 11:28
@yihuang yihuang merged commit edb321e into crypto-org-chain:main Apr 10, 2023
@yihuang yihuang deleted the async-snapshot branch April 10, 2023 20:15
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.

Problem: memiavl don't support async snapshotting
2 participants