diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2025-02-27 23:20:45 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2025-02-27 23:20:45 -0300 |
| commit | 737b4c19d14a12e05ec862d23f8f29ff790a73c2 (patch) | |
| tree | 3e70dc1de58debfdc01c289a3bf1f49223cd2140 /lib | |
| parent | 355690f76f3ca895ade25d281beb1eea27e1f53e (diff) | |
| download | Sakura-737b4c19d14a12e05ec862d23f8f29ff790a73c2.tar.gz Sakura-737b4c19d14a12e05ec862d23f8f29ff790a73c2.zip | |
add partition and debugger
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/disk.ml | 32 | ||||
| -rw-r--r-- | lib/planner.ml | 37 | ||||
| -rw-r--r-- | lib/relation.ml | 5 |
3 files changed, 50 insertions, 24 deletions
diff --git a/lib/disk.ml b/lib/disk.ml index b9f8155..503eda3 100644 --- a/lib/disk.ml +++ b/lib/disk.ml @@ -242,10 +242,10 @@ module Executor = struct Ok ((commit, locations), Some computed_hash) | None -> Ok ((commit, locations), None)) - let read ({ files; _ } as _commit : commit) (locations : locations) ~filename - = - let history : Hashes.history = StringMap.find filename files in - let { values = location_hashes; _ } : Hashes.t = List.hd history in + let read ({ files; _ } as _commit : commit) (locations : locations) ~filename = + let open Extensions.Option in + let+ history : Hashes.history = StringMap.find_opt filename files in + let+ { values = location_hashes; _ } : Hashes.t = match history with [] -> None | history -> Some(List.hd history) in let physical_locations = List.map (fun hash -> StringMap.find hash locations) location_hashes in @@ -259,13 +259,16 @@ module Executor = struct physical_locations in (*Bytes.concat Bytes.empty @@*) - List.rev content + Some (List.rev content) let read_location ~hash (locations : locations) = - let ({ offset; size; _ } : Location.t) = StringMap.find hash locations in - match FS.read FS.Storage offset size with - | Ok x -> x - | Error err -> failwith err + match StringMap.find_opt hash locations with + | Some ({ offset; size; _ } : Location.t) -> + begin match FS.read FS.Storage offset size with + | Ok x -> x + | Error err -> failwith err + end + | None -> failwith "Location could not be found." end module Startup = struct @@ -315,7 +318,7 @@ module Command = struct (fun (kind, timestamp, hash, filename, entity_id, content) -> { kind; timestamp; hash; filename; entity_id; content }) Data_encoding.( - tup6 command_kind_encoding float string string (option int64) string) + tup6 command_kind_encoding float string string (option int64) string) let parse_command ~data = let contract_encoding = @@ -391,7 +394,14 @@ module Command = struct print_endline "READ"; print_endline relation_name; let entities : string list Executor.IntMap.t = - Executor.StringMap.find relation_name commit.references + print_endline command.filename; + Executor.StringMap.find_opt command.filename commit.references + |> function Some entities -> + print_endline "-----> A"; + entities + | None -> + print_endline "-----> B"; + Executor.IntMap.empty in let content = Executor.IntMap.fold diff --git a/lib/planner.ml b/lib/planner.ml index 1d4d830..0d333f1 100644 --- a/lib/planner.ml +++ b/lib/planner.ml @@ -1,17 +1,28 @@ +module type Action = sig + (* Names of the attributes & The tuples *) + type tuples = string list * bytes list list + val execute: tuples -> int +end + module Scan = struct - (* open Disk - let execute commit locations (entity: string) = - let binary = Executor.read commit locations ~filename:("schema~" ^ entity) in - let relation = - Result.map_error (fun _ -> "Failed to deserialize relation from binary format.") - @@ Data_encoding.Binary.of_bytes Schema.Protocol.relation_encoding (Bytes.concat Bytes.empty binary) in - match relation with - | Ok relation -> - begin - let attrs = List.map (fun (a: Schema.Protocol.attribute) -> relation.name ^ "/" ^ a.name) relation.attributes in - Executor.read commit locations ~filename:("schema~" ^ entity) - end - | Error err -> failwith err *) + open Disk + let execute commit locations (entity: string) = + Executor.read commit locations ~filename:("schema~" ^ entity) + |> function + | Some binary -> + begin + let relation = + Result.map_error (fun _ -> "Failed to deserialize relation from binary format.") + @@ Data_encoding.Binary.of_bytes Schema.Protocol.relation_encoding (Bytes.concat Bytes.empty binary) in + match relation with + | Ok relation -> + begin + let _attrs = List.map (fun (a: Schema.Protocol.attribute) -> relation.name ^ "/" ^ a.name) relation.attributes in + Executor.read commit locations ~filename:("schema~" ^ entity) + end + | Error err -> failwith err + end + | None -> failwith "" end module Join = struct diff --git a/lib/relation.ml b/lib/relation.ml index c01c761..798a082 100644 --- a/lib/relation.ml +++ b/lib/relation.ml @@ -112,6 +112,11 @@ let write_and_retrieve () = let+ _, (Command.Read content as response) = Command.commit_and_perform commit locations command_read in + Executor.StringMap.iter (fun k v -> print_endline ("→ " ^ k ^ ": "); + Executor.IntMap.iter (fun k v -> + print_endline (" ↳ " ^ (Int64.to_string k)); + List.iter (fun v -> print_endline (" → " ^ v)) v) v; + print_newline()) references; print_endline (Command.show_return response); Ok (commit, locations) [@@warning "-8-27-26"] |
