This function handle the cache lookup result. If MISS, try to open cache write_vc for writing. Otherwise, use the vc returned by the cache to read the data from the cache. */
| 262 | open cache write_vc for writing. Otherwise, use the vc returned |
| 263 | by the cache to read the data from the cache. */ |
| 264 | int |
| 265 | state_handle_cache_lookup(TSCont contp, TSEvent event, TSVConn vc) |
| 266 | { |
| 267 | TxnSM *txn_sm = static_cast<TxnSM *>(TSContDataGet(contp)); |
| 268 | int64_t response_size; |
| 269 | int ret_val; |
| 270 | |
| 271 | Dbg(dbg_ctl, "enter state_handle_cache_lookup"); |
| 272 | |
| 273 | switch (event) { |
| 274 | case TS_EVENT_CACHE_OPEN_READ: |
| 275 | Dbg(dbg_ctl, "cache hit!!!"); |
| 276 | /* Cache hit. */ |
| 277 | |
| 278 | /* Write log */ |
| 279 | ret_val = TSTextLogObjectWrite(protocol_plugin_log, "%s %s %d \n", txn_sm->q_file_name, txn_sm->q_server_name, 1); |
| 280 | if (ret_val != TS_SUCCESS) { |
| 281 | TSError("[%s] Fail to write into log", PLUGIN_NAME); |
| 282 | } |
| 283 | |
| 284 | txn_sm->q_cache_vc = vc; |
| 285 | txn_sm->q_pending_action = nullptr; |
| 286 | |
| 287 | /* Get the size of the cached doc. */ |
| 288 | response_size = TSVConnCacheObjectSizeGet(txn_sm->q_cache_vc); |
| 289 | |
| 290 | /* Allocate IOBuffer to store data from the cache. */ |
| 291 | txn_sm->q_client_response_buffer = TSIOBufferCreate(); |
| 292 | if (!txn_sm->q_client_response_buffer) { |
| 293 | return prepare_to_die(contp); |
| 294 | } |
| 295 | txn_sm->q_client_response_buffer_reader = TSIOBufferReaderAlloc(txn_sm->q_client_response_buffer); |
| 296 | if (!txn_sm->q_client_response_buffer_reader) { |
| 297 | return prepare_to_die(contp); |
| 298 | } |
| 299 | txn_sm->q_cache_read_buffer = TSIOBufferCreate(); |
| 300 | if (!txn_sm->q_cache_read_buffer) { |
| 301 | return prepare_to_die(contp); |
| 302 | } |
| 303 | txn_sm->q_cache_read_buffer_reader = TSIOBufferReaderAlloc(txn_sm->q_cache_read_buffer); |
| 304 | if (!txn_sm->q_cache_read_buffer_reader) { |
| 305 | return prepare_to_die(contp); |
| 306 | } |
| 307 | |
| 308 | /* Read doc from the cache. */ |
| 309 | set_handler(txn_sm->q_current_handler, (TxnSMHandler)&state_handle_cache_read_response); |
| 310 | txn_sm->q_cache_read_vio = TSVConnRead(txn_sm->q_cache_vc, contp, txn_sm->q_cache_read_buffer, response_size); |
| 311 | |
| 312 | break; |
| 313 | |
| 314 | case TS_EVENT_CACHE_OPEN_READ_FAILED: |
| 315 | /* Cache miss or error, open cache write_vc. */ |
| 316 | Dbg(dbg_ctl, "cache miss or error!!!"); |
| 317 | /* Write log */ |
| 318 | ret_val = TSTextLogObjectWrite(protocol_plugin_log, "%s %s %d \n", txn_sm->q_file_name, txn_sm->q_server_name, 0); |
| 319 | |
| 320 | if (ret_val != TS_SUCCESS) { |
| 321 | TSError("[%s] Fail to write into log", PLUGIN_NAME); |
nothing calls this directly
no test coverage detected