Lock room creation to ensure atomic creation & node assignment (#46)

* Lock room creation to ensure atomic creation & node assignment

* more tests
This commit is contained in:
David Zhao
2021-07-12 14:50:14 -07:00
committed by GitHub
parent c0bff83a36
commit d38fc43b89
9 changed files with 287 additions and 7 deletions
+8
View File
@@ -54,6 +54,14 @@ func NewRoomManager(rp RoomStore, router routing.Router, currentNode routing.Loc
// CreateRoom creates a new room from a request and allocates it to a node to handle
// it'll also monitor fits state, and cleans it up when appropriate
func (r *RoomManager) CreateRoom(req *livekit.CreateRoomRequest) (*livekit.Room, error) {
token, err := r.roomStore.LockRoom(req.Name, 5*time.Second)
if err != nil {
return nil, err
}
defer func() {
_ = r.roomStore.UnlockRoom(req.Name, token)
}()
// find existing room and update it
rm, err := r.roomStore.GetRoom(req.Name)
if err == ErrRoomNotFound {