Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 10ad9e6

Browse files
authored
Add guide comments to network folder's README. (#1411)
1 parent c4112f8 commit 10ad9e6

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/network/README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
# Networking
22

33
## Overview
4-
A prototype implementation of the Postgres network protocol in C++ in order to support communication with Postgres shell clients with Terrier.
4+
A prototype implementation of the Postgres network protocol in C++ in order to support communication with Postgres shell clients (psql) with NoisePage.
5+
6+
## Description
7+
8+
- Expected callee: `DBMain`
9+
- Entry point of the network layer: `NoisePageServer::RunServer()` in `noisepage_server.h`
10+
- `NoisePageServer::RunServer()` will:
11+
1. Create a `ConnectionDispatcherTask` (CDT) with a specified `ProtocolInterpreter` and a list of file descriptors.
12+
Each file descriptor is registered with `libevent` to invoke a callback `connection_dispatcher_fn` whenever
13+
the respective file descriptor becomes readable. The `ProtocolInterpreter` is saved for later use.
14+
When the CDT is run, a pool of `ConnectionHandlerTask` (CHT) threads are created.
15+
2. When a file descriptor `fd` becomes readable, the descriptor is dispatched from the CDT to an idle CHT with the `ProtocolInterpreter` from above.
16+
3. The CHT creates (or reuses) a new `ConnectionHandle` (CH) to handle `fd` and invokes `ConnectionHandle::RegisterToReceiveEvents()`.
17+
4. The CH makes a `NetworkIOWrapper` around `fd` and registers two events:
18+
- `workpool_event_`: DOESN'T DO ANYTHING RIGHT NOW. Originally envisioned for future callback support.
19+
- `network_event_`: Handle transitions through the state machine of the `ProtocolInterpreter`, which is currently always `PostgresProtocolInterpreter`. See footnote A1.
20+
5. It is through `ProtocolInterpreter::Process()` that control flow proceeds to the next layer of the system.
21+
An example is `PostgresProtocolInterpreter::Process() -> SimpleQueryCommand::Exec()`, which goes through the
22+
`TrafficCop` before returning control flow to the `PostgresProtocolInterpreter`.
23+
24+
**Footnote A1.**
25+
It was envisioned that the internal Terrier protocol (ITP) would use the same network state machine as Postgres does.
26+
However, the `Messenger` system serves this purpose instead. This is because it does not necessarily make sense for
27+
an internal communication protocol to have the same `TryRead`, `TryWrite`, etc., that the Postgres connection handler does.
528

6-
## Scope
7-
>Which parts of the system will this feature rely on or modify? Write down specifics so people involved can review the design doc
829

930
## Glossary
1031

@@ -26,18 +47,3 @@ A prototype implementation of the Postgres network protocol in C++ in order to s
2647
* RowDescription (T)
2748
* DataRow (D)
2849
* CommandComplete (C)
29-
30-
## Architectural Design
31-
>Explain the input and output of the component, describe interactions and breakdown the smaller components if any. Include diagrams if appropriate.
32-
33-
## Design Rationale
34-
>Explain the goals of this design and how the design achieves these goals. Present alternatives considered and document why they are not chosen.
35-
36-
## Testing Plan
37-
Unit testing of basic command handling is provided by `test/network/network_test.cpp`. More complete test coverage will be handled by the Junit integration tests.
38-
39-
## Trade-offs and Potential Problems
40-
>Write down any conscious trade-off you made that can be problematic in the future, or any problems discovered during the design process that remain unaddressed (technical debts).
41-
42-
## Future Work
43-
- Support internal protocol for server-to-server communications

src/network/postgres/postgres_network_commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Transition SimpleQueryCommand::Exec(const common::ManagedPointer<ProtocolInterpr
101101
const auto statement = std::make_unique<network::Statement>(
102102
std::move(query_text), std::move(std::get<std::unique_ptr<parser::ParseResult>>(parse_result)));
103103

104-
// TODO(Matt:) Clients may send multiple statements in a single SimpleQuery packet/string. Handling that would
104+
// TODO(Matt): Clients may send multiple statements in a single SimpleQuery packet/string. Handling that would
105105
// probably exist here, looping over all of the elements in the ParseResult. It's not clear to me how the binder would
106106
// handle that though since you pass the ParseResult in for binding. Maybe bind ParseResult once?
107107

0 commit comments

Comments
 (0)