|
smollerGraph 0.20.2
A small graph database, from scratch
|
Accepted
Google's C++ style guide, which the code follows (0001), doesn't use exceptions. So from episode 1, a function that could fail returned a bool, and wrote what went wrong into a string its caller passed it, as LoadFacts did. Episode 1 gave the reason for a value: "An error that comes back as a value also shows up in the function's signature, so a caller
can see that it has to check." By episode 4 the pager, the record files, the graph and the facts all worked that way, and a string can't say what kind of error it holds.
absl::Status, or absl::StatusOr<T> when it returns a value (ep004/step-2). A status is a code and a message, and the codes are a fixed list, the canonical errors, such as not found, invalid argument and permission denied, "so the code that gets an
error can tell one kind from another without reading the message".ErrnoToStatus turns the system's error into the code that goes with it, such as not found for a missing folder, and a fact that can't be read is an invalid argument, with the line as its message.absl::StrCat puts messages together, and absl::SimpleAtoi reads numbers from the command line.bool and an error string, as the code did until episode 4.absl::StatusOr<std::string>, and sg serve turns their codes into HTTP's: 404 for something that isn't there, and 400 for a request that's wrong, such as a query that doesn't parse (episodes 4 and 7).absl::OkStatus(), so a failure prints the code and the message.Graph that can't get its temporary files stops with the status's text (episodes 2 and 4). A page that can't be read or written once its file is open stops it too, as that "leaves nothing
sensible to carry on with"; "in a database meant to run for months, we'd want something gentler" (Fail in pager.cc, episode 2). And a buffer pool whose pages are all pinned has "nothing to
evict, so we stop with an error" (BufferPool::Victim, episode 5)..clang-tidy tells performance-no-automatic-move that an absl::Status returned without a move is fine, as a status is cheap to copy (episode 4).smollergraph gets Abseil too, and a first build compiles the parts of it we link.