Directory
eXtremeDB_rt/samples/rt_policy_adaptableDescription
rt_polic_adaptable illustrates the adaptable deadline policy.
Used API
mco_trans_rt_start(), mco_trans_commit(), mco_trans_rt_estimate_rollback_time()Code snippet
mco_bool adaptable_policy_transaction(mco_db_h db, unsigned int n_ops) { .... /* Start the transaction passing the deadline through the tx_params */ tx_params.deadline = 100; start_ts = mco_system_get_current_time(); CHECK(mco_trans_rt_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &tx_params, &t)); /* Continue work until we have something to do and transaction is not aborted * either due to timeout expiration either because of some other database error. */ for (n = 0; n < n_ops && mco_get_last_error(t) == MCO_S_OK; ++n) { Measurement obj; int id = lcg_rand() % N_OBJECTS; rc = Measurement_pk_find(t, id, &obj); if (rc == MCO_S_NOTFOUND) { rc = Measurement_new(t, &obj); if (rc == MCO_S_OK) { Measurement_id_put(&obj, id); Measurement_checkpoint(&obj); } n_insert++; } if (rc == MCO_S_OK) { Measurement_val_put(&obj, id * 3.1415); if (lcg_rand() % 5 == 3) { Measurement_delete(&obj); n_delete++; } else { n_update++; } } } commit_rc = mco_trans_commit(t); commit_ts = mco_system_get_current_time(); if (commit_rc != MCO_S_OK) { CHECK(mco_trans_rt_estimate_rollback_time(t, &rollback_time_estimation)); CHECK(mco_rollback_buf_info(t, &rb_info)); rback_rc = mco_trans_rollback(t); } ....What to expect as an output
./target/bin/rt_policy_adaptable Sample 'realtime' demonstrates usage of realtime transactions. eXtremeDB/rt runtime version 1.4, Debug Copyright (c) 2001-2024 McObject LLC. All Rights Reserved. Set memory throughput to 355 Mbytes/sec Transaction deadline 100, acutal time 4802. Workload : #ops 1000 (#inserts 993 + #updates 797 + #deletes 203) Commit : SUCCESS DB stat : #objects 790. Free pages 130128 of 131011 Transaction deadline 100, acutal time 6402. Workload : #ops 1500 (#inserts 1481 + #updates 1195 + #deletes 305) Commit : SUCCESS DB stat : #objects 1966. Free pages 128896 of 131011 Transaction deadline 100, acutal time 10384. Workload : #ops 2250 (#inserts 2195 + #updates 1771 + #deletes 479) Commit : SUCCESS DB stat : #objects 3682. Free pages 127095 of 131011