initRuntime
(params *startRuntimeParams)
| 46 | |
| 47 | // initRuntime |
| 48 | func (info *RuntimeInfo) initRuntime(params *startRuntimeParams) error { |
| 49 | preInit, _ := strconv.ParseInt(params.urlParams.Get("initstart"), 10, 64) |
| 50 | postInit, _ := strconv.ParseInt(params.urlParams.Get("initdone"), 10, 64) |
| 51 | |
| 52 | info.invokeLock.Lock() |
| 53 | defer info.invokeLock.Unlock() |
| 54 | |
| 55 | if info.State != RuntimeStateCold && info.State != RuntimeStateWarmUp { |
| 56 | logs.Errorf("runtime %s current states is %s", info.RuntimeID, info.State) |
| 57 | return fmt.Errorf("duplicate runtime") |
| 58 | } |
| 59 | |
| 60 | // TODO: CommitID could be missing, when controller restarted |
| 61 | if len(info.CommitID) == 0 { |
| 62 | info.SetCommitID(params.commitID) |
| 63 | } |
| 64 | if info.CommitID != params.commitID { |
| 65 | return fmt.Errorf("commit id %s is not equal to %s", info.CommitID, params.commitID) |
| 66 | } |
| 67 | |
| 68 | cm := params.urlParams.Get("concurrentmode") |
| 69 | // When service's concurrent mode is true, the value of runtime concurrent mode makes sense |
| 70 | if info.ConcurrentMode == true && cm == "false" { |
| 71 | info.ConcurrentMode = false |
| 72 | } |
| 73 | logs.V(9).Infof("runtime[%s] concurrentMode is %t", info.RuntimeID, info.ConcurrentMode) |
| 74 | |
| 75 | info.SetInitTime(preInit, postInit) |
| 76 | info.SetState(RuntimeStateWarm) |
| 77 | info.SetUsed(true) |
| 78 | if params.warmNotify != nil { |
| 79 | close(params.warmNotify) |
| 80 | } |
| 81 | // when runtime restart |
| 82 | // requestChan and runtimeStopChan should be reset |
| 83 | if info.WithStreamMode { |
| 84 | info.httpRequestChan = make(chan *InvokeHTTPRequest, 100) |
| 85 | info.httpResponseChan = make(chan *InvokeHTTPResponse, 100) |
| 86 | info.retryDeadline = time.Duration(info.WaitRuntimeAliveTimeout) * time.Second |
| 87 | } else { |
| 88 | info.requestChan = make(chan *InvokeRequest, 100) |
| 89 | } |
| 90 | info.runtimeStopChan = make(chan struct{}) |
| 91 | info.runtimeStoppingChan = make(chan struct{}) |
| 92 | |
| 93 | info.sendRequestLoop(params) |
| 94 | close(info.runtimeRunChan) |
| 95 | return nil |
| 96 | } |
| 97 | |
| 98 | // startRuntimeLoop |
| 99 | func (info *RuntimeInfo) startRuntimeLoop(params *startRuntimeParams) error { |