- Single process.
- Single system directory (e.g.,
/var/nfsys). - NS does not store file contents:
- Files’ bytes live only on Storage Servers (SS).
- NS stores metadata: users, files, ACLs, placements, version hints, plus any in-memory caches it wants.
-
Acceptor thread:
- Calls
accept()on:- Client port (7000)
- SS-Control port (7001)
- For each new connection, chooses a worker and hands over the
fd.
- Calls
-
Two worker classes, both using
epoll:- Client-NS workers
- Handle Client connections on port 7000.
- Decode client requests (LOGIN/VIEW/INFO/CREATE/DELETE/ACCESS/… and *_TICKET ops).
- For any request that requires contacting an SS (CREATE/DELETE/FETCH/SYNC, etc.), they enqueue a message to the appropriate NS-SS worker.
- NS-SS workers
- Handle persistent SS-Control connections on port 7001.
- Own SS-Control fds and run
epollon them. - Send NS→SS control messages, read SS→NS responses, and forward results back to the originating Client-NS worker.
- Client-NS workers
-
Once an
fdis assigned to a worker, it stays on that worker until closed.
-
Maintain
assigned_fds[worker_id]separately for:- Client-NS worker pool, and
- NS-SS worker pool.
-
Initialize a threshold
T = 2per pool. -
For each newly accepted connection in a pool:
- Scan workers in that pool round-robin and pick one with
< TFDs. - Assign the
fdto that worker and increment its count. - If all workers in that pool have
≥ TFDs, then setT ← 2Tfor that pool and continue.
- Scan workers in that pool round-robin and pick one with
-
Keep a global map
fd → worker_id(andfd → pool_type) for debugging/metrics and routing.
Each worker has:
InboundQ: queue of “work items” this worker should process.OutboundQ: queue of “work items” this worker wants some other worker to process.
Queues can be implemented as:
std::queue<T>+std::mutex+std::condition_variable(simple and fine).
Patterns:
-
When a Client-NS worker needs to call an SS (e.g., CREATE on SS #7):
- It builds a work item:
{ server_id, target_fd, opcode, protobuf_payload, client_fd, corr_id }. - It pushes this onto the InboundQ of the NS-SS worker that owns the SS #7 control
fd. - The NS-SS worker’s event loop:
- dequeues the work item,
- writes the framed message to the SS-Control
fd, - and later, when a response arrives on that
fd, decodes it and pushes a result work item to the originating Client-NS worker’sInboundQ.
- It builds a work item:
-
When an NS-SS worker has a response for a client:
- It constructs a result item (including
client_fdandcorr_id) and pushes it to the relevant Client-NS worker’sInboundQ. - The Client-NS worker then completes the original client request and writes the final response to the client
fd.
- It constructs a result item (including
The queues are entirely inside NS. SS still sees a normal persistent control connection and standard NS⇄SS messages defined in the HLD.
There are two kinds of external connections:
- Client connections (Client⇄NS on port 7000), owned by Client-NS workers.
- SS-Control connections (SS⇄NS on port 7001), owned by NS-SS workers.
-
Per-FD state:
CONNECTING → LOGGED_IN (user_id bound) → READY → CLOSING
-
Per-request tracking:
- Maintain a map:
(fd, CorrId) → { opcode, decode_state, payload_buf, deadline, route } routeincludes any info needed to map responses from SS back to this client request (e.g. whichserver_idwe called, which NS-SS worker we used).
- Maintain a map:
-
STOP / session timeout logic:
-
Each client connection has a
login_time. -
If a Client sends
F_STOP, or 30 minutes have elapsed sinceLOGINon thatfd:- Reject new requests from that
fd(respond withSESSION_EXPIRED/SESSION_TIMEOUT). - Allow all tracked
(fd, CorrId)to finish normally. - Once no in-flight requests remain, close the
fdand transition the FD state toCLOSING.
- Reject new requests from that
-
-
These are persistent control connections from SS to NS, owned by NS-SS workers.
-
Per-FD state:
CONNECTING → REGISTERED (after OP_SS_REGISTER) → READY → CLOSING
-
NS-SS workers:
- Read:
OP_SS_REGISTERon first message to bindserver_idand endpoints.OP_SS_HEARTBEATperiodically.OP_SS_FILE_UPDATE_NOTIFY,OP_SS_SYNC_RESULT, etc.
- Write:
OP_SS_CREATE,OP_SS_DELETE,OP_SS_LIST_FILES,OP_SS_FETCH_FILE,OP_SS_FILE_METADATA_REQUEST,OP_SS_SYNC_REQUEST, etc., based on work items from Client-NS workers.
- Read:
-
Failures & timeouts:
- If heartbeats from a given SS stop for longer than allowed, or any fatal socket error occurs:
- Mark that
server_idas unavailable in NS metadata. - Close the SS-Control
fdand move it toCLOSING.
- Mark that
- If heartbeats from a given SS stop for longer than allowed, or any fatal socket error occurs: