22
22
#include < utility>
23
23
#include < vector>
24
24
25
- #include " glog/logging.h"
26
- #include " dingosdk/client.h"
27
25
#include " common/logging.h"
26
+ #include " dingosdk/client.h"
28
27
#include " dingosdk/status.h"
28
+ #include " glog/logging.h"
29
29
30
30
using dingodb::sdk::Status;
31
31
@@ -65,7 +65,7 @@ static void CreateRegion(std::string name, std::string start_key, std::string en
65
65
CHECK (start_key < end_key) << " start_key must < end_key" ;
66
66
CHECK (replicas > 0 ) << " replicas must > 0" ;
67
67
68
- dingodb::sdk::RegionCreator * tmp_creator;
68
+ dingodb::sdk::RegionCreator* tmp_creator;
69
69
Status built = g_client->NewRegionCreator (&tmp_creator);
70
70
CHECK (built.IsOK ()) << " dingo creator build fail" ;
71
71
std::shared_ptr<dingodb::sdk::RegionCreator> creator (tmp_creator);
@@ -102,7 +102,7 @@ static std::shared_ptr<dingodb::sdk::Transaction> NewOptimisticTransaction(dingo
102
102
options.kind = dingodb::sdk::kOptimistic ;
103
103
options.keep_alive_ms = keep_alive_ms;
104
104
105
- dingodb::sdk::Transaction * tmp;
105
+ dingodb::sdk::Transaction* tmp;
106
106
Status built = g_client->NewTransaction (options, &tmp);
107
107
CHECK (built.ok ()) << " dingo txn build fail" ;
108
108
std::shared_ptr<dingodb::sdk::Transaction> txn (tmp);
@@ -138,7 +138,7 @@ static void OptimisticTxnPostClean(dingodb::sdk::TransactionIsolation isolation)
138
138
void OptimisticTxnBatch () {
139
139
auto txn = NewOptimisticTransaction (dingodb::sdk::kSnapshotIsolation );
140
140
141
- for (const auto & key : keys) {
141
+ for (const auto & key : keys) {
142
142
std::string tmp;
143
143
Status got = txn->Get (key, tmp);
144
144
CHECK (got.IsNotFound ());
@@ -167,7 +167,7 @@ void OptimisticTxnBatch() {
167
167
s = txn->BatchGet (keys, tmp);
168
168
CHECK (s.ok ());
169
169
CHECK_EQ (tmp.size (), kvs.size ());
170
- for (const auto & kv : tmp) {
170
+ for (const auto & kv : tmp) {
171
171
CHECK_EQ (kv.value , key_values[kv.key ]);
172
172
}
173
173
}
@@ -181,7 +181,7 @@ void OptimisticTxnBatch() {
181
181
s = txn->BatchGet (keys, tmp);
182
182
CHECK (s.ok ());
183
183
CHECK_EQ (tmp.size (), kvs.size ());
184
- for (const auto & kv : tmp) {
184
+ for (const auto & kv : tmp) {
185
185
CHECK_EQ (kv.value , key_values[kv.key ]);
186
186
}
187
187
}
@@ -206,7 +206,7 @@ void OptimisticTxnBatch() {
206
206
s = txn->BatchGet (keys, tmp);
207
207
CHECK (s.ok ());
208
208
CHECK_EQ (tmp.size (), kvs.size ());
209
- for (const auto & kv : tmp) {
209
+ for (const auto & kv : tmp) {
210
210
CHECK_EQ (kv.value , key_values[kv.key ]);
211
211
}
212
212
}
@@ -215,7 +215,7 @@ void OptimisticTxnBatch() {
215
215
// batch put override exist kvs, then batch delete
216
216
std::vector<dingodb::sdk::KVPair> new_kvs;
217
217
new_kvs.reserve (keys.size ());
218
- for (auto & key : keys) {
218
+ for (auto & key : keys) {
219
219
new_kvs.push_back ({key, key});
220
220
}
221
221
@@ -226,7 +226,7 @@ void OptimisticTxnBatch() {
226
226
s = txn->BatchGet (keys, tmp);
227
227
CHECK (s.ok ());
228
228
CHECK_EQ (tmp.size (), new_kvs.size ());
229
- for (const auto & kv : tmp) {
229
+ for (const auto & kv : tmp) {
230
230
CHECK_EQ (kv.value , kv.key );
231
231
}
232
232
@@ -272,7 +272,7 @@ void OptimisticTxnSingleOp() {
272
272
}
273
273
274
274
{
275
- dingodb::sdk::Transaction * tmp;
275
+ dingodb::sdk::Transaction* tmp;
276
276
Status built = g_client->NewTransaction (options, &tmp);
277
277
CHECK (built.ok ()) << " dingo txn build fail" ;
278
278
CHECK_NOTNULL (tmp);
@@ -284,7 +284,7 @@ void OptimisticTxnSingleOp() {
284
284
CHECK (got.ok ());
285
285
CHECK_EQ (kvs.size (), 2 );
286
286
287
- for (const auto & kv : kvs) {
287
+ for (const auto & kv : kvs) {
288
288
CHECK (kv.key == put_key || kv.key == put_if_absent_key);
289
289
if (kv.key == put_key) {
290
290
CHECK_EQ (kv.value , key_values[put_key]);
@@ -370,7 +370,7 @@ void OptimisticTxnLockConflict() {
370
370
CHECK (got.ok ());
371
371
CHECK_EQ (kvs.size (), 2 );
372
372
373
- for (const auto & kv : kvs) {
373
+ for (const auto & kv : kvs) {
374
374
CHECK (kv.key == put_key || kv.key == put_if_absent_key);
375
375
if (kv.key == put_key) {
376
376
CHECK_EQ (kv.value , key_values[put_key]);
@@ -445,7 +445,7 @@ void OptimisticTxnReadSnapshotAndReadCommiited() {
445
445
CHECK (got.ok ());
446
446
CHECK_EQ (kvs.size (), 2 );
447
447
448
- for (const auto & kv : kvs) {
448
+ for (const auto & kv : kvs) {
449
449
CHECK (kv.key == put_key || kv.key == put_if_absent_key);
450
450
if (kv.key == put_key) {
451
451
CHECK_EQ (kv.value , key_values[put_key]);
@@ -545,7 +545,7 @@ void OptimisticTxnScan() {
545
545
CHECK (got.ok ());
546
546
CHECK_EQ (kvs.size (), 2 );
547
547
548
- for (const auto & kv : kvs) {
548
+ for (const auto & kv : kvs) {
549
549
CHECK (kv.key == put_key || kv.key == put_if_absent_key);
550
550
DINGO_LOG (INFO) << " batch get, key:" << kv.key << " ,value:" << kv.value ;
551
551
if (kv.key == put_key) {
@@ -567,7 +567,7 @@ void OptimisticTxnScan() {
567
567
}
568
568
CHECK_EQ (kvs.size (), 2 );
569
569
570
- for (const auto & kv : kvs) {
570
+ for (const auto & kv : kvs) {
571
571
CHECK (kv.key == put_key || kv.key == put_if_absent_key);
572
572
if (kv.key == put_key) {
573
573
CHECK_EQ (kv.value , key_values[put_key]);
@@ -618,77 +618,6 @@ void OptimisticTxnScanReadSelf() {
618
618
DINGO_LOG (INFO) << " txn commit:" << commit.ToString ();
619
619
}
620
620
621
- auto read_commit_txn = NewOptimisticTransaction (dingodb::sdk::kReadCommitted );
622
- {
623
- std::string self_put_key = " xb02" ;
624
- std::string self_put_if_absent_key = " xc02" ;
625
- std::string self_delete_key = " xd02" ;
626
-
627
- to_check.emplace (self_put_key);
628
- to_check.emplace (self_put_if_absent_key);
629
- to_check.emplace (self_delete_key);
630
- {
631
- {
632
- // overwrite
633
- read_commit_txn->Put (put_key, put_key);
634
- read_commit_txn->PutIfAbsent (put_if_absent_key, put_if_absent_key);
635
- read_commit_txn->Delete (delete_key);
636
- read_commit_txn->Delete (put_keyl);
637
- }
638
-
639
- read_commit_txn->Put (self_put_key, self_put_key);
640
- read_commit_txn->PutIfAbsent (self_put_if_absent_key, self_put_if_absent_key);
641
- read_commit_txn->Delete (self_delete_key);
642
- }
643
-
644
- {
645
- // scan without limit
646
- std::vector<dingodb::sdk::KVPair> kvs;
647
- Status scan = read_commit_txn->Scan (" xa00000000" , " xz00000000" , 0 , kvs);
648
- DINGO_LOG (INFO) << " read_commit_txn scan:" << scan.ToString ();
649
- CHECK (scan.ok ());
650
- for (const auto &kv : kvs) {
651
- DINGO_LOG (INFO) << " read_commit_txn scan key:" << kv.key << " , value:" << kv.value ;
652
- }
653
- if (kvs.size () != 5 ) {
654
- DINGO_LOG (WARNING) << " Internal error, expected kvs size:" << 2 << " , ectual:" << kvs.size ();
655
- }
656
- CHECK_EQ (kvs.size (), 5 );
657
-
658
- for (const auto &kv : kvs) {
659
- if (kv.key != put_if_absent_key && kv.key != put_keyf) {
660
- CHECK_EQ (kv.value , kv.key );
661
- } else {
662
- CHECK_EQ (kv.value , key_values[kv.key ]);
663
- }
664
- to_check.erase (kv.key );
665
- }
666
- CHECK_EQ (to_check.size (), 3 );
667
- CHECK (to_check.find (delete_key) != to_check.cend ());
668
- CHECK (to_check.find (self_delete_key) != to_check.cend ());
669
- CHECK (to_check.find (put_keyl) != to_check.cend ());
670
- }
671
-
672
- {
673
- // scan without limit
674
- int limit = 2 ;
675
- std::vector<dingodb::sdk::KVPair> kvs;
676
- Status scan = read_commit_txn->Scan (" xa00000000" , " xz00000000" , limit, kvs);
677
- DINGO_LOG (INFO) << " read_commit_txn scan:" << scan.ToString ();
678
- CHECK (scan.ok ());
679
- for (const auto &kv : kvs) {
680
- DINGO_LOG (INFO) << " read_commit_txn scan key:" << kv.key << " , value:" << kv.value ;
681
- }
682
- CHECK_EQ (kvs.size (), 2 );
683
- // TODO: check key prefix is xb
684
- }
685
-
686
- Status precommit = read_commit_txn->PreCommit ();
687
- DINGO_LOG (INFO) << " read_commit_txn precommit:" << precommit.ToString ();
688
- Status commit = read_commit_txn->Commit ();
689
- DINGO_LOG (INFO) << " read_commit_txn commit:" << commit.ToString ();
690
- }
691
-
692
621
{
693
622
std::vector<std::string> keys (to_check.begin (), to_check.end ());
694
623
{
@@ -715,7 +644,7 @@ void OptimisticTxnScanReadSelf() {
715
644
OptimisticTxnPostClean (dingodb::sdk::kSnapshotIsolation );
716
645
}
717
646
718
- int main (int argc, char * argv[]) {
647
+ int main (int argc, char * argv[]) {
719
648
FLAGS_minloglevel = google::GLOG_INFO;
720
649
FLAGS_logtostdout = true ;
721
650
FLAGS_colorlogtostdout = true ;
@@ -733,7 +662,7 @@ int main(int argc, char *argv[]) {
733
662
734
663
CHECK (!FLAGS_addrs.empty ());
735
664
736
- dingodb::sdk::Client * tmp;
665
+ dingodb::sdk::Client* tmp;
737
666
Status built = dingodb::sdk::Client::BuildFromAddrs (FLAGS_addrs, &tmp);
738
667
if (!built.ok ()) {
739
668
DINGO_LOG (ERROR) << " Fail to build client, please check parameter --addrs=" << FLAGS_addrs;
0 commit comments