MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / cdb2_effects_request

Function cdb2_effects_request

cdb2api/cdb2api.c:2942–3016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2940}
2941
2942static int cdb2_effects_request(cdb2_hndl_tp *hndl)
2943{
2944 if (hndl && !hndl->in_trans) {
2945 return -1;
2946 }
2947
2948 if (hndl->error_in_trans)
2949 return -1;
2950
2951 clear_responses(hndl);
2952 CDB2QUERY query = CDB2__QUERY__INIT;
2953 CDB2DBINFO dbinfoquery = CDB2__DBINFO__INIT;
2954 dbinfoquery.dbname = hndl->dbname;
2955 dbinfoquery.has_want_effects = 1;
2956 dbinfoquery.want_effects = 1;
2957 query.sqlquery = NULL;
2958 query.dbinfo = &dbinfoquery;
2959
2960 int len = cdb2__query__get_packed_size(&query);
2961 unsigned char *buf = malloc(len + 1);
2962
2963 cdb2__query__pack(&query, buf);
2964
2965 struct newsqlheader hdr = {.type = ntohl(CDB2_REQUEST_TYPE__CDB2QUERY),
2966 .compression = ntohl(0),
2967 .length = ntohl(len)};
2968
2969 sbuf2write((char *)&hdr, sizeof(hdr), hndl->sb);
2970 sbuf2write((char *)buf, len, hndl->sb);
2971
2972 int rc = sbuf2flush(hndl->sb);
2973 free(buf);
2974 if (rc < 0)
2975 return -1;
2976
2977 int type;
2978
2979retry_read:
2980 rc = cdb2_read_record(hndl, &hndl->first_buf, &len, &type);
2981 if (rc) {
2982 free((void *)hndl->first_buf);
2983 hndl->first_buf = NULL;
2984 sbuf2close(hndl->sb);
2985 hndl->sb = NULL;
2986 return -1;
2987 }
2988 if (type ==
2989 RESPONSE_HEADER__SQL_RESPONSE) { /* This might be the error that
2990 happened within transaction. */
2991 hndl->firstresponse =
2992 cdb2__sqlresponse__unpack(NULL, len, hndl->first_buf);
2993 hndl->error_in_trans =
2994 cdb2_convert_error_code(hndl->firstresponse->error_code);
2995 if (hndl->firstresponse->error_string)
2996 strcpy(hndl->errstr, hndl->firstresponse->error_string);
2997 goto retry_read;
2998 }
2999

Callers 1

cdb2_get_effectsFunction · 0.85

Calls 5

clear_responsesFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.85
cdb2_read_recordFunction · 0.85
cdb2_convert_error_codeFunction · 0.85

Tested by

no test coverage detected