Summary
Implement the EventLoopProvider and WorkerLoop interfaces on the epoll engine, allowing database/cache driver connections to be registered on epoll workers.
Design
Changes to engine/epoll/loop.go
- Add
driverConns map[int]*driverConn to Loop struct
driverConn holds onRecv func([]byte), onClose func(), and a write buffer
RegisterConn(fd): adds FD to epoll interest set with EPOLLIN | EPOLLET, stores in driverConns
UnregisterConn(fd): removes from epoll, calls onClose, deletes from map
Write(fd, data): queues data and adds EPOLLOUT to interest set
- In the event loop dispatch: check if FD is in
driverConns before HTTP conn lookup — call onRecv for EPOLLIN, flush write buffer for EPOLLOUT
Atomic Guard
hasDriverConns atomic.Bool on Loop — set to true on first RegisterConn, checked before the driver FD lookup path to avoid map access when no drivers are registered
Acceptance Criteria
Dependencies
Summary
Implement the
EventLoopProviderandWorkerLoopinterfaces on the epoll engine, allowing database/cache driver connections to be registered on epoll workers.Design
Changes to
engine/epoll/loop.godriverConns map[int]*driverConntoLoopstructdriverConnholdsonRecv func([]byte),onClose func(), and a write bufferRegisterConn(fd): adds FD to epoll interest set withEPOLLIN | EPOLLET, stores indriverConnsUnregisterConn(fd): removes from epoll, callsonClose, deletes from mapWrite(fd, data): queues data and addsEPOLLOUTto interest setdriverConnsbefore HTTP conn lookup — callonRecvforEPOLLIN, flush write buffer forEPOLLOUTAtomic Guard
hasDriverConns atomic.BoolonLoop— set totrueon firstRegisterConn, checked before the driver FD lookup path to avoid map access when no drivers are registeredAcceptance Criteria
LoopimplementsEventLoopProviderRegisterConn/UnregisterConn/Writework correctlyDependencies