|
|
@ -158,6 +158,7 @@ TEST(TestCreateiCreatei, Parallel) { |
|
|
|
//检查
|
|
|
|
findKeysByCityIndex(db, false); |
|
|
|
findKeysByAgeIndex(db, true); |
|
|
|
checkDataInKVAndIndex(db, "age"); |
|
|
|
|
|
|
|
delete db; |
|
|
|
} |
|
|
@ -181,14 +182,14 @@ TEST(TestPutDeleteOne, Parallel) { |
|
|
|
std::vector<std::thread> threads(thread_num_); |
|
|
|
for (size_t i = 0; i < thread_num_; i++) |
|
|
|
{ |
|
|
|
if (i % 2 == 0) {//2线程删除索引address
|
|
|
|
if (i % 2 == 0) { |
|
|
|
threads[i] = std::thread([db](){ |
|
|
|
for (size_t j = 0; j < 100; j++) |
|
|
|
{ |
|
|
|
InsertOneField(db, std::to_string(j)); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else {//1线程创建索引age
|
|
|
|
} else { |
|
|
|
threads[i] = std::thread([db](){ |
|
|
|
for (size_t j = 0; j < 100; j++) |
|
|
|
{ |
|
|
@ -257,7 +258,7 @@ TEST(TestWrite, Parallel) { |
|
|
|
age20Keys.clear(); |
|
|
|
db->CreateIndexOnField("address", op); |
|
|
|
InsertFieldData(db, 2); //先填点数据,让创建索引的时间久一点
|
|
|
|
int thread_num_ = 5; |
|
|
|
int thread_num_ = 4; |
|
|
|
std::vector<std::thread> threads(thread_num_); |
|
|
|
threads[0] = std::thread([db](){db->CreateIndexOnField("age", op);}); |
|
|
|
threads[1] = std::thread([db](){ |
|
|
@ -270,15 +271,15 @@ TEST(TestWrite, Parallel) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
WriteFieldData(db, 1);}); |
|
|
|
// threads[3] = std::thread([db](){
|
|
|
|
// while (db->GetIndexStatus("age") == NotExist){
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// DeleteFieldData(db, 0);});
|
|
|
|
threads[3] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
DeleteFieldData(db, 0);}); |
|
|
|
threads[4] = std::thread([db](){ |
|
|
|
while (db->GetIndexStatus("age") == NotExist){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
db->DeleteIndex("age", op);}); |
|
|
|
|
|
|
|
for (auto& t : threads) { |
|
|
@ -288,6 +289,10 @@ TEST(TestWrite, Parallel) { |
|
|
|
} |
|
|
|
|
|
|
|
//检查
|
|
|
|
//如果加入delete线程就不能保证下面被读到
|
|
|
|
GetFieldData(db, false, 0); |
|
|
|
GetFieldData(db, false, 1); |
|
|
|
GetFieldData(db, false, 2); |
|
|
|
checkDataInKVAndIndex(db); |
|
|
|
ASSERT_EQ(db->GetIndexStatus("age"), NotExist); //删除索引的请求应该被pend在创建之上
|
|
|
|
//删掉最后一个线程,可以测试创建age索引时并发的写入能不能保持age的一致性
|
|
|
|