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

Replace some rocksdb databases with lmdb #15810

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from
Draft

Conversation

Geometer1729
Copy link
Member

Explain your changes:
*

Explain how you tested your changes:
*

Checklist:

  • Dependency versions are unchanged
    • Notify Velocity team if dependencies must change in CI
  • Modified the current draft of release notes with details on what is completed or incomplete within this project
  • Document code purpose, how to use it
    • Mention expected invariants, implicit constraints
  • Tests were added for the new behavior
    • Document test purpose, significance of failures
    • Test names should reflect their purpose
  • All tests pass (CI will check this if you didn't)
  • Serialized types are in stable-versioned modules
  • Does this close issues? List them
  • Closes #0000

@Geometer1729 Geometer1729 self-assigned this Jul 10, 2024
@Geometer1729 Geometer1729 mentioned this pull request Jul 10, 2024
4 tasks
@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-toolchain-me

Copy link
Member

@rbonichon rbonichon left a comment

Choose a reason for hiding this comment

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

Not approving since this is for now a draft PR. Keep up the good work @Geometer1729

src/lib/mina_ledger/lmdb_kvdb.ml Outdated Show resolved Hide resolved
src/lib/mina_ledger/lmdb_kvdb.ml Outdated Show resolved Hide resolved
; path = name
; uuid =
name_to_uuid name
(* Can this be the same, if not what can I use instead of the path? *)
Copy link
Member

Choose a reason for hiding this comment

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

what can I use instead of the path

Path and something related to a timestamp ?


let to_alist t =
Lmdb.Cursor.fold_left ~f:(fun xs k v -> List.cons (k, v) xs) [] t.lmdb
(* TODO this feels like a bad idea performance wise *)
Copy link
Member

Choose a reason for hiding this comment

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

It is a bad idea. However, for this PR, it is fair to keep the same functionalities.

A quick grep within the codebase shows it's mostly used to List.map over the resulting alist.
This functionality (map) should probably be offered by this module instead to avoid allocating (possibly) big intermediate structures.

Removing usage of to_alist looks like a benefitial follow-up task to me. If we actually need a sequence, we should probably implement a to_seq function instead.

src/lib/mina_ledger/ledger.ml Outdated Show resolved Hide resolved
src/lib/mina_ledger/ledger.ml Outdated Show resolved Hide resolved
let get t ~key =
try Some (Lmdb.Map.get t.lmdb key) with Not_found_s _ -> None
(* | Not_found -> None *)
(* TODO does Not_found_s subsume Not_found ? if not how do I get the compiler to let me do this? *)
Copy link
Member

Choose a reason for hiding this comment

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

2 comments:

  1. Documentation seems to state that get returns Not_found not Not_found_s.
  2. The compiler cannot help here. Exceptions are extensible variants, that the compiler cannot check for exhaustiveness. There have been some effort here and there to analyze whether all exceptions were caught (see this discussion)

Copy link
Member Author

@Geometer1729 Geometer1729 Jul 11, 2024

Choose a reason for hiding this comment

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

Sorry my comment was not very clear, what I meant was how do I get the compiler not to complain about Not_found being deprecated

File "src/lib/mina_ledger/lmdb_kvdb.ml", line 61, characters 9-18:
 > 61 |     with Not_found (* LMDB raises Not_found when the key is absent *) -> ()
 >               ^^^^^^^^^
 > Error (alert deprecated): Not_found

it seems to be [@alert "-deprecated"]

Copy link
Member

@rbonichon rbonichon Jul 11, 2024

Choose a reason for hiding this comment

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

Understood. This is the reason.

The solution here is to disable the alert for this function (and link to the API stating where the Not_found comes from).

This should work

let[@alert "-deprecated"] get  ~key =
    try Some (Lmdb.Map.get t.lmdb key) with Not_found -> None

@Geometer1729
Copy link
Member Author

@rbonichon Thanks so much for looking this over and for your suggestions

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

@Geometer1729
Copy link
Member Author

!ci-build-me

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.

None yet

3 participants