Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'couchbase/unstable' into HEAD
http: //ci-eventing.northscale.in/eventing-24.01.2021-13.05.pass.html
Change-Id: Ic89298e166250812126f2c12585ee9c9d8b7e5ad
  • Loading branch information
jeelanp2003 committed Jan 26, 2021
2 parents 9a3f9dc + fbfd093 commit f5c7040
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 13 deletions.
93 changes: 92 additions & 1 deletion service_manager/http_handlers.go
Expand Up @@ -2576,6 +2576,7 @@ func (m *ServiceMgr) functionsHandler(w http.ResponseWriter, r *http.Request) {
functionsPause := regexp.MustCompile("^/api/v1/functions/(.*[^/])/pause/?$")
functionsResume := regexp.MustCompile("^/api/v1/functions/(.*[^/])/resume/?$")
functionsAppcode := regexp.MustCompile("^/api/v1/functions/(.*[^/])/appcode(/checksum)?/?$")
functionsConfig := regexp.MustCompile("^/api/v1/functions/(.*[^/])/config/?$")

if match := functionsNameRetry.FindStringSubmatch(r.URL.Path); len(match) != 0 {
appName := match[1]
Expand Down Expand Up @@ -2698,7 +2699,6 @@ func (m *ServiceMgr) functionsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", string(response))

case "POST":

info := &runtimeInfo{}
appState := m.superSup.GetAppState(appName)
if appState == common.AppStateEnabled {
Expand Down Expand Up @@ -2746,6 +2746,97 @@ func (m *ServiceMgr) functionsHandler(w http.ResponseWriter, r *http.Request) {
runtimeInfo.Info = fmt.Sprintf("Function: %s appcode stored in the metakv.", appName)
m.sendRuntimeInfo(w, runtimeInfo)

default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
} else if match := functionsConfig.FindStringSubmatch(r.URL.Path); len(match) != 0 {
appName := match[1]
switch r.Method {
case "GET":
app, info := m.getTempStore(appName)
if info.Code != m.statusCodes.ok.Code {
m.sendErrorInfo(w, info)
return
}
response, err := json.MarshalIndent(app.DeploymentConfig, "", " ")
if err != nil {
info.Code = m.statusCodes.errMarshalResp.Code
info.Info = fmt.Sprintf("Failed to marshal config, err : %v", err)
logging.Errorf("%s %s", logPrefix, info.Info)
m.sendErrorInfo(w, info)
return
}

w.Header().Add(headerKey, strconv.Itoa(m.statusCodes.ok.Code))
fmt.Fprintf(w, "%s", string(response))

case "POST":
info := &runtimeInfo{}
appState := m.superSup.GetAppState(appName)
if appState == common.AppStateEnabled {
info.Code = m.statusCodes.errAppDeployed.Code
info.Info = fmt.Sprintf("Function: %s is in deployed state, config can only be updated when a function is either undeployed or paused", appName)
logging.Errorf("%s %s", logPrefix, info.Info)
m.sendErrorInfo(w, info)
return
}

data, err := ioutil.ReadAll(r.Body)
if err != nil {
info.Code = m.statusCodes.errReadReq.Code
info.Info = fmt.Sprintf("Failed to read request body, err: %v", err)
logging.Errorf("%s %s", logPrefix, info.Info)
m.sendErrorInfo(w, info)
return
}

app, info := m.getTempStore(appName)
appCopy := app
if info.Code != m.statusCodes.ok.Code {
m.sendErrorInfo(w, info)
return
}

config := depCfg{}
unmarshalErr := json.Unmarshal(data, &config)
if unmarshalErr != nil {
info.Code = m.statusCodes.errReadReq.Code
info.Info = fmt.Sprintf("Failed to Unmarshal request body, err: %v", err)
logging.Errorf("%s %s", logPrefix, info.Info)
m.sendErrorInfo(w, info)
return
}
app.DeploymentConfig = config

// Validate Recursion Checks and deployment configurations
if info = m.validateApplication(&app); info.Code != m.statusCodes.ok.Code {
m.sendErrorInfo(w, info)
return
}

// Don't allow the user to change the meta and source keyspaces
if appState == common.AppStatePaused {
app.Settings["dcp_stream_boundary"] = "from_prior"
if !CheckIfAppKeyspacesAreSame(appCopy, app) {
info.Code = m.statusCodes.errInvalidConfig.Code
info.Info = "Source and Meta Keyspaces can only be changed when the function is in undeployed state."
m.sendErrorInfo(w, info)
return
}
}

runtimeInfo := m.savePrimaryStore(&app)
if runtimeInfo.Code == m.statusCodes.ok.Code {
audit.Log(auditevent.SaveDraft, r, appName)
if tempInfo := m.saveTempStore(app); tempInfo.Code != m.statusCodes.ok.Code {
m.sendErrorInfo(w, tempInfo)
return
}
}
runtimeInfo.Info = fmt.Sprintf("Function: %s config stored in the metakv.", appName)
m.sendRuntimeInfo(w, runtimeInfo)

default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
Expand Down
9 changes: 8 additions & 1 deletion v8_consumer/include/timer.h
Expand Up @@ -18,6 +18,13 @@

#include "timer_defs.h"

struct TIMER_MSG {
TIMER_MSG(bool success, std::string message)
: success(success), message(message){};
bool success;
std::string message;
};

extern thread_local std::mt19937_64 rng;

class Timer {
Expand All @@ -26,7 +33,7 @@ class Timer {
int32_t timer_reduction_ratio);
virtual ~Timer();

bool CreateTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args);
TIMER_MSG CreateTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args);
bool CancelTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args);

uint16_t timer_mask_bits_{0};
Expand Down
30 changes: 19 additions & 11 deletions v8_consumer/src/timer.cc
Expand Up @@ -58,19 +58,20 @@ timer::EpochInfo Timer::Epoch(const v8::Local<v8::Value> &date_val) {
return {true, epoch};
}

bool Timer::CreateTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args) {
TIMER_MSG
Timer::CreateTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args) {
if (!ValidateArgs(args)) {
return false;
return TIMER_MSG(false, "Unable to Validate Arguments");
}

v8::HandleScope handle_scope(isolate_);

auto js_exception = UnwrapData(isolate_)->js_exception;
auto epoch_info = Epoch(args[1]);
if (!epoch_info.is_valid) {
js_exception->ThrowEventingError(
"Unable to compute epoch for the given Date instance");
return false;
std::string err_msg = "Unable to compute epoch for the given Date instance";
js_exception->ThrowEventingError(err_msg);
return TIMER_MSG(false, err_msg);
}

auto utils = UnwrapData(isolate_)->utils;
Expand All @@ -92,19 +93,21 @@ bool Timer::CreateTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args) {
FillTimerPartition(timer_info, v8worker->num_vbuckets_);

if (timer_info.context.size() > static_cast<unsigned>(timer_context_size)) {
js_exception->ThrowEventingError(
std::string err_msg =
"The context payload size is more than the configured size:" +
std::to_string(timer_context_size) + " bytes");
std::to_string(timer_context_size) + " bytes";
js_exception->ThrowEventingError(err_msg);
timer_context_size_exceeded_counter++;
return false;
return TIMER_MSG(false, err_msg);
}
auto err = v8worker->SetTimer(timer_info);
if (err != LCB_SUCCESS) {
js_exception->ThrowKVError(v8worker->GetTimerLcbHandle(), err);
return false;
// TODO: Reformat this error with precise message
return TIMER_MSG(false, "Set Timer Failed with KV Error");
}
args.GetReturnValue().Set(v8Str(isolate_, timer_info.reference));
return true;
return TIMER_MSG(true, "Timer Creation Successfull");
}

bool Timer::CancelTimerImpl(const v8::FunctionCallbackInfo<v8::Value> &args) {
Expand Down Expand Up @@ -218,8 +221,13 @@ void CreateTimer(const v8::FunctionCallbackInfo<v8::Value> &args) {
}

auto timer = UnwrapData(isolate)->timer;
if (timer->CreateTimerImpl(args)) {
auto response = timer->CreateTimerImpl(args);
if (response.success) {
++timer_create_counter;
} else {
++timer_create_failure;
LOG(logError) << "Timer Creation failed with message: " << response.message
<< "\n";
}
}

Expand Down

0 comments on commit f5c7040

Please sign in to comment.